use of uk.nhs.adaptors.scr.logging.LogExecutionTime in project summary-care-record-api by NHSDigital.
the class SpineClient method sendScrData.
@SneakyThrows
@Override
@LogExecutionTime
public Response<String> sendScrData(String requestBody, String nhsdAsid, String nhsdIdentity, String nhsdSessionUrid) {
var url = spineConfiguration.getUrl() + spineConfiguration.getScrEndpoint();
LOGGER.info("Sending SCR Upload request to SPINE. URL: {}", url);
LOGGER.debug("Body: {}", requestBody);
var request = new HttpPost(url);
setUploadScrHeaders(request, nhsdAsid, nhsdIdentity, nhsdSessionUrid);
request.setEntity(new StringEntity(requestBody, UTF_8));
var response = spineHttpClient.sendRequest(request, stringResponseHandler);
var statusCode = response.getStatusCode();
if (statusCode != ACCEPTED.value()) {
LOGGER.error("Unexpected spine SCR POST response: {} {}", statusCode, response.getBody());
throw new UnexpectedSpineResponseException("Unexpected spine 'send data' response " + statusCode);
}
LOGGER.info("Received Spine {} interaction response: HTTP status {}", UPLOAD_SCR_SOAP_ACTION, response.getStatusCode());
return response;
}
use of uk.nhs.adaptors.scr.logging.LogExecutionTime in project summary-care-record-api by NHSDigital.
the class SpineClient method getScrProcessingResult.
@Override
@LogExecutionTime
public ProcessingResult getScrProcessingResult(String contentLocation, long initialWaitTime, String nhsdAsid, String nhsdIdentity, String nhsdSessionUrid) {
var repeatTimeout = spineConfiguration.getScrResultRepeatTimeout();
var template = RetryTemplate.builder().withinMillis(repeatTimeout).customBackoff(new ScrRetryBackoffPolicy()).retryOn(NoSpineResultException.class).build();
LOGGER.info("Starting polling result. First request in {}ms", initialWaitTime);
try {
Thread.sleep(initialWaitTime);
} catch (InterruptedException e) {
throw new ScrTimeoutException(e);
}
return template.execute(ctx -> {
LOGGER.info("Fetching SCR processing result. RetryCount={}", ctx.getRetryCount());
var request = new HttpGet(spineConfiguration.getUrl() + contentLocation);
setCommonHeaders(request, nhsdAsid, nhsdIdentity, nhsdSessionUrid);
var result = spineHttpClient.sendRequest(request, stringResponseHandler);
int statusCode = result.getStatusCode();
if (statusCode == OK.value()) {
LOGGER.info("{} processing result received.", statusCode);
return ProcessingResult.parseProcessingResult(result.getBody());
} else if (statusCode == ACCEPTED.value()) {
var nextRetryAfter = Long.parseLong(SpineHttpClient.getHeader(result.getHeaders(), RETRY_AFTER));
LOGGER.info("{} received. NextRetry in {}ms", statusCode, nextRetryAfter);
throw new NoSpineResultException(nextRetryAfter);
} else {
LOGGER.error("Unexpected spine polling response: {} {}", statusCode, result.getBody());
throw new UnexpectedSpineResponseException("Unexpected spine polling response " + statusCode);
}
});
}
use of uk.nhs.adaptors.scr.logging.LogExecutionTime in project summary-care-record-api by NHSDigital.
the class GetScrController method getScrId.
@GetMapping(path = "/DocumentReference", produces = { APPLICATION_FHIR_JSON_VALUE })
@SuppressWarnings("checkstyle:parameternumber")
@LogExecutionTime
public String getScrId(@RequestHeader(NHSD_ASID) @NotNull String nhsdAsid, @RequestHeader(CLIENT_IP) @NotNull String clientIp, @RequestParam("patient") @NotNull @PatientId String patient, @RequestParam(required = false) @TypeCode String type, @RequestParam(name = "_sort", required = false) @SortMethod String sort, @RequestParam(name = "_count", required = false) @RecordCount Integer count) {
LOGGER.info("Received GET SCR ID request");
String nhsNumber = extractNhsNumber(patient);
Bundle bundle = getScrService.getScrId(nhsNumber, nhsdAsid, clientIp);
return fhirParser.encodeToJson(bundle);
}
use of uk.nhs.adaptors.scr.logging.LogExecutionTime in project summary-care-record-api by NHSDigital.
the class GetScrService method getScr.
@LogExecutionTime
public Bundle getScr(String nhsNumber, String compositionId, String nhsdAsid, String clientIp) {
Document scrIdXml = getScrIdRawXml(nhsNumber, nhsdAsid, clientIp);
checkDetectedIssues(scrIdXml);
EventListQueryResponse response = eventListQueryResponseParser.parseXml(scrIdXml);
if (StringUtils.equals(response.getLatestScrId(), compositionId)) {
Document document = getScrRawXml(response.getLatestScrId(), nhsNumber, nhsdAsid, clientIp);
logXml("Received SCR XML: {}", document);
checkDetectedIssues(document);
var bundle = interactionMapper.map(document);
Patient patient = recordTargetMapper.mapPatient(document);
Stream.of(gpSummaryMapper, diagnosisMapper, findingMapper).map(mapper -> mapper.map(document)).flatMap(resources -> resources.stream()).peek(it -> setPatientReferences(it, patient)).map(resource -> getBundleEntryComponent(resource)).forEach(bundle::addEntry);
bundle.addEntry(getBundleEntryComponent(patient));
bundle.setTotal(bundle.getEntry().size());
return bundle;
} else {
return interactionMapper.mapToEmpty();
}
}
use of uk.nhs.adaptors.scr.logging.LogExecutionTime in project summary-care-record-api by NHSDigital.
the class GetScrService method getScrId.
@LogExecutionTime
public Bundle getScrId(String nhsNumber, String nhsdAsid, String clientIp) {
Document scrIdXml = getScrIdRawXml(nhsNumber, nhsdAsid, clientIp);
checkDetectedIssues(scrIdXml);
EventListQueryResponse response = eventListQueryResponseParser.parseXml(scrIdXml);
Bundle bundle = buildBundle();
if (StringUtils.isNotEmpty(response.getLatestScrId())) {
bundle.setTotal(1);
Patient patient = buildPatientResource(nhsNumber);
DocumentReference documentReference = buildDocumentReference(nhsNumber, response, patient);
bundle.addEntry(new BundleEntryComponent().setFullUrl(getScrUrl() + "/DocumentReference/" + documentReference.getId()).setResource(documentReference).setSearch(new Bundle.BundleEntrySearchComponent().setMode(MATCH)));
bundle.addEntry(new BundleEntryComponent().setFullUrl(patient.getId()).setResource(patient));
} else {
bundle.setTotal(0);
}
return bundle;
}
Aggregations