Search in sources :

Example 1 with ItkReportHeader

use of uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader in project integration-adaptor-111 by nhsconnect.

the class EncounterReportBundleServiceTest method shouldMapIncomingReferralWithPractitioners.

@Test
@SuppressWarnings("MagicNumber")
public void shouldMapIncomingReferralWithPractitioners() throws XmlException {
    ItkReportHeader itkReportHeader = new ItkReportHeader();
    List<Reference> recipients = new ArrayList<>();
    when(reference.getResource()).thenReturn(PRACTITIONER);
    recipients.add(reference);
    REFERRAL_REQUEST.setRecipient(recipients);
    Bundle encounterBundle = encounterReportBundleService.createEncounterBundle(document, itkReportHeader, MESSAGEID);
    List<BundleEntryComponent> entries = encounterBundle.getEntry();
    verifyEntry(entries.get(7), REFERRAL_REQUEST_ID.getValue(), ResourceType.ReferralRequest);
    verifyEntry(entries.get(8), PRACTITIONER_ID.getValue(), ResourceType.Practitioner);
}
Also used : BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Reference(org.hl7.fhir.dstu3.model.Reference) Bundle(org.hl7.fhir.dstu3.model.Bundle) ItkReportHeader(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 2 with ItkReportHeader

use of uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader in project integration-adaptor-111 by nhsconnect.

the class MessageHeaderServiceTest method shouldCreateMessageHeader.

@Test
public void shouldCreateMessageHeader() {
    ItkReportHeader itkReportHeader = new ItkReportHeader();
    itkReportHeader.setSpecKey(SPECIFICATION_KEY);
    itkReportHeader.setSpecVal(SPECIFICATION_VALUE);
    itkReportHeader.setAddressList(Arrays.asList(ADDRESS));
    MessageHeader messageHeader = messageHeaderService.createMessageHeader(itkReportHeader, MESSAGEID, EFFECTIVE_TIME);
    assertThat(messageHeader.getId()).isEqualTo(MESSAGEID);
    Coding event = messageHeader.getEvent();
    assertThat(event.getSystem()).isEqualTo(MessageHeaderEvent.SYSTEM);
    assertThat(event.getCode()).isEqualTo(DISCHARGE_DETAILS.getCode());
    assertThat(event.getDisplay()).isEqualTo(DISCHARGE_DETAILS.getDisplay());
    MessageSourceComponent source = messageHeader.getSource();
    assertThat(source.getName()).isEqualTo(MESSAGE_SOURCE_NAME);
    assertThat(source.getEndpoint()).isEqualTo(ENDPOINT);
    assertThat(messageHeader.getReason().getCodingFirstRep().getSystem()).isEqualTo(SPECIFICATION_KEY);
    assertThat(messageHeader.getReason().getCodingFirstRep().getCode()).isEqualTo(SPECIFICATION_VALUE);
    assertThat(messageHeader.getDestinationFirstRep().getEndpoint()).isEqualTo(ADDRESS);
    assertThat(messageHeader.getTimestampElement()).isEqualToComparingFieldByField(DateUtil.parseToInstantType(EFFECTIVE_TIME));
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) ItkReportHeader(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader) MessageSourceComponent(org.hl7.fhir.dstu3.model.MessageHeader.MessageSourceComponent) MessageHeader(org.hl7.fhir.dstu3.model.MessageHeader) Test(org.junit.jupiter.api.Test)

Example 3 with ItkReportHeader

use of uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader 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 4 with ItkReportHeader

use of uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader in project integration-adaptor-111 by nhsconnect.

the class EncounterReportBundleServiceTest method shouldCreateEncounterBundle.

@Test
@SuppressWarnings("MagicNumber")
public void shouldCreateEncounterBundle() throws XmlException {
    ItkReportHeader itkReportHeader = new ItkReportHeader();
    itkReportHeader.setSpecKey(SPECIFICATION_KEY);
    itkReportHeader.setSpecVal(SPECIFICATION_VALUE);
    Bundle encounterBundle = encounterReportBundleService.createEncounterBundle(document, itkReportHeader, MESSAGEID);
    assertThat(encounterBundle.getType()).isEqualTo(MESSAGE);
    assertThat(encounterBundle.getIdentifier().getValue()).isEqualTo(TWO.toString());
    assertThat(encounterBundle.getEntry().size()).isEqualTo(22);
    List<BundleEntryComponent> entries = encounterBundle.getEntry();
    verifyEntry(entries.get(0), MESSAGE_HEADER_ID.getValue(), ResourceType.MessageHeader);
    verifyEntry(entries.get(1), ENCOUNTER_ID.getValue(), ResourceType.Encounter);
    verifyEntry(entries.get(2), SERVICE_PROVIDER_ID.getValue(), ResourceType.Organization);
    verifyEntry(entries.get(3), PRACTITIONER_ID.getValue(), ResourceType.Practitioner);
    verifyEntry(entries.get(4), LOCATION_ID.getValue(), ResourceType.Location);
    verifyEntry(entries.get(5), PATIENT_ID.getValue(), ResourceType.Patient);
    verifyEntry(entries.get(6), HEALTHCARE_SERVICE_ID.getValue(), ResourceType.HealthcareService);
    verifyEntry(entries.get(7), REFERRAL_REQUEST_ID.getValue(), ResourceType.ReferralRequest);
    verifyEntry(entries.get(8), APPOINTMENT_ID.getValue(), ResourceType.Appointment);
    verifyEntry(entries.get(9), COMPOSITION_ID.getValue(), ResourceType.Composition);
    verifyEntry(entries.get(10), CAREPLAN_ID.getValue(), ResourceType.CarePlan);
    verifyEntry(entries.get(11), CONSENT_ID.getValue(), ResourceType.Consent);
    verifyEntry(entries.get(12), CONDITION_ID.getValue(), ResourceType.Condition);
    verifyEntry(entries.get(13), QUESTIONNAIRE_RESPONSE_ID.getValue(), ResourceType.QuestionnaireResponse);
    verifyEntry(entries.get(14), OBSERVATION_ID.getValue(), ResourceType.Observation);
    verifyEntry(entries.get(15), AUTHOR_ROLE_ID.getValue(), ResourceType.PractitionerRole);
    verifyEntry(entries.get(16), AUTHOR_ORG_ID.getValue(), ResourceType.Organization);
    verifyEntry(entries.get(17), PRACTITIONER_ROLE_ID.getValue(), ResourceType.PractitionerRole);
    verifyEntry(entries.get(18), PRACTITIONER_ORG_ID.getValue(), ResourceType.Organization);
    verifyEntry(entries.get(19), RELATED_PERSON_ID.getValue(), ResourceType.RelatedPerson);
    verifyEntry(entries.get(20), DEVICE_ID.getValue(), ResourceType.Device);
    verifyEntry(entries.get(21), LIST_RESOURCE_ID.getValue(), ResourceType.List);
}
Also used : BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.dstu3.model.Bundle) ItkReportHeader(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader) Test(org.junit.jupiter.api.Test)

