Search in sources :

Example 6 with RCMRIN030000UK06Message

use of org.hl7.v3.RCMRIN030000UK06Message in project nia-patient-switching-standard-adaptor by NHSDigital.

the class NackAckPreparationServiceTest method When_SendNackMessageRCMR_WithGeneralFailure_Expect_ShouldHaveCorrectNackCode.

@Test
public void When_SendNackMessageRCMR_WithGeneralFailure_Expect_ShouldHaveCorrectNackCode() throws JAXBException {
    RCMRIN030000UK06Message payload = unmarshallString(readInboundMessagePayloadFromFile(), RCMRIN030000UK06Message.class);
    nackAckPreparationService.sendNackMessage(NACKReason.LARGE_MESSAGE_GENERAL_FAILURE, payload, CONVERSATION_ID);
    verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture());
    assertEquals("30", ackMessageDataCaptor.getValue().getNackCode());
}
Also used : RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) Test(org.junit.jupiter.api.Test)

Example 7 with RCMRIN030000UK06Message

use of org.hl7.v3.RCMRIN030000UK06Message in project nia-patient-switching-standard-adaptor by NHSDigital.

the class NackAckPreparationServiceTest method When_SendNackMessageRCMR_WithEHRExtractCannotBeProcessed_Expect_ShouldHaveCorrectNackCode.

@Test
public void When_SendNackMessageRCMR_WithEHRExtractCannotBeProcessed_Expect_ShouldHaveCorrectNackCode() throws JAXBException {
    RCMRIN030000UK06Message payload = unmarshallString(readInboundMessagePayloadFromFile(), RCMRIN030000UK06Message.class);
    nackAckPreparationService.sendNackMessage(NACKReason.EHR_EXTRACT_CANNOT_BE_PROCESSED, payload, CONVERSATION_ID);
    verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture());
    assertEquals("21", ackMessageDataCaptor.getValue().getNackCode());
}
Also used : RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) Test(org.junit.jupiter.api.Test)

Example 8 with RCMRIN030000UK06Message

use of org.hl7.v3.RCMRIN030000UK06Message in project nia-patient-switching-standard-adaptor by NHSDigital.

the class NackAckPreparationServiceTest method When_SendNackMessageRCMR_WithNoErrors_Expect_ShouldUpdateLog.

@Test
public void When_SendNackMessageRCMR_WithNoErrors_Expect_ShouldUpdateLog() throws JAXBException {
    RCMRIN030000UK06Message payload = unmarshallString(readInboundMessagePayloadFromFile(), RCMRIN030000UK06Message.class);
    when(sendNACKMessageHandler.prepareAndSendMessage(any(NACKMessageData.class))).thenReturn(true);
    assertTrue(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) RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) Test(org.junit.jupiter.api.Test)

Example 9 with RCMRIN030000UK06Message

use of org.hl7.v3.RCMRIN030000UK06Message in project nia-patient-switching-standard-adaptor by NHSDigital.

the class EhrExtractMessageHandler method handleMessage.

