From bedf65bdee73a1b9d59e031f4f15d8baf0284252 Mon Sep 17 00:00:00 2001 From: kollil Date: Tue, 27 Jan 2026 17:31:37 -0800 Subject: [PATCH 1/2] Adding new grid to BSU assignment dashboard and in the alert email. --- .../study/AssignmentsUnderTheAge.query.xml | 10 +++++ .../queries/study/AssignmentsUnderTheAge.sql | 44 +++++++++++++++++++ .../notification/BehaviorNotification.java | 29 ++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.query.xml create mode 100644 onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.sql diff --git a/onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.query.xml b/onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.query.xml new file mode 100644 index 000000000..62259a6b4 --- /dev/null +++ b/onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.query.xml @@ -0,0 +1,10 @@ + + + + + + Animals under the age of 2.5 with an active assignment +
+
+
+
diff --git a/onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.sql b/onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.sql new file mode 100644 index 000000000..def00c004 --- /dev/null +++ b/onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.sql @@ -0,0 +1,44 @@ +SELECT + Id, + Id.demographics.gender as Sex, + Id.Age.ageinyears, + Id.curlocation.room as Room, + Id.curlocation.cage as Cage, + project.displayname as project, + project.protocol.displayname as Protocol, + project.title as Title, + project.protocol.investigatorId.lastname as ProjectInvestigator, + CAST(date AS DATE) AS AssignDate, + CAST(enddate AS DATE) AS ReleaseDate, + CAST(projectedRelease AS DATE) AS ProjectedReleaseDate, + assignmentType, + assignCondition.meaning as AssignCondition, + projectedReleaseCondition.meaning as ProjectedReleaseCondition, + releaseCondition.meaning as ConditionAtRelease, + /* Display the (active) Assignment pool note text */ + ( + SELECT MAX(n.value) + FROM study.Notes n + WHERE n.Id = Assignment.Id + AND n.value LIKE '%Assignment pool%' + AND n.endDate IS NULL + ) AS BSU_Notes +FROM Assignment +WHERE Id.Age.ageinyears <= 2.5 + AND enddate IS NULL + AND + ( + ( + /* Active assignment, excluding U42/U42E colony maintenance center projects */ + project.displayname NOT IN ('0492-02', '0492-03') + ) + OR + /* Has "Assignment pool" note in study.Notes */ + EXISTS ( + SELECT 1 + FROM study.Notes n + WHERE n.Id = Assignment.Id + AND n.value LIKE '%Assignment pool%' + AND n.endDate IS NULL --active + ) + ) \ No newline at end of file diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java index 958d70a3f..307f82544 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java @@ -122,12 +122,41 @@ public String getMessageBodyHTML(Container c, User u) assignmentsStartingNext1to14Days(c,u,msg); assignmentsStartedPast1to7Days(c,u,msg); + //Added by Kollil, Jan 2026 + //Refer to tkt # 14056 + assignmentsUnderTheAge(c,u,msg); + notesEndingToday(c, u, msg, Arrays.asList("BSU Notes"), null); saveValues(c, toSave); return msg.toString(); } + /* Added by Kollil, Jan 2026 + Refer to tkt # 14056 + The grid should include: + - Animals under the age of 2.5 with an active assignment. Exclude the U42 and U42E colony maintenance assignments, I believe the center projects for these are 0492-02 and 0492-03. + - Animals under the age of 2.5 with an "Assignment pool" note in PRIMe (under general>notes) + */ + private void assignmentsUnderTheAge(final Container c, User u, final StringBuilder msg) + { + TableInfo ti = getStudySchema(c, u).getTable("AssignmentsUnderTheAge"); + + TableSelector ts = new TableSelector(ti, null, new Sort("Id")); + long total = ts.getRowCount(); + + if (total > 0) + { + msg.append("Animals under the age of 2.5 with an active assignment excluding the U42 and U42E assignments, and animals with an \"Assignment pool\" notes:

"); + msg.append( total + " entries found. "); + msg.append("Click here to view them\n"); + msg.append("


