Skip to content

Commit

Permalink
Get Reject and cancel status form fhir
Browse files Browse the repository at this point in the history
  • Loading branch information
azizdiakite committed May 6, 2024
1 parent 05782d9 commit 084137f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 16 deletions.
3 changes: 2 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.4.0-SNAPSHOT</version>
<version>1.5.1-SNAPSHOT</version>
</parent>

<artifactId>labonfhir-api</artifactId>
Expand All @@ -27,6 +27,7 @@
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.openmrs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.hl7.fhir.r4.model.Task;
import org.hl7.fhir.r4.model.codesystems.TaskStatus;
import org.openmrs.Order;
import org.openmrs.Order.FulfillerStatus;
import org.openmrs.api.OrderService;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirDiagnosticReportService;
Expand Down Expand Up @@ -125,7 +126,12 @@ public void execute() {
// Get List of Tasks that belong to this instance and update them
Bundle taskBundle = client.search().forResource(Task.class)
.where(Task.IDENTIFIER.hasSystemWithAnyCode(FhirConstants.OPENMRS_FHIR_EXT_TASK_IDENTIFIER))
.where(Task.STATUS.exactly().code(TaskStatus.COMPLETED.toCode())).lastUpdated(lastUpdated)
.where(Task.STATUS.exactly().codes(
TaskStatus.COMPLETED.toCode(),
TaskStatus.REQUESTED.toCode(),
TaskStatus.ACCEPTED.toCode(),
TaskStatus.REJECTED.toCode(),
TaskStatus.CANCELLED.toCode())).lastUpdated(lastUpdated)
.returnBundle(Bundle.class).execute();

List<Bundle> taskBundles = new ArrayList<>();
Expand Down Expand Up @@ -158,6 +164,7 @@ public void shutdown() {

private Boolean updateTasksInBundle(List<Bundle> taskBundles) {
Boolean tasksUpdated = false;
String commentText = "Update Order with remote fhir status :)";
for (Bundle bundle : taskBundles) {
for (Iterator tasks = bundle.getEntry().iterator(); tasks.hasNext();) {
String openmrsTaskUuid = null;
Expand All @@ -172,19 +179,42 @@ private Boolean updateTasksInBundle(List<Bundle> taskBundles) {
// Only update if matching OpenMRS Task found
if (openmrsTask != null) {
// Handle status
openmrsTask.setStatus(openelisTask.getStatus());
if (openelisTask.getStatus().toString().equals(TaskStatus.COMPLETED.toString())) {

openmrsTask.setStatus(openelisTask.getStatus());

Boolean taskOutPutUpdated = false;
if(openmrsTask.hasBasedOn()){
setOrderNumberFromLIS(openmrsTask.getBasedOn());
Boolean taskOutPutUpdated = false;
if(openmrsTask.hasBasedOn()){
setOrderNumberFromLIS(openmrsTask.getBasedOn());
}
if (openelisTask.hasOutput()) {
// openmrsTask.setOutput(openelisTask.getOutput());
taskOutPutUpdated = updateOutput(openelisTask.getOutput(), openmrsTask);
}
if (taskOutPutUpdated) {
taskService.update(openmrsTaskUuid, openmrsTask);
tasksUpdated = taskOutPutUpdated;
}
}
if (openelisTask.hasOutput()) {
// openmrsTask.setOutput(openelisTask.getOutput());
taskOutPutUpdated = updateOutput(openelisTask.getOutput(), openmrsTask);

if(openelisTask.getStatus().toString().equals(TaskStatus.REJECTED.toString()) ){
openmrsTask.setStatus(openelisTask.getStatus());
commentText = openelisTask.getStatusReason().getText().toString().isEmpty() ? commentText: openelisTask.getStatusReason().getText();
setOrderStatus(openmrsTask.getBasedOn(), openelisTask.getStatus().toCode(), Order.FulfillerStatus.EXCEPTION, commentText);
tasksUpdated = true;
}
if (taskOutPutUpdated) {
taskService.update(openmrsTaskUuid, openmrsTask);
tasksUpdated = taskOutPutUpdated;

if(openelisTask.getStatus().toString().equals(TaskStatus.CANCELLED.toString()) ){
openmrsTask.setStatus(openelisTask.getStatus());
commentText = TaskStatus.CANCELLED.toString();
setOrderStatus(openmrsTask.getBasedOn(), openelisTask.getStatus().toCode(), Order.FulfillerStatus.EXCEPTION, commentText);
tasksUpdated = true;
}

if(openelisTask.getStatus().toString().equals(TaskStatus.REQUESTED.toString()) || openelisTask.getStatus().toString().equals(TaskStatus.ACCEPTED.toString()) ){
openmrsTask.setStatus(openelisTask.getStatus());
setOrderStatus(openmrsTask.getBasedOn(), openelisTask.getStatus().toCode(), Order.FulfillerStatus.RECEIVED, commentText);
tasksUpdated = true;
}
}
}
Expand All @@ -210,7 +240,7 @@ private void setOrderNumberFromLIS(List<Reference> basedOn) {
if (order != null) {
String commentText = "Update Order with Accesion Number From LIS";
String accessionNumber = serviceRequest.getRequisition().getValue();
orderService.updateOrderFulfillerStatus(order, Order.FulfillerStatus.IN_PROGRESS,
orderService.updateOrderFulfillerStatus(order, Order.FulfillerStatus.COMPLETED,
commentText, accessionNumber);
}
}
Expand Down Expand Up @@ -285,6 +315,32 @@ private Boolean updateOutput(List<Task.TaskOutputComponent> output, Task openmrs
}
return taskOutPutUpdated;
}
private void setOrderStatus(List<Reference> basedOn, String string, FulfillerStatus fulfillerStatus, String commentText) {
basedOn.forEach(ref -> {
if (ref.hasReferenceElement()) {
System.out.println("concidtion: 1");
IIdType referenceElement = ref.getReferenceElement();
if ("ServiceRequest".equals(referenceElement.getResourceType())) {
System.out.println("concidtion: 2");
String serviceRequestUuid = referenceElement.getIdPart();
try {

Order order = orderService.getOrderByUuid(serviceRequestUuid);
if (order != null) {
String accessionNumber = "";
orderService.updateOrderFulfillerStatus(order, fulfillerStatus,
commentText, accessionNumber);
}

}
catch (ResourceNotFoundException e) {
log.error(
"Could not Fetch ServiceRequest/" + serviceRequestUuid + ":" + e.toString() + getStackTrace(e));
}
}
}
});
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
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.4.0-SNAPSHOT</version>
<version>1.5.1-SNAPSHOT</version>
</parent>

<artifactId>labonfhir-omod</artifactId>
Expand Down
4 changes: 2 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.4.0-SNAPSHOT</version>
<version>1.5.1-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 @@ -44,7 +44,7 @@
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<version>${openmrsPlatformVersion}</version>
<version>2.6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit 084137f

Please sign in to comment.