diff --git a/onprc_ehr/resources/queries/study/DVMAlertforAlopeciaCases.sql b/onprc_ehr/resources/queries/study/DVMAlertforAlopeciaCases.sql new file mode 100644 index 000000000..e266815ef --- /dev/null +++ b/onprc_ehr/resources/queries/study/DVMAlertforAlopeciaCases.sql @@ -0,0 +1,34 @@ +/* Added by Kollil 09/22/2025 +When BSU creates a case AND scores the alopecia at either 4 or 5 (only those scores) THEN the vet assigned to that animal should receive an alert. +Show open cases in last 7 days +Refer to tkt # 12523 +*/ +SELECT + co.Id, + co.date AS MostRecentDate, + co.observation AS MostRecentAlopeciaScore, + co.performedby, + co.enteredSincevetReview, + co.Id.assignedVet.AssignedVet as AssignedVet, + c.date as BehaviorCaseOpenDate +FROM study.clinical_observations AS co + INNER JOIN study.demographics AS d + ON co.Id = d.Id + INNER JOIN study.Cases AS c + ON c.Id = co.Id + AND c.category = 'Behavior' + AND c.allProblemCategories = 'Behavioral: Alopecia' + AND c.enddate IS NULL +WHERE + co.category = 'Alopecia Score' + AND co.observation IN ('4', '5') + --AND co.date >= '2025-01-01' + AND d.calculated_status = 'Alive' + AND co.date = ( + SELECT MAX(co2.date) + FROM study.clinical_observations AS co2 + WHERE co2.Id = co.Id + AND co2.category = 'Alopecia Score' + AND co2.observation IN ('4', '5') +) + AND c.date >= TIMESTAMPADD(SQL_TSI_DAY, -7, now()) \ No newline at end of file diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/VetReviewNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/VetReviewNotification.java index 9008df054..ff3d3b5d1 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/notification/VetReviewNotification.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/VetReviewNotification.java @@ -86,12 +86,37 @@ public String getMessageBodyHTML(Container c, User u) StringBuilder msg = new StringBuilder(); /* remarksWithoutAssignedVet(c, u, msg);*/ + DVMAlopeciaAlert(c,u,msg); vetRecordsUnderReview(c, u, msg); animalsWithoutAssignedVet(c, u, msg); return msg.toString(); } + /* Added by Kollil 09/22/2025 + When BSU creates a case AND scores the alopecia at either 4 or 5 (only those scores) THEN the vet assigned to that animal should receive an alert. Show open cases in last 7 days + Refer to tkt # 12523 + */ + private void DVMAlopeciaAlert(final Container c, User u, final StringBuilder msg) + { + TableInfo ti = getStudySchema(c, u).getTable("DVMAlertforAlopeciaCases"); + + TableSelector ts = new TableSelector(ti, null, null); + long total = ts.getRowCount(); +// msg.append("ALERT: Animals with alopecia score of 4 or 5 with open behavioral case for alopecia in last 7 days:

"); + if (total > 0) + { + msg.append("ALERT: Animals with alopecia score of 4 or 5 with open behavioral case for alopecia in last 7 days:

"); + msg.append("There are " + total + " entries found. "); + msg.append("

Click here to view them

\n"); + msg.append("
\n\n"); + } + else + { + msg.append("WARNING: No animals found with alopecia score of 4 or 5 with open behavioral case for alopecia in last 7 days!

\n"); + } + } + public void vetRecordsUnderReview(Container c, User u, final StringBuilder msg) { int duration = 7;