Search in sources :

Example 16 with RCMRIN030000UK06Message

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

the class BundleMapperService method mapToBundle.

public Bundle mapToBundle(RCMRIN030000UK06Message xmlMessage, String losingPracticeOdsCode) throws BundleMappingException {
    try {
        Bundle bundle = generator.generateBundle();
        final RCMRMT030101UK04EhrExtract ehrExtract = getEhrExtract(xmlMessage);
        final RCMRMT030101UK04EhrFolder ehrFolder = getEhrFolder(xmlMessage);
        var agents = mapAgentDirectories(ehrFolder);
        var patient = mapPatient(getEhrExtract(xmlMessage), getPatientOrganization(agents));
        addEntry(bundle, patient);
        Organization authorOrg = organizationMapper.mapAuthorOrganization(losingPracticeOdsCode);
        addEntry(bundle, authorOrg);
        addEntries(bundle, agents);
        var mappedEncounterEhrCompositions = mapEncounters(ehrExtract, patient, losingPracticeOdsCode);
        var encounters = handleMappedEncounterResources(mappedEncounterEhrCompositions, bundle);
        var locations = mapLocations(ehrFolder, losingPracticeOdsCode);
        addEntries(bundle, locations);
        var procedureRequests = procedureRequestMapper.mapResources(ehrExtract, patient, encounters, losingPracticeOdsCode);
        addEntries(bundle, procedureRequests);
        var referralRequests = referralRequestMapper.mapResources(ehrExtract, patient, encounters, losingPracticeOdsCode);
        addEntries(bundle, referralRequests);
        var medicationResources = medicationRequestMapper.mapResources(ehrExtract, patient, encounters, losingPracticeOdsCode);
        addEntries(bundle, medicationResources);
        var bloodPressures = bloodPressureMapper.mapResources(ehrExtract, patient, encounters, losingPracticeOdsCode);
        addEntries(bundle, bloodPressures);
        var observations = observationMapper.mapResources(ehrExtract, patient, encounters, losingPracticeOdsCode);
        addEntries(bundle, observations);
        var immunizations = immunizationMapper.mapResources(ehrExtract, patient, encounters, losingPracticeOdsCode);
        addEntries(bundle, immunizations);
        var conditions = conditionMapper.mapResources(ehrExtract, patient, encounters, losingPracticeOdsCode);
        addEntries(bundle, conditions);
        var observationComments = observationCommentMapper.mapResources(ehrExtract, patient, encounters, losingPracticeOdsCode);
        addEntries(bundle, observationComments);
        var documentReferences = documentReferenceMapper.mapResources(ehrExtract, patient, encounters, authorOrg);
        addEntries(bundle, documentReferences);
        var templates = templateMapper.mapResources(ehrExtract, patient, encounters, losingPracticeOdsCode);
        addEntries(bundle, templates);
        var allergyIntolerances = allergyIntoleranceMapper.mapResources(ehrExtract, patient, encounters, losingPracticeOdsCode);
        addEntries(bundle, allergyIntolerances);
        mapDiagnosticReports(bundle, ehrExtract, patient, encounters, observations, observationComments, losingPracticeOdsCode);
        conditionMapper.addReferences(bundle, conditions, ehrExtract);
        unknownPractitionerHandler.updateUnknownPractitionersRefs(bundle);
        LOGGER.debug("Mapped Bundle with [{}] entries", bundle.getEntry().size());
        return bundle;
    } catch (Exception e) {
        throw new BundleMappingException(e.getMessage());
    }
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) RCMRMT030101UK04EhrExtract(org.hl7.v3.RCMRMT030101UK04EhrExtract) Bundle(org.hl7.fhir.dstu3.model.Bundle) RCMRMT030101UK04EhrFolder(org.hl7.v3.RCMRMT030101UK04EhrFolder) BundleMappingException(uk.nhs.adaptors.pss.translator.exception.BundleMappingException) BundleMappingException(uk.nhs.adaptors.pss.translator.exception.BundleMappingException)

Example 17 with RCMRIN030000UK06Message

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

the class InboundMessageMergingService method mergeAndBundleMessage.

public void mergeAndBundleMessage(String conversationId) throws JAXBException, JsonProcessingException {
    if (!StringUtils.hasText(conversationId)) {
        throw new ValidationException(CONVERSATION_ID_HAS_NOT_BEEN_GIVEN);
    }
    PatientMigrationRequest migrationRequest = migrationRequestDao.getMigrationRequest(conversationId);
    var inboundMessage = objectMapper.readValue(migrationRequest.getInboundMessage(), InboundMessage.class);
    RCMRIN030000UK06Message payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
    try {
        var attachmentLogs = getUndeletedLogsForConversation(conversationId);
        var attachmentsContainSkeletonMessage = attachmentLogs.stream().anyMatch(log -> log.getSkeleton().equals(true));
        if (attachmentsContainSkeletonMessage) {
            findAndReplaceSkeleton(attachmentLogs, inboundMessage, conversationId);
        }
        // process attachments
        var bypassPayloadLoadingArray = new String[attachmentLogs.size()];
        Arrays.fill(bypassPayloadLoadingArray, "");
        var messageAttachments = attachmentHandlerService.buildInboundAttachmentsFromAttachmentLogs(attachmentLogs, Arrays.asList(bypassPayloadLoadingArray), conversationId);
        var newPayloadStr = attachmentReferenceUpdaterService.updateReferenceToAttachment(messageAttachments, conversationId, inboundMessage.getPayload());
        // process bundle
        inboundMessage.setPayload(newPayloadStr);
        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);
    } catch (InlineAttachmentProcessingException | SAXException | TransformerException | BundleMappingException | JAXBException | AttachmentNotFoundException | JsonProcessingException e) {
        LOGGER.error("failed to merge Large Message Parts", e);
        nackAckPreparationService.sendNackMessage(EHR_EXTRACT_CANNOT_BE_PROCESSED, payload, conversationId);
    }
}
Also used : AttachmentNotFoundException(uk.nhs.adaptors.pss.translator.exception.AttachmentNotFoundException) ValidationException(javax.xml.bind.ValidationException) JAXBException(javax.xml.bind.JAXBException) XmlUnmarshallUtil.unmarshallString(uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString) SAXException(org.xml.sax.SAXException) PatientMigrationRequest(uk.nhs.adaptors.connector.model.PatientMigrationRequest) BundleMappingException(uk.nhs.adaptors.pss.translator.exception.BundleMappingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TransformerException(javax.xml.transform.TransformerException) RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) InlineAttachmentProcessingException(uk.nhs.adaptors.pss.translator.exception.InlineAttachmentProcessingException)

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