Skip to content

Commit b7af8e0

Browse files
authored
Merge pull request #180
* U4X-790: Handle 400 bad request on UgandaEMR end to end orders with d… * call method when adding of logging is completed. * change to use one try and catch statement. * remove unnecessary formatting
1 parent 5446fe3 commit b7af8e0

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

api/src/main/java/org/openmrs/module/ugandaemrsync/tasks/SendViralLoadRequestToCentralServerTask.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,22 @@ public void execute() {
7878
try {
7979
Map map = ugandaEMRHttpURLConnection.sendPostBy(syncTaskType.getUrl(), syncTaskType.getUrlUserName(), syncTaskType.getUrlPassword(), "", json, false);
8080
if (map != null) {
81+
Map responseType = handleReturnedResponses(order, map);
82+
Integer response = (Integer) map.get("responseCode");
83+
84+
if (map.get("responseCode").toString().equals("400") && responseType.get("responseType").toString().equals("Duplicate")) {
85+
response = 200;
86+
}
87+
8188
SyncTask newSyncTask = new SyncTask();
8289
newSyncTask.setDateSent(new Date());
8390
newSyncTask.setCreator(Context.getUserService().getUser(1));
8491
newSyncTask.setSentToUrl(syncTaskType.getUrl());
8592
newSyncTask.setRequireAction(true);
8693
newSyncTask.setActionCompleted(false);
8794
newSyncTask.setSyncTask(order.getAccessionNumber());
88-
newSyncTask.setStatusCode((Integer) map.get("responseCode"));
89-
newSyncTask.setStatus((String)map.get("responseMessage"));
95+
newSyncTask.setStatusCode((Integer) response);
96+
newSyncTask.setStatus((String) map.get("responseMessage"));
9097
newSyncTask.setSyncTaskType(ugandaEMRSyncService.getSyncTaskTypeByUUID(VIRAL_LOAD_SYNC_TYPE_UUID));
9198
ugandaEMRSyncService.saveSyncTask(newSyncTask);
9299
}
@@ -97,6 +104,25 @@ public void execute() {
97104
}
98105
}
99106

107+
private Map handleReturnedResponses(Order order, Map response) {
108+
Map responseType = new HashMap<>();
109+
OrderService orderService = Context.getOrderService();
110+
try {
111+
if (response.get("responseCode").equals(400) && response.get("responseMessage").toString().contains("The specimen ID:") && response.get("responseMessage").toString().contains("is not HIE compliant")) {
112+
orderService.discontinueOrder(order, response.get("responseMessage").toString(), new Date(), order.getOrderer(), order.getEncounter());
113+
responseType.put("responseType", "Not HIE compliant");
114+
} else if (response.get("responseCode").equals(400) && response.get("responseMessage").toString().toLowerCase().contains("duplicate")) {
115+
//TODO need to update openmrs version in sync in order to support updating fulfiller status
116+
responseType.put("responseType", "Duplicate");
117+
}
118+
} catch (Exception e) {
119+
log.error(e);
120+
}
121+
122+
return responseType;
123+
}
124+
125+
100126
/**
101127
* @return
102128
*/

0 commit comments

Comments
 (0)