Skip to content

Commit

Permalink
Move processing of HL7 messages to HL7queue (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzy11 authored Dec 9, 2024
1 parent cf29141 commit b13b331
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public interface NotificationsPullPointClient {

List<Message> getNewMessages();
boolean getNewMessages();

List<Message> getNewMessages(Location currentLocation);
boolean getNewMessages(Location currentLocation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,19 +74,20 @@ public class NotificationsPullPointClientImpl extends WebServiceGatewaySupport i


@Override
public List<Message> 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<Location> locations = Context.getLocationService().getLocationsByTag(loginLocationTag);
List<Message> returnMessages = new ArrayList<>();
for (Location location : locations) {
returnMessages.addAll(this.getNewMessages(location));
success = this.getNewMessages(location);
}
return returnMessages;
return success;
}

@Override
public List<Message> getNewMessages(Location currentLocation) {
public boolean getNewMessages(Location currentLocation) {
boolean success = false ;
GetMessages request = new GetMessages();
String siteCode = null;

Expand All @@ -101,7 +103,6 @@ public List<Message> getNewMessages(Location currentLocation) {
currentLocation.getName() + ": " + currentLocation.getId() + ": " + siteCode);
request.getOtherAttributes().put(new QName(FACILITY_QNAME), siteCode);

List<Message> result = new ArrayList<>();
GetMessagesResponse response;
try {
response = getResponseHttpClient(request);
Expand All @@ -117,17 +118,21 @@ public List<Message> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down

0 comments on commit b13b331

Please sign in to comment.