Skip to content
Open
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
17 changes: 12 additions & 5 deletions nirc_ehr/resources/queries/study/demographicsCagemates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ SELECT
FROM study.housing h

JOIN study.housing h2
ON (h2.Id.demographics.calculated_status = 'Alive'
AND (h.cage = h2.cage))
ON (h.cage = h2.cage
AND h2.Id.demographics.calculated_status = 'Alive'
AND h2.Id.demographics.qcstate.publicdata = true
AND h2.enddateTimeCoalesced >= now()
AND h2.qcstate.publicdata = true)

WHERE h.enddateTimeCoalesced >= now()
GROUP BY h.id, h.room, h.cage
-- cage holds the ehr_lookups.cage location key, so a null means this row's location never resolved; such a row gets no cagemates rather than sharing one group with every other unresolved row
WHERE h.cage IS NOT NULL
AND h.enddateTimeCoalesced >= now()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a need to look at the startDate? for a housing record whose date is in the future satisfies it and is treated as current cage mates?

AND h.qcstate.publicdata = true
GROUP BY h.id, h.cage

) t ON (t.id = d.id)

WHERE d.calculated_status = 'Alive'
WHERE d.calculated_status = 'Alive'
AND d.qcstate.publicdata = true