Skip to content

Commit 282da21

Browse files
committed
Adjust date range such that all the sessions from the past are included
1 parent e00291c commit 282da21

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

app/lib/patient_merger.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,47 @@ def call
112112
academic_year: patient_location.academic_year,
113113
location_id: patient_location.location_id
114114
)
115+
patient_location_to_keep =
116+
patient_to_keep
117+
.patient_locations
118+
.where(
119+
academic_year: patient_location.academic_year,
120+
location_id: patient_location.location_id
121+
)
122+
.sole
123+
124+
begin_date_to_keep =
125+
if patient_location.date_range.begin &&
126+
patient_location_to_keep.date_range.begin
127+
[
128+
patient_location.date_range.begin,
129+
patient_location_to_keep.date_range.begin
130+
].min
131+
else
132+
patient_location_to_keep.date_range.begin
133+
end
134+
135+
end_date_to_keep =
136+
if patient_location.date_range.end == ::Float::INFINITY &&
137+
patient_location_to_keep.date_range.end != ::Float::INFINITY
138+
Date.current
139+
elsif patient_location.date_range.end &&
140+
patient_location_to_keep.date_range.end
141+
[
142+
patient_location.date_range.end,
143+
patient_location_to_keep.date_range.end
144+
].max
145+
else
146+
patient_location_to_keep.date_range.end
147+
end
148+
149+
date_range_to_keep = Range.new(begin_date_to_keep, end_date_to_keep)
150+
151+
patient_location_to_keep.update_column(
152+
:date_range,
153+
date_range_to_keep
154+
)
155+
115156
next
116157
end
117158
patient_location.update_column(:patient_id, patient_to_keep.id)

0 commit comments

Comments
 (0)