public void handleMessage(InboundMessage inboundMessage, String conversationId) throws JAXBException, JsonProcessingException, InlineAttachmentProcessingException, BundleMappingException, AttachmentNotFoundException, ParseException, SAXException {
    RCMRIN030000UK06Message payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
    PatientMigrationRequest migrationRequest = migrationRequestDao.getMigrationRequest(conversationId);
    MigrationStatusLog migrationStatusLog = migrationStatusLogService.getLatestMigrationStatusLog(conversationId);
    migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_RECEIVED, conversationId);
    try {
        Document ebXmlDocument = getEbXmlDocument(inboundMessage);
        String messageId = xPathService.getNodeValue(ebXmlDocument, MESSAGE_ID_PATH);
        boolean hasExternalAttachment = !(inboundMessage.getExternalAttachments() == null || inboundMessage.getExternalAttachments().isEmpty());
        // Manage attachments against the EHR message
        var attachments = inboundMessage.getAttachments();
        if (attachments != null) {
            attachmentHandlerService.storeAttachments(attachments, conversationId);
            for (var i = 0; i < attachments.size(); i++) {
                var attachment = attachments.get(i);
                PatientAttachmentLog newAttachmentLog = buildPatientAttachmentLogFromAttachment(messageId, migrationRequest, attachment);
                patientAttachmentLogService.addAttachmentLog(newAttachmentLog);
            }
        }
        if (!hasExternalAttachment) {
            var fileUpdatedPayload = attachmentReferenceUpdaterService.updateReferenceToAttachment(inboundMessage.getAttachments(), conversationId, inboundMessage.getPayload());
            inboundMessage.setPayload(fileUpdatedPayload);
            payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
            var bundle = bundleMapperService.mapToBundle(payload, migrationRequest.getLosingPracticeOdsCode());
            migrationStatusLogService.updatePatientMigrationRequestAndAddMigrationStatusLog(conversationId, fhirParser.encodeToJson(bundle), objectMapper.writeValueAsString(inboundMessage), EHR_EXTRACT_TRANSLATED);
            nackAckPreparationService.sendAckMessage(payload, conversationId);
        }
        // sending continue message
        if (hasExternalAttachment) {
            String patientNhsNumber = XmlParseUtilService.parseNhsNumber(payload);
            for (InboundMessage.ExternalAttachment externalAttachment : inboundMessage.getExternalAttachments()) {
                PatientAttachmentLog patientAttachmentLog;
                // save COPC_UK01 messages
                patientAttachmentLog = buildPatientAttachmentLogFromExternalAttachment(migrationRequest, externalAttachment);
                patientAttachmentLogService.addAttachmentLog(patientAttachmentLog);
            }
            migrationStatusLogService.updatePatientMigrationRequestAndAddMigrationStatusLog(conversationId, null, objectMapper.writeValueAsString(inboundMessage), EHR_EXTRACT_TRANSLATED);
            sendContinueRequest(payload, conversationId, patientNhsNumber, migrationRequest.getWinningPracticeOdsCode(), migrationStatusLog.getDate().toInstant());
        }
    } catch (BundleMappingException | DataFormatException | JsonProcessingException | InlineAttachmentProcessingException | AttachmentNotFoundException | SAXException | StorageException ex) {
        nackAckPreparationService.sendNackMessage(EHR_EXTRACT_CANNOT_BE_PROCESSED, payload, conversationId);
        throw ex;
    } catch (ParseException ex) {
        throw ex;
    }
}
Also used : AttachmentNotFoundException(uk.nhs.adaptors.pss.translator.exception.AttachmentNotFoundException) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) XmlUnmarshallUtil.unmarshallString(uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) PatientMigrationRequest(uk.nhs.adaptors.connector.model.PatientMigrationRequest) DataFormatException(ca.uhn.fhir.parser.DataFormatException) PatientAttachmentLog(uk.nhs.adaptors.connector.model.PatientAttachmentLog) MigrationStatusLog(uk.nhs.adaptors.connector.model.MigrationStatusLog) BundleMappingException(uk.nhs.adaptors.pss.translator.exception.BundleMappingException) ParseException(java.text.ParseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StorageException(uk.nhs.adaptors.pss.translator.storage.StorageException) RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) InlineAttachmentProcessingException(uk.nhs.adaptors.pss.translator.exception.InlineAttachmentProcessingException)

Example 10 with RCMRIN030000UK06Message

use of org.hl7.v3.RCMRIN030000UK06Message in project nia-patient-switching-standard-adaptor by NHSDigital.

the class EHRTimeoutHandler method sendNackMessage.

private void sendNackMessage(InboundMessage inboundMessage, String conversationId) throws JAXBException {
    RCMRIN030000UK06Message payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
    NACKMessageData messageData = NACKMessageData.builder().nackCode(LARGE_MESSAGE_TIMEOUT.getCode()).fromAsid(outboundMessageUtil.parseFromAsid(payload)).toAsid(outboundMessageUtil.parseToAsid(payload)).toOdsCode(outboundMessageUtil.parseToOdsCode(payload)).messageRef(outboundMessageUtil.parseMessageRef(payload)).conversationId(conversationId).build();
    LOGGER.debug("EHR Extract message timed out: sending NACK message");
    migrationStatusLogService.addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId);
    sendNACKMessageHandler.prepareAndSendMessage(messageData);
}
Also used : NACKMessageData(uk.nhs.adaptors.pss.translator.model.NACKMessageData) RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message)

Aggregations

RCMRIN030000UK06Message (org.hl7.v3.RCMRIN030000UK06Message)16 Test (org.junit.jupiter.api.Test)13 NACKMessageData (uk.nhs.adaptors.pss.translator.model.NACKMessageData)4 BundleMappingException (uk.nhs.adaptors.pss.translator.exception.BundleMappingException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Bundle (org.hl7.fhir.dstu3.model.Bundle)2 Organization (org.hl7.fhir.dstu3.model.Organization)2 RCMRMT030101UK04EhrExtract (org.hl7.v3.RCMRMT030101UK04EhrExtract)2 SAXException (org.xml.sax.SAXException)2 PatientMigrationRequest (uk.nhs.adaptors.connector.model.PatientMigrationRequest)2 AttachmentNotFoundException (uk.nhs.adaptors.pss.translator.exception.AttachmentNotFoundException)2 InlineAttachmentProcessingException (uk.nhs.adaptors.pss.translator.exception.InlineAttachmentProcessingException)2 XmlUnmarshallUtil.unmarshallString (uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString)2 DataFormatException (ca.uhn.fhir.parser.DataFormatException)1 ParseException (java.text.ParseException)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 ValidationException (javax.xml.bind.ValidationException)1