Search in sources :

Example 1 with POCDMT000002UK01ClinicalDocument1

use of uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1 in project integration-adaptor-111 by nhsconnect.

the class AppointmentServiceTest method setUp.

@BeforeEach
public void setUp() {
    clinicalDocument1 = mock(POCDMT000002UK01ClinicalDocument1.class);
    POCDMT000002UK01Component2 component2 = mock(POCDMT000002UK01Component2.class);
    POCDMT000002UK01StructuredBody structuredBody = mock(POCDMT000002UK01StructuredBody.class);
    POCDMT000002UK01Component3 component3 = mock(POCDMT000002UK01Component3.class);
    section = mock(POCDMT000002UK01Section.class);
    patient = mock(Reference.class);
    when(clinicalDocument1.getComponent()).thenReturn(component2);
    when(component2.getStructuredBody()).thenReturn(structuredBody);
    when(structuredBody.getComponentArray()).thenReturn(new POCDMT000002UK01Component3[] { component3 });
    when(component3.getSection()).thenReturn(section);
}
Also used : POCDMT000002UK01Component2(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component2) POCDMT000002UK01StructuredBody(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01StructuredBody) POCDMT000002UK01Component3(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3) POCDMT000002UK01Section(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section) Reference(org.hl7.fhir.dstu3.model.Reference) POCDMT000002UK01ClinicalDocument1(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with POCDMT000002UK01ClinicalDocument1

use of uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1 in project integration-adaptor-111 by nhsconnect.

the class EncounterMapper method getLocationComponents.

private List<EncounterLocationComponent> getLocationComponents(POCDMT000002UK01ClinicalDocument1 clinicalDocument1) {
    List<EncounterLocationComponent> locations = new ArrayList<>();
    if (clinicalDocument1.sizeOfRecordTargetArray() > 0) {
        locations = stream(clinicalDocument1.getRecordTargetArray()).filter(recordTarget -> recordTarget.getPatientRole().getProviderOrganization() != null).map(recordTarget -> recordTarget.getPatientRole().getProviderOrganization()).map(locationMapper::mapOrganizationToLocationComponent).collect(Collectors.toList());
    }
    EncounterLocationComponent healthcareFacility = locationMapper.mapHealthcareFacilityToLocationComponent(clinicalDocument1);
    if (healthcareFacility != null) {
        locations.add(healthcareFacility);
    }
    return locations;
}
Also used : Arrays(java.util.Arrays) REFERRAL(uk.nhs.adaptors.oneoneone.cda.report.enums.MessageHeaderEvent.REFERRAL) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) NodeUtil(uk.nhs.adaptors.oneoneone.cda.report.util.NodeUtil) POCDMT000002UK01Section(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section) AppointmentService(uk.nhs.adaptors.oneoneone.cda.report.service.AppointmentService) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) ArrayList(java.util.ArrayList) Organization(org.hl7.fhir.dstu3.model.Organization) Group(org.hl7.fhir.dstu3.model.Group) Period(org.hl7.fhir.dstu3.model.Period) POCDMT000002UK01ClinicalDocument1(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1) POCDMT000002UK01Component3(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3) EncounterParticipantComponent(org.hl7.fhir.dstu3.model.Encounter.EncounterParticipantComponent) POCDMT000002UK01PatientRole(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01PatientRole) FINISHED(org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED) Reference(org.hl7.fhir.dstu3.model.Reference) EncounterLocationComponent(org.hl7.fhir.dstu3.model.Encounter.EncounterLocationComponent) IVLTS(uk.nhs.connect.iucds.cda.ucr.IVLTS) Collectors(java.util.stream.Collectors) POCDMT000002UK01Entry(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Entry) Encounter(org.hl7.fhir.dstu3.model.Encounter) DISCHARGE_DETAILS(uk.nhs.adaptors.oneoneone.cda.report.enums.MessageHeaderEvent.DISCHARGE_DETAILS) List(java.util.List) Component(org.springframework.stereotype.Component) POCDMT000002UK01Encounter(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Encounter) Narrative(org.hl7.fhir.dstu3.model.Narrative) Patient(org.hl7.fhir.dstu3.model.Patient) GENERATED(org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus.GENERATED) ResourceUtil(uk.nhs.adaptors.oneoneone.cda.report.util.ResourceUtil) Optional(java.util.Optional) POCDMT000002UK01Informant12(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Informant12) AllArgsConstructor(lombok.AllArgsConstructor) Arrays.stream(java.util.Arrays.stream) PractitionerRole(org.hl7.fhir.dstu3.model.PractitionerRole) EncounterLocationComponent(org.hl7.fhir.dstu3.model.Encounter.EncounterLocationComponent) ArrayList(java.util.ArrayList)

