Search in sources :

Example 1 with Response

use of uk.nhs.adaptors.scr.clients.spine.SpineHttpClient.Response in project summary-care-record-api by NHSDigital.

the class SandboxSpineClient method sendScrData.

@SneakyThrows
@Override
public Response<String> sendScrData(String requestBody, String nhsdAsid, String nhsdIdentity, String nhsdSessionUrid) {
    Header[] headers = { new BasicHeader(CONTENT_LOCATION, ""), new BasicHeader(RETRY_AFTER, "100") };
    sleep(scrConfiguration.getSandboxDelay());
    return new Response(ACCEPTED.value(), headers, null);
}
Also used : Response(uk.nhs.adaptors.scr.clients.spine.SpineHttpClient.Response) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) BasicHeader(org.apache.http.message.BasicHeader) SneakyThrows(lombok.SneakyThrows)

Example 2 with Response

use of uk.nhs.adaptors.scr.clients.spine.SpineHttpClient.Response 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();
    }
}
Also used : SpineClientContract(uk.nhs.adaptors.scr.clients.spine.SpineClientContract) TemplateUtils(uk.nhs.adaptors.scr.utils.TemplateUtils) Mustache(com.github.mustachejava.Mustache) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Identifier(org.hl7.fhir.r4.model.Identifier) Response(uk.nhs.adaptors.scr.clients.spine.SpineHttpClient.Response) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) DocumentReferenceContextComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContextComponent) Autowired(org.springframework.beans.factory.annotation.Autowired) EventListQueryResponse(uk.nhs.adaptors.scr.models.EventListQueryResponse) Reference(org.hl7.fhir.r4.model.Reference) OffsetDateTime.now(java.time.OffsetDateTime.now) StringUtils(org.apache.commons.lang3.StringUtils) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) EventListQueryResponseParser(uk.nhs.adaptors.scr.models.EventListQueryResponseParser) GpSummaryMapper(uk.nhs.adaptors.scr.mappings.from.hl7.GpSummaryMapper) Attachment(org.hl7.fhir.r4.model.Attachment) DocumentReferenceContentComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent) Document(org.w3c.dom.Document) Arrays.asList(java.util.Arrays.asList) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) SpineConfiguration(uk.nhs.adaptors.scr.config.SpineConfiguration) CURRENT(org.hl7.fhir.r4.model.Enumerations.DocumentReferenceStatus.CURRENT) HtmlParser.serialize(uk.nhs.adaptors.scr.mappings.from.hl7.HtmlParser.serialize) Patient(org.hl7.fhir.r4.model.Patient) DiagnosisMapper(uk.nhs.adaptors.scr.mappings.from.hl7.DiagnosisMapper) MATCH(org.hl7.fhir.r4.model.Bundle.SearchEntryMode.MATCH) TemplateUtils.loadTemplate(uk.nhs.adaptors.scr.utils.TemplateUtils.loadTemplate) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) ScrConfiguration(uk.nhs.adaptors.scr.config.ScrConfiguration) InteractionMapper(uk.nhs.adaptors.scr.mappings.from.hl7.InteractionMapper) Resource(org.hl7.fhir.r4.model.Resource) SEARCHSET(org.hl7.fhir.r4.model.Bundle.BundleType.SEARCHSET) Composition(org.hl7.fhir.r4.model.Composition) EventQueryParams(uk.nhs.adaptors.scr.models.EventQueryParams) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) FindingMapper(uk.nhs.adaptors.scr.mappings.from.hl7.FindingMapper) Coding(org.hl7.fhir.r4.model.Coding) MDC(org.slf4j.MDC) EventListQueryParams(uk.nhs.adaptors.scr.models.EventListQueryParams) DateTimeFormatter(java.time.format.DateTimeFormatter) UTC(java.time.ZoneOffset.UTC) FhirHelper.randomUUID(uk.nhs.adaptors.scr.utils.FhirHelper.randomUUID) Bundle(org.hl7.fhir.r4.model.Bundle) RecordTargetMapper(uk.nhs.adaptors.scr.mappings.from.hl7.RecordTargetMapper) LogExecutionTime(uk.nhs.adaptors.scr.logging.LogExecutionTime) EventListQueryResponse(uk.nhs.adaptors.scr.models.EventListQueryResponse) Patient(org.hl7.fhir.r4.model.Patient) Document(org.w3c.dom.Document) LogExecutionTime(uk.nhs.adaptors.scr.logging.LogExecutionTime)

Example 3 with Response

use of uk.nhs.adaptors.scr.clients.spine.SpineHttpClient.Response in project summary-care-record-api by NHSDigital.

the class SandboxSpineClient method sendAcsData.

@SneakyThrows
@Override
public Response<Document> sendAcsData(String requestBody, String nhsdAsid) {
    Document document = parseXml(requestBody);
    String nhsNumber = xmlUtils.getValueByXPath(document, SET_ACS_NHS_NUMBER_XPATH);
    if (EXISTING_NHS_NUMBER.equals(nhsNumber)) {
        return new Response(OK.value(), null, getResourceAsXmlDocument(setAcsSuccess));
    } else {
        return new Response(OK.value(), null, getResourceAsXmlDocument(setAcsIncorrectNhsNumber));
    }
}
Also used : Response(uk.nhs.adaptors.scr.clients.spine.SpineHttpClient.Response) Document(org.w3c.dom.Document) SneakyThrows(lombok.SneakyThrows)

Example 4 with Response

use of uk.nhs.adaptors.scr.clients.spine.SpineHttpClient.Response in project summary-care-record-api by NHSDigital.

the class SandboxSpineClient method sendGetScrId.

@SneakyThrows
@Override
public Response<Document> sendGetScrId(String requestBody, String nhsdAsid) {
    sleep(scrConfiguration.getSandboxDelay());
    Document document = parseXml(requestBody);
    String nhsNumber = xmlUtils.getValueByXPath(document, GET_SCR_ID_NHS_NUMBER_XPATH);
    switch(nhsNumber) {
        case EXISTING_NHS_NUMBER:
            return new Response(OK.value(), null, getResourceAsXmlDocument(getScrIdSuccess));
        default:
            return new Response(OK.value(), null, getResourceAsXmlDocument(getScrIdNoConsent));
    }
}
Also used : Response(uk.nhs.adaptors.scr.clients.spine.SpineHttpClient.Response) Document(org.w3c.dom.Document) SneakyThrows(lombok.SneakyThrows)

Aggregations

Response (uk.nhs.adaptors.scr.clients.spine.SpineHttpClient.Response)4 SneakyThrows (lombok.SneakyThrows)3 Document (org.w3c.dom.Document)3 Mustache (com.github.mustachejava.Mustache)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 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Header (org.apache.http.Header)1 BasicHeader (org.apache.http.message.BasicHeader)1 Attachment (org.hl7.fhir.r4.model.Attachment)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)1 SEARCHSET (org.hl7.fhir.r4.model.Bundle.BundleType.SEARCHSET)1 MATCH (org.hl7.fhir.r4.model.Bundle.SearchEntryMode.MATCH)1 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)1