diff --git a/nirc_ehr/resources/queries/study/clinical_observations.js b/nirc_ehr/resources/queries/study/clinical_observations.js
index 38f07036..6c50146b 100644
--- a/nirc_ehr/resources/queries/study/clinical_observations.js
+++ b/nirc_ehr/resources/queries/study/clinical_observations.js
@@ -12,6 +12,7 @@ var triggerHelper = new org.labkey.nirc_ehr.query.NIRC_EHRTriggerHelper(LABKEY.S
function onInit(event, helper) {
helper.decodeExtraContextProperty('orderTasksInTransaction');
+ triggerHelper.clearScheduledObsTaskMap();
}
function onUpsert(helper, scriptErrors, row, oldRow) {
@@ -67,6 +68,7 @@ function onUpsert(helper, scriptErrors, row, oldRow) {
row.orderid = orderData.orderId;
row.area = orderData.area;
row.type = orderData.type;
+ row.taskid = orderData.taskId;
}
}
}
diff --git a/nirc_ehr/resources/queries/study/clinical_observations/.qview.xml b/nirc_ehr/resources/queries/study/clinical_observations/.qview.xml
index a48d5a51..daaa82db 100644
--- a/nirc_ehr/resources/queries/study/clinical_observations/.qview.xml
+++ b/nirc_ehr/resources/queries/study/clinical_observations/.qview.xml
@@ -14,5 +14,6 @@
+
\ No newline at end of file
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java b/nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java
index 22112ed5..a4b08fd2 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java
@@ -40,6 +40,7 @@
import org.labkey.api.util.PageFlowUtil;
import org.labkey.nirc_ehr.NIRCOrchardFileGenerator;
import org.labkey.nirc_ehr.NIRC_EHRManager;
+import org.labkey.nirc_ehr.dataentry.form.NIRCClinicalObservationsFormType;
import org.labkey.nirc_ehr.notification.NIRCClinicalMoveNotification;
import org.labkey.nirc_ehr.notification.NIRCDeathNotification;
import org.labkey.nirc_ehr.notification.NIRCPregnancyOutcomeNotification;
@@ -66,6 +67,10 @@ public class NIRC_EHRTriggerHelper
private static final Logger _log = LogManager.getLogger(NIRC_EHRTriggerHelper.class);
private final Map _cachedDrugFormulary = new HashMap<>();
+ // Maps an originating observation order's taskid to the task its scheduled observations are grouped under,
+ // for the duration of a single save batch (the same helper instance is reused across rows in the batch).
+ private final Map _scheduledObsTaskMap = new HashMap<>();
+
private final SimpleDateFormat _dateFormat;
public NIRC_EHRTriggerHelper(int userId, String containerId)
@@ -798,6 +803,10 @@ public Map handleScheduledObservations(Map row,
{
Map order = orders[i];
+ // Group every entry by the originating order's taskid into a new task per group.
+ String orderTaskId = ConvertHelper.convert(order.get("taskid"), String.class);
+ String groupTaskId = resolveGroupTaskId(orderTaskId, taskid, qcstate);
+
// First order we find will fill out the information in the row passing through the trigger
if (i == 0)
{
@@ -806,6 +815,7 @@ public Map handleScheduledObservations(Map row,
triggerOrder.put("area", order.get("area"));
triggerOrder.put("orderId", order.get("objectid"));
triggerOrder.put("type", order.get("type"));
+ triggerOrder.put("taskId", groupTaskId);
continue;
}
@@ -822,7 +832,7 @@ public Map handleScheduledObservations(Map row,
obsRow.put("performedBy", performedBy);
obsRow.put("orderId", order.get("objectid"));
obsRow.put("type", order.get("type"));
- obsRow.put("taskid", order.get("taskid"));
+ obsRow.put("taskid", groupTaskId);
List