Skip to content

Commit

Permalink
Process treatment_orders with a NULL enddate (#1197)
Browse files Browse the repository at this point in the history
* allow enddate to be NULL

* replace enddateCoalesced with alternate

* fix typo

* cast enddate as DATE

* Use parallel enddate IS NULL

Adopt Ben Bimber's suggestion to modify both enddate comparisons to the same solution and use the one that is transparent about the problem being solved.

* Reformat

* Accommodate NULL treatment-order enddates

* Remove added blank lines
  • Loading branch information
brentlogan authored Dec 26, 2024
1 parent 66cfb0d commit 36896af
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ FROM (
FROM ehr_lookups.dateRange dr

Join study."Treatment Orders" t1
ON (dr.dateOnly >= t1.dateOnly and dr.dateOnly <= t1.enddateCoalesced AND
ON (dr.dateOnly >= t1.dateOnly AND (dr.dateOnly <= t1.enddate OR t1.enddate IS NULL) AND
mod(CAST(timestampdiff('SQL_TSI_DAY', CAST(t1.dateOnly as timestamp), dr.dateOnly) as integer), t1.frequency.intervalindays) = 0
)

Expand Down Expand Up @@ -93,7 +93,7 @@ WHERE t1.date is not null
) s ON (s.animalid = h.id)
WHERE h.calculated_status = 'Alive'
--account for date/time in schedule
and s.date >= s.startDate and s.date <= s.enddate
AND s.date >= s.startDate AND (s.date <= s.enddate OR s.enddate IS NULL)


-- /*
Expand Down
4 changes: 2 additions & 2 deletions onprc_ehr/resources/queries/study/treatmentSchedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ FROM ehr_lookups.dateRange dr

JOIN study."Treatment Orders" t1
--NOTE: should the enddate consider date/time?
ON (dr.dateOnly >= t1.dateOnly and dr.dateOnly <= t1.enddateCoalesced AND
ON (dr.dateOnly >= t1.dateOnly AND (dr.dateOnly <= t1.enddate OR t1.enddate IS NULL) AND
--technically the first day of the treatment is day 1, not day 0
( (mod(CAST(timestampdiff('SQL_TSI_DAY', CAST(t1.dateOnly as timestamp), dr.dateOnly) as integer), t1.frequency.intervalindays) = 0 And t1.frequency.intervalindays is not null And t1.frequency.dayofweek is null )

Expand Down Expand Up @@ -116,4 +116,4 @@ WHERE (d.lastDayatCenter Is Null or d.lastDayAtCenter > s.enddate)


--account for date/time in schedule
and s.date >= s.startDate and s.date <= s.enddate
AND s.date >= s.startDate AND (s.date <= s.enddate OR s.enddate IS NULL) -- some treatment_orders can have NULL enddates
4 changes: 2 additions & 2 deletions onprc_ehr/resources/queries/study/treatmentScheduleMPA.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ FROM study.demographics h JOIN (
FROM ehr_lookups.dateRange dr

Join study."Treatment Orders" t1
ON (dr.dateOnly >= t1.dateOnly and dr.dateOnly <= t1.enddateCoalesced AND
ON (dr.dateOnly >= t1.dateOnly AND (dr.dateOnly <= t1.enddate OR t1.enddate IS NULL) AND
mod(CAST(timestampdiff('SQL_TSI_DAY', CAST(t1.dateOnly as timestamp), dr.dateOnly) as integer), t1.frequency.intervalindays) = 0
)

Expand Down Expand Up @@ -92,4 +92,4 @@ WHERE h.calculated_status = 'Alive'
--account for date/time in schedule
--and s.date >= s.startDate and s.date <= s.enddate
--Added the enddate = null clause by Kollil, 10/25/24. Refer to ticket #11471
and s.date >= s.startDate and (s.date <= s.enddate or s.enddate is null)
AND s.date >= s.startDate AND (s.date <= s.enddate OR s.enddate is null)
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ FROM dateRangedata dr

JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.study."Treatment Orders" t1
--NOTE: should the enddate consider date/time?
ON (dr.dateOnly >= t1.dateOnly and dr.dateOnly <= t1.enddateCoalesced AND
ON (dr.dateOnly >= t1.dateOnly AND (dr.dateOnly <= t1.enddate OR t1.enddate IS NULL) AND
--technically the first day of the treatment is day 1, not day 0
mod(CAST(timestampdiff('SQL_TSI_DAY', CAST(t1.dateOnly as timestamp), dr.dateOnly) as integer), t1.frequency.intervalindays) = 0
OR (t1.frequency.dayofweek is not null And t1.frequency.intervalindays is null And dr.DayOfWeek in (select k.value from onprc_ehr.Frequency_DayofWeek k where k.FreqKey = t1.frequency.rowid ))
Expand Down Expand Up @@ -115,4 +115,4 @@ WHERE --d.calculated_status = 'Alive'

--account for date/time in schedule
--and
s.date >= s.startDate and s.date <= s.enddate
s.date >= s.startDate AND (s.date <= s.enddate OR s.enddate IS NULL) -- some treatment_orders can have NULL enddates

0 comments on commit 36896af

Please sign in to comment.