Search in sources :

Example 1 with DiagnosisMapper

use of uk.nhs.adaptors.scr.mappings.from.hl7.DiagnosisMapper 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)

Aggregations

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 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 Coding (org.hl7.fhir.r4.model.Coding)1 Composition (org.hl7.fhir.r4.model.Composition)1 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)1 DocumentReferenceContentComponent (org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent)1 DocumentReferenceContextComponent (org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContextComponent)1