Example 3 with POCDMT000002UK01ClinicalDocument1

use of uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1 in project integration-adaptor-111 by nhsconnect.

the class EncounterMapper method getEncounterParticipantComponents.

private List<EncounterParticipantComponent> getEncounterParticipantComponents(POCDMT000002UK01ClinicalDocument1 clinicalDocument, List<PractitionerRole> authorPractitionerRoles, Optional<PractitionerRole> responsibleParty, Encounter encounter) {
    List<EncounterParticipantComponent> encounterParticipantComponents = stream(clinicalDocument.getParticipantArray()).filter(it -> !PARTCIPANT_TYPE_CODE_REFT.equals(it.getTypeCode())).map(participantMapper::mapEncounterParticipant).collect(Collectors.toList());
    if (authorPractitionerRoles.size() > 0) {
        authorPractitionerRoles.stream().map(it -> buildParticipantComponent(it, AUTHOR_PARTICIPANT_CODE, AUTHOR_PARTICIPANT_DISPLAY)).forEach(encounterParticipantComponents::add);
    }
    if (clinicalDocument.sizeOfInformantArray() > 0) {
        stream(clinicalDocument.getInformantArray()).map(informantMapper::mapInformantIntoParticipantComponent).filter(Optional::isPresent).map(Optional::get).forEach(encounterParticipantComponents::add);
        for (POCDMT000002UK01Informant12 informant : clinicalDocument.getInformantArray()) {
            EncounterParticipantComponent encounterParticipantComponent = participantMapper.mapEncounterRelatedPerson(informant, encounter);
            encounterParticipantComponents.add(encounterParticipantComponent);
        }
    }
    if (clinicalDocument.isSetDataEnterer()) {
        encounterParticipantComponents.add(dataEntererMapper.mapDataEntererIntoParticipantComponent(clinicalDocument.getDataEnterer()));
    }
    responsibleParty.ifPresent(it -> encounterParticipantComponents.add(buildParticipantComponent(it, RESPONSIBLE_PARTY_PARTICIPANT_CODE, RESPONSIBLE_PARTY_PARTICIPANT_DISPLAY)));
    return encounterParticipantComponents;
}
Also used : EncounterParticipantComponent(org.hl7.fhir.dstu3.model.Encounter.EncounterParticipantComponent) Arrays(java.util.Arrays) REFERRAL(uk.nhs.adaptors.oneoneone.cda.report.enums.MessageHeaderEvent.REFERRAL) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) NodeUtil(uk.nhs.adaptors.oneoneone.cda.report.util.NodeUtil) POCDMT000002UK01Section(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section) AppointmentService(uk.nhs.adaptors.oneoneone.cda.report.service.AppointmentService) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) ArrayList(java.util.ArrayList) Organization(org.hl7.fhir.dstu3.model.Organization) Group(org.hl7.fhir.dstu3.model.Group) Period(org.hl7.fhir.dstu3.model.Period) POCDMT000002UK01ClinicalDocument1(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1) POCDMT000002UK01Component3(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3) EncounterParticipantComponent(org.hl7.fhir.dstu3.model.Encounter.EncounterParticipantComponent) POCDMT000002UK01PatientRole(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01PatientRole) FINISHED(org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED) Reference(org.hl7.fhir.dstu3.model.Reference) EncounterLocationComponent(org.hl7.fhir.dstu3.model.Encounter.EncounterLocationComponent) IVLTS(uk.nhs.connect.iucds.cda.ucr.IVLTS) Collectors(java.util.stream.Collectors) POCDMT000002UK01Entry(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Entry) Encounter(org.hl7.fhir.dstu3.model.Encounter) DISCHARGE_DETAILS(uk.nhs.adaptors.oneoneone.cda.report.enums.MessageHeaderEvent.DISCHARGE_DETAILS) List(java.util.List) Component(org.springframework.stereotype.Component) POCDMT000002UK01Encounter(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Encounter) Narrative(org.hl7.fhir.dstu3.model.Narrative) Patient(org.hl7.fhir.dstu3.model.Patient) GENERATED(org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus.GENERATED) ResourceUtil(uk.nhs.adaptors.oneoneone.cda.report.util.ResourceUtil) Optional(java.util.Optional) POCDMT000002UK01Informant12(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Informant12) AllArgsConstructor(lombok.AllArgsConstructor) Arrays.stream(java.util.Arrays.stream) PractitionerRole(org.hl7.fhir.dstu3.model.PractitionerRole) POCDMT000002UK01Informant12(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Informant12) Optional(java.util.Optional)

