Search in sources :

Example 6 with COPCIN000001UK01Message

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);
    }
}
Also used : PatientMigrationRequest(uk.nhs.adaptors.connector.model.PatientMigrationRequest) ValidationException(javax.xml.bind.ValidationException) PatientAttachmentLog(uk.nhs.adaptors.connector.model.PatientAttachmentLog) XmlUnmarshallUtil.unmarshallString(uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString) ParseException(java.text.ParseException) Document(org.w3c.dom.Document) COPCIN000001UK01Message(org.hl7.v3.COPCIN000001UK01Message) InlineAttachmentProcessingException(uk.nhs.adaptors.pss.translator.exception.InlineAttachmentProcessingException) SAXException(org.xml.sax.SAXException)

Example 7 with COPCIN000001UK01Message

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());
}
Also used : COPCIN000001UK01Message(org.hl7.v3.COPCIN000001UK01Message) Test(org.junit.jupiter.api.Test)

Example 8 with COPCIN000001UK01Message

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());
}
Also used : COPCIN000001UK01Message(org.hl7.v3.COPCIN000001UK01Message) Test(org.junit.jupiter.api.Test)

Example 9 with COPCIN000001UK01Message

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);
}
Also used : NACKMessageData(uk.nhs.adaptors.pss.translator.model.NACKMessageData) COPCIN000001UK01Message(org.hl7.v3.COPCIN000001UK01Message) Test(org.junit.jupiter.api.Test)

Example 10 with COPCIN000001UK01Message

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());
}
Also used : NACKMessageData(uk.nhs.adaptors.pss.translator.model.NACKMessageData) COPCIN000001UK01Message(org.hl7.v3.COPCIN000001UK01Message) Test(org.junit.jupiter.api.Test)

Aggregations

COPCIN000001UK01Message (org.hl7.v3.COPCIN000001UK01Message)12 Test (org.junit.jupiter.api.Test)11 NACKMessageData (uk.nhs.adaptors.pss.translator.model.NACKMessageData)3 ParseException (java.text.ParseException)1 ValidationException (javax.xml.bind.ValidationException)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1 PatientAttachmentLog (uk.nhs.adaptors.connector.model.PatientAttachmentLog)1 PatientMigrationRequest (uk.nhs.adaptors.connector.model.PatientMigrationRequest)1 InlineAttachmentProcessingException (uk.nhs.adaptors.pss.translator.exception.InlineAttachmentProcessingException)1 XmlUnmarshallUtil.unmarshallString (uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString)1