Skip to content
Open
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 @@ -3,7 +3,7 @@
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="AssignmentPoolUnderTheAge" tableDbType="TABLE">
<tableTitle>Animals under the age of 3 with an assignment pool note</tableTitle>
<tableTitle>Animals under the age of 3 with an assignment pool flag</tableTitle>
</table>
</tables>
</metadata>
Expand Down
48 changes: 23 additions & 25 deletions onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
/* Added by Kollil, Jan 2026
Refer to tkt # 14056
- Extract animals under the age of 2.5 with an "Assignment pool" note in PRIMe (under general>notes)
*/
-- /* Added by Kollil, June 2026
-- Refer to tkt # 14056
-- Instead of a general > note, they now have a flag - Category: Assign Alias, Meaning: Assignment pool.
-- I think we could keep the grid the same, except replace the field "notes pertaining to DAR" with
-- the "Meaning" field from the active flags page. Although could we rename the column so it's called "Flag"?
-- */

SELECT
a.Id,
a.Id.demographics.gender AS Sex,
a.Id.Age.ageinyears,
a.Id.Age.ageinyears AS Age,
a.Id.curlocation.room AS Room,
a.Id.curlocation.cage AS Cage,
/* Display the (active) Notes Pertaining to DAR note text */
(
SELECT MAX(n.value)
FROM study.Notes n
WHERE n.Id = a.Id
AND n.category = 'Notes Pertaining to DAR'
AND n.endDate IS NULL
) AS Notes_Pertaining_to_DAR,
/* Concatenate all active cagemate IDs into one cell */
'Assignment Pool' AS Flag,

(
SELECT GROUP_CONCAT(DISTINCT CAST(h.roommateId AS VARCHAR), ', ')
FROM housingRoommatesDivider h
Expand All @@ -26,11 +21,12 @@ SELECT
AND h.roommateEnd IS NULL
AND h.roommateId IS NOT NULL
) AS Cagemates,
/* Concatenate all active projects & investigator into one cell */

(
SELECT GROUP_CONCAT(DISTINCT CAST('[' + d.project.protocol.investigatorId.lastname + ']' + d.project.displayname + '' AS VARCHAR), ', ')
SELECT GROUP_CONCAT(DISTINCT CAST(d.project.displayname AS VARCHAR), ', ')
FROM housingRoommatesDivider h
LEFT JOIN study.assignment d ON d.Id = h.roommateId
LEFT JOIN study.assignment d
ON d.Id = h.roommateId
WHERE h.Id = a.Id
AND h.removalDate IS NULL
AND h.roommateEnd IS NULL
Expand All @@ -40,17 +36,19 @@ SELECT
AND d.project.displayname NOT IN ('0492-02', '0492-03')
) AS Cagemate_Assignments

FROM Assignment a
FROM study.Assignment a
WHERE
a.Id.Age.ageinyears <= 3
a.enddate IS NULL
AND a.isActive = 1
AND a.Id.Age.ageinyears <= 3
AND a.project.displayname NOT IN ('0492-02', '0492-03')
AND a.Id.demographics.species = 'Rhesus Macaque'
AND EXISTS (
SELECT 1
FROM study.Notes n
WHERE n.Id = a.Id
AND n.value LIKE '%Assignment pool%'
AND n.endDate IS NULL
)

FROM study.flags f
WHERE f.Id = a.Id
AND f.flag.category = 'Assign Alias'
AND f.flag.value = 'Assignment Pool'
AND f.enddate IS NULL
)