Example 4 with POCDMT000002UK01ClinicalDocument1

use of uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1 in project integration-adaptor-111 by nhsconnect.

the class ReportController method postReport.

@PostMapping(value = "/report", consumes = { APPLICATION_XML_VALUE, TEXT_XML_VALUE }, produces = TEXT_XML_VALUE)
@ResponseStatus(value = ACCEPTED)
public ResponseEntity<String> postReport(@RequestBody String reportXml) {
    String toAddress = null;
    String messageId;
    try {
        ReportItems reportItems = reportParserUtil.parseReportXml(reportXml);
        itkValidator.checkItkConformance(reportItems);
        soapValidator.checkSoapItkConformance(reportItems.getSoapHeader());
        itkAddressValidator.checkItkOdsAndDosId(reportItems.getItkHeader());
        ItkReportHeader headerValues = headerParserUtil.getHeaderValues(reportItems.getItkHeader());
        toAddress = getValueOrDefaultAddress(reportItems.getSoapAddress());
        LOGGER.info("ITK SOAP message received. MessageId: {}, ItkTrackingId: {}", reportItems.getMessageId(), headerValues.getTrackingId());
        DistributionEnvelopeDocument distributionEnvelope = reportRequestUtils.extractDistributionEnvelope(reportItems.getDistributionEnvelope());
        validate(distributionEnvelope);
        POCDMT000002UK01ClinicalDocument1 clinicalDocument = reportRequestUtils.extractClinicalDocument(distributionEnvelope);
        validate(clinicalDocument);
        encounterReportService.transformAndPopulateToGP(clinicalDocument, reportItems.getMessageId(), headerValues);
        return new ResponseEntity<>(itkResponseUtil.createSuccessResponseEntity(reportItems.getMessageId(), randomUUID().toString().toUpperCase()), OK);
    } catch (SAXException e) {
        LOGGER.error(e.getMessage(), e);
        return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, "This is not a valid XML message", e.getMessage()), INTERNAL_SERVER_ERROR);
    } catch (XmlException e) {
        LOGGER.error(e.getMessage(), e);
        return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, "schema validation failed", e.getMessage()), INTERNAL_SERVER_ERROR);
    } catch (ItkXmlException e) {
        LOGGER.error(e.getReason(), e);
        return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, e.getReason(), e.getMessage()), INTERNAL_SERVER_ERROR);
    } catch (SoapClientException e) {
        LOGGER.error(e.getReason(), e);
        return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, e.getReason(), e.getMessage()), INTERNAL_SERVER_ERROR);
    } catch (SoapMustUnderstandException e) {
        LOGGER.error(e.getReason(), e);
        return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_MUSTUNDERSTAND, e.getReason(), e.getMessage()), INTERNAL_SERVER_ERROR);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return new ResponseEntity<>(createErrorResponseBody(toAddress, INTERNAL_PROCESSING_ERROR_CODE, FAULT_CODE_CLIENT, INTERNAL_USER_ERROR_MESSAGE, INTERNAL_ERROR_MESSAGE), INTERNAL_SERVER_ERROR);
    }
}
Also used : SoapMustUnderstandException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapMustUnderstandException) ReportItems(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ReportItems) POCDMT000002UK01ClinicalDocument1(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1) ItkXmlException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.ItkXmlException) XmlException(org.apache.xmlbeans.XmlException) SAXException(org.xml.sax.SAXException) SoapClientException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException) SoapMustUnderstandException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapMustUnderstandException) SAXException(org.xml.sax.SAXException) ResponseEntity(org.springframework.http.ResponseEntity) DistributionEnvelopeDocument(uk.nhs.itk.envelope.DistributionEnvelopeDocument) SoapClientException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException) ItkXmlException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.ItkXmlException) XmlException(org.apache.xmlbeans.XmlException) ItkReportHeader(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader) ItkXmlException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.ItkXmlException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 5 with POCDMT000002UK01ClinicalDocument1

