Skip to content

Commit

Permalink
Simplify the JAXB classes, by combining the 06 and 07 classes into one (
Browse files Browse the repository at this point in the history
#711)

This duplication was causing a bug within the COPCMessageHandler where
the handler was trying to unmarshall an 07 message into an 06 class.

By combining the two classes into one we remove this whole class of
defect.
  • Loading branch information
adrianclay authored Jul 19, 2024
1 parent 201aaa5 commit 3258109
Show file tree
Hide file tree
Showing 31 changed files with 628 additions and 1,792 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.hl7.fhir.dstu3.model.Practitioner;
import org.hl7.fhir.dstu3.model.PractitionerRole;
import org.hl7.fhir.dstu3.model.ResourceType;
import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UKMessage;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
Expand Down Expand Up @@ -160,8 +160,8 @@ public void When_MappingBundle_With_DocumentsAndMatchingRepresentedOrganisation_
}

@SneakyThrows
private RCMRIN030000UK06Message unmarshallEhrExtractFromFile(String filename) {
return unmarshallFile(getFile("classpath:" + XML_RESOURCES_BASE + filename), RCMRIN030000UK06Message.class);
private RCMRIN030000UKMessage unmarshallEhrExtractFromFile(String filename) {
return unmarshallFile(getFile("classpath:" + XML_RESOURCES_BASE + filename), RCMRIN030000UKMessage.class);
}

private List<Organization> extractOrganisationsFromBundle(Bundle bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UKMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -44,7 +44,7 @@ public class AcknowledgeRecordService {
);

public boolean prepareAndSendAcknowledgementMessage(AcknowledgeRecordMessage acknowledgeRecordMessage) {
RCMRIN030000UK06Message message;
RCMRIN030000UKMessage message;

try {
message = parseOriginalMessage(acknowledgeRecordMessage);
Expand All @@ -67,12 +67,12 @@ public boolean prepareAndSendAcknowledgementMessage(AcknowledgeRecordMessage ack
return nackAckPrepInterface.sendNackMessage(nackReason, message, conversationId);
}

private RCMRIN030000UK06Message parseOriginalMessage(AcknowledgeRecordMessage message)
private RCMRIN030000UKMessage parseOriginalMessage(AcknowledgeRecordMessage message)
throws JAXBException, JsonProcessingException {
var payload = objectMapper.readValue(message.getOriginalMessage(), InboundMessage.class)
.getPayload();

return unmarshallString(payload, RCMRIN030000UK06Message.class);
return unmarshallString(payload, RCMRIN030000UKMessage.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.hl7.fhir.dstu3.model.Organization;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.ResourceType;
import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UK07Message;
import org.hl7.v3.RCMRIN030000UKMessage;
import org.hl7.v3.RCMRMT030101UKComponent3;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
Expand Down Expand Up @@ -249,30 +247,11 @@ private Organization getPatientOrganization(List<? extends DomainResource> agent
}

private RCMRMT030101UKEhrFolder getEhrFolder(RCMRIN030000UKMessage xmlMessage) {
if (xmlMessage instanceof RCMRIN030000UK07Message rcmrin030000uk07message) {

return rcmrin030000uk07message.getControlActEvent()
.getSubject()
.getEhrExtract()
.getComponent()
.get(0)
.getEhrFolder();
} else {
return ((RCMRIN030000UK06Message) xmlMessage).getControlActEvent()
.getSubject()
.getEhrExtract()
.getComponent()
.get(0)
.getEhrFolder();
}
return getEhrExtract(xmlMessage).getComponent().get(0).getEhrFolder();
}

private RCMRMT030101UKEhrExtract getEhrExtract(RCMRIN030000UKMessage xmlMessage) {
if (xmlMessage instanceof RCMRIN030000UK07Message rcmrin030000uk07message) {
return rcmrin030000uk07message.getControlActEvent().getSubject().getEhrExtract();
} else {
return ((RCMRIN030000UK06Message) xmlMessage).getControlActEvent().getSubject().getEhrExtract();
}
return xmlMessage.getControlActEvent().getSubject().getEhrExtract();
}

private <T extends DomainResource> void addEntries(Bundle bundle, Collection<T> resources) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import jakarta.xml.bind.ValidationException;
import javax.xml.transform.TransformerException;

import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UKMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void mergeAndBundleMessage(String conversationId) throws JAXBException, J

PatientMigrationRequest migrationRequest = migrationRequestDao.getMigrationRequest(conversationId);
var inboundMessage = objectMapper.readValue(migrationRequest.getInboundMessage(), InboundMessage.class);
RCMRIN030000UK06Message payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
RCMRIN030000UKMessage payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UKMessage.class);

try {
var attachmentLogs = getUndeletedLogsForConversation(conversationId);
Expand Down Expand Up @@ -102,7 +102,7 @@ public void mergeAndBundleMessage(String conversationId) throws JAXBException, J

// process bundle
inboundMessage.setPayload(newPayloadStr);
payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UKMessage.class);

var attachments = patientAttachmentLogService.findAttachmentLogs(conversationId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package uk.nhs.adaptors.pss.translator.service;

import org.hl7.v3.COPCIN000001UK01Message;
import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UKMessage;
import uk.nhs.adaptors.pss.translator.model.NACKMessageData;
import uk.nhs.adaptors.pss.translator.model.NACKReason;

public interface NackAckPrepInterface {

boolean sendAckMessage(RCMRIN030000UK06Message payload, String conversationId);
boolean sendAckMessage(RCMRIN030000UKMessage payload, String conversationId);

boolean sendAckMessage(COPCIN000001UK01Message payload, String conversationId, String losingPracticeOdsCode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static uk.nhs.adaptors.common.enums.MigrationStatus.FINAL_ACK_SENT;

import org.hl7.v3.COPCIN000001UK01Message;
import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UKMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -28,7 +27,7 @@ public class NackAckPreparationService implements NackAckPrepInterface {
private final SendACKMessageHandler sendACKMessageHandler;
private final MigrationStatusLogService migrationStatusLogService;

public boolean sendAckMessage(RCMRIN030000UK06Message payload, String conversationId) {
public boolean sendAckMessage(RCMRIN030000UKMessage payload, String conversationId) {

LOGGER.debug("Sending Final ACK message for Conversation ID: [{}]", conversationId);

Expand All @@ -55,8 +54,8 @@ public boolean sendAckMessage(COPCIN000001UK01Message payload, String conversati
));
}

private ACKMessageData prepareAckMessageData(RCMRIN030000UK06Message payload,
String conversationId) {
private ACKMessageData prepareAckMessageData(RCMRIN030000UKMessage payload,
String conversationId) {

String toOdsCode = XmlParseUtilService.parseToOdsCode(payload);
String messageRef = XmlParseUtilService.parseMessageRef(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import jakarta.xml.bind.ValidationException;

import org.hl7.v3.COPCIN000001UK01Message;
import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UKMessage;
import org.jdbi.v3.core.ConnectionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -485,7 +485,7 @@ private void failMigration(String conversationId, NACKReason reason) throws Json
PatientMigrationRequest migrationRequest = migrationRequestDao.getMigrationRequest(conversationId);

InboundMessage inboundMessage = inboundMessageUtil.readMessage(migrationRequest.getInboundMessage());
RCMRIN030000UK06Message ehrExtract = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
RCMRIN030000UKMessage ehrExtract = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UKMessage.class);
String ehrExtractMessageId = outboundMessageUtil.parseMessageRef(ehrExtract);

NACKMessageData messageData = NACKMessageData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import lombok.extern.slf4j.Slf4j;

import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UK07Message;
import org.hl7.v3.RCMRIN030000UKMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -75,7 +73,7 @@ public class EhrExtractMessageHandler {

private static final String MESSAGE_ID_PATH = "/Envelope/Header/MessageHeader/MessageData/MessageId";

public void handleMessage(InboundMessage inboundMessage, String conversationId, Class<? extends RCMRIN030000UKMessage> destinationClass)
public void handleMessage(InboundMessage inboundMessage, String conversationId)
throws
JAXBException,
JsonProcessingException,
Expand All @@ -85,7 +83,7 @@ public void handleMessage(InboundMessage inboundMessage, String conversationId,
ParseException,
SAXException, TransformerException {

RCMRIN030000UKMessage payload = unmarshallString(inboundMessage.getPayload(), destinationClass);
RCMRIN030000UKMessage payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UKMessage.class);
PatientMigrationRequest migrationRequest = migrationRequestDao.getMigrationRequest(conversationId);
MigrationStatusLog migrationStatusLog = migrationStatusLogService.getLatestMigrationStatusLog(conversationId);

Expand All @@ -110,7 +108,7 @@ public void handleMessage(InboundMessage inboundMessage, String conversationId,
if (!hasExternalAttachment) {
// If there are no external attachments, process the entire message now
processAndCompleteEHRMessage(inboundMessage, conversationId, skeletonCIDAttachmentLog,
migrationRequest, messageId, destinationClass);
migrationRequest, messageId);
} else {
//process MID messages and send continue message if external messages exist
processExternalAttachmentsAndSendContinueMessage(inboundMessage,
Expand Down Expand Up @@ -167,7 +165,7 @@ private PatientAttachmentLog processInternalAttachmentsAndReturnSkeletonLog(Inbo

private void processAndCompleteEHRMessage(InboundMessage inboundMessage,
String conversationId, PatientAttachmentLog skeletonCIDAttachmentLog,
PatientMigrationRequest migrationRequest, String messageId, Class<? extends RCMRIN030000UKMessage> destinationClass)
PatientMigrationRequest migrationRequest, String messageId)
throws JAXBException, TransformerException,
SAXException, AttachmentNotFoundException, InlineAttachmentProcessingException,
BundleMappingException, JsonProcessingException {
Expand All @@ -192,12 +190,7 @@ private void processAndCompleteEHRMessage(InboundMessage inboundMessage,

// now we have the transformed payload, lets create our bundle
Bundle bundle = null;
RCMRIN030000UKMessage payload = null;
if (destinationClass.getCanonicalName().contains("RCMRIN030000UK07Message")) {
payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK07Message.class);
} else {
payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
}
RCMRIN030000UKMessage payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UKMessage.class);
bundle = bundleMapperService.mapToBundle(payload, migrationRequest.getLosingPracticeOdsCode(), attachments);

// update the db migration request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import jakarta.xml.bind.JAXBException;
import javax.xml.transform.TransformerException;

import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UK07Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -78,10 +76,8 @@ public boolean handleMessage(Message message) {

if (ACKNOWLEDGEMENT_INTERACTION_ID.equals(interactionId)) {
acknowledgmentMessageHandler.handleMessage(inboundMessage, conversationId);
} else if (EHR_EXTRACT_INTERACTION_ID06.equals(interactionId)) {
ehrExtractMessageHandler.handleMessage(inboundMessage, conversationId, RCMRIN030000UK06Message.class);
} else if (EHR_EXTRACT_INTERACTION_ID07.equals(interactionId)) {
ehrExtractMessageHandler.handleMessage(inboundMessage, conversationId, RCMRIN030000UK07Message.class);
} else if (EHR_EXTRACT_INTERACTION_ID06.equals(interactionId) || EHR_EXTRACT_INTERACTION_ID07.equals(interactionId)) {
ehrExtractMessageHandler.handleMessage(inboundMessage, conversationId);
} else if (CONTINUE_ATTACHMENT_INTERACTION_ID.equals(interactionId)) {
continueMessageHandler.handleMessage(inboundMessage, conversationId);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import jakarta.xml.bind.JAXBException;

import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UKMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -180,7 +180,7 @@ private void handleMigrationTimeout(PatientMigrationRequest migrationRequest, NA

private void sendNackMessage(InboundMessage inboundMessage, String conversationId, NACKReason reason) throws JAXBException {

RCMRIN030000UK06Message payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
RCMRIN030000UKMessage payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UKMessage.class);

NACKMessageData messageData = NACKMessageData
.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package uk.nhs.adaptors.pss.translator.util;

import org.hl7.v3.RCMRIN030000UK06Message;
import org.hl7.v3.RCMRIN030000UKMessage;
import org.springframework.stereotype.Component;

@Component
public class OutboundMessageUtil {
public String parseFromAsid(RCMRIN030000UK06Message payload) {
public String parseFromAsid(RCMRIN030000UKMessage payload) {
return payload.getCommunicationFunctionRcv()
.get(0)
.getDevice()
Expand All @@ -14,15 +14,15 @@ public String parseFromAsid(RCMRIN030000UK06Message payload) {
.getExtension();
}

public String parseToAsid(RCMRIN030000UK06Message payload) {
public String parseToAsid(RCMRIN030000UKMessage payload) {
return payload.getCommunicationFunctionSnd()
.getDevice()
.getId()
.get(0)
.getExtension();
}

public String parseToOdsCode(RCMRIN030000UK06Message payload) {
public String parseToOdsCode(RCMRIN030000UKMessage payload) {
return payload.getControlActEvent()
.getSubject()
.getEhrExtract()
Expand All @@ -33,7 +33,7 @@ public String parseToOdsCode(RCMRIN030000UK06Message payload) {
.getExtension();
}

public String parseMessageRef(RCMRIN030000UK06Message payload) {
public String parseMessageRef(RCMRIN030000UKMessage payload) {
return payload.getId().getRoot();
}
}
Loading

0 comments on commit 3258109

Please sign in to comment.