Skip to content

Commit b4ca388

Browse files
Merge 26.1 to develop
2 parents 20a22fe + ce13021 commit b4ca388

9 files changed

Lines changed: 79 additions & 6 deletions

File tree

nirc_ehr/resources/queries/study/deaths.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,7 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
142142
if (!helper.isETL() && event === 'insert') {
143143
triggerHelper.sendDeathNotification(ids[0]);
144144
}
145+
146+
triggerHelper.updateProcedureOrdersToCompleted(ids);
145147
}
146148
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
require("ehr/triggers").initScript(this);
22

3+
var triggerHelper = new org.labkey.nirc_ehr.query.NIRC_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
4+
var departures = [];
5+
36
function onInit(event, helper){
47
helper.setScriptOptions({
58
requiresStatusRecalc: false
69
});
710

811
}
912

13+
EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.AFTER_INSERT, 'study', 'departure', function(helper, scriptErrors, row, oldRow) {
14+
15+
if (row.id) {
16+
departures.push(row.id);
17+
}
18+
});
19+
20+
EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.COMPLETE, 'study', 'departure', function(event, errors, helper){
21+
22+
if (!helper.isETL() && helper.isEHRDataEntry()) {
23+
triggerHelper.updateProcedureOrdersToCompleted(departures);
24+
}
25+
});
26+

nirc_ehr/resources/queries/study/prcOverdue.query.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
<columns>
88
<column columnName="objectid">
99
<isHidden>true</isHidden>
10-
<isKeyField>true</isKeyField>
10+
</column>
11+
<column columnName="lsid">
12+
<isHidden>true</isHidden>
1113
</column>
1214
<column columnName="Id">
1315
<fk>

nirc_ehr/resources/queries/study/prcOverdue.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SELECT
99
po.remark,
1010
po.caseid,
1111
po.objectid,
12+
po.lsid,
1213
CASE WHEN po.qcstate.label = 'Completed' THEN 'Completed' ELSE '' END as status
1314
FROM prc_order po
1415
WHERE now() > windowEnd AND po.qcstate.label != 'Completed'

nirc_ehr/resources/queries/study/prcSchedule.query.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
<columns>
88
<column columnName="objectid">
99
<isHidden>true</isHidden>
10-
<isKeyField>true</isKeyField>
10+
</column>
11+
<column columnName="lsid">
12+
<isHidden>true</isHidden>
1113
</column>
1214
<column columnName="Id">
1315
<fk>

nirc_ehr/resources/queries/study/prcSchedule.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SELECT
99
po.remark,
1010
po.caseid,
1111
po.objectid,
12+
po.lsid,
1213
CASE WHEN po.qcstate.label = 'Completed' THEN 'Completed' ELSE '' END as status
1314
FROM prc_order po
1415
WHERE now() >= windowStart AND now() <= windowEnd

nirc_ehr/resources/web/nirc_ehr/buttons/ProcedureOrderCompleteButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Ext4.define('NIRC_EHR.window.ProcedureOrderCompleteWindow', {
5151
if (completedRowId) {
5252
for (const row of selectedRows) {
5353
rowsToInsert.push({
54-
objectid: row,
54+
lsid: row,
5555
qcstate: completedRowId
5656
});
5757
}

nirc_ehr/resources/web/nirc_ehr/buttons/RecordProcedureButton.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ Ext4.define('NIRC_EHR.window.RecordProcedureWindow', {
7171
LABKEY.Query.selectRows({
7272
schemaName: 'study',
7373
queryName: 'prc_order',
74-
filterArray: [LABKEY.Filter.create('objectid', selectedRows.join(';'), LABKEY.Filter.Types.EQUALS_ONE_OF)],
74+
filterArray: [LABKEY.Filter.create('lsid', selectedRows.join(';'), LABKEY.Filter.Types.EQUALS_ONE_OF)],
7575
scope: this,
76-
columns: 'Id,objectid,procedure,category,caseid,orderedby',
76+
columns: 'Id,objectid,procedure,category,caseid,orderedby,lsid',
7777
success: function (data) {
7878
const rowsToInsert = [];
7979
Ext4.each(data.rows, function(row) {
8080
Ext4.each(selectedRows, function(selectedRow) {
81-
if (row.objectid === selectedRow) {
81+
if (row.lsid === selectedRow) {
8282
rowsToInsert.push({
8383
Id: row.Id,
8484
procedure: row.procedure,

nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,54 @@ public void markProcedureOrderComplete(List<String> orderids)
927927
}
928928
}
929929

930+
public void updateProcedureOrdersToCompleted(List<String> ids)
931+
{
932+
if (ids == null || ids.size() < 1) // Native array doesn't support isEmpty
933+
{
934+
_log.warn("No IDs provided to updateProcedureOrdersToCompleted");
935+
return;
936+
}
937+
938+
TableInfo ti = getTableInfo("study", "prc_order");
939+
940+
// Get the QC state IDs for "Request: Approved" and "Completed"
941+
Integer approvedQcStateId = EHRService.get().getQCStates(_container).get(EHRService.QCSTATES.RequestApproved.getLabel()).getRowId();
942+
Integer completedQcStateId = EHRService.get().getQCStates(_container).get(EHRService.QCSTATES.Completed.getLabel()).getRowId();
943+
944+
// Query for rows matching the IDs and having "Request: Approved" status
945+
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("Id"), ids, CompareType.IN);
946+
filter.addCondition(FieldKey.fromString("qcstate"), approvedQcStateId, CompareType.EQUAL);
947+
948+
TableSelector ts = new TableSelector(ti, PageFlowUtil.set("objectid"), filter, null);
949+
Map<String, Object>[] results = ts.getMapArray();
950+
951+
if (results.length == 0)
952+
{
953+
_log.info("No prc_order rows found with 'Request: Approved' status for the provided IDs");
954+
return;
955+
}
956+
957+
// Build the update rows
958+
List<Map<String, Object>> rows = new ArrayList<>();
959+
for (Map<String, Object> result : results)
960+
{
961+
Map<String, Object> row = new HashMap<>();
962+
row.put("objectid", result.get("objectid"));
963+
row.put("qcstate", completedQcStateId);
964+
rows.add(row);
965+
}
966+
967+
try
968+
{
969+
ti.getUpdateService().updateRows(_user, _container, rows, null, null, getExtraContext());
970+
_log.info("Successfully updated " + rows.size() + " prc_order rows to 'Completed' status");
971+
}
972+
catch (Exception e)
973+
{
974+
_log.error("Error updating prc_order rows to completed", e);
975+
}
976+
}
977+
930978
public void sendPregnancyOutcomeNotification(final String animalId, Map<String, Object> row) throws Exception
931979
{
932980
//check whether Notification is enabled

0 commit comments

Comments
 (0)