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
@@ -0,0 +1,41 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="WeightMMA" tableDbType="NOT_IN_DB">
<tableTitle>DVM alert for new alopecia cases with a score of 4 or 5</tableTitle>
<columns>
<column columnName="Id">
<isHidden>false</isHidden>
<fk>
<fkDbSchema>study</fkDbSchema>
<fkTable>animal</fkTable>
<fkColumnName>id</fkColumnName>
</fk>
</column>
<column columnName="AlertObservationDate">
<isHidden>false</isHidden>
<columnTitle>Alert Observation Date</columnTitle>
</column>
<column columnName="AlopeciaScore">
<columnTitle>Alopecia Score</columnTitle>
</column>
<column columnName="performedby">
<columnTitle>Performed By</columnTitle>
</column>
<column columnName="enteredSincevetReview">
<columnTitle>Entered Since Last Vet Review?</columnTitle>
</column>
<column columnName="AssignedVet">
<columnTitle>Assigned Vet</columnTitle>
</column>
<column columnName="BehaviorCaseOpenDate">
<columnTitle>Behavior Case Open Date</columnTitle>
</column>
<column columnName="VetReviewDueDate">
<columnTitle>Vet Review Due Date</columnTitle>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
52 changes: 52 additions & 0 deletions onprc_ehr/resources/queries/study/DVMAlertforAlopeciaCases.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* 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 AlertObservationDate,
co.observation AS AlopeciaScore,
co.performedby,
co.enteredSincevetReview,
co.Id.assignedVet.AssignedVet AS AssignedVet,
c.BehaviorCaseOpenDate,
TIMESTAMPADD(SQL_TSI_DAY, 7, c.BehaviorCaseOpenDate) AS VetReviewDueDate
FROM study.clinical_observations co
INNER JOIN study.demographics d
ON d.Id = co.Id
INNER JOIN (
SELECT
x.Id,
MAX(x.date) AS BehaviorCaseOpenDate
FROM study.Cases x
WHERE x.category = 'Behavior'
AND x.allProblemCategories = 'Behavioral: Alopecia'
AND x.enddate IS NULL
GROUP BY x.Id
) c
ON c.Id = co.Id
WHERE co.category = 'Alopecia Score'
AND co.observation IN ('4', '5')
AND d.calculated_status = 'Alive'
AND NOT EXISTS (
SELECT 1
FROM study.clinical_observations prev
WHERE prev.Id = co.Id
AND prev.category = 'Alopecia Score'
AND prev.observation IN ('4', '5')
AND prev.date < co.date
AND prev.date >
COALESCE(
(
SELECT MAX(reset.date)
FROM study.clinical_observations reset
WHERE reset.Id = co.Id
AND reset.category = 'Alopecia Score'
AND reset.observation IN ('0', '1', '2', '3')
AND reset.date < co.date
),
'1900-01-01'
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,38 @@ public String getMessageBodyHTML(Container c, User u)
StringBuilder msg = new StringBuilder();

/* remarksWithoutAssignedVet(c, u, msg);*/
DVMAlopeciaAlert(c,u,msg); //Added by Kolli, March 2026
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();

if (total > 0)
{
msg.append("<b>ALERT: Animals with alopecia score of 4 or 5 with open behavioral case for alopecia in last 7 days:</b><p>");
msg.append("There are " + total + " entries found. ");
msg.append("<a href='" + getExecuteQueryUrl(c, "study", "DVMAlertforAlopeciaCases", null) + "'>Click here to view them</a>\n");
msg.append("<hr>\n\n");
}
else
{
msg.append("<b>WARNING: No animals found with alopecia score of 4 or 5 with open behavioral case for alopecia in last 7 days!</b><br><hr>\n");
}
}

public void vetRecordsUnderReview(Container c, User u, final StringBuilder msg)
{
int duration = 7;
Expand Down
Loading