Search in sources :

Example 1 with ReportItems

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

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

the class ItkValidatorTest method setUp.

@BeforeEach
public void setUp() {
    reportItems = new ReportItems();
    reportItems.setMessageId(MESSAGE_ID);
    reportItems.setSoapAddress(SOAP_ADDRESS);
    reportItems.setDistributionEnvelope(mock(Node.class));
    reportItems.setItkHeader(prepareItkHeaderElement());
    reportItems.setSoapHeader(prepareSoapHeaderElement());
    reportItems.setPayloads(prepareItkPayloadsElement());
}
Also used : Node(org.w3c.dom.Node) ReportItems(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ReportItems) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ReportItems (uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ReportItems)2 XmlException (org.apache.xmlbeans.XmlException)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 Node (org.w3c.dom.Node)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 POCDMT000002UK01ClinicalDocument1 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1)1 DistributionEnvelopeDocument (uk.nhs.itk.envelope.DistributionEnvelopeDocument)1