From e1fd08aa4cfd13007199de2adb387e18979889e4 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Tue, 1 Sep 2026 16:32:45 -0600 Subject: [PATCH 1/8] Send the death notification on the first non-draft save MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The notification and procedure-order update only fired when the record landed on 'Request: Pending', so a death entered alongside its necropsy — which goes straight to 'Review Required' or 'Completed' — never triggered either. A delete reaches the COMPLETE handler as the deleted row with a null oldRow, so it is now skipped rather than read as a draft leaving draft. --- nbri_ehr/resources/queries/study/deaths.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/nbri_ehr/resources/queries/study/deaths.js b/nbri_ehr/resources/queries/study/deaths.js index fc9b3e9..bfeb968 100644 --- a/nbri_ehr/resources/queries/study/deaths.js +++ b/nbri_ehr/resources/queries/study/deaths.js @@ -185,19 +185,21 @@ 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() || []; 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 non-draft save: '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 && row.QCStateLabel.toUpperCase() !== 'IN PROGRESS') { console.log("Sending NBRI Death Notification") triggerHelper.sendDeathNotification(row.Id); From 17e65ed4050851367b2a67954220429225dcbb01 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Tue, 1 Sep 2026 16:33:49 -0600 Subject: [PATCH 2/8] Format birth and arrival dates as date-time so entry keeps the time The EHR data-entry framework only offers a time-of-day editor when the column's display format contains hour information, so both forms were storing every event at midnight. --- nbri_ehr/resources/queries/study/arrival.query.xml | 1 + nbri_ehr/resources/queries/study/birth.query.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/nbri_ehr/resources/queries/study/arrival.query.xml b/nbri_ehr/resources/queries/study/arrival.query.xml index 84e30cc..eb3af07 100644 --- a/nbri_ehr/resources/queries/study/arrival.query.xml +++ b/nbri_ehr/resources/queries/study/arrival.query.xml @@ -11,6 +11,7 @@ Arrival Date + DateTime Arrival Type diff --git a/nbri_ehr/resources/queries/study/birth.query.xml b/nbri_ehr/resources/queries/study/birth.query.xml index f424994..fc7174f 100644 --- a/nbri_ehr/resources/queries/study/birth.query.xml +++ b/nbri_ehr/resources/queries/study/birth.query.xml @@ -11,6 +11,7 @@ Birth Date + DateTime Conception Id From fa674a5ee422edcdf535b24c0e4edac356b70d6d Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Tue, 1 Sep 2026 16:33:49 -0600 Subject: [PATCH 3/8] Stop stripping the time from birth dates The birth trigger set the EHR removeTimeFromDate script option, so every birth date and the assignment, protocol assignment, group membership, and housing records derived from it were saved at midnight. --- nbri_ehr/resources/queries/study/birth.js | 1 - 1 file changed, 1 deletion(-) diff --git a/nbri_ehr/resources/queries/study/birth.js b/nbri_ehr/resources/queries/study/birth.js index 6531bc9..2c06b1b 100644 --- a/nbri_ehr/resources/queries/study/birth.js +++ b/nbri_ehr/resources/queries/study/birth.js @@ -43,7 +43,6 @@ function onInit(event, helper){ skipHousingCheck: true, announceAllModifiedParticipants: true, allowDatesInDistantPast: true, - removeTimeFromDate: true, skipAssignmentCheck: true, }); From 4ea5b39b2ab126e5259c8ff8b45a9808b462659a Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Tue, 1 Sep 2026 16:33:49 -0600 Subject: [PATCH 4/8] Fix duplicate Assign To dropdown in the Submit For Review window The combo claimed a page-wide element name and Cancel only hid the window rather than discarding it, so reopening the dialog rendered the previous window's field alongside the new one. The input name is now set explicitly, since Ext otherwise derives it from the component id. --- .../resources/web/nbri_ehr/buttons/deathNecropsyButtons.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nbri_ehr/resources/web/nbri_ehr/buttons/deathNecropsyButtons.js b/nbri_ehr/resources/web/nbri_ehr/buttons/deathNecropsyButtons.js index efee481..b07a7a5 100644 --- a/nbri_ehr/resources/web/nbri_ehr/buttons/deathNecropsyButtons.js +++ b/nbri_ehr/resources/web/nbri_ehr/buttons/deathNecropsyButtons.js @@ -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: [{ @@ -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, }] From f9552a52d5826ed6620192d6227e6722a6c7d80d Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Thu, 3 Sep 2026 05:29:25 -0600 Subject: [PATCH 5/8] Keep the time on group memberships derived from birth and arrival The shared animal_group_members script sets removeTimeFromDate, so these rows were saved at midnight while the birth or arrival row they came from kept its time. --- nbri_ehr/resources/scripts/nbri_triggers.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nbri_ehr/resources/scripts/nbri_triggers.js b/nbri_ehr/resources/scripts/nbri_triggers.js index 320c63f..2c806fe 100644 --- a/nbri_ehr/resources/scripts/nbri_triggers.js +++ b/nbri_ehr/resources/scripts/nbri_triggers.js @@ -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 }); }); From f5b4589a1a6d46d9488f375722b2cd5e7506ca9b Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Thu, 3 Sep 2026 06:31:47 -0600 Subject: [PATCH 6/8] Show the stored time of day on death and derived record dates The study framework formats dataset date columns as date-only, so the time these triggers already preserve was neither visible nor editable. --- .../resources/queries/study/animal_group_members.query.xml | 1 + nbri_ehr/resources/queries/study/deaths.query.xml | 1 + nbri_ehr/resources/queries/study/housing.query.xml | 1 + nbri_ehr/resources/queries/study/necropsy.query.xml | 1 + nbri_ehr/resources/queries/study/protocolAssignment.query.xml | 4 +++- 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/nbri_ehr/resources/queries/study/animal_group_members.query.xml b/nbri_ehr/resources/queries/study/animal_group_members.query.xml index 09a5157..d8767f5 100644 --- a/nbri_ehr/resources/queries/study/animal_group_members.query.xml +++ b/nbri_ehr/resources/queries/study/animal_group_members.query.xml @@ -7,6 +7,7 @@ Date Added + DateTime Date Removed diff --git a/nbri_ehr/resources/queries/study/deaths.query.xml b/nbri_ehr/resources/queries/study/deaths.query.xml index e28e2f0..f66b06d 100644 --- a/nbri_ehr/resources/queries/study/deaths.query.xml +++ b/nbri_ehr/resources/queries/study/deaths.query.xml @@ -6,6 +6,7 @@ Death Date + DateTime Death Type diff --git a/nbri_ehr/resources/queries/study/housing.query.xml b/nbri_ehr/resources/queries/study/housing.query.xml index e1a21a3..ebf4ee4 100644 --- a/nbri_ehr/resources/queries/study/housing.query.xml +++ b/nbri_ehr/resources/queries/study/housing.query.xml @@ -6,6 +6,7 @@ In Date + DateTime true diff --git a/nbri_ehr/resources/queries/study/necropsy.query.xml b/nbri_ehr/resources/queries/study/necropsy.query.xml index 35290a8..f8054a1 100644 --- a/nbri_ehr/resources/queries/study/necropsy.query.xml +++ b/nbri_ehr/resources/queries/study/necropsy.query.xml @@ -5,6 +5,7 @@ Exam Date + DateTime Category diff --git a/nbri_ehr/resources/queries/study/protocolAssignment.query.xml b/nbri_ehr/resources/queries/study/protocolAssignment.query.xml index d95eb07..0bd18c5 100644 --- a/nbri_ehr/resources/queries/study/protocolAssignment.query.xml +++ b/nbri_ehr/resources/queries/study/protocolAssignment.query.xml @@ -4,7 +4,9 @@ - + + DateTime + true From 2cfc5e0ac062ee35de40c18a4a8273a6aa0a3b13 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Thu, 3 Sep 2026 06:41:29 -0600 Subject: [PATCH 7/8] Update demographics.query.xml --- nbri_ehr/resources/queries/study/demographics.query.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nbri_ehr/resources/queries/study/demographics.query.xml b/nbri_ehr/resources/queries/study/demographics.query.xml index 0323b4a..6e6f2cc 100644 --- a/nbri_ehr/resources/queries/study/demographics.query.xml +++ b/nbri_ehr/resources/queries/study/demographics.query.xml @@ -13,7 +13,7 @@ Species - Date + DateTime Birth /query/executeQuery.view? schemaName=study& @@ -22,7 +22,7 @@ - Date + DateTime Death /query/executeQuery.view? schemaName=study& From 3189bae35e1b425ba7f7a11ed3bc2085389d2722 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Thu, 3 Sep 2026 07:03:59 -0600 Subject: [PATCH 8/8] Batch procedure order updates and restrict death notification states Only 'Request: Pending', 'Review Required' and 'Completed' count as a declaration of death, so a draft moved to a state like 'Delete Requested' no longer notifies or closes procedure orders. End dates on the derived datasets now display as date-time, matching their start dates. --- .../study/animal_group_members.query.xml | 1 + .../queries/study/assignment.query.xml | 4 +++- nbri_ehr/resources/queries/study/deaths.js | 19 +++++++++++++++---- .../resources/queries/study/housing.query.xml | 1 + .../study/protocolAssignment.query.xml | 4 +++- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/nbri_ehr/resources/queries/study/animal_group_members.query.xml b/nbri_ehr/resources/queries/study/animal_group_members.query.xml index d8767f5..3f4678e 100644 --- a/nbri_ehr/resources/queries/study/animal_group_members.query.xml +++ b/nbri_ehr/resources/queries/study/animal_group_members.query.xml @@ -11,6 +11,7 @@ Date Removed + DateTime false diff --git a/nbri_ehr/resources/queries/study/assignment.query.xml b/nbri_ehr/resources/queries/study/assignment.query.xml index df55a2e..6360ef8 100644 --- a/nbri_ehr/resources/queries/study/assignment.query.xml +++ b/nbri_ehr/resources/queries/study/assignment.query.xml @@ -7,7 +7,9 @@ DateTime - + + DateTime + ehr diff --git a/nbri_ehr/resources/queries/study/deaths.js b/nbri_ehr/resources/queries/study/deaths.js index bfeb968..87dd9ec 100644 --- a/nbri_ehr/resources/queries/study/deaths.js +++ b/nbri_ehr/resources/queries/study/deaths.js @@ -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 @@ -190,6 +194,7 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even 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; @@ -197,14 +202,20 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even if (helper.isETL() || !row || !row.Id || !row.QCStateLabel) continue; - // Notify once, on the first non-draft save: 'Submit Death' lands on 'Request: Pending', but a death entered alongside its necropsy goes straight to 'Review Required' or 'Completed'. + // 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 && row.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); + } }); \ No newline at end of file diff --git a/nbri_ehr/resources/queries/study/housing.query.xml b/nbri_ehr/resources/queries/study/housing.query.xml index ebf4ee4..9c8a81f 100644 --- a/nbri_ehr/resources/queries/study/housing.query.xml +++ b/nbri_ehr/resources/queries/study/housing.query.xml @@ -14,6 +14,7 @@ true true Out Date + DateTime Location diff --git a/nbri_ehr/resources/queries/study/protocolAssignment.query.xml b/nbri_ehr/resources/queries/study/protocolAssignment.query.xml index 0bd18c5..ccd46a8 100644 --- a/nbri_ehr/resources/queries/study/protocolAssignment.query.xml +++ b/nbri_ehr/resources/queries/study/protocolAssignment.query.xml @@ -7,7 +7,9 @@ DateTime - + + DateTime + true