Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
<column columnName="Id"/>
<column columnName="date">
<columnTitle>Date Added</columnTitle>
<formatString>DateTime</formatString>
</column>
<column columnName="enddate">
<columnTitle>Date Removed</columnTitle>
<formatString>DateTime</formatString>
<isHidden>false</isHidden>
</column>
<column columnName="groupId">
Expand Down
1 change: 1 addition & 0 deletions nbri_ehr/resources/queries/study/arrival.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<column columnName="Id"/>
<column columnName="date">
<columnTitle>Arrival Date</columnTitle>
<formatString>DateTime</formatString>
</column>
<column columnName="arrivalType">
<columnTitle>Arrival Type</columnTitle>
Expand Down
4 changes: 3 additions & 1 deletion nbri_ehr/resources/queries/study/assignment.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<column columnName="date">
<formatString>DateTime</formatString>
</column>
<column columnName="endDate"/>
<column columnName="endDate">
<formatString>DateTime</formatString>
</column>
<column columnName="project">
<fk>
<fkDbSchema>ehr</fkDbSchema>
Expand Down
1 change: 0 additions & 1 deletion nbri_ehr/resources/queries/study/birth.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ function onInit(event, helper){
skipHousingCheck: true,
announceAllModifiedParticipants: true,
allowDatesInDistantPast: true,
removeTimeFromDate: true,
skipAssignmentCheck: true,
});

Expand Down
1 change: 1 addition & 0 deletions nbri_ehr/resources/queries/study/birth.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<column columnName="Id" />
<column columnName="date">
<columnTitle>Birth Date</columnTitle>
<formatString>DateTime</formatString>
</column>
<column columnName="conceptId">
<columnTitle>Conception Id</columnTitle>
Expand Down
33 changes: 23 additions & 10 deletions nbri_ehr/resources/queries/study/deaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var idMap = {};
var deathIdMap = {};
var idsToSync = [];

// QC states that mean a death has been declared. Leaving draft for anything else -- 'Delete Requested', a denied
// request -- is not a declaration, so it must not notify or close out the animal's procedure orders.
var NOTIFY_STATES = ['REQUEST: PENDING', 'REVIEW REQUIRED', 'COMPLETED'];

function onInit(event, helper){

// the script scope can outlive a single save, so never inherit ids from a prior one
Expand Down Expand Up @@ -185,24 +189,33 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
idsToSync = [];
}

// A delete arrives here as the deleted row with a null oldRow, which otherwise reads as a draft leaving draft.
if (event === 'delete')
return;

