Skip to content
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

U4X-790: Handle 400 bad request on UgandaEMR end to end orders with duplicates found on CPHL END #180

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,22 @@ public void execute() {
try {
Map map = ugandaEMRHttpURLConnection.sendPostBy(syncTaskType.getUrl(), syncTaskType.getUrlUserName(), syncTaskType.getUrlPassword(), "", json, false);
if (map != null) {
Map responseType = handleReturnedResponses(order, map);
Integer response = (Integer) map.get("responseCode");

if (map.get("responseCode").toString().equals("400") && responseType.get("responseType").toString().equals("Duplicate")) {
response = 200;
}

SyncTask newSyncTask = new SyncTask();
newSyncTask.setDateSent(new Date());
newSyncTask.setCreator(Context.getUserService().getUser(1));
newSyncTask.setSentToUrl(syncTaskType.getUrl());
newSyncTask.setRequireAction(true);
newSyncTask.setActionCompleted(false);
newSyncTask.setSyncTask(order.getAccessionNumber());
newSyncTask.setStatusCode((Integer) map.get("responseCode"));
newSyncTask.setStatus((String)map.get("responseMessage"));
newSyncTask.setStatusCode((Integer) response);
newSyncTask.setStatus((String) map.get("responseMessage"));
newSyncTask.setSyncTaskType(ugandaEMRSyncService.getSyncTaskTypeByUUID(VIRAL_LOAD_SYNC_TYPE_UUID));
ugandaEMRSyncService.saveSyncTask(newSyncTask);
}
Expand All @@ -97,6 +104,25 @@ public void execute() {
}
}

private Map handleReturnedResponses(Order order, Map response) {
Map responseType = new HashMap<>();
OrderService orderService = Context.getOrderService();
try {
if (response.get("responseCode").equals(400) && response.get("responseMessage").toString().contains("The specimen ID:") && response.get("responseMessage").toString().contains("is not HIE compliant")) {
orderService.discontinueOrder(order, response.get("responseMessage").toString(), new Date(), order.getOrderer(), order.getEncounter());
responseType.put("responseType", "Not HIE compliant");
} else if (response.get("responseCode").equals(400) && response.get("responseMessage").toString().toLowerCase().contains("duplicate")) {
//TODO need to update openmrs version in sync in order to support updating fulfiller status
responseType.put("responseType", "Duplicate");
}
} catch (Exception e) {
log.error(e);
}

return responseType;
}


/**
* @return
*/
Expand Down
Loading