Search in sources :

Example 1 with Finding

use of uk.nhs.adaptors.scr.models.xml.Finding in project summary-care-record-api by NHSDigital.

the class ObservationMapper method mapFinding.

private static Finding mapFinding(Observation observation, Bundle bundle) {
    var finding = new Finding();
    finding.setIdRoot(observation.getIdentifierFirstRep().getValue());
    finding.setCodeCode(observation.getCode().getCodingFirstRep().getCode());
    finding.setCodeDisplayName(observation.getCode().getCodingFirstRep().getDisplay());
    finding.setStatusCodeCode(mapStatus(observation.getStatus()));
    if (observation.getEffective() instanceof DateTimeType) {
        finding.setEffectiveTimeCenter(formatDateToHl7(observation.getEffectiveDateTimeType()));
    } else if (observation.getEffective() instanceof Period) {
        var period = observation.getEffectivePeriod();
        if (period.hasStart()) {
            finding.setEffectiveTimeLow(formatDateToHl7(period.getStartElement()));
        }
        if (period.hasEnd()) {
            finding.setEffectiveTimeHigh(formatDateToHl7(period.getEndElement()));
        }
    } else {
        throw new FhirValidationException("Observation.effective must be of type DateTimeType or Period");
    }
    var encounterReference = observation.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", observation.getEncounter().getReference(), observation.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 = mapAuthor1(bundle, encounterParticipant);
                finding.setAuthor(author);
            } else if ("INF".equals(code)) {
                var informant = mapInformant(bundle, encounterParticipant);
                finding.setInformant(informant);
            } else if ("PRF".equals(code)) {
                var performer = mapPerformer(bundle, encounterParticipant);
                finding.setPerformer(performer);
            } else {
                throw new FhirValidationException(String.format("Invalid encounter %s participant code %s", encounter.getId(), code));
            }
        }
    }
    return finding;
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Coding(org.hl7.fhir.r4.model.Coding) Finding(uk.nhs.adaptors.scr.models.xml.Finding) Period(org.hl7.fhir.r4.model.Period) Encounter(org.hl7.fhir.r4.model.Encounter) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Aggregations

Coding (org.hl7.fhir.r4.model.Coding)1 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)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 Finding (uk.nhs.adaptors.scr.models.xml.Finding)1