var rows = helper.getRows() || [];
var idsToComplete = [];
for (var i = 0; i < rows.length; i++) {
var row = rows[i].row;
var oldRow = rows[i].oldRow;

// Notification will get sent when:
// 1) a brand-new row saved directly as 'Request: Pending' (i.e., when a user clicks 'Submit Death'), or
// 2) a draft death record moving from 'In Progress' to 'Request: Pending'.
if (!helper.isETL() &&
row && row.Id &&
row.QCStateLabel &&
row.QCStateLabel.toUpperCase() === 'REQUEST: PENDING' &&
(!oldRow || !oldRow.QCStateLabel || oldRow.QCStateLabel.toUpperCase() === 'IN PROGRESS')) {
if (helper.isETL() || !row || !row.Id || !row.QCStateLabel)
continue;

// Notify once, on the first save that leaves draft: 'Submit Death' lands on 'Request: Pending', but a death entered alongside its necropsy goes straight to 'Review Required' or 'Completed'.
var wasDraft = !oldRow || !oldRow.QCStateLabel || oldRow.QCStateLabel.toUpperCase() === 'IN PROGRESS';
if (wasDraft && NOTIFY_STATES.indexOf(row.QCStateLabel.toUpperCase()) > -1) {
console.log("Sending NBRI Death Notification")
triggerHelper.sendDeathNotification(row.Id);

console.log("Updating Procedure Orders to Completed for Animal: " + row.Id + "")
triggerHelper.updateProcedureOrdersToCompleted([row.Id]);
if (idsToComplete.indexOf(row.Id) === -1)
idsToComplete.push(row.Id);
}
}

// One pass for the whole save: the helper filters and updates in bulk, so a call per row multiplies round trips.
if (idsToComplete.length) {
console.log("Updating Procedure Orders to Completed for: " + idsToComplete.join(', '))
triggerHelper.updateProcedureOrdersToCompleted(idsToComplete);
}
});
1 change: 1 addition & 0 deletions nbri_ehr/resources/queries/study/deaths.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<column columnName="Id"/>
<column columnName="date">
<columnTitle>Death Date</columnTitle>
<formatString>DateTime</formatString>
</column>
<column columnName="type">
<columnTitle>Death Type</columnTitle>
Expand Down
4 changes: 2 additions & 2 deletions nbri_ehr/resources/queries/study/demographics.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<columnTitle>Species</columnTitle>
</column>
<column columnName="birth">
<formatString>Date</formatString>
<formatString>DateTime</formatString>
<columnTitle>Birth</columnTitle>
<url>/query/executeQuery.view?
schemaName=study&amp;
Expand All @@ -22,7 +22,7 @@
</url>
</column>
<column columnName="death">
<formatString>Date</formatString>
<formatString>DateTime</formatString>
<columnTitle>Death</columnTitle>
<url>/query/executeQuery.view?
schemaName=study&amp;
Expand Down
2 changes: 2 additions & 0 deletions nbri_ehr/resources/queries/study/housing.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
<column columnName="Id"/>
<column columnName="date">
<columnTitle>In Date</columnTitle>
<formatString>DateTime</formatString>
</column>
<column columnName="enddate">
<nullable>true</nullable>
<isHidden>false</isHidden>
<shownInInsertView>true</shownInInsertView>
<shownInDetailsView>true</shownInDetailsView>
<columnTitle>Out Date</columnTitle>
<formatString>DateTime</formatString>
</column>
<column columnName="cage">
<columnTitle>Location</columnTitle>
Expand Down
1 change: 1 addition & 0 deletions nbri_ehr/resources/queries/study/necropsy.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<columns>
<column columnName="date">
<columnTitle>Exam Date</columnTitle>
<formatString>DateTime</formatString>
</column>
<column columnName="category">
<columnTitle>Category</columnTitle>
Expand Down
8 changes: 6 additions & 2 deletions nbri_ehr/resources/queries/study/protocolAssignment.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
<table tableName="protocolAssignment" tableDbType="TABLE" useColumnOrder="true">
<columns>
<column columnName="Id"/>
<column columnName="date"/>
<column columnName="endDate"/>
<column columnName="date">
<formatString>DateTime</formatString>
</column>
<column columnName="endDate">
<formatString>DateTime</formatString>
</column>
<column columnName="project">
<isHidden>true</isHidden>
</column>
Expand Down
4 changes: 3 additions & 1 deletion nbri_ehr/resources/scripts/nbri_triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ exports.init = function (EHR) {
// group memberships are routinely backdated, so historical dates must not raise a warning
helper.setScriptOptions({
requiresStatusRecalc: false,
allowDatesInDistantPast: true
allowDatesInDistantPast: true,
// Overrides the shared animal_group_members script, which sets this true.
removeTimeFromDate: false
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Ext4.define('NBRI_EHR.window.DeathNecropsySubmitForReviewWindow', {
text: 'Cancel',
scope: this,
handler: function(btn){
btn.up('window').hide();
btn.up('window').close();
}
}],
items: [{
Expand All @@ -127,8 +127,10 @@ Ext4.define('NBRI_EHR.window.DeathNecropsySubmitForReviewWindow', {
value: this.getDefaultRecipient(),
displayField: 'DisplayName',
valueField: 'UserId',
// No global 'id' here: a reopened window would adopt the previous window's element and render a second combo.
itemId: 'assignedTo',
id: 'assignedTo',
// Ext derives the input's name from the component id when 'name' is absent, so set it explicitly rather than leaning on the id.
name: 'assignedTo',
anyMatch: true,
caseSensitive: false,
}]
Expand Down