From 93fb97fb2821abedf17e400a4accb253387833c1 Mon Sep 17 00:00:00 2001 From: kollil Date: Thu, 9 Jul 2026 09:06:59 -0700 Subject: [PATCH 1/4] Added email report to the alopecia score section. --- .../AlopeciaScoreMissingBehaviorCases.sql | 6 +- .../notification/BehaviorNotification.java | 65 ++++++++++++++++--- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql b/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql index 0096f2725..80d69dbb3 100644 --- a/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql +++ b/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql @@ -9,7 +9,11 @@ Added date comparison to check only dates and ignore time SELECT mr.Id, d.species, - d.gender, + CASE + WHEN LOWER(d.gender) = 'f' THEN 'Female' + WHEN LOWER(d.gender) = 'm' THEN 'Male' + ELSE d.gender + END AS gender, d.Id.age.ageinYearsRounded, d.Id.curLocation.area, d.Id.curLocation.room, 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 e2829e445..acbb31309 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java @@ -394,17 +394,62 @@ private void AlopeciaScoreAlert(final Container c, User u, final StringBuilder m TableInfo ti = getStudySchema(c, u).getTable("AlopeciaScoreMissingBehaviorCases"); TableSelector ts = new TableSelector(ti, null, null); - long total = ts.getRowCount(); - msg.append("Animals with alopecia score of 4 or 5, but does not have an open behavioral case for alopecia:

"); - if (total > 0) - { - msg.append( total + " entries found. "); - msg.append("Click here to view them\n"); - msg.append("


\n\n"); + long count = ts.getRowCount(); + + //Get num of rows + if (count > 0) { + msg.append("Animals with alopecia score of 4 or 5, but does not have an open behavioral case for alopecia:

"); + msg.append( count + " entries found. "); + msg.append("Click here to view them in a separate window\n"); + msg.append("\n\n"); + + //CHnages made byKolli, July 2026, Refer to tkt # 14974 + //Display the daily report in the email + Set columns = new HashSet<>(); + columns.add(FieldKey.fromString("Id")); + columns.add(FieldKey.fromString("species")); + columns.add(FieldKey.fromString("gender")); + columns.add(FieldKey.fromString("ageinYearsRounded")); + columns.add(FieldKey.fromString("area")); + columns.add(FieldKey.fromString("room")); + columns.add(FieldKey.fromString("cage")); + columns.add(FieldKey.fromString("MostRecentAlopeciaScore")); + columns.add(FieldKey.fromString("date")); + columns.add(FieldKey.fromString("performedby")); + + final Map colMap = QueryService.get().getColumns(ti, columns); + TableSelector ts2 = new TableSelector(ti, colMap.values(), null, new Sort("Id")); + + msg.append(""); + msg.append(""); + msg.append(""); + + ts2.forEach(object -> { + Results rs = new ResultsImpl(object, colMap); + String url = getParticipantURL(c, rs.getString("Id")); + + msg.append(""); + msg.append("\n"); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + java.sql.Date date = rs.getDate("date"); + msg.append(""); + msg.append(""); + msg.append(""); + }); + msg.append("
Id Species Sex Age(Years, Rounded) Area Room Cage Most Recent Alopecia Score Date Performed By
" + PageFlowUtil.filter(rs.getString("Id")) + " " + PageFlowUtil.filter(rs.getString("Species")) + "" + PageFlowUtil.filter(rs.getString("gender")) + "" + PageFlowUtil.filter(rs.getString("ageinYearsRounded")) + "" + PageFlowUtil.filter(rs.getString("area")) + "" + PageFlowUtil.filter(rs.getString("room")) + "" + PageFlowUtil.filter(rs.getString("cage")) + "" + PageFlowUtil.filter(rs.getString("MostRecentAlopeciaScore")) + "") + .append(PageFlowUtil.filter( + date == null ? "" : new java.text.SimpleDateFormat("MM/dd/yyyy").format(date) + )) + .append("" + PageFlowUtil.filter(rs.getString("performedby")) + "


"); } - else - { - msg.append("WARNING: No animals found with alopecia score of 4 or 5, but does not have an open behavioral case for alopecia!

\n"); + else { + msg.append("WARNING: No animals found with alopecia score of 4 or 5, there fore no open behavioral case(s) for alopecia!

\n"); } } From 44089919bfb1871daf3fad18737e45dc936fd2ac Mon Sep 17 00:00:00 2001 From: kollil Date: Thu, 9 Jul 2026 16:22:00 -0700 Subject: [PATCH 2/4] Updated the query --- .../AlopeciaScoreMissingBehaviorCases.sql | 7 ++-- .../notification/BehaviorNotification.java | 37 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql b/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql index 80d69dbb3..1e1698605 100644 --- a/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql +++ b/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql @@ -5,6 +5,9 @@ Show 1 year data. Modified by Kollil 09/15/2025 Added date comparison to check only dates and ignore time + +Modified by Kollil July 2026 +Showing only 1 week data, Refer to tkt # 14974 */ SELECT mr.Id, @@ -33,7 +36,7 @@ FROM ( WHERE co2.Id = co.Id AND co2.category = 'Alopecia Score' - AND co2.created >= TIMESTAMPADD(SQL_TSI_YEAR, -1, NOW()) + AND co2.created >= TIMESTAMPADD(SQL_TSI_DAY, -7, NOW()) ) ) AS mr INNER JOIN study.demographics AS d ON mr.Id = d.Id @@ -47,8 +50,6 @@ WHERE c.Id = mr.Id AND c.category = 'Behavior' AND c.allProblemCategories = 'Behavioral: Alopecia' --- AND c.date <= mr.date --- AND (c.enddate IS NULL OR c.enddate > mr.date) AND CAST(c.date AS DATE) <= CAST(mr.date AS DATE) AND (c.enddate IS NULL OR CAST(c.enddate AS DATE) >= CAST(mr.date AS DATE)) ) 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 acbb31309..aaed5fe1b 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/BehaviorNotification.java @@ -351,8 +351,7 @@ private void assignmentsReleasedInPast1Day(final Container c, User u, final Stri final Map colMap = QueryService.get().getColumns(ti, columns); TableSelector ts2 = new TableSelector(ti, colMap.values(), null, new Sort("Id")); -// msg.append("
Assignments with new \"Release date\" added within the last 24hrs:

\n"); - msg.append(""); + msg.append("
"); msg.append(""); msg.append(""); @@ -360,22 +359,22 @@ private void assignmentsReleasedInPast1Day(final Container c, User u, final Stri Results rs = new ResultsImpl(object, colMap); String url = getParticipantURL(c, rs.getString("Id")); - msg.append(""); - msg.append("\n"); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); - msg.append(""); + msg.append(""); + msg.append("\n"); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); msg.append(""); }); msg.append("
Id Sex Room Cage Project Protocol Title Project Investigator Assign Date Release Date Projected Release Date Assignment Type Assign Condition Projected Release Condition Condition At Release
" + PageFlowUtil.filter(rs.getString("Id")) + " " + PageFlowUtil.filter(rs.getString("Sex")) + "" + PageFlowUtil.filter(rs.getString("Room")) + "" + PageFlowUtil.filter(rs.getString("Cage")) + "" + PageFlowUtil.filter(rs.getString("project")) + "" + PageFlowUtil.filter(rs.getString("Protocol")) + "" + PageFlowUtil.filter(rs.getString("Title")) + "" + PageFlowUtil.filter(rs.getString("ProjectInvestigator")) + "" + PageFlowUtil.filter(rs.getString("AssignDate")) + "" + PageFlowUtil.filter(rs.getString("ReleaseDate")) + "" + PageFlowUtil.filter(rs.getString("ProjectedReleaseDate")) + "" + PageFlowUtil.filter(rs.getString("assignmentType")) + "" + PageFlowUtil.filter(rs.getString("assignCondition")) + "" + PageFlowUtil.filter(rs.getString("projectedReleaseCondition")) + "" + PageFlowUtil.filter(rs.getString("ConditionAtRelease")) + "
" + PageFlowUtil.filter(rs.getString("Id")) + " " + PageFlowUtil.filter(rs.getString("Sex")) + "" + PageFlowUtil.filter(rs.getString("Room")) + "" + PageFlowUtil.filter(rs.getString("Cage")) + "" + PageFlowUtil.filter(rs.getString("project")) + "" + PageFlowUtil.filter(rs.getString("Protocol")) + "" + PageFlowUtil.filter(rs.getString("Title")) + "" + PageFlowUtil.filter(rs.getString("ProjectInvestigator")) + "" + PageFlowUtil.filter(rs.getString("AssignDate")) + "" + PageFlowUtil.filter(rs.getString("ReleaseDate")) + "" + PageFlowUtil.filter(rs.getString("ProjectedReleaseDate")) + "" + PageFlowUtil.filter(rs.getString("assignmentType")) + "" + PageFlowUtil.filter(rs.getString("assignCondition")) + "" + PageFlowUtil.filter(rs.getString("projectedReleaseCondition")) + "" + PageFlowUtil.filter(rs.getString("ConditionAtRelease")) + "


"); @@ -403,7 +402,7 @@ private void AlopeciaScoreAlert(final Container c, User u, final StringBuilder m msg.append("Click here to view them in a separate window\n"); msg.append("\n\n"); - //CHnages made byKolli, July 2026, Refer to tkt # 14974 + //Changes made byKolli, July 2026, Refer to tkt # 14974 //Display the daily report in the email Set columns = new HashSet<>(); columns.add(FieldKey.fromString("Id")); From 1d09d98c5d01f44fbfe17ec138014dc937871dcd Mon Sep 17 00:00:00 2001 From: kollil Date: Thu, 9 Jul 2026 16:25:40 -0700 Subject: [PATCH 3/4] Updated the query #2 --- .../queries/study/AlopeciaScoreMissingBehaviorCases.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql b/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql index 1e1698605..621b78126 100644 --- a/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql +++ b/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql @@ -29,14 +29,14 @@ FROM ( FROM study.clinical_observations AS co WHERE co.category = 'Alopecia Score' - AND co.created >= TIMESTAMPADD(SQL_TSI_YEAR, -1, NOW()) + AND co.created >= TIMESTAMPADD(SQL_TSI_MONTH, -1, NOW()) AND co.created = ( SELECT MAX(co2.created) FROM study.clinical_observations AS co2 WHERE co2.Id = co.Id AND co2.category = 'Alopecia Score' - AND co2.created >= TIMESTAMPADD(SQL_TSI_DAY, -7, NOW()) + AND co2.created >= TIMESTAMPADD(SQL_TSI_MONTH, -1, NOW()) ) ) AS mr INNER JOIN study.demographics AS d ON mr.Id = d.Id From 4b01d10b4d9d900f540ae744e1069ae3c60f3736 Mon Sep 17 00:00:00 2001 From: kollil Date: Mon, 13 Jul 2026 10:26:09 -0700 Subject: [PATCH 4/4] Updated the query and the title --- .../study/AlopeciaScoreMissingBehaviorCases.query.xml | 10 ++++++++++ .../study/AlopeciaScoreMissingBehaviorCases.sql | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.query.xml diff --git a/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.query.xml b/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.query.xml new file mode 100644 index 000000000..a7f5d6805 --- /dev/null +++ b/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.query.xml @@ -0,0 +1,10 @@ + + + + + + Animals with alopecia score 4 or 5 with missing behavior cases +
+
+
+
diff --git a/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql b/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql index 621b78126..dc670937a 100644 --- a/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql +++ b/onprc_ehr/resources/queries/study/AlopeciaScoreMissingBehaviorCases.sql @@ -7,7 +7,7 @@ Modified by Kollil 09/15/2025 Added date comparison to check only dates and ignore time Modified by Kollil July 2026 -Showing only 1 week data, Refer to tkt # 14974 +Showing only 1 month data, Refer to tkt # 14974 */ SELECT mr.Id,