Search in sources :

Example 1 with CodedEntry

use of uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry in project summary-care-record-api by NHSDigital.

the class DiagnosisMapper method map.

@SneakyThrows
public List<Resource> map(Node document) {
    var resources = new ArrayList<Resource>();
    NodeList pertinentNodes = xmlUtils.getNodeListByXPath(document, PERTINENT_CRET_BASE_PATH);
    for (int i = 0; i < pertinentNodes.getLength(); i++) {
        Node pertinentCREType = xmlUtils.getNodeAndDetachFromParent(pertinentNodes, i);
        var pertinentCRETypeCode = xmlUtils.getValueByXPath(pertinentCREType, PERTINENT_CODE_CODE_XPATH);
        var pertinentCRETypeDisplay = xmlUtils.getValueByXPath(pertinentCREType, PERTINENT_CODE_DISPLAY_XPATH);
        NodeList diagnosisNodes = xmlUtils.getNodeListByXPath(pertinentCREType, DIAGNOSIS_BASE_PATH);
        for (int j = 0; j < diagnosisNodes.getLength(); j++) {
            Node node = xmlUtils.getNodeAndDetachFromParent(diagnosisNodes, j);
            CodedEntry entry = codedEntryMapper.getCommonCodedEntryValues(node);
            if (COVID_19_ENTRIES.contains(entry.getCodeValue())) {
                var pertinentSupportingInfo = xmlUtils.getOptionalValueByXPath(node, DIAGNOSIS_PERTINENT_SUPPORTING_INFO_XPATH);
                var condition = new Condition();
                condition.setId(entry.getId());
                condition.addIdentifier().setValue(entry.getId());
                condition.setCode(new CodeableConcept().addCoding(new Coding().setCode(entry.getCodeValue()).setSystem(SNOMED_SYSTEM).setDisplay(entry.getCodeDisplay())));
                setConditionStatus(condition, entry.getStatus());
                condition.addCategory(new CodeableConcept(new Coding().setSystem(SNOMED_SYSTEM).setCode(pertinentCRETypeCode).setDisplay(pertinentCRETypeDisplay)));
                if (entry.getEffectiveTimeHigh().isPresent()) {
                    condition.setOnset(entry.getEffectiveTimeLow().get());
                    condition.setAbatement(entry.getEffectiveTimeHigh().get());
                } else {
                    condition.setOnset(entry.getEffectiveTimeLow().get());
                }
                resources.add(condition);
                pertinentSupportingInfo.map(value -> new Annotation().setText(value)).ifPresent(condition::addNote);
                xmlUtils.getNodesByXPath(node, DIAGNOSIS_PERTINENT_FINDINGS_XPATH).stream().map(it -> xmlUtils.getValueByXPath(it, DIAGNOSIS_PERTINENT_FINDING_ID_XPATH)).map(it -> new Reference(new Observation().setId(it))).map(reference -> new Condition.ConditionEvidenceComponent().addDetail(reference)).forEach(condition::addEvidence);
                mapEncounter(node, condition, resources);
            }
        }
    }
    return resources;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) SneakyThrows(lombok.SneakyThrows) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Encounter(org.hl7.fhir.r4.model.Encounter) Node(org.w3c.dom.Node) CodedEntryMapper(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntryMapper) Observation(org.hl7.fhir.r4.model.Observation) NodeList(org.w3c.dom.NodeList) Period(org.hl7.fhir.r4.model.Period) Resource(org.hl7.fhir.r4.model.Resource) FINISHED(org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) Component(org.springframework.stereotype.Component) List(java.util.List) XmlToFhirMapper.parseDate(uk.nhs.adaptors.scr.mappings.from.hl7.XmlToFhirMapper.parseDate) Coding(org.hl7.fhir.r4.model.Coding) FhirHelper.randomUUID(uk.nhs.adaptors.scr.utils.FhirHelper.randomUUID) Optional(java.util.Optional) XmlUtils(uk.nhs.adaptors.scr.utils.XmlUtils) Annotation(org.hl7.fhir.r4.model.Annotation) CodedEntry(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry) Reference(org.hl7.fhir.r4.model.Reference) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Annotation(org.hl7.fhir.r4.model.Annotation) CodedEntry(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry) Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) SneakyThrows(lombok.SneakyThrows)

Example 2 with CodedEntry

use of uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry in project summary-care-record-api by NHSDigital.

the class FindingMapper method mapObservation.

private void mapObservation(ArrayList<Resource> resources, String creTypeCode, String creTypeDisplay, Node node) {
    CodedEntry entry = codedEntryMapper.getCommonCodedEntryValues(node);
    if (SARS_COV_2_CODE.equals(entry.getCodeValue())) {
        var effectiveTimeCentre = xmlUtils.getOptionalValueByXPath(node, EFFECTIVE_TIME_CENTRE_XPATH).map(it -> parseDate(it, DateTimeType.class));
        var observation = new Observation();
        observation.setId(entry.getId());
        observation.setMeta(new Meta().addProfile(UK_CORE_OBSERVATION_META));
        observation.addIdentifier(new Identifier().setValue(entry.getId()));
        observation.setCode(new CodeableConcept().addCoding(new Coding().setCode(entry.getCodeValue()).setSystem(SNOMED_SYSTEM).setDisplay(entry.getCodeDisplay())));
        observation.setStatus(mapStatus(entry.getStatus()));
        if (entry.getEffectiveTimeLow().isPresent() || entry.getEffectiveTimeHigh().isPresent()) {
            var period = new Period();
            entry.getEffectiveTimeLow().ifPresent(period::setStartElement);
            entry.getEffectiveTimeHigh().ifPresent(period::setEndElement);
            observation.setEffective(period);
        } else {
            effectiveTimeCentre.ifPresent(observation::setEffective);
        }
        observation.addCategory(new CodeableConcept(new Coding().setSystem(SNOMED_SYSTEM).setCode(creTypeCode).setDisplay(creTypeDisplay)));
        mapEncounter(node, observation, resources);
        resources.add(observation);
    }
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) Period(org.hl7.fhir.r4.model.Period) CodedEntry(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)2 Coding (org.hl7.fhir.r4.model.Coding)2 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)2 Observation (org.hl7.fhir.r4.model.Observation)2 Period (org.hl7.fhir.r4.model.Period)2 CodedEntry (uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 SneakyThrows (lombok.SneakyThrows)1 Annotation (org.hl7.fhir.r4.model.Annotation)1 Condition (org.hl7.fhir.r4.model.Condition)1 Encounter (org.hl7.fhir.r4.model.Encounter)1 EncounterParticipantComponent (org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent)1 FINISHED (org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED)1 Identifier (org.hl7.fhir.r4.model.Identifier)1 Meta (org.hl7.fhir.r4.model.Meta)1 PractitionerRole (org.hl7.fhir.r4.model.PractitionerRole)1 Reference (org.hl7.fhir.r4.model.Reference)1