Skip to content

Commit e104040

Browse files
authored
Parentage dam mismatch in Colony alert (#1643)
* Added a new report in the Colony alert: Parentage Dam mismatch records * Fixed a few comments and typos
1 parent 65b720a commit e104040

4 files changed

Lines changed: 138 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<query xmlns="http://labkey.org/data/xml/query">
2+
<metadata>
3+
<tables xmlns="http://labkey.org/data/xml">
4+
<table tableName="ParentageDamMismatch" tableDbType="TABLE">
5+
<tableTitle>Mismatched Genetic and Observed Dams</tableTitle>
6+
</table>
7+
</tables>
8+
</metadata>
9+
</query>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Added by Kolli, Feb 2026
3+
Refer tkt# 14114 for details
4+
Display 4 columns: Animal Id, Area, Genetic dam, Observed dam
5+
6+
Get genetic and observed dam mismatch data.
7+
Use the following criteria,
8+
* 1. One genetic dam per animal
9+
* 2. Included Alive + Dead animals
10+
* 3. Excludes animals that have a foster dam
11+
* 4. Excludes rows where observedDam or geneticDam IS BLANK
12+
* 5. Keeps only mismatches between observed and genetic dams
13+
* 6. Excludes old parentage entries, enddate IS BLANK
14+
*/
15+
16+
SELECT
17+
d.Id,
18+
d.Id.curLocation.area AS Area,
19+
coalesce(p2.parent, '') as geneticDam,
20+
coalesce(b.dam, '') as observedDam
21+
FROM study.demographics d
22+
23+
LEFT JOIN (
24+
SELECT
25+
p2.Id,
26+
MAX(p2.parent) AS parent
27+
FROM study.parentage p2
28+
WHERE (p2.method = 'Genetic' OR p2.method = 'Provisional Genetic')
29+
AND p2.relationship = 'Dam'
30+
AND p2.enddate IS NULL
31+
GROUP BY p2.Id
32+
) p2 ON d.Id = p2.Id
33+
34+
LEFT JOIN (
35+
SELECT
36+
p3.Id,
37+
MAX(p3.parent) AS parent
38+
FROM study.parentage p3
39+
WHERE p3.relationship = 'Foster Dam'
40+
AND p3.enddate IS NULL
41+
GROUP BY p3.Id
42+
) p3 ON d.Id = p3.Id
43+
44+
LEFT JOIN study.birth b
45+
ON b.Id = d.Id
46+
47+
WHERE d.calculated_status.code IN ('Alive', 'Dead') AND d.qcstate = 18
48+
/* exclude foster-dam cases (NULL or blank only) */
49+
AND COALESCE(RTRIM(LTRIM(CAST(p3.parent AS VARCHAR(50)))), '') = ''
50+
51+
/* exclude blank observed dam */
52+
AND COALESCE(RTRIM(LTRIM(CAST(b.dam AS VARCHAR(50)))), '') <> ''
53+
54+
/* exclude blank genetic dam */
55+
AND COALESCE(RTRIM(LTRIM(CAST(p2.parent AS VARCHAR(50)))), '') <> ''
56+
57+
/* mismatch observed vs genetic */
58+
AND COALESCE(RTRIM(LTRIM(CAST(b.dam AS VARCHAR(50)))), '') <>
59+
COALESCE(RTRIM(LTRIM(CAST(p2.parent AS VARCHAR(50)))), '')
60+
61+

onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyAlertsNotification.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,70 @@ protected void roomsReportingNegativeCagesAvailable(final Container c, User u, f
312312
}
313313
}
314314

