Search in sources :

Example 1 with DistributionEnvelopeDocument

use of uk.nhs.itk.envelope.DistributionEnvelopeDocument 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 2 with DistributionEnvelopeDocument

use of uk.nhs.itk.envelope.DistributionEnvelopeDocument in project integration-adaptor-111 by nhsconnect.

the class ReportRequestUtilsTest method extractDistributionEnvelopeShouldReturnDistributionEnvelopeDocument.

@SneakyThrows
@Test
public void extractDistributionEnvelopeShouldReturnDistributionEnvelopeDocument() {
    when(xmlUtils.serialize(distributionEnvelope)).thenReturn(REPEAT_CALLER_XML);
    DistributionEnvelopeDocument distributionEnvelopeDocumentTest = reportRequestUtils.extractDistributionEnvelope(distributionEnvelope);
    assertThat(distributionEnvelopeDocumentTest).isNotEqualTo(null);
    assertThat(distributionEnvelopeDocumentTest.getDistributionEnvelope().getPayloads().getCount()).isEqualTo(PAYLOADS_COUNT);
    assertThat(distributionEnvelopeDocumentTest.getDistributionEnvelope().getHeader().getManifest().getManifestitemArray(0).getId()).isEqualTo(MANIFEST_ID);
    assertThat(distributionEnvelopeDocumentTest.getDistributionEnvelope().getPayloads().getPayloadArray(0).getDomNode().getChildNodes().item(1).getNodeName()).isEqualTo(CLINICAL_DOCUMENT_NODE_NAME);
}
Also used : DistributionEnvelopeDocument(uk.nhs.itk.envelope.DistributionEnvelopeDocument) Test(org.junit.jupiter.api.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

DistributionEnvelopeDocument (uk.nhs.itk.envelope.DistributionEnvelopeDocument)2 SneakyThrows (lombok.SneakyThrows)1 XmlException (org.apache.xmlbeans.XmlException)1 Test (org.junit.jupiter.api.Test)1 ResponseEntity (org.springframework.http.ResponseEntity)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 SoapClientException (uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException)1 SoapMustUnderstandException (uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapMustUnderstandException)1 ItkReportHeader (uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader)1 ReportItems (uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ReportItems)1 POCDMT000002UK01ClinicalDocument1 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1)1