Search in sources :

Example 6 with LogExecutionTime

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

the class UploadScrService method uploadScr.

@LogExecutionTime
public void uploadScr(RequestData requestData) {
    Bundle bundle = fhirParser.parseResource(requestData.getBody(), Bundle.class);
    var spineRequest = bundleMapper.map(bundle, requestData.getNhsdAsid());
    checkPermission(bundle, requestData.getNhsdAsid(), requestData.getClientIp());
    var response = spineClient.sendScrData(spineRequest, requestData.getNhsdAsid(), requestData.getNhsdIdentity(), requestData.getNhsdSessionUrid());
    String contentLocation;
    long retryAfter;
    try {
        contentLocation = getHeader(response.getHeaders(), CONTENT_LOCATION);
        retryAfter = parseLong(getHeader(response.getHeaders(), RETRY_AFTER));
    } catch (Exception ex) {
        throw new UnexpectedSpineResponseException("Unable to extract required headers", ex);
    }
    var processingResult = spineClient.getScrProcessingResult(contentLocation, retryAfter, requestData.getNhsdAsid(), requestData.getNhsdIdentity(), requestData.getNhsdSessionUrid());
    validateProcessingResult(processingResult);
}
Also used : UnexpectedSpineResponseException(uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException) Bundle(org.hl7.fhir.r4.model.Bundle) XPathExpressionException(javax.xml.xpath.XPathExpressionException) UnexpectedSpineResponseException(uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException) NonSuccessSpineProcessingResultException(uk.nhs.adaptors.scr.exceptions.NonSuccessSpineProcessingResultException) LogExecutionTime(uk.nhs.adaptors.scr.logging.LogExecutionTime)

Example 7 with LogExecutionTime

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

the class BundleMapper method map.

@LogExecutionTime
public String map(Bundle bundle, String nhsdAsid) {
    try {
        GpSummary gpSummary = GpSummary.fromBundle(bundle, nhsdAsid);
        gpSummary.setPartyIdFrom(scrConfiguration.getPartyIdFrom());
        gpSummary.setPartyIdTo(scrConfiguration.getPartyIdTo());
        gpSummary.setNhsdAsidTo(scrConfiguration.getNhsdAsidTo());
        return TemplateUtils.fillTemplate(REPC_RM150007UK05_TEMPLATE, gpSummary);
    } catch (Exception ex) {
        throw new FhirMappingException(ex.getMessage());
    }
}
Also used : GpSummary(uk.nhs.adaptors.scr.models.GpSummary) FhirMappingException(uk.nhs.adaptors.scr.exceptions.FhirMappingException) FhirMappingException(uk.nhs.adaptors.scr.exceptions.FhirMappingException) LogExecutionTime(uk.nhs.adaptors.scr.logging.LogExecutionTime)

Example 8 with LogExecutionTime

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

the class SpineHttpClient method sendRequest.

@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", justification = "SpotBugs issue with fix not yet released https://github.com/spotbugs/spotbugs/pull/1248")
@LogExecutionTime
public <T> Response<T> sendRequest(HttpRequestBase request, ResponseHandler<? extends Response<T>> responseHandler) {
    LOGGER.debug("Attempting to send SPINE request: {}", request.getRequestLine().toString());
    try {
        LOGGER.info("Leased connections: " + clientConnectionManager.getTotalStats().getLeased());
        LOGGER.info("Available connections: " + clientConnectionManager.getTotalStats().getAvailable());
        return client.execute(request, responseHandler, HttpClientContext.create());
    } catch (IOException e) {
        LOGGER.error("Error while sending SPINE request", e);
        throw new ScrBaseException("Unexpected exception while sending Spine request", e);
    }
}
Also used : ScrBaseException(uk.nhs.adaptors.scr.exceptions.ScrBaseException) IOException(java.io.IOException) LogExecutionTime(uk.nhs.adaptors.scr.logging.LogExecutionTime) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 9 with LogExecutionTime

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

the class SpineClient method sendGetScrId.

@SneakyThrows
@Override
@LogExecutionTime
public Response<Document> sendGetScrId(String requestBody, String nhsdAsid) {
    LOGGER.info("Sending GET SCR ID Spine request");
    LOGGER.debug("Body: {}", requestBody);
    var request = new HttpPost(spineConfiguration.getUrl() + spineConfiguration.getPsisQueriesEndpoint());
    setSoapHeaders(request, PSIS_EVENT_LIST_QUERY, TEXT_XML_VALUE);
    request.setEntity(new StringEntity(requestBody, UTF_8));
    var response = spineHttpClient.sendRequest(request, xmlResponseHandler);
    var statusCode = response.getStatusCode();
    if (statusCode != OK.value()) {
        LOGGER.error("Unexpected spine GET SCR ID response: {} {}", statusCode, serialize(response.getBody()));
        throw new UnexpectedSpineResponseException("Unexpected spine send response " + statusCode);
    }
    LOGGER.info("Received Spine {} interaction response: HTTP status {}", PSIS_EVENT_LIST_QUERY, response.getStatusCode());
    return response;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) UnexpectedSpineResponseException(uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException) LogExecutionTime(uk.nhs.adaptors.scr.logging.LogExecutionTime) SneakyThrows(lombok.SneakyThrows)

Example 10 with LogExecutionTime

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

the class SpineClient method sendAlert.

@Override
@SneakyThrows
@LogExecutionTime
public Response<String> sendAlert(String requestBody, String nhsdAsid, String nhsdIdentity, String nhsdSessionUrid) {
    LOGGER.info("Sending ALERT Spine request");
    LOGGER.debug("Body: {}", requestBody);
    var request = new HttpPost(spineConfiguration.getUrl() + spineConfiguration.getAlertEndpoint());
    request.addHeader(CONTENT_TYPE, APPLICATION_FHIR_JSON_VALUE);
    setCommonHeaders(request, nhsdAsid, nhsdIdentity, nhsdSessionUrid);
    request.setEntity(new StringEntity(requestBody, UTF_8));
    Response<String> response = spineHttpClient.sendRequest(request, stringResponseHandler);
    LOGGER.info("Received Spine {} FHIR operation response: HTTP status {}", spineConfiguration.getAlertEndpoint(), response.getStatusCode());
    return response;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) LogExecutionTime(uk.nhs.adaptors.scr.logging.LogExecutionTime) SneakyThrows(lombok.SneakyThrows)

Aggregations

LogExecutionTime (uk.nhs.adaptors.scr.logging.LogExecutionTime)12 UnexpectedSpineResponseException (uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException)6 SneakyThrows (lombok.SneakyThrows)5 HttpPost (org.apache.http.client.methods.HttpPost)5 StringEntity (org.apache.http.entity.StringEntity)5 Bundle (org.hl7.fhir.r4.model.Bundle)4 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)2 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)2 Patient (org.hl7.fhir.r4.model.Patient)2 Document (org.w3c.dom.Document)2 EventListQueryResponse (uk.nhs.adaptors.scr.models.EventListQueryResponse)2 Mustache (com.github.mustachejava.Mustache)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 IOException (java.io.IOException)1 OffsetDateTime.now (java.time.OffsetDateTime.now)1 UTC (java.time.ZoneOffset.UTC)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Arrays.asList (java.util.Arrays.asList)1 Stream (java.util.stream.Stream)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1