use of org.hl7.v3.COPCIN000001UK01Message in project nia-patient-switching-standard-adaptor by NHSDigital.
the class COPCMessageHandler method handleMessage.
public void handleMessage(InboundMessage inboundMessage, String conversationId) throws JAXBException, InlineAttachmentProcessingException, SAXException, AttachmentLogException, AttachmentNotFoundException, BundleMappingException, JsonProcessingException {
COPCIN000001UK01Message payload = unmarshallString(inboundMessage.getPayload(), COPCIN000001UK01Message.class);
PatientMigrationRequest migrationRequest = migrationRequestDao.getMigrationRequest(conversationId);
try {
Document ebXmlDocument = getEbXmlDocument(inboundMessage);
String messageId = xPathService.getNodeValue(ebXmlDocument, MESSAGE_ID_PATH);
PatientAttachmentLog patientAttachmentLog = patientAttachmentLogService.findAttachmentLog(messageId, conversationId);
// If there is no PatientAttachmentLog for this message then we have receieved a message out of order
if (patientAttachmentLog == null) {
addLogForEarlyFragmentAndStore(inboundMessage, conversationId, payload, ebXmlDocument, migrationRequest.getId());
} else {
if (isManifestMessage(ebXmlDocument)) {
extractFragmentsAndLog(migrationRequest, patientAttachmentLog, conversationId, inboundMessage);
} else {
storeCOPCAttachment(patientAttachmentLog, inboundMessage, conversationId);
patientAttachmentLog.setUploaded(true);
patientAttachmentLogService.updateAttachmentLog(patientAttachmentLog, conversationId);
}
}
nackAckPreparationService.sendAckMessage(payload, conversationId, migrationRequest.getLosingPracticeOdsCode());
checkAndMergeFileParts(inboundMessage, conversationId);
// merge and uncompress large EHR message
if (inboundMessageMergingService.canMergeCompleteBundle(conversationId)) {
inboundMessageMergingService.mergeAndBundleMessage(conversationId);
}
} catch (ParseException | InlineAttachmentProcessingException | ValidationException | SAXException e) {
LOGGER.error("failed to parse COPC_IN000001UK01 ebxml: " + "failed to extract \"mid:\" from xlink:href, before sending the continue message", e);
nackAckPreparationService.sendNackMessage(EHR_EXTRACT_CANNOT_BE_PROCESSED, payload, conversationId);
}
}
use of org.hl7.v3.COPCIN000001UK01Message in project nia-patient-switching-standard-adaptor by NHSDigital.
the class NackAckPreparationServiceTest method When_SendNackMessageCOPC_WithGeneralFailure_Expect_ShouldHaveCorrectNackCode.
@Test
public void When_SendNackMessageCOPC_WithGeneralFailure_Expect_ShouldHaveCorrectNackCode() throws JAXBException {
COPCIN000001UK01Message payload = unmarshallString(readSubsequentInboundMessagePayloadFromFile(), COPCIN000001UK01Message.class);
nackAckPreparationService.sendNackMessage(NACKReason.LARGE_MESSAGE_GENERAL_FAILURE, payload, CONVERSATION_ID);
verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture());
assertEquals("30", ackMessageDataCaptor.getValue().getNackCode());
}
use of org.hl7.v3.COPCIN000001UK01Message in project nia-patient-switching-standard-adaptor by NHSDigital.
the class NackAckPreparationServiceTest method When_SendNackMessageCOPC_WithEHRExtractCannotBeProcessed_Expect_ShouldHaveCorrectNackCode.
@Test
public void When_SendNackMessageCOPC_WithEHRExtractCannotBeProcessed_Expect_ShouldHaveCorrectNackCode() throws JAXBException {
COPCIN000001UK01Message payload = unmarshallString(readSubsequentInboundMessagePayloadFromFile(), COPCIN000001UK01Message.class);
nackAckPreparationService.sendNackMessage(NACKReason.EHR_EXTRACT_CANNOT_BE_PROCESSED, payload, CONVERSATION_ID);
verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture());
assertEquals("21", ackMessageDataCaptor.getValue().getNackCode());
}
use of org.hl7.v3.COPCIN000001UK01Message in project nia-patient-switching-standard-adaptor by NHSDigital.
the class NackAckPreparationServiceTest method When_SendNackMessageCOPC_WithErrors_Expect_ShouldUpdateLog.
@Test
public void When_SendNackMessageCOPC_WithErrors_Expect_ShouldUpdateLog() throws JAXBException {
COPCIN000001UK01Message payload = unmarshallString(readSubsequentInboundMessagePayloadFromFile(), COPCIN000001UK01Message.class);
when(sendNACKMessageHandler.prepareAndSendMessage(any(NACKMessageData.class))).thenReturn(false);
assertFalse(nackAckPreparationService.sendNackMessage(NACKReason.LARGE_MESSAGE_GENERAL_FAILURE, payload, CONVERSATION_ID));
verify(migrationStatusLogService).addMigrationStatusLog(ERROR_LRG_MSG_GENERAL_FAILURE, CONVERSATION_ID);
}
use of org.hl7.v3.COPCIN000001UK01Message in project nia-patient-switching-standard-adaptor by NHSDigital.
the class NackAckPreparationServiceTest method When_SendNackMessageCOPC_WithValidParameters_Expect_ShouldParseMessageDataCorrectly.
@Test
public void When_SendNackMessageCOPC_WithValidParameters_Expect_ShouldParseMessageDataCorrectly() throws JAXBException {
NACKMessageData expectedMessageData = NACKMessageData.builder().nackCode(TEST_NACK_CODE).toOdsCode(TEST_TO_ODS).toAsid(TEST_TO_ASID).fromAsid(TEST_FROM_ASID).conversationId(CONVERSATION_ID).messageRef(TEST_MESSAGE_REF).build();
COPCIN000001UK01Message payload = unmarshallString(readSubsequentInboundMessagePayloadFromFile(), COPCIN000001UK01Message.class);
nackAckPreparationService.sendNackMessage(NACKReason.LARGE_MESSAGE_GENERAL_FAILURE, payload, CONVERSATION_ID);
verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture());
assertEquals(expectedMessageData, ackMessageDataCaptor.getValue());
}
Aggregations