Skip to content

Commit

Permalink
Add Order Accesion Number from LIMS (#40)
Browse files Browse the repository at this point in the history
* format

* add sidep config

* Update Order Accesion Number from LMIS

* minor fix
  • Loading branch information
mozzy11 committed Nov 2, 2023
1 parent 1e78054 commit 05782d9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
6 changes: 5 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>labonfhir</artifactId>
<version>1.3.2-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
</parent>

<artifactId>labonfhir-api</artifactId>
Expand All @@ -24,6 +24,10 @@
<description>API project for FHIR-based laboratory workflows</description>

<dependencies>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs</groupId>
<artifactId>event-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +46,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;

@Component
Expand Down Expand Up @@ -72,6 +78,9 @@ public class FetchTaskUpdates extends AbstractTask implements ApplicationContext
@Autowired
FhirObservationService observationService;

@Autowired
OrderService orderService;

@Autowired
ObservationReferenceTranslator observationReferenceTranslator;

Expand Down Expand Up @@ -166,6 +175,9 @@ private Boolean updateTasksInBundle(List<Bundle> 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);
Expand All @@ -184,6 +196,34 @@ private Boolean updateTasksInBundle(List<Bundle> taskBundles) {
return tasksUpdated;
}

private void setOrderNumberFromLIS(List<Reference> 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<Task.TaskOutputComponent> output, Task openmrsTask) {

Reference encounterReference = openmrsTask.getEncounter();
Expand Down
2 changes: 1 addition & 1 deletion omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>labonfhir</artifactId>
<version>1.3.2-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
</parent>

<artifactId>labonfhir-omod</artifactId>
Expand Down
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>org.openmrs.module</groupId>
<artifactId>labonfhir</artifactId>
<version>1.3.2-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Lab on FHIR</name>
<description>A module to support lab order communication between OpenMRS and an LIS like OpenELIS using FHIR-based
Expand Down Expand Up @@ -41,6 +41,12 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<version>${openmrsPlatformVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs</groupId>
<artifactId>event-api</artifactId>
Expand Down Expand Up @@ -245,7 +251,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputEncoding>UTF-8</project.build.outputEncoding>
<openmrsPlatformVersion>2.0.5</openmrsPlatformVersion>
<openmrsPlatformVersion>2.3.1</openmrsPlatformVersion>
<hapifhirVersion>4.2.0</hapifhirVersion>
</properties>
</project>

0 comments on commit 05782d9

Please sign in to comment.