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
@@ -0,0 +1,122 @@
/*
* Copyright (c) 2013-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
Ext4.define('ONPRC_EHR.data.ClinicalEncountersClientStore', {
extend: 'EHR.data.DataEntryClientStore',

constructor: function(){
this.callParent(arguments);

this.on('add', this.onAddRecord, this);
},

onAddRecord: function(store, records){
Ext4.each(records, function(record){
this.onRecordUpdate(record, ['procedureid']);
}, this);
},

afterEdit: function(record, modifiedFieldNames){
this.onRecordUpdate(record, modifiedFieldNames);

this.callParent(arguments);
},

onRecordUpdate: function(record, modifiedFieldNames){
if (record.get('procedureid')){
modifiedFieldNames = modifiedFieldNames || [];

var lookupRec = this.getProcedureRecord(record.get('procedureid'));
if (!lookupRec)
return;

if (lookupRec.get('remark')&& record.get('remark')== null){
record.beginEdit();
record.set('remark', lookupRec.get('remark'));
record.endEdit(true);
}

if (lookupRec.get('name')&& lookupRec.get('name')== 'TMB breeding'){
record.beginEdit();
record.set('chargetype', 'TMB');
record.endEdit(true);
}
}

if (modifiedFieldNames && (modifiedFieldNames.indexOf('Id') > -1 || modifiedFieldNames.indexOf('project') > -1 || modifiedFieldNames.indexOf('chargetype') > -1)){
if (record.get('objectid')){
var toApply = {
Id: record.get('Id'),
project: record.get('project'),
chargetype: record.get('chargetype')
};

this.storeCollection.clientStores.each(function(cs){
if (cs.storeId == this.storeCollection.collectionId + '-' + 'encounters'){
return;
}

var projectField = cs.getFields().get('project');
var chargeTypeField = cs.getFields().get('chargetype');
var hasChanges = false;

if (cs.getFields().get('parentid')){
if (cs.getFields().get('Id') || cs.getFields().get('project')){
cs.each(function(r){
if (r.get('parentid') === record.get('objectid')){
var obj = {};

if (projectField){
if (!r.get('project') || (projectField.inheritFromParent && r.get('project') !== record.get('project'))){
obj.project = record.get('project');
}
}

if (chargeTypeField){
if (!r.get('chargetype') || (chargeTypeField.inheritFromParent && r.get('chargetype') !== record.get('chargetype'))){
obj.chargetype = record.get('chargetype');
}
}

if (r.get('Id') !== record.get('Id')){
obj.Id = record.get('Id');
}

if (!Ext4.Object.isEmpty(obj)){
r.beginEdit();
r.set(obj);
r.endEdit(true);
hasChanges = true;
}
}
}, this);
}
}

if (hasChanges){
cs.fireEvent('datachanged', cs);
}
}, this);
}
}
},

getProcedureRecord: function(procedureId){
var procedureStore = EHR.DataEntryUtils.getProceduresStore();
LDK.Assert.assertNotEmpty('Unable to find procedureStore from ClinicalEncountersClientStore', procedureStore);

// If the store is not loaded this will call again. No need to do a load callback here just return undefined if not loaded.
if (LABKEY.ext4.Util.hasStoreLoaded(procedureStore)) {
var procRecIdx = procedureStore.findExact('rowid', procedureId);
LDK.Assert.assertTrue('Unable to find procedure record in ClinicalEncountersClientStore for procedureId: [' + procedureId + ']', procRecIdx > -1);

var procedureRec = procedureStore.getAt(procRecIdx);
LDK.Assert.assertNotEmpty('Unable to find procedure record from ClinicalEncountersClientStore. ProcedureId was: [' + procedureId + ']', procedureRec);

return procedureRec;
}
return undefined;
}
});
35 changes: 4 additions & 31 deletions onprc_ehr/resources/web/onprc_ehr/model/sources/ASB_Services.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ EHR.model.DataModelManager.registerMetadata('ASB_Services', {
'study.encounters': {
chargetype: {
defaultValue: 'DCM: ASB Services',
hidden: true
hidden: false
},
date: {
xtype: 'xdatetime',
Expand Down Expand Up @@ -89,7 +89,7 @@ EHR.model.DataModelManager.registerMetadata('ASB_Services', {
'study.blood': {
chargetype: {
defaultValue: 'DCM: ASB Services',
hidden: true
hidden: false
},
performedby: {
//defaultValue: LABKEY.Security.currentUser.displayName,
Expand All @@ -105,7 +105,7 @@ EHR.model.DataModelManager.registerMetadata('ASB_Services', {
'study.drug': {
chargetype: {
defaultValue: 'DCM: ASB Services',
hidden: true
hidden: false
},
date: {
xtype: 'xdatetime',
Expand Down Expand Up @@ -147,33 +147,6 @@ EHR.model.DataModelManager.registerMetadata('ASB_Services', {
}

}
// Modified: 7-27-2017 R.Blasa not needed for this version
//'study.treatment_order': {
// chargetype: {
// defaultValue: 'DCM: ASB Services',
// hidden: true
// },
// date: {
// defaultValue: new Date()
// },
// Billable: {
// defaultValue: 'Yes',
// hidden: true
// },
// code: {
// header: 'Agent',
// editorConfig: {
// defaultSubset: 'Research'
// }
// },
// category: {
// defaultValue: 'Research',
// hidden: true
// },
// remark: {
// header: 'Special Instructions',
// hidden: false
// }
//}

}
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public ClinicalEncountersFormSection()
{
super("study", "encounters", "Procedures", "ehr-gridpanel", EHRService.FORM_SECTION_LOCATION.Body);
addClientDependency(ClientDependency.supplierFromPath("ehr/buttons/encounterButtons.js"));
addClientDependency(ClientDependency.supplierFromPath("ehr/data/ClinicalEncountersClientStore.js"));
setClientStoreClass("EHR.data.ClinicalEncountersClientStore");
addClientDependency(ClientDependency.supplierFromPath("onprc_ehr/data/sources/ClinicalEncountersClientStore.js"));
setClientStoreClass("ONPRC_EHR.data.ClinicalEncountersClientStore");
//Modified 8-24-2015 Blasa Shows Template menus
// setTemplateMode(TEMPLATE_MODE.NONE);

Expand Down
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
Loading