diff --git a/api/src/main/java/org/openmrs/module/xdssender/api/notificationspullpoint/NotificationsPullPointClient.java b/api/src/main/java/org/openmrs/module/xdssender/api/notificationspullpoint/NotificationsPullPointClient.java index 686165e..d2cc80a 100644 --- a/api/src/main/java/org/openmrs/module/xdssender/api/notificationspullpoint/NotificationsPullPointClient.java +++ b/api/src/main/java/org/openmrs/module/xdssender/api/notificationspullpoint/NotificationsPullPointClient.java @@ -8,7 +8,7 @@ public interface NotificationsPullPointClient { - List getNewMessages(); + boolean getNewMessages(); - List getNewMessages(Location currentLocation); + boolean getNewMessages(Location currentLocation); } diff --git a/api/src/main/java/org/openmrs/module/xdssender/api/notificationspullpoint/impl/NotificationsPullPointClientImpl.java b/api/src/main/java/org/openmrs/module/xdssender/api/notificationspullpoint/impl/NotificationsPullPointClientImpl.java index 068ac9d..364e0e4 100644 --- a/api/src/main/java/org/openmrs/module/xdssender/api/notificationspullpoint/impl/NotificationsPullPointClientImpl.java +++ b/api/src/main/java/org/openmrs/module/xdssender/api/notificationspullpoint/impl/NotificationsPullPointClientImpl.java @@ -24,6 +24,7 @@ import org.openmrs.LocationAttribute; import org.openmrs.LocationTag; import org.openmrs.api.context.Context; +import org.openmrs.hl7.HL7InQueue; import org.openmrs.hl7.HL7Service; import org.openmrs.module.labintegration.api.hl7.messages.util.OruR01Util; import org.openmrs.module.xdssender.XdsSenderConfig; @@ -73,19 +74,20 @@ public class NotificationsPullPointClientImpl extends WebServiceGatewaySupport i @Override - public List getNewMessages() { + public boolean getNewMessages() { + boolean success = false ; lastRequestDate = Context.getAdministrationService().getGlobalProperty(XdsSenderConstants.PULL_NOTIFICATIONS_TASK_LAST_SUCCESS_RUN , ""); LocationTag loginLocationTag = Context.getLocationService().getLocationTagByName(LOCATION_TAG_NAME); List locations = Context.getLocationService().getLocationsByTag(loginLocationTag); - List returnMessages = new ArrayList<>(); for (Location location : locations) { - returnMessages.addAll(this.getNewMessages(location)); + success = this.getNewMessages(location); } - return returnMessages; + return success; } @Override - public List getNewMessages(Location currentLocation) { + public boolean getNewMessages(Location currentLocation) { + boolean success = false ; GetMessages request = new GetMessages(); String siteCode = null; @@ -101,7 +103,6 @@ public List getNewMessages(Location currentLocation) { currentLocation.getName() + ": " + currentLocation.getId() + ": " + siteCode); request.getOtherAttributes().put(new QName(FACILITY_QNAME), siteCode); - List result = new ArrayList<>(); GetMessagesResponse response; try { response = getResponseHttpClient(request); @@ -117,17 +118,21 @@ public List getNewMessages(Location currentLocation) { .replaceAll("\\[[0-9]{4}\\]", "")); log.debug(parsedMessage); - Message message = hl7Service.parseHL7String(parsedMessage); - - result.add(message); + HL7InQueue hl7InQueue = new HL7InQueue(); + hl7InQueue.setHL7Data(parsedMessage); + hl7InQueue.setHL7Source(hl7Service.getHL7Source(1)); + hl7InQueue.setHL7SourceKey(currentLocation.getName()); + hl7Service.saveHL7InQueue(hl7InQueue); + success = true; } } } catch (Exception e) { + success = false; log.error("Error getting response in NotificationsPullPointClientImpl: ", e); } - return result; + return success; } private Object getResponse(Object requestPayload) throws Exception { diff --git a/api/src/main/java/org/openmrs/module/xdssender/api/scheduler/PullNotificationsTask.java b/api/src/main/java/org/openmrs/module/xdssender/api/scheduler/PullNotificationsTask.java index 8fc5313..a2019b3 100644 --- a/api/src/main/java/org/openmrs/module/xdssender/api/scheduler/PullNotificationsTask.java +++ b/api/src/main/java/org/openmrs/module/xdssender/api/scheduler/PullNotificationsTask.java @@ -26,18 +26,8 @@ public class PullNotificationsTask extends AbstractTask { @Override public void execute() { LOGGER.info("Executing " + TASK_NAME); - HL7Service hl7Service = Context.getHL7Service(); - boolean success = false; - for (Message msg : getNotificationsPullPointClient().getNewMessages()) { - try { - hl7Service.processHL7Message(msg); - success = true; - } - catch (Exception e) { - success = false; - LOGGER.error(e.getMessage(), e); - } - } + + boolean success = getNotificationsPullPointClient().getNewMessages(); if(success){ Context.getAdministrationService().setGlobalProperty(XdsSenderConstants.PULL_NOTIFICATIONS_TASK_LAST_SUCCESS_RUN ,DateTimeFormatter.ISO_INSTANT.format(Instant.now()));