Skip to content
Merged
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,9 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="ParentageDamMismatch" tableDbType="TABLE">
<tableTitle>Mismatched Genetic and Observed Dams</tableTitle>
</table>
</tables>
</metadata>
</query>
61 changes: 61 additions & 0 deletions onprc_ehr/resources/queries/study/ParentageDamMismatch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Added by Kolli, Feb 2026
Refer tkt# 14114 for details
Display 4 columns: Animal Id, Area, Genetic dam, Observed dam

Get genetic and observed dam mismatch data.
Use the following criteria,
* 1. One genetic dam per animal
* 2. Included Alive + Dead animals
* 3. Excludes animals that have a foster dam
* 4. Excludes rows where observedDam or geneticDam IS BLANK
* 5. Keeps only mismatches between observed and genetic dams
* 6. Excludes old parentage entries, enddate IS BLANK
*/

SELECT
d.Id,
d.Id.curLocation.area AS Area,
coalesce(p2.parent, '') as geneticDam,
coalesce(b.dam, '') as observedDam
FROM study.demographics d

LEFT JOIN (
SELECT
p2.Id,
MAX(p2.parent) AS parent
FROM study.parentage p2
WHERE (p2.method = 'Genetic' OR p2.method = 'Provisional Genetic')
AND p2.relationship = 'Dam'
AND p2.enddate IS NULL
GROUP BY p2.Id
) p2 ON d.Id = p2.Id

LEFT JOIN (
SELECT
p3.Id,
MAX(p3.parent) AS parent
FROM study.parentage p3
WHERE p3.relationship = 'Foster Dam'
AND p3.enddate IS NULL
GROUP BY p3.Id
) p3 ON d.Id = p3.Id

LEFT JOIN study.birth b
ON b.Id = d.Id

WHERE d.calculated_status.code IN ('Alive', 'Dead') AND d.qcstate = 18
/* exclude foster-dam cases (NULL or blank only) */
AND COALESCE(RTRIM(LTRIM(CAST(p3.parent AS VARCHAR(50)))), '') = ''

/* exclude blank observed dam */
AND COALESCE(RTRIM(LTRIM(CAST(b.dam AS VARCHAR(50)))), '') <> ''

/* exclude blank genetic dam */
AND COALESCE(RTRIM(LTRIM(CAST(p2.parent AS VARCHAR(50)))), '') <> ''

/* mismatch observed vs genetic */
AND COALESCE(RTRIM(LTRIM(CAST(b.dam AS VARCHAR(50)))), '') <>
COALESCE(RTRIM(LTRIM(CAST(p2.parent AS VARCHAR(50)))), '')


Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,70 @@ protected void roomsReportingNegativeCagesAvailable(final Container c, User u, f
}
}

/**
* Kollil, Jan, 2026 :
* Refer tkt# 14114 for more details
* Alert title: WARNING: There are [x total] mismatches of observed and genetic dam data requiring review
* Format: Table
* 4 columns: Animal Id, Area, Genetic dam, Observed dam
* Alert criteria:
* 1. One genetic dam per animal
* 2. Included Alive + Dead animals
* 3. Excludes animals that have a foster dam
* 4. Excludes rows where observedDam or geneticDam IS BLANK
* 5. Keeps only mismatches between observed and genetic dams
* 6. Excludes old parentage entries, enddate IS BLANK
*/
protected void mismatchedObservedAndGeneticDam(final Container c, User u, final StringBuilder msg)
{
if (QueryService.get().getUserSchema(u, c, "study") == null) {
msg.append("<b>Warning: The study schema has not been enabled in this folder, so the alert cannot run.<p><hr>");
return;
}

//Dam mismatch query
TableInfo ti = QueryService.get().getUserSchema(u, c, "study").getTable("ParentageDamMismatch", ContainerFilter.Type.AllFolders.create(c, u));
TableSelector ts = new TableSelector(ti, null, null);
long count = ts.getRowCount();

//Get num of rows
if (count > 0) {
msg.append("<b> WARNING: There are " + count + " mismatches of observed and genetic dam data requiring review.</b>");
msg.append("<a href='" + getExecuteQueryUrl(c, "study", "ParentageDamMismatch", null) + "&query.containerFilterName=AllFolders'> Click here to view them in a grid</a>\n");

//Display the report in the email
Set<FieldKey> columns = new HashSet<>();
columns.add(FieldKey.fromString("Id"));
columns.add(FieldKey.fromString("area"));
columns.add(FieldKey.fromString("geneticdam"));
columns.add(FieldKey.fromString("observeddam"));

final Map<FieldKey, ColumnInfo> colMap = QueryService.get().getColumns(ti, columns);
TableSelector ts2 = new TableSelector(ti, colMap.values(), null, null);

msg.append("<br><br>\n");
msg.append("<table border=1 style='border-collapse: collapse;'>");
msg.append("<tr bgcolor = " + '"' + "#FFFACD" + '"' + "style='font-weight: bold;'>");
msg.append("<td>Id </td><td>Area </td><td>Genetic Dam </td><td>Observed Dam </td></tr>");

ts2.forEach(object -> {
Results rs = new ResultsImpl(object, colMap);
String url = getParticipantURL(c, rs.getString("Id"));
msg.append("<tr><td><b> <a href='" + url + "'>" + PageFlowUtil.filter(rs.getString("Id")) + "</a> </b></td>\n");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("area")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("geneticdam")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("observeddam")) + "</td>");
msg.append("</tr>");
});
}
else {
msg.append("<b> There are NO mismatches of observed and genetic dam data. </b>");
}
msg.append("</table>");
msg.append("<hr>\n");
}
//End of Dam mismatch report

/**
* Finds all rooms with animals of mixed viral status
* Modified by Kollil, 2/17/2023
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public String getMessageBodyHTML(Container c, User u)
doHousingChecks(c, u, msg);
transfersYesterday(c, u, msg);
roomsWithMixedViralStatus(c, u, msg);
/*Added by kollil, Jan, 2026
Refer to tkt # 14114
*/
mismatchedObservedAndGeneticDam(c, u, msg);
livingAnimalsWithoutWeight(c, u, msg);
hospitalAnimalsWithoutCase(c, u, msg);

Expand Down