Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process treatment_orders with a NULL enddate #1197

Merged
merged 9 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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