-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Track progress of fhir task status #50
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -119,13 +120,20 @@ public void execute() { | |
lastRequstDate = dateFormat.format(lastRequest.getRequestDate()); | ||
} | ||
|
||
String practitionerId = config.getLisUserUuid(); | ||
|
||
String currentTime = dateFormat.format(newDate); | ||
DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(lastRequstDate).setUpperBound(currentTime); | ||
|
||
// 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.OWNER.hasId(practitionerId)) | ||
.where(Task.STATUS.exactly().codes( | ||
TaskStatus.COMPLETED.toCode(), | ||
TaskStatus.ACCEPTED.toCode(), | ||
TaskStatus.REJECTED.toCode(), | ||
TaskStatus.CANCELLED.toCode())).lastUpdated(lastUpdated) | ||
.returnBundle(Bundle.class).execute(); | ||
|
||
List<Bundle> taskBundles = new ArrayList<>(); | ||
|
@@ -158,6 +166,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; | ||
|
@@ -172,19 +181,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.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 (openelisTask.hasOutput()) { | ||
// openmrsTask.setOutput(openelisTask.getOutput()); | ||
taskOutPutUpdated = updateOutput(openelisTask.getOutput(), openmrsTask); | ||
|
||
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 (taskOutPutUpdated) { | ||
taskService.update(openmrsTaskUuid, openmrsTask); | ||
tasksUpdated = taskOutPutUpdated; | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
tasksUpdated = true; | ||
} | ||
} | ||
} | ||
|
@@ -210,7 +242,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); | ||
} | ||
} | ||
|
@@ -285,6 +317,30 @@ 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()) { | ||
IIdType referenceElement = ref.getReferenceElement(); | ||
if ("ServiceRequest".equals(referenceElement.getResourceType())) { | ||
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 { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azizdiakite you removed the
REQUESTED
status. this should be ACCEPTEDThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done