Search in sources :

Example 1 with Diagnosis

use of uk.nhs.adaptors.scr.models.xml.Diagnosis 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

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 Condition (org.hl7.fhir.r4.model.Condition)1 Encounter (org.hl7.fhir.r4.model.Encounter)1 Period (org.hl7.fhir.r4.model.Period)1 FhirMappingException (uk.nhs.adaptors.scr.exceptions.FhirMappingException)1 FhirValidationException (uk.nhs.adaptors.scr.exceptions.FhirValidationException)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 GpSummary (uk.nhs.adaptors.scr.models.GpSummary)1 Diagnosis (uk.nhs.adaptors.scr.models.xml.Diagnosis)1 DateUtil.formatDateToHl7 (uk.nhs.adaptors.scr.utils.DateUtil.formatDateToHl7)1 FhirHelper.getDomainResourceList (uk.nhs.adaptors.scr.utils.FhirHelper.getDomainResourceList)1 FhirHelper.getResourceByReference (uk.nhs.adaptors.scr.utils.FhirHelper.getResourceByReference)1