use of uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1 in project integration-adaptor-111 by nhsconnect.

the class ObservationMapper method mapObservations.

public List<Observation> mapObservations(POCDMT000002UK01ClinicalDocument1 clinicalDocument, Encounter encounter) {
    List<Observation> observations = new ArrayList<>();
    POCDMT000002UK01Component2 component = clinicalDocument.getComponent();
    if (component.isSetStructuredBody()) {
        POCDMT000002UK01Component3[] components = component.getStructuredBody().getComponentArray();
        for (POCDMT000002UK01Component3 component3 : components) {
            POCDMT000002UK01Section section = component3.getSection();
            for (POCDMT000002UK01Component5 component5 : section.getComponentArray()) {
                ST title = component5.getSection().getTitle();
                if (nodeUtil.getNodeValueString(title).matches(PATIENTS_CONDITION_REGEXP)) {
                    StrucDocContent[] contentArray = component5.getSection().getText().getContentArray();
                    List<String> sectionText = stream(contentArray).map(it -> nodeUtil.getNodeValueString(it)).collect(toList());
                    observations.add(createObservation(encounter, sectionText));
                }
            }
        }
    }
    return observations;
}
Also used : ST(uk.nhs.connect.iucds.cda.ucr.ST) Strings.join(org.apache.logging.log4j.util.Strings.join) Coding(org.hl7.fhir.dstu3.model.Coding) NodeUtil(uk.nhs.adaptors.oneoneone.cda.report.util.NodeUtil) POCDMT000002UK01Section(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section) StrucDocContent(uk.nhs.connect.iucds.cda.ucr.StrucDocContent) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) FINAL(org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL) Observation(org.hl7.fhir.dstu3.model.Observation) ArrayList(java.util.ArrayList) Encounter(org.hl7.fhir.dstu3.model.Encounter) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Component(org.springframework.stereotype.Component) POCDMT000002UK01Component2(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component2) ResourceUtil(uk.nhs.adaptors.oneoneone.cda.report.util.ResourceUtil) POCDMT000002UK01ClinicalDocument1(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1) POCDMT000002UK01Component3(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3) POCDMT000002UK01Component5(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component5) StringType(org.hl7.fhir.dstu3.model.StringType) AllArgsConstructor(lombok.AllArgsConstructor) Arrays.stream(java.util.Arrays.stream) ST(uk.nhs.connect.iucds.cda.ucr.ST) POCDMT000002UK01Section(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section) ArrayList(java.util.ArrayList) StrucDocContent(uk.nhs.connect.iucds.cda.ucr.StrucDocContent) POCDMT000002UK01Component2(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component2) POCDMT000002UK01Component3(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3) Observation(org.hl7.fhir.dstu3.model.Observation) POCDMT000002UK01Component5(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component5)

Aggregations

POCDMT000002UK01ClinicalDocument1 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1)10 List (java.util.List)5 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)5 Coding (org.hl7.fhir.dstu3.model.Coding)5 Encounter (org.hl7.fhir.dstu3.model.Encounter)5 Component (org.springframework.stereotype.Component)5 ResourceUtil (uk.nhs.adaptors.oneoneone.cda.report.util.ResourceUtil)5 Arrays.stream (java.util.Arrays.stream)4 AllArgsConstructor (lombok.AllArgsConstructor)4 Reference (org.hl7.fhir.dstu3.model.Reference)4 POCDMT000002UK01Component3 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3)4 POCDMT000002UK01Section (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section)4 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Identifier (org.hl7.fhir.dstu3.model.Identifier)3 Period (org.hl7.fhir.dstu3.model.Period)3 NodeUtil (uk.nhs.adaptors.oneoneone.cda.report.util.NodeUtil)3 Arrays (java.util.Arrays)2 EncounterLocationComponent (org.hl7.fhir.dstu3.model.Encounter.EncounterLocationComponent)2