315+
/**
316+
* Kollil, Jan, 2026 :
317+
* Refer tkt# 14114 for more details
318+
* Alert title: WARNING: There are [x total] mismatches of observed and genetic dam data requiring review
319+
* Format: Table
320+
* 4 columns: Animal Id, Area, Genetic dam, Observed dam
321+
* Alert criteria:
322+
* 1. One genetic dam per animal
323+
* 2. Included Alive + Dead animals
324+
* 3. Excludes animals that have a foster dam
325+
* 4. Excludes rows where observedDam or geneticDam IS BLANK
326+
* 5. Keeps only mismatches between observed and genetic dams
327+
* 6. Excludes old parentage entries, enddate IS BLANK
328+
*/
329+
protected void mismatchedObservedAndGeneticDam(final Container c, User u, final StringBuilder msg)
330+
{
331+
if (QueryService.get().getUserSchema(u, c, "study") == null) {
332+
msg.append("<b>Warning: The study schema has not been enabled in this folder, so the alert cannot run.<p><hr>");
333+
return;
334+
}
335+
336+
//Dam mismatch query
337+
TableInfo ti = QueryService.get().getUserSchema(u, c, "study").getTable("ParentageDamMismatch", ContainerFilter.Type.AllFolders.create(c, u));
338+
TableSelector ts = new TableSelector(ti, null, null);
339+
long count = ts.getRowCount();
340+
341+
//Get num of rows
342+
if (count > 0) {
343+
msg.append("<b> WARNING: There are " + count + " mismatches of observed and genetic dam data requiring review.</b>");
344+
msg.append("<a href='" + getExecuteQueryUrl(c, "study", "ParentageDamMismatch", null) + "&query.containerFilterName=AllFolders'> Click here to view them in a grid</a>\n");
345+
346+
//Display the report in the email
347+
Set<FieldKey> columns = new HashSet<>();
348+
columns.add(FieldKey.fromString("Id"));
349+
columns.add(FieldKey.fromString("area"));
350+
columns.add(FieldKey.fromString("geneticdam"));
351+
columns.add(FieldKey.fromString("observeddam"));
352+
353+
final Map<FieldKey, ColumnInfo> colMap = QueryService.get().getColumns(ti, columns);
354+
TableSelector ts2 = new TableSelector(ti, colMap.values(), null, null);
355+
356+
msg.append("<br><br>\n");
357+
msg.append("<table border=1 style='border-collapse: collapse;'>");
358+
msg.append("<tr bgcolor = " + '"' + "#FFFACD" + '"' + "style='font-weight: bold;'>");
359+
msg.append("<td>Id </td><td>Area </td><td>Genetic Dam </td><td>Observed Dam </td></tr>");
360+
361+
ts2.forEach(object -> {
362+
Results rs = new ResultsImpl(object, colMap);
363+
String url = getParticipantURL(c, rs.getString("Id"));
364+
msg.append("<tr><td><b> <a href='" + url + "'>" + PageFlowUtil.filter(rs.getString("Id")) + "</a> </b></td>\n");
365+
msg.append("<td>" + PageFlowUtil.filter(rs.getString("area")) + "</td>");
366+
msg.append("<td>" + PageFlowUtil.filter(rs.getString("geneticdam")) + "</td>");
367+
msg.append("<td>" + PageFlowUtil.filter(rs.getString("observeddam")) + "</td>");
368+
msg.append("</tr>");
369+
});
370+
}
371+
else {
372+
msg.append("<b> There are NO mismatches of observed and genetic dam data. </b>");
373+
}
374+
msg.append("</table>");
375+
msg.append("<hr>\n");
376+
}
377+
//End of Dam mismatch report
378+
315379
/**
316380
* Finds all rooms with animals of mixed viral status
317381
* Modified by Kollil, 2/17/2023

onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyMgmtNotification.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public String getMessageBodyHTML(Container c, User u)
7474
doHousingChecks(c, u, msg);
7575
transfersYesterday(c, u, msg);
7676
roomsWithMixedViralStatus(c, u, msg);
77+
/*Added by kollil, Jan, 2026
78+
Refer to tkt # 14114
79+
*/
80+
mismatchedObservedAndGeneticDam(c, u, msg);
7781
livingAnimalsWithoutWeight(c, u, msg);
7882
hospitalAnimalsWithoutCase(c, u, msg);
7983

0 commit comments

Comments
 (0)