Skip to content

Commit

Permalink
Accommodate NULL treatment-order enddates
Browse files Browse the repository at this point in the history
  • Loading branch information
brentlogan committed Dec 14, 2024
1 parent 8923636 commit 54be93a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 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/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,8 +115,5 @@ WHERE --d.calculated_status = 'Alive'

--account for date/time in schedule
--and
s.date >= s.startDate
AND (
s.date <= s.enddate
OR s.enddate IS NULL -- some treatment_orders can have NULL enddates
)
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 54be93a

Please sign in to comment.