From 1a6897bca001ba8908bb7ec2fff35fd8d30b4da8 Mon Sep 17 00:00:00 2001 From: Ken Omondi Date: Wed, 31 Jan 2024 07:13:58 +0300 Subject: [PATCH] Resolved merge conflicts (#42) --- .../module/labonfhir/api/LabOrderHandler.java | 30 +++++++++++-------- .../api/event/LabCreationListener.java | 3 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java b/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java index 0f43b35..cfbd8a2 100644 --- a/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java +++ b/api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java @@ -52,7 +52,7 @@ public Task createOrder(Order order) throws OrderCreationException { mappedTestsExist = true; } } - + if (!mappedTestsExist && config.filterOrderByTestUuuids()) { return null; } @@ -85,26 +85,31 @@ public Task createOrder(Order order) throws OrderCreationException { // Create References List basedOnRefs = Collections.singletonList( newReference(order.getUuid(), FhirConstants.SERVICE_REQUEST)); - + Reference forReference = newReference(order.getPatient().getUuid(), FhirConstants.PATIENT); - + Reference ownerRef = newReference(config.getLisUserUuid(), FhirConstants.PRACTITIONER); - + Reference encounterRef = newReference(order.getEncounter().getUuid(), FhirConstants.ENCOUNTER); - + Optional requesterProvider = order.getEncounter().getActiveEncounterProviders().stream() .findFirst(); - + Reference requesterRef = requesterProvider.map( encounterProvider -> newReference(encounterProvider.getUuid(), FhirConstants.PRACTITIONER)).orElse(null); - + + Reference locationRef = null; + if (order.getEncounter().getLocation() != null) { + locationRef = newReference(order.getEncounter().getLocation().getUuid(), FhirConstants.LOCATION); + } + // Create Task Resource for given Order - Task newTask = createTask(basedOnRefs, forReference, ownerRef, encounterRef ,taskInputs); + Task newTask = createTask(basedOnRefs, forReference, ownerRef, encounterRef, locationRef ,taskInputs); if (order.getEncounter().getActiveEncounterProviders().isEmpty()) { newTask.setRequester(requesterRef); } - + // Save the new Task Resource try { newTask = taskService.create(newTask); @@ -116,7 +121,7 @@ public Task createOrder(Order order) throws OrderCreationException { } private Task createTask(List basedOnRefs, Reference forReference, Reference ownerRef, - Reference encounterRef ,List taskInputs) { + Reference encounterRef, Reference locationRef ,List taskInputs) { Task newTask = new Task(); newTask.setStatus(Task.TaskStatus.REQUESTED); newTask.setIntent(Task.TaskIntent.ORDER); @@ -124,6 +129,7 @@ private Task createTask(List basedOnRefs, Reference forReference, Ref newTask.setFor(forReference); newTask.setOwner(ownerRef); newTask.setEncounter(encounterRef); + newTask.setLocation(locationRef); if (taskInputs != null) { newTask.setInput(taskInputs); } @@ -171,9 +177,9 @@ public Task createOrder(Encounter encounter) throws OrderCreationException { taskInputs.add(input); } } - + // Create Task Resource for given Order - Task newTask = createTask(basedOnRefs, forReference, ownerRef, encounterRef ,taskInputs); + Task newTask = createTask(basedOnRefs, forReference, ownerRef, encounterRef, locationRef ,taskInputs); newTask.setLocation(locationRef); if (!encounter.getActiveEncounterProviders().isEmpty()) { diff --git a/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java b/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java index 4979b43..8f07841 100644 --- a/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java +++ b/api/src/main/java/org/openmrs/module/labonfhir/api/event/LabCreationListener.java @@ -86,13 +86,14 @@ public Bundle createLabBundle(Task task) { includes.add(new Include("Task:owner")); includes.add(new Include("Task:encounter")); includes.add(new Include("Task:based-on")); + includes.add(new Include("Task:location")); IBundleProvider labBundle = fhirTaskService.searchForTasks(new TaskSearchParams(null, null, null, uuid, null, null, includes)); Bundle transactionBundle = new Bundle(); transactionBundle.setType(Bundle.BundleType.TRANSACTION); List labResources = labBundle.getAllResources(); - if (!task.getLocation().isEmpty() && config.getLabUpdateTriggerObject().equals("Encounter")) { + if (!task.getLocation().isEmpty()) { labResources.add(fhirLocationService.get(FhirUtils.referenceToId(task.getLocation().getReference()).get())); } for (IBaseResource r : labResources) {