Search in sources :

Example 1 with NonSuccessSpineProcessingResultException

use of uk.nhs.adaptors.scr.exceptions.NonSuccessSpineProcessingResultException in project summary-care-record-api by NHSDigital.

the class UploadScrService method validateProcessingResult.

@SneakyThrows
private void validateProcessingResult(ProcessingResult processingResult) {
    var hl7Document = parseDocument(processingResult.getHl7());
    var acknowledgementXPath = XPathFactory.newInstance().newXPath().compile("/MCCI_IN010000UK13/acknowledgement");
    var acknowledgementNode = ((NodeList) acknowledgementXPath.evaluate(hl7Document, XPathConstants.NODESET)).item(0);
    String acknowledgementTypeCode;
    try {
        acknowledgementTypeCode = acknowledgementNode.getAttributes().getNamedItem("typeCode").getNodeValue();
    } catch (Exception ex) {
        LOGGER.error("Unable to extract acknowledgement code:\n{}", processingResult.getHl7());
        throw new UnexpectedSpineResponseException("Unable to extract acknowledgement code");
    }
    if (!acknowledgementTypeCode.equals("AA")) {
        var errors = getErrors(hl7Document);
        LOGGER.error("Non success spine processing result:\n{}\n{}", processingResult.getSoapEnvelope(), processingResult.getHl7());
        throw new NonSuccessSpineProcessingResultException(errors);
    }
}
Also used : NonSuccessSpineProcessingResultException(uk.nhs.adaptors.scr.exceptions.NonSuccessSpineProcessingResultException) UnexpectedSpineResponseException(uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException) NodeList(org.w3c.dom.NodeList) XPathExpressionException(javax.xml.xpath.XPathExpressionException) UnexpectedSpineResponseException(uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException) NonSuccessSpineProcessingResultException(uk.nhs.adaptors.scr.exceptions.NonSuccessSpineProcessingResultException) SneakyThrows(lombok.SneakyThrows)

Aggregations

XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 SneakyThrows (lombok.SneakyThrows)1 NodeList (org.w3c.dom.NodeList)1 NonSuccessSpineProcessingResultException (uk.nhs.adaptors.scr.exceptions.NonSuccessSpineProcessingResultException)1 UnexpectedSpineResponseException (uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException)1