diff --git a/onprc_ehr/resources/queries/study/TreatmentSchedulePostOps.sql b/onprc_ehr/resources/queries/study/TreatmentSchedulePostOps.sql index ece5f0b8e..dd7919804 100644 --- a/onprc_ehr/resources/queries/study/TreatmentSchedulePostOps.sql +++ b/onprc_ehr/resources/queries/study/TreatmentSchedulePostOps.sql @@ -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 ) @@ -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) -- /* diff --git a/onprc_ehr/resources/queries/study/treatmentSchedule.sql b/onprc_ehr/resources/queries/study/treatmentSchedule.sql index 6a0e2e993..2fc4bc5bd 100644 --- a/onprc_ehr/resources/queries/study/treatmentSchedule.sql +++ b/onprc_ehr/resources/queries/study/treatmentSchedule.sql @@ -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 ) @@ -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 \ No newline at end of file + AND s.date >= s.startDate AND (s.date <= s.enddate OR s.enddate IS NULL) -- some treatment_orders can have NULL enddates diff --git a/onprc_ehr/resources/queries/study/treatmentScheduleMPA.sql b/onprc_ehr/resources/queries/study/treatmentScheduleMPA.sql index 56a16d278..2d513e4bb 100644 --- a/onprc_ehr/resources/queries/study/treatmentScheduleMPA.sql +++ b/onprc_ehr/resources/queries/study/treatmentScheduleMPA.sql @@ -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 ) @@ -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) diff --git a/treatmentETL/resources/queries/study/treatmentScheduleUpdate.sql b/treatmentETL/resources/queries/study/treatmentScheduleUpdate.sql index 4efde2469..c8e70c90a 100644 --- a/treatmentETL/resources/queries/study/treatmentScheduleUpdate.sql +++ b/treatmentETL/resources/queries/study/treatmentScheduleUpdate.sql @@ -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 )) @@ -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