\n\n"); + } + else { + msg.append("WARNING: No animals under the age of 2.5 with an active assignment, and with an \"Assignment pool\" notes!

\n"); + } + } + /* Added by Kollil Nov, 2025 Priority 4: Add links to grids 3 and 4 in daily Behavior Alerts email (do not need to display full grid in email) - for grid 3 - "There are __ assignments starting in the Next 1-14 days" with a link From 2b92175bdede11f1c67ed4c67718e9d975397e82 Mon Sep 17 00:00:00 2001 From: kollil Date: Wed, 28 Jan 2026 20:21:00 -0800 Subject: [PATCH 2/2] Updated queries --- .../study/AssignmentPoolUnderTheAge.query.xml | 10 +++ .../study/AssignmentPoolUnderTheAge.sql | 49 +++++++++++++ .../queries/study/AssignmentsUnderTheAge.sql | 73 ++++++++----------- .../notification/BehaviorNotification.java | 24 +++++- 4 files changed, 111 insertions(+), 45 deletions(-) create mode 100644 onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.query.xml create mode 100644 onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.sql diff --git a/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.query.xml b/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.query.xml new file mode 100644 index 000000000..ee363ecd0 --- /dev/null +++ b/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.query.xml @@ -0,0 +1,10 @@ + + + + + + Animals under the age of 2.5 with an assignment pool note +
+
+
+
diff --git a/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.sql b/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.sql new file mode 100644 index 000000000..48765931d --- /dev/null +++ b/onprc_ehr/resources/queries/study/AssignmentPoolUnderTheAge.sql @@ -0,0 +1,49 @@ +SELECT + a.Id, + a.Id.demographics.gender AS Sex, + a.Id.Age.ageinyears, + a.Id.curlocation.room AS Room, + a.Id.curlocation.cage AS Cage, + a.project.displayname AS project, + a.project.protocol.displayname AS Protocol, + a.project.title AS Title, + a.project.protocol.investigatorId.lastname AS ProjectInvestigator, + CAST(a.date AS DATE) AS AssignDate, + CAST(a.enddate AS DATE) AS ReleaseDate, + CAST(a.projectedRelease AS DATE) AS ProjectedReleaseDate, + a.assignmentType, + a.projectedReleaseCondition.meaning AS ProjectedReleaseCondition, + a.releaseCondition.meaning AS ConditionAtRelease, + + /* 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, + + h.roommateId AS Cagemate, + d.use AS Cagemate_Assignment + +FROM Assignment a + LEFT JOIN housingRoommatesDivider h + ON h.Id = a.Id + AND h.removalDate IS NULL + AND h.roommateEnd IS NULL + LEFT JOIN study.demographicsUtilization d + ON d.Id = h.roommateId +WHERE + a.Id.Age.ageinyears <= 2.5 + 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 + ) + + diff --git a/onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.sql b/onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.sql index def00c004..441ddd847 100644 --- a/onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.sql +++ b/onprc_ehr/resources/queries/study/AssignmentsUnderTheAge.sql @@ -1,44 +1,31 @@ SELECT - Id, - Id.demographics.gender as Sex, - Id.Age.ageinyears, - Id.curlocation.room as Room, - Id.curlocation.cage as Cage, - project.displayname as project, - project.protocol.displayname as Protocol, - project.title as Title, - project.protocol.investigatorId.lastname as ProjectInvestigator, - CAST(date AS DATE) AS AssignDate, - CAST(enddate AS DATE) AS ReleaseDate, - CAST(projectedRelease AS DATE) AS ProjectedReleaseDate, - assignmentType, - assignCondition.meaning as AssignCondition, - projectedReleaseCondition.meaning as ProjectedReleaseCondition, - releaseCondition.meaning as ConditionAtRelease, - /* Display the (active) Assignment pool note text */ - ( - SELECT MAX(n.value) - FROM study.Notes n - WHERE n.Id = Assignment.Id - AND n.value LIKE '%Assignment pool%' - AND n.endDate IS NULL - ) AS BSU_Notes -FROM Assignment -WHERE Id.Age.ageinyears <= 2.5 - AND enddate IS NULL - AND - ( - ( - /* Active assignment, excluding U42/U42E colony maintenance center projects */ - project.displayname NOT IN ('0492-02', '0492-03') - ) - OR - /* Has "Assignment pool" note in study.Notes */ - EXISTS ( - SELECT 1 - FROM study.Notes n - WHERE n.Id = Assignment.Id - AND n.value LIKE '%Assignment pool%' - AND n.endDate IS NULL --active - ) - ) \ No newline at end of file + a.Id, + a.Id.demographics.gender AS Sex, + a.Id.Age.ageinyears, + a.Id.curlocation.room AS Room, + a.Id.curlocation.cage AS Cage, + a.project.displayname AS project, + a.project.protocol.displayname AS Protocol, + a.project.title AS Title, + a.project.protocol.investigatorId.lastname AS ProjectInvestigator, + CAST(a.date AS DATE) AS AssignDate, + CAST(a.enddate AS DATE) AS ReleaseDate, + CAST(a.projectedRelease AS DATE) AS ProjectedReleaseDate, + a.assignmentType, + a.projectedReleaseCondition.meaning AS ProjectedReleaseCondition, + a.releaseCondition.meaning AS ConditionAtRelease, + h.roommateId AS Cagemate, + d.use AS Cagemate_Assignment +FROM Assignment a + LEFT JOIN housingRoommatesDivider h + ON h.Id = a.Id + AND h.removalDate IS NULL + AND h.roommateEnd IS NULL + LEFT JOIN study.demographicsUtilization d + ON d.Id = h.roommateId +WHERE + a.Id.Age.ageinyears <= 2.5 + AND a.Id.demographics.species = 'Rhesus Macaque' + AND a.enddate IS NULL + AND a.isActive = 1 + AND a.project.displayname NOT IN ('0492-02', '0492-03') diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java index 307f82544..f2e8e57f5 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java @@ -124,7 +124,8 @@ public String getMessageBodyHTML(Container c, User u) //Added by Kollil, Jan 2026 //Refer to tkt # 14056 - assignmentsUnderTheAge(c,u,msg); + activeAssignmentsUnderTheAge(c,u,msg); + assignmentPoolUnderTheAge(c,u,msg); notesEndingToday(c, u, msg, Arrays.asList("BSU Notes"), null); saveValues(c, toSave); @@ -138,7 +139,7 @@ public String getMessageBodyHTML(Container c, User u) - Animals under the age of 2.5 with an active assignment. Exclude the U42 and U42E colony maintenance assignments, I believe the center projects for these are 0492-02 and 0492-03. - Animals under the age of 2.5 with an "Assignment pool" note in PRIMe (under general>notes) */ - private void assignmentsUnderTheAge(final Container c, User u, final StringBuilder msg) + private void activeAssignmentsUnderTheAge(final Container c, User u, final StringBuilder msg) { TableInfo ti = getStudySchema(c, u).getTable("AssignmentsUnderTheAge"); @@ -157,6 +158,25 @@ private void assignmentsUnderTheAge(final Container c, User u, final StringBuild } } + private void assignmentPoolUnderTheAge(final Container c, User u, final StringBuilder msg) + { + TableInfo ti = getStudySchema(c, u).getTable("AssignmentPoolUnderTheAge"); + + TableSelector ts = new TableSelector(ti, null, new Sort("Id")); + long total = ts.getRowCount(); + + if (total > 0) + { + msg.append("Animals under the age of 2.5 with \"Assignment pool\" notes:

"); + msg.append( total + " entries found. "); + msg.append("Click here to view them\n"); + msg.append("


\n\n"); + } + else { + msg.append("WARNING: No animals under the age of 2.5 with an \"Assignment pool\" notes!

\n"); + } + } + /* Added by Kollil Nov, 2025 Priority 4: Add links to grids 3 and 4 in daily Behavior Alerts email (do not need to display full grid in email) - for grid 3 - "There are __ assignments starting in the Next 1-14 days" with a link