diff --git a/api/pom.xml b/api/pom.xml
index db14146..49410d3 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -15,7 +15,7 @@
org.openmrs.module
labonfhir
- 1.3.2-SNAPSHOT
+ 1.4.0-SNAPSHOT
labonfhir-api
@@ -24,6 +24,10 @@
API project for FHIR-based laboratory workflows
+
+ org.openmrs.api
+ openmrs-api
+
org.openmrs
event-api
diff --git a/api/src/main/java/org/openmrs/module/labonfhir/api/scheduler/FetchTaskUpdates.java b/api/src/main/java/org/openmrs/module/labonfhir/api/scheduler/FetchTaskUpdates.java
index 8a343f3..dcd14b4 100644
--- a/api/src/main/java/org/openmrs/module/labonfhir/api/scheduler/FetchTaskUpdates.java
+++ b/api/src/main/java/org/openmrs/module/labonfhir/api/scheduler/FetchTaskUpdates.java
@@ -11,20 +11,25 @@
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.gclient.TokenClientParam;
import ca.uhn.fhir.rest.param.DateRangeParam;
+import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import lombok.AccessLevel;
import lombok.Setter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.hl7.fhir.instance.model.api.IBaseBundle;
+import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.DiagnosticReport;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.ResourceType;
+import org.hl7.fhir.r4.model.ServiceRequest;
import org.hl7.fhir.r4.model.Task;
import org.hl7.fhir.r4.model.codesystems.TaskStatus;
+import org.openmrs.Order;
+import org.openmrs.api.OrderService;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirDiagnosticReportService;
import org.openmrs.module.fhir2.api.FhirObservationService;
@@ -41,6 +46,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
+
import java.text.SimpleDateFormat;
@Component
@@ -72,6 +78,9 @@ public class FetchTaskUpdates extends AbstractTask implements ApplicationContext
@Autowired
FhirObservationService observationService;
+ @Autowired
+ OrderService orderService;
+
@Autowired
ObservationReferenceTranslator observationReferenceTranslator;
@@ -166,6 +175,9 @@ private Boolean updateTasksInBundle(List taskBundles) {
openmrsTask.setStatus(openelisTask.getStatus());
Boolean taskOutPutUpdated = false;
+ if(openmrsTask.hasBasedOn()){
+ setOrderNumberFromLIS(openmrsTask.getBasedOn());
+ }
if (openelisTask.hasOutput()) {
// openmrsTask.setOutput(openelisTask.getOutput());
taskOutPutUpdated = updateOutput(openelisTask.getOutput(), openmrsTask);
@@ -184,6 +196,34 @@ private Boolean updateTasksInBundle(List taskBundles) {
return tasksUpdated;
}
+ private void setOrderNumberFromLIS(List basedOn) {
+ basedOn.forEach(ref -> {
+ if (ref.hasReferenceElement()) {
+ IIdType referenceElement = ref.getReferenceElement();
+ if ("ServiceRequest".equals(referenceElement.getResourceType())) {
+ String serviceRequestUuid = referenceElement.getIdPart();
+ try {
+ ServiceRequest serviceRequest = client.read().resource(ServiceRequest.class)
+ .withId(serviceRequestUuid).execute();
+ if (serviceRequest.hasRequisition()) {
+ Order order = orderService.getOrderByUuid(serviceRequestUuid);
+ if (order != null) {
+ String commentText = "Update Order with Accesion Number From LIS";
+ String accessionNumber = serviceRequest.getRequisition().getValue();
+ orderService.updateOrderFulfillerStatus(order, Order.FulfillerStatus.IN_PROGRESS,
+ commentText, accessionNumber);
+ }
+ }
+ }
+ catch (ResourceNotFoundException e) {
+ log.error(
+ "Could not Fetch ServiceRequest/" + serviceRequestUuid + ":" + e.toString() + getStackTrace(e));
+ }
+ }
+ }
+ });
+ }
+
private Boolean updateOutput(List output, Task openmrsTask) {
Reference encounterReference = openmrsTask.getEncounter();
diff --git a/omod/pom.xml b/omod/pom.xml
index 5269e5e..750b938 100644
--- a/omod/pom.xml
+++ b/omod/pom.xml
@@ -3,7 +3,7 @@
org.openmrs.module
labonfhir
- 1.3.2-SNAPSHOT
+ 1.4.0-SNAPSHOT
labonfhir-omod
diff --git a/pom.xml b/pom.xml
index c3bda6d..e8519eb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
org.openmrs.module
labonfhir
- 1.3.2-SNAPSHOT
+ 1.4.0-SNAPSHOT
pom
Lab on FHIR
A module to support lab order communication between OpenMRS and an LIS like OpenELIS using FHIR-based
@@ -41,6 +41,12 @@
+
+ org.openmrs.api
+ openmrs-api
+ ${openmrsPlatformVersion}
+ provided
+
org.openmrs
event-api
@@ -245,7 +251,7 @@
1.8
UTF-8
UTF-8
- 2.0.5
+ 2.3.1
4.2.0