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 4 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
11 changes: 8 additions & 3 deletions onprc_ehr/resources/queries/study/treatmentSchedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ SELECT
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
--COALESCE returns results for treatment orders without an enddate and with s.date in the future. This is needed for
--printable report Clinical Medications
ON (dr.dateOnly >= t1.dateOnly AND dr.dateOnly <= COALESCE(CAST(t1.enddate AS DATE), dr.dateOnly) AND
brentlogan marked this conversation as resolved.
Show resolved Hide resolved
--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 +117,8 @@ 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
)
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ 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
)