Search in sources :

Example 1 with FhirMappingException

use of uk.nhs.adaptors.scr.exceptions.FhirMappingException 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 2 with FhirMappingException

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

the class CompositionMapper method setPresentation.

private static void setPresentation(GpSummary gpSummary, Composition composition) throws FhirMappingException {
    if (!composition.hasSection()) {
        throw new FhirMappingException("Missing mandatory Composition.section");
    }
    Presentation presentation = new Presentation();
    var htmlDocument = createNewDocument("html", "xhtml:NPfIT:PresentationText");
    var bodyNode = htmlDocument.createElement("body");
    htmlDocument.getDocumentElement().appendChild(bodyNode);
    for (Composition.SectionComponent section : composition.getSection()) {
        var h2Node = htmlDocument.createElement("h2");
        h2Node.setAttribute("id", section.getCode().getCodingFirstRep().getCode());
        h2Node.appendChild(htmlDocument.createTextNode(section.getTitle()));
        bodyNode.appendChild(h2Node);
        var divDocument = parseDocument(section.getText().getDiv().getValueAsString());
        removeEmptyNodes(divDocument);
        var divChildNodes = divDocument.getDocumentElement().getChildNodes();
        for (int i = 0; i < divChildNodes.getLength(); i++) {
            bodyNode.appendChild(htmlDocument.importNode(divChildNodes.item(i), true));
        }
    }
    presentation.setPresentationId(randomUUID());
    presentation.setPresentationText(serialize(htmlDocument));
    gpSummary.setPresentation(presentation);
}
Also used : Composition(org.hl7.fhir.r4.model.Composition) Presentation(uk.nhs.adaptors.scr.models.xml.Presentation) FhirMappingException(uk.nhs.adaptors.scr.exceptions.FhirMappingException)

Example 3 with FhirMappingException

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

the class ConditionMapper method mapDiagnosis.

private static Diagnosis mapDiagnosis(Condition condition, Bundle bundle) throws FhirMappingException {
    var diagnosis = new Diagnosis();
    diagnosis.setIdRoot(condition.getIdentifierFirstRep().getValue());
    diagnosis.setCodeCode(condition.getCode().getCodingFirstRep().getCode());
    diagnosis.setCodeDisplayName(condition.getCode().getCodingFirstRep().getDisplay());
    diagnosis.setStatusCodeCode(mapStatus(condition));
    if (condition.hasOnsetDateTimeType()) {
        diagnosis.setEffectiveTimeLow(formatDateToHl7(condition.getOnsetDateTimeType()));
    }
    if (condition.hasOnsetPeriod()) {
        Period period = condition.getOnsetPeriod();
        diagnosis.setEffectiveTimeLow(formatDateToHl7(period.getStartElement()));
        diagnosis.setEffectiveTimeHigh(formatDateToHl7(period.getEndElement()));
    }
    Optional.ofNullable(condition.getEvidenceFirstRep().getDetailFirstRep().getReference()).map(reference -> reference.split("/")[1]).ifPresent(diagnosis::setFindingId);
    diagnosis.setSupportingInformation(condition.getNoteFirstRep().getText());
    LOGGER.debug("Looking up Encounter for Condition.id={}", condition.getIdElement().getIdPart());
    var encounterReference = condition.getEncounter().getReference();
    if (StringUtils.isNotBlank(encounterReference)) {
        var encounter = getResourceByReference(bundle, encounterReference, Encounter.class).orElseThrow(() -> new FhirValidationException(String.format("Bundle is Missing Encounter %s that is linked to Condition %s", condition.getEncounter().getReference(), condition.getId())));
        for (var encounterParticipant : encounter.getParticipant()) {
            Coding coding = encounterParticipant.getTypeFirstRep().getCodingFirstRep();
            if (!PARTICIPATION_TYPE_SYSTEM.equals(coding.getSystem())) {
                throw new FhirValidationException("Unsupported encounter participant system: " + coding.getSystem());
            }
            var code = coding.getCode();
            if ("AUT".equals(code)) {
                var author = mapAuthor(bundle, encounterParticipant);
                diagnosis.setAuthor(author);
            } else if ("INF".equals(code)) {
                var informant = mapInformant(bundle, encounterParticipant);
                diagnosis.setInformant(informant);
            } else {
                throw new FhirValidationException(String.format("Invalid encounter %s participant code %s", encounter.getId(), code));
            }
        }
    }
    return diagnosis;
}
Also used : ParticipantAgentMapper.mapAuthor(uk.nhs.adaptors.scr.mappings.from.fhir.ParticipantAgentMapper.mapAuthor) Diagnosis(uk.nhs.adaptors.scr.models.xml.Diagnosis) DateUtil.formatDateToHl7(uk.nhs.adaptors.scr.utils.DateUtil.formatDateToHl7) FhirHelper.getDomainResourceList(uk.nhs.adaptors.scr.utils.FhirHelper.getDomainResourceList) Period(org.hl7.fhir.r4.model.Period) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) FhirHelper.getResourceByReference(uk.nhs.adaptors.scr.utils.FhirHelper.getResourceByReference) Condition(org.hl7.fhir.r4.model.Condition) Encounter(org.hl7.fhir.r4.model.Encounter) GpSummary(uk.nhs.adaptors.scr.models.GpSummary) Slf4j(lombok.extern.slf4j.Slf4j) ParticipantAgentMapper.mapInformant(uk.nhs.adaptors.scr.mappings.from.fhir.ParticipantAgentMapper.mapInformant) Coding(org.hl7.fhir.r4.model.Coding) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) FhirMappingException(uk.nhs.adaptors.scr.exceptions.FhirMappingException) StringUtils(io.micrometer.core.instrument.util.StringUtils) Coding(org.hl7.fhir.r4.model.Coding) Period(org.hl7.fhir.r4.model.Period) Encounter(org.hl7.fhir.r4.model.Encounter) Diagnosis(uk.nhs.adaptors.scr.models.xml.Diagnosis) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Aggregations

FhirMappingException (uk.nhs.adaptors.scr.exceptions.FhirMappingException)3 GpSummary (uk.nhs.adaptors.scr.models.GpSummary)2 StringUtils (io.micrometer.core.instrument.util.StringUtils)1 Optional (java.util.Optional)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Bundle (org.hl7.fhir.r4.model.Bundle)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 Condition (org.hl7.fhir.r4.model.Condition)1 Encounter (org.hl7.fhir.r4.model.Encounter)1 Period (org.hl7.fhir.r4.model.Period)1 FhirValidationException (uk.nhs.adaptors.scr.exceptions.FhirValidationException)1 LogExecutionTime (uk.nhs.adaptors.scr.logging.LogExecutionTime)1 ParticipantAgentMapper.mapAuthor (uk.nhs.adaptors.scr.mappings.from.fhir.ParticipantAgentMapper.mapAuthor)1 ParticipantAgentMapper.mapInformant (uk.nhs.adaptors.scr.mappings.from.fhir.ParticipantAgentMapper.mapInformant)1 Diagnosis (uk.nhs.adaptors.scr.models.xml.Diagnosis)1 Presentation (uk.nhs.adaptors.scr.models.xml.Presentation)1 DateUtil.formatDateToHl7 (uk.nhs.adaptors.scr.utils.DateUtil.formatDateToHl7)1 FhirHelper.getDomainResourceList (uk.nhs.adaptors.scr.utils.FhirHelper.getDomainResourceList)1