Search in sources :

Example 1 with PatientMigrationRequest

use of uk.nhs.adaptors.connector.model.PatientMigrationRequest in project nia-patient-switching-standard-adaptor by NHSDigital.

the class EhrExtractMessageHandlerTest method When_HandleMessage_WithEncodeToJsonThrows_Expect_DataFormatException.

@Test
public void When_HandleMessage_WithEncodeToJsonThrows_Expect_DataFormatException() throws BundleMappingException, AttachmentNotFoundException, ValidationException, InlineAttachmentProcessingException {
    InboundMessage inboundMessage = new InboundMessage();
    inboundMessage.setPayload(readInboundMessagePayloadFromFile());
    Bundle bundle = new Bundle();
    bundle.setId("Test");
    inboundMessage.setPayload(readInboundMessagePayloadFromFile());
    inboundMessage.setExternalAttachments(new ArrayList<>());
    PatientMigrationRequest migrationRequest = PatientMigrationRequest.builder().losingPracticeOdsCode(LOSING_ODE_CODE).winningPracticeOdsCode(WINNING_ODE_CODE).build();
    when(bundleMapperService.mapToBundle(any(RCMRIN030000UK06Message.class), eq(LOSING_ODE_CODE))).thenReturn(bundle);
    when(migrationRequestDao.getMigrationRequest(CONVERSATION_ID)).thenReturn(migrationRequest);
    when(attachmentReferenceUpdaterService.updateReferenceToAttachment(inboundMessage.getAttachments(), CONVERSATION_ID, inboundMessage.getPayload())).thenReturn(inboundMessage.getPayload());
    doThrow(new DataFormatException()).when(fhirParser).encodeToJson(bundle);
    assertThrows(DataFormatException.class, () -> ehrExtractMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID));
}
Also used : PatientMigrationRequest(uk.nhs.adaptors.connector.model.PatientMigrationRequest) DataFormatException(ca.uhn.fhir.parser.DataFormatException) Bundle(org.hl7.fhir.dstu3.model.Bundle) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) Test(org.junit.jupiter.api.Test)

Example 2 with PatientMigrationRequest

use of uk.nhs.adaptors.connector.model.PatientMigrationRequest in project nia-patient-switching-standard-adaptor by NHSDigital.

the class COPCMessageHandlerTest method prepareMocks.

private void prepareMocks() {
    PatientMigrationRequest migrationRequest = PatientMigrationRequest.builder().id(1).losingPracticeOdsCode(LOSING_ODE_CODE).winningPracticeOdsCode(WINNING_ODE_CODE).build();
    when(migrationRequestDao.getMigrationRequest(CONVERSATION_ID)).thenReturn(migrationRequest);
}
Also used : PatientMigrationRequest(uk.nhs.adaptors.connector.model.PatientMigrationRequest)

Example 3 with PatientMigrationRequest

use of uk.nhs.adaptors.connector.model.PatientMigrationRequest 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 4 with PatientMigrationRequest

use of uk.nhs.adaptors.connector.model.PatientMigrationRequest 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 5 with PatientMigrationRequest

use of uk.nhs.adaptors.connector.model.PatientMigrationRequest in project nia-patient-switching-standard-adaptor by NHSDigital.

the class PatientTransferServiceTest method handlePatientMigrationRequestWhenRequestIsInProgress.

@Test
public void handlePatientMigrationRequestWhenRequestIsInProgress() {
    PatientMigrationRequest expectedPatientMigrationRequest = createPatientMigrationRequest();
    MigrationStatusLog expectedMigrationStatusLog = createMigrationStatusLog();
    when(mdcService.getConversationId()).thenReturn(CONVERSATION_ID);
    when(patientMigrationRequestDao.getMigrationRequest(CONVERSATION_ID)).thenReturn(expectedPatientMigrationRequest);
    when(migrationStatusLogDao.getLatestMigrationStatusLog(expectedPatientMigrationRequest.getId())).thenReturn(expectedMigrationStatusLog);
    MigrationStatusLog patientMigrationRequest = service.handlePatientMigrationRequest(parameters, HEADERS);
    assertThat(patientMigrationRequest).isEqualTo(expectedMigrationStatusLog);
    verifyNoInteractions(pssQueuePublisher);
    verify(patientMigrationRequestDao).getMigrationRequest(CONVERSATION_ID);
    verifyNoMoreInteractions(patientMigrationRequestDao);
}
Also used : PatientMigrationRequest(uk.nhs.adaptors.connector.model.PatientMigrationRequest) MigrationStatusLog(uk.nhs.adaptors.connector.model.MigrationStatusLog) Test(org.junit.jupiter.api.Test)

Aggregations

PatientMigrationRequest (uk.nhs.adaptors.connector.model.PatientMigrationRequest)13 Test (org.junit.jupiter.api.Test)5 InlineAttachmentProcessingException (uk.nhs.adaptors.pss.translator.exception.InlineAttachmentProcessingException)5 InboundMessage (uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage)5 RCMRIN030000UK06Message (org.hl7.v3.RCMRIN030000UK06Message)4 SAXException (org.xml.sax.SAXException)4 BundleMappingException (uk.nhs.adaptors.pss.translator.exception.BundleMappingException)4 XmlUnmarshallUtil.unmarshallString (uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ParseException (java.text.ParseException)3 ValidationException (javax.xml.bind.ValidationException)3 Document (org.w3c.dom.Document)3 MigrationStatusLog (uk.nhs.adaptors.connector.model.MigrationStatusLog)3 PatientAttachmentLog (uk.nhs.adaptors.connector.model.PatientAttachmentLog)3 AttachmentNotFoundException (uk.nhs.adaptors.pss.translator.exception.AttachmentNotFoundException)3 DataFormatException (ca.uhn.fhir.parser.DataFormatException)2 JAXBException (javax.xml.bind.JAXBException)2 Bundle (org.hl7.fhir.dstu3.model.Bundle)2 COPCIN000001UK01Message (org.hl7.v3.COPCIN000001UK01Message)2 ArrayList (java.util.ArrayList)1