Search in sources :

Example 61 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class ArgonautConverter method processAllergiesSection.

private void processAllergiesSection(CDAUtilities cda, Convert convert, Element section, Context context) throws Exception {
    scanSection("Allergies", section);
    ListResource list = new ListResource();
    list.setId(context.getBaseId() + "-list-allergies");
    list.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/list-daf-dafallergylist");
    list.setSubject(context.getSubjectRef());
    list.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(section, "code")), null));
    list.setTitle(cda.getChild(section, "title").getTextContent());
    list.setStatus(ListStatus.CURRENT);
    list.setDateElement(context.getNow());
    list.setSource(context.getAuthorRef());
    list.setMode(ListMode.SNAPSHOT);
    buildNarrative(list, cda.getChild(section, "text"));
    int i = 0;
    for (Element c : cda.getChildren(section, "entry")) {
        // allergy problem act
        Element apa = cda.getChild(c, "act");
        AllergyIntolerance ai = new AllergyIntolerance();
        ai.setId(context.getBaseId() + "-allergy-" + i);
        ai.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/allergyintolerance-daf-dafallergyintolerance");
        i++;
        ai.setPatient(context.getSubjectRef());
        ai.setAssertedDateElement(convert.makeDateTimeFromTS(cda.getChild(cda.getChild(apa, "effectiveTime"), "low")));
        boolean found = false;
        for (Element e : cda.getChildren(apa, "id")) {
            Identifier id = convert.makeIdentifierFromII(e);
            ai.getIdentifier().add(id);
        }
        if (!found) {
            list.addEntry().setItem(new Reference().setReference("AllergyIntolerance/" + ai.getId()));
            // allergy observation
            Element ao = cda.getChild(cda.getChild(apa, "entryRelationship"), "observation");
            if (!cda.getChild(ao, "value").getAttribute("code").equals("419511003"))
                throw new Error("unexpected code");
            // nothing....
            // no allergy status observation
            List<Element> reactions = cda.getChildren(ao, "entryRelationship");
            Element pe = cda.getChild(cda.getChild(cda.getChild(ao, "participant"), "participantRole"), "playingEntity");
            Element pec = cda.getChild(pe, "code");
            if (pec == null || !Utilities.noString(pec.getAttribute("nullFlavor"))) {
                String n = cda.getChild(pe, "name").getTextContent();
                // if (n.contains("No Known Drug Allergies") && reactions.isEmpty())
                // ai.setSubstance(new CodeableConcept().setText(n)); // todo: what do with this?
                // else
                ai.setCode(new CodeableConcept().setText(n));
            } else
                ai.setCode(inspectCode(convert.makeCodeableConceptFromCD(pec), null));
            recordAllergyCode(ai.getCode());
            if (!reactions.isEmpty()) {
                AllergyIntoleranceReactionComponent aie = ai.addReaction();
                for (Element er : reactions) {
                    Element ro = cda.getChild(er, "observation");
                    aie.addManifestation(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(ro, "value")), null));
                }
            }
            saveResource(ai);
        }
    }
    saveResource(list);
}
Also used : Element(org.w3c.dom.Element) AllergyIntoleranceReactionComponent(org.hl7.fhir.dstu3.model.AllergyIntolerance.AllergyIntoleranceReactionComponent)

Example 62 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class ArgonautConverter method processImmunizationsSection.