Example 5 with ItkReportHeader

use of uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader in project integration-adaptor-111 by nhsconnect.

the class EncounterReportServiceTest method shouldTransformAndPopulateToGP.

@Test
public void shouldTransformAndPopulateToGP() throws JMSException, XmlException {
    ItkReportHeader header = new ItkReportHeader();
    header.setTrackingId(TRACKING_ID);
    header.setSpecKey(SPECIFICATION_KEY);
    header.setSpecVal(SPECIFICATION_VALUE);
    POCDMT000002UK01ClinicalDocument1 clinicalDoc = mock(POCDMT000002UK01ClinicalDocument1.class);
    Bundle encounterBundle = mock(Bundle.class);
    when(encounterReportBundleService.createEncounterBundle(clinicalDoc, header, MESSAGE_ID)).thenReturn(encounterBundle);
    IParser parser = mock(IParser.class);
    when(fhirContext.newJsonParser()).thenReturn(parser);
    when(parser.setPrettyPrint(true)).thenReturn(parser);
    when(parser.encodeResourceToString(encounterBundle)).thenReturn(ENCOUNTER_REPORT_MAPPING);
    Session session = mock(Session.class);
    when(session.createTextMessage(any())).thenReturn(textMessage);
    encounterReportService.transformAndPopulateToGP(clinicalDoc, MESSAGE_ID, header);
    ArgumentCaptor<MessageCreator> argumentCaptor = ArgumentCaptor.forClass(MessageCreator.class);
    verify(jmsTemplate).send(eq(QUEUE_NAME), argumentCaptor.capture());
    argumentCaptor.getValue().createMessage(session);
    verify(session).createTextMessage(ENCOUNTER_REPORT_MAPPING);
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) ItkReportHeader(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader) POCDMT000002UK01ClinicalDocument1(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1) MessageCreator(org.springframework.jms.core.MessageCreator) IParser(ca.uhn.fhir.parser.IParser) Session(javax.jms.Session) Test(org.junit.jupiter.api.Test)

Aggregations

ItkReportHeader (uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader)7 Test (org.junit.jupiter.api.Test)5 Bundle (org.hl7.fhir.dstu3.model.Bundle)3 POCDMT000002UK01ClinicalDocument1 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1)3 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)2 IParser (ca.uhn.fhir.parser.IParser)1 ArrayList (java.util.ArrayList)1 Session (javax.jms.Session)1 XmlException (org.apache.xmlbeans.XmlException)1 Coding (org.hl7.fhir.dstu3.model.Coding)1 MessageHeader (org.hl7.fhir.dstu3.model.MessageHeader)1 MessageSourceComponent (org.hl7.fhir.dstu3.model.MessageHeader.MessageSourceComponent)1 Reference (org.hl7.fhir.dstu3.model.Reference)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 ResponseEntity (org.springframework.http.ResponseEntity)1 MessageCreator (org.springframework.jms.core.MessageCreator)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 SAXException (org.xml.sax.SAXException)1 ItkXmlException (uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.ItkXmlException)1