diff --git a/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.query.xml b/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.query.xml index 2d839c69e..584c6110f 100644 --- a/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.query.xml +++ b/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.query.xml @@ -3,7 +3,7 @@ - Animals under the age of 3 with an assignment pool note + Animals under the age of 3 with an assignment pool flag
diff --git a/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.sql b/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.sql index da5ff511a..6094ceff9 100644 --- a/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.sql +++ b/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.sql @@ -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 @@ -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 @@ -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 +)