Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions nirc_ehr/resources/queries/study/deaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,7 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
if (!helper.isETL() && event === 'insert') {
triggerHelper.sendDeathNotification(ids[0]);
}

triggerHelper.updateProcedureOrdersToCompleted(ids);
}
});
17 changes: 17 additions & 0 deletions nirc_ehr/resources/queries/study/departure.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
require("ehr/triggers").initScript(this);

var triggerHelper = new org.labkey.nirc_ehr.query.NIRC_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
var departures = [];

function onInit(event, helper){
helper.setScriptOptions({
requiresStatusRecalc: false
});

}

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.AFTER_INSERT, 'study', 'departure', function(helper, scriptErrors, row, oldRow) {

if (row.id) {
departures.push(row.id);
}
});

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.COMPLETE, 'study', 'departure', function(event, errors, helper){

if (!helper.isETL() && helper.isEHRDataEntry()) {
triggerHelper.updateProcedureOrdersToCompleted(departures);
}
});

4 changes: 3 additions & 1 deletion nirc_ehr/resources/queries/study/prcOverdue.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<columns>
<column columnName="objectid">
<isHidden>true</isHidden>
<isKeyField>true</isKeyField>
</column>
<column columnName="lsid">
<isHidden>true</isHidden>
</column>
<column columnName="Id">
<fk>
Expand Down
1 change: 1 addition & 0 deletions nirc_ehr/resources/queries/study/prcOverdue.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SELECT
po.remark,
po.caseid,
po.objectid,
po.lsid,
CASE WHEN po.qcstate.label = 'Completed' THEN 'Completed' ELSE '' END as status
FROM prc_order po
WHERE now() > windowEnd AND po.qcstate.label != 'Completed'
4 changes: 3 additions & 1 deletion nirc_ehr/resources/queries/study/prcSchedule.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<columns>
<column columnName="objectid">
<isHidden>true</isHidden>
<isKeyField>true</isKeyField>
</column>
<column columnName="lsid">
<isHidden>true</isHidden>
</column>
<column columnName="Id">
<fk>
Expand Down
1 change: 1 addition & 0 deletions nirc_ehr/resources/queries/study/prcSchedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SELECT
po.remark,
po.caseid,
po.objectid,
po.lsid,
CASE WHEN po.qcstate.label = 'Completed' THEN 'Completed' ELSE '' END as status
FROM prc_order po
WHERE now() >= windowStart AND now() <= windowEnd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Ext4.define('NIRC_EHR.window.ProcedureOrderCompleteWindow', {
if (completedRowId) {
for (const row of selectedRows) {
rowsToInsert.push({
objectid: row,
lsid: row,
qcstate: completedRowId
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ Ext4.define('NIRC_EHR.window.RecordProcedureWindow', {
LABKEY.Query.selectRows({
schemaName: 'study',
queryName: 'prc_order',
filterArray: [LABKEY.Filter.create('objectid', selectedRows.join(';'), LABKEY.Filter.Types.EQUALS_ONE_OF)],
filterArray: [LABKEY.Filter.create('lsid', selectedRows.join(';'), LABKEY.Filter.Types.EQUALS_ONE_OF)],
scope: this,
columns: 'Id,objectid,procedure,category,caseid,orderedby',
columns: 'Id,objectid,procedure,category,caseid,orderedby,lsid',
success: function (data) {
const rowsToInsert = [];
Ext4.each(data.rows, function(row) {
Ext4.each(selectedRows, function(selectedRow) {
if (row.objectid === selectedRow) {
if (row.lsid === selectedRow) {
rowsToInsert.push({
Id: row.Id,
procedure: row.procedure,
Expand Down
48 changes: 48 additions & 0 deletions nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,54 @@ public void markProcedureOrderComplete(List<String> orderids)
}
}

public void updateProcedureOrdersToCompleted(List<String> ids)
{
if (ids == null || ids.size() < 1) // Native array doesn't support isEmpty
{
_log.warn("No IDs provided to updateProcedureOrdersToCompleted");
return;
}

TableInfo ti = getTableInfo("study", "prc_order");

// Get the QC state IDs for "Request: Approved" and "Completed"
Integer approvedQcStateId = EHRService.get().getQCStates(_container).get("Request: Approved").getRowId();
Integer completedQcStateId = EHRService.get().getQCStates(_container).get("Completed").getRowId();
Comment thread
labkey-martyp marked this conversation as resolved.
Outdated

// Query for rows matching the IDs and having "Request: Approved" status
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("Id"), ids, CompareType.IN);
filter.addCondition(FieldKey.fromString("qcstate"), approvedQcStateId, CompareType.EQUAL);

TableSelector ts = new TableSelector(ti, PageFlowUtil.set("objectid"), filter, null);
Map<String, Object>[] results = ts.getMapArray();

if (results.length == 0)
{
_log.info("No prc_order rows found with 'Request: Approved' status for the provided IDs");
return;
}

// Build the update rows
List<Map<String, Object>> rows = new ArrayList<>();
for (Map<String, Object> result : results)
{
Map<String, Object> row = new HashMap<>();
row.put("objectid", result.get("objectid"));
row.put("qcstate", completedQcStateId);
rows.add(row);
}

try
{
ti.getUpdateService().updateRows(_user, _container, rows, null, null, getExtraContext());
_log.info("Successfully updated " + rows.size() + " prc_order rows to 'Completed' status");
}
catch (Exception e)
{
_log.error("Error updating prc_order rows to completed", e);
}
}

public void sendPregnancyOutcomeNotification(final String animalId, Map<String, Object> row) throws Exception
{
//check whether Notification is enabled
Expand Down