private void processImmunizationsSection(CDAUtilities cda, Convert convert, Element section, Context context) throws Exception {
    scanSection("Immunizations", section);
    ListResource list = new ListResource();
    list.setId(context.getBaseId() + "-list-immunizations");
    list.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/list-daf-dafimmunizationlist");
    list.setSubject(context.getSubjectRef());
    list.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(section, "code")), null));
    list.setTitle(cda.getChild(section, "title").getTextContent());
    list.setStatus(ListStatus.CURRENT);
    list.setMode(ListMode.SNAPSHOT);
    list.setDateElement(context.getNow());
    list.setSource(context.getAuthorRef());
    buildNarrative(list, cda.getChild(section, "text"));
    int i = 0;
    for (Element c : cda.getChildren(section, "entry")) {
        // allergy problem act
        Element sa = cda.getChild(c, "substanceAdministration");
        Immunization imm = new Immunization();
        imm.setId(context.getBaseId() + "-immunization-" + i);
        imm.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/immunization-daf-dafimmunization");
        i++;
        imm.setPatient(context.getSubjectRef());
        imm.setEncounter(new Reference().setReference("Encounter/" + context.getEncounter().getId()));
        imm.setNotGiven("true".equals(sa.getAttribute("negationInd")));
        imm.setStatus(convertImmunizationStatus(cda.getChild(sa, "statusCode")));
        boolean found = false;
        for (Element e : cda.getChildren(sa, "id")) {
            Identifier id = convert.makeIdentifierFromII(e);
            imm.getIdentifier().add(id);
        }
        if (!found) {
            list.addEntry().setItem(new Reference().setReference("Immunization/" + imm.getId()));
            imm.setDateElement(convert.makeDateTimeFromTS(cda.getChild(cda.getChild(sa, "effectiveTime"), "low")));
            if (imm.getNotGiven()) {
                Element reason = cda.getChild(cda.getChildByAttribute(sa, "entryRelationship", "typeCode", "RSON"), "observation");
                imm.setExplanation(new ImmunizationExplanationComponent());
                imm.getExplanation().addReasonNotGiven(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(reason, "code")), null));
            }
            Element mm = cda.getChild(cda.getChild(cda.getChild(sa, "consumable"), "manufacturedProduct"), "manufacturedMaterial");
            imm.setVaccineCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(mm, "code")), null));
            imm.setRoute(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(sa, "routeCode")), null));
            if (cda.getChild(mm, "lotNumberText") != null)
                imm.setLotNumber(cda.getChild(mm, "lotNumberText").getTextContent());
            Element mr = cda.getChild(cda.getChild(cda.getChild(sa, "consumable"), "manufacturedProduct"), "manufacturerOrganization");
            if (mr != null)
                imm.setManufacturer(new Reference().setDisplay(cda.getChild(mr, "name").getTextContent()));
            // the problem with this is that you can't have just a dose sequence number
            // Element subject = cda.getChild(cda.getChildByAttribute(sa, "entryRelationship", "typeCode", "SUBJ"), "observation");
            // if (subject != null)
            // imm.addVaccinationProtocol().setDoseSequence(Integer.parseInt(cda.getChild(subject, "value").getAttribute("value")));
            boolean hasprf = false;
            for (Element e : cda.getChildren(sa, "performer")) {
                if (imm.hasPractitioner())
                    throw new Error("additional performer discovered");
                Practitioner p = processPerformer(cda, convert, context, e, "assignedEntity", "assignedPerson");
                Reference ref = new Reference().setReference("Practitioner/" + p.getId()).setDisplay(p.getUserString("display"));
                imm.addPractitioner().setActor(ref).setRole(new org.hl7.fhir.dstu3.model.CodeableConcept().addCoding(new Coding().setSystem("http://hl7.org/fhir/v2/0443").setCode("AP")));
                hasprf = true;
            }
            imm.setPrimarySource(hasprf);
            saveResource(imm);
        }
    }
    saveResource(list);
}
Also used : Element(org.w3c.dom.Element) ImmunizationExplanationComponent(org.hl7.fhir.dstu3.model.Immunization.ImmunizationExplanationComponent)

Example 63 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class ArgonautConverter method convert.

private void convert(String sourceFolder, String filename, Coding clss) throws IOException {
    if (new File(Utilities.path(sourceFolder, filename)).length() == 0)
        return;
    CDAUtilities cda;
    try {
        System.out.println("Process " + Utilities.path(sourceFolder, filename));
        cda = new CDAUtilities(new FileInputStream(Utilities.path(sourceFolder, filename)));
        zipJ = new ZipGenerator(Utilities.path(destFolder, "json/doc", Utilities.changeFileExt(filename, ".json.zip")));
        zipX = new ZipGenerator(Utilities.path(destFolder, "xml/doc", Utilities.changeFileExt(filename, ".xml.zip")));
        Element doc = cda.getElement();
        Convert convert = new Convert(cda, ucumSvc, "-0400");
        convert.setGenerateMissingExtensions(true);
        Context context = new Context();
        context.setBaseId(Utilities.changeFileExt(filename, ""));
        context.setEncClass(clss);
        makeSubject(cda, convert, doc, context, context.getBaseId() + "-patient");
        makeAuthor(cda, convert, doc, context, context.getBaseId() + "-author");
        makeEncounter(cda, convert, doc, context, context.getBaseId() + "-encounter");
        Element body = cda.getDescendent(doc, "component/structuredBody");
        for (Element c : cda.getChildren(body, "component")) {
            processSection(cda, convert, context, cda.getChild(c, "section"));
        }
        oids.addAll(convert.getOids());
        saveResource(context.getEncounter());
        makeBinary(sourceFolder, filename, context);
        makeDocumentReference(cda, convert, doc, context);
        zipJ.close();
        zipX.close();
    } catch (Exception e) {
        throw new Error("Unable to process " + Utilities.path(sourceFolder, filename) + ": " + e.getMessage(), e);
    }
}
Also used : SimpleWorkerContext(org.hl7.fhir.dstu3.context.SimpleWorkerContext) Convert(org.hl7.fhir.convertors.misc.Convert) CDAUtilities(org.hl7.fhir.convertors.misc.CDAUtilities) Element(org.w3c.dom.Element) File(java.io.File) ZipGenerator(org.hl7.fhir.utilities.ZipGenerator) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 64 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class CCDAConverter method processSocialHistorySection.

protected SectionComponent processSocialHistorySection(Element section) throws Exception {
    ListResource list = new ListResource();
    for (Element entry : cda.getChildren(section, "entry")) {
        Element observation = cda.getlastChild(entry);
        if (cda.hasTemplateId(observation, "2.16.840.1.113883.10.20.22.4.38")) {
            processSocialObservation(list, observation, SocialHistoryType.SocialHistory);
        } else if (cda.hasTemplateId(observation, "2.16.840.1.113883.10.20.15.3.8")) {
            processSocialObservation(list, observation, SocialHistoryType.Pregnancy);
        } else if (cda.hasTemplateId(observation, "2.16.840.1.113883.10.20.22.4.78")) {
            processSocialObservation(list, observation, SocialHistoryType.SmokingStatus);
        } else if (cda.hasTemplateId(observation, "2.16.840.1.113883.10.20.22.4.85")) {
            processSocialObservation(list, observation, SocialHistoryType.TobaccoUse);
        } else
            throw new Exception("Unhandled Section template ids: " + cda.showTemplateIds(observation));
    }
    // todo: text
    SectionComponent s = new Composition.SectionComponent();
    s.setCode(convert.makeCodeableConceptFromCD(cda.getChild(section, "code")));
    // todo: check subject
    s.addEntry(Factory.makeReference(addReference(list, "Procedures", makeUUIDReference())));
    return s;
}
Also used : Element(org.w3c.dom.Element) SectionComponent(org.hl7.fhir.dstu3.model.Composition.SectionComponent)

Example 65 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class CCDAConverter method processProceduresSection.

protected SectionComponent processProceduresSection(Element section) throws Exception {
    ListResource list = new ListResource();
    for (Element entry : cda.getChildren(section, "entry")) {
        Element procedure = cda.getlastChild(entry);
        if (cda.hasTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.14")) {
            processProcedure(list, procedure, ProcedureType.Procedure);
        } else if (cda.hasTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.13")) {
            processProcedure(list, procedure, ProcedureType.Observation);
        } else if (cda.hasTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.12")) {
            processProcedure(list, procedure, ProcedureType.Act);
        } else
            throw new Exception("Unhandled Section template ids: " + cda.showTemplateIds(procedure));
    }
    // todo: text
    SectionComponent s = new Composition.SectionComponent();
    s.setCode(convert.makeCodeableConceptFromCD(cda.getChild(section, "code")));
    // todo: check subject
    s.addEntry(Factory.makeReference(addReference(list, "Procedures", makeUUIDReference())));
    return s;
}
Also used : Element(org.w3c.dom.Element) SectionComponent(org.hl7.fhir.dstu3.model.Composition.SectionComponent)

Aggregations

ArrayList (java.util.ArrayList)21 Element (org.w3c.dom.Element)11 IOException (java.io.IOException)10 LinkedHashMap (java.util.LinkedHashMap)9 Section (org.hl7.fhir.utilities.xml.SchematronWriter.Section)9 POCDMT000002UK01Section (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section)8 Rule (org.hl7.fhir.utilities.xml.SchematronWriter.Rule)7 POCDMT000002UK01Component3 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3)7 Reference (org.hl7.fhir.dstu3.model.Reference)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 SectionComponent (org.hl7.fhir.dstu3.model.Composition.SectionComponent)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 HashMap (java.util.HashMap)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 IdType (org.hl7.fhir.dstu3.model.IdType)4 Section (org.hl7.fhir.utilities.turtle.Turtle.Section)4 Subject (org.hl7.fhir.utilities.turtle.Turtle.Subject)4 POCDMT000002UK01Component5 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component5)4 FileNotFoundException (java.io.FileNotFoundException)3