Search in sources :

Example 86 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet in project org.hl7.fhir.core by hapifhir.

the class ICD11Generator method buildValueSet.

private String buildValueSet(CodeSystem cs, String code, String name, JsonObject o, String dest) throws IOException {
    String id = code + "-" + name;
    String url = "http://id.who.int/icd11/ValueSet/" + id;
    ValueSet vs = new ValueSet();
    vs.setId(id);
    vs.setUrl(url);
    vs.setName("VS" + name + "4" + code);
    vs.setTitle("Value Set for " + name + " on " + code);
    vs.setStatus(PublicationStatus.ACTIVE);
    vs.setExperimental(false);
    vs.setDate(cs.getDate());
    vs.setPublisher("WHO");
    vs.setCopyright("Consult WHO For terms of use");
    vs.setVersion(cs.getVersion());
    vs.setStatus(cs.getStatus());
    ConceptSetComponent inc = vs.getCompose().addInclude();
    inc.setSystem(cs.getUrl());
    for (JsonElement e : o.getAsJsonArray("scaleEntity")) {
        inc.addFilter().setProperty("concept").setOp(FilterOperator.ISA).setValue(tail(e.getAsString()));
    }
    new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "vs-" + id + ".xml")), vs);
    return url;
}
Also used : ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) XmlParser(org.hl7.fhir.r4.formats.XmlParser) JsonElement(com.google.gson.JsonElement) FileOutputStream(java.io.FileOutputStream)

Example 87 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet in project org.hl7.fhir.core by hapifhir.

the class CCDAConverter method processAllergyProblemAct.

protected void processAllergyProblemAct(ListResource list, Element concern) throws Exception {
    cda.checkTemplateId(concern, "2.16.840.1.113883.10.20.22.4.30");
    // Allergy Problem Act - this is a concern - we treat the concern as information about it's place in the list
    checkNoNegationOrNullFlavor(concern, "Allergy Problem Act");
    checkNoSubject(concern, "Allergy Problem Act");
    // SHALL contain exactly one [1..1] Allergy - intolerance Observation
    for (Element entry : cda.getChildren(concern, "entryRelationship")) {
        Element obs = cda.getChild(entry, "observation");
        cda.checkTemplateId(obs, "2.16.840.1.113883.10.20.22.4.7");
        checkNoNegationOrNullFlavor(obs, "Allergy - intolerance Observation");
        checkNoSubject(obs, "Allergy Problem Act");
        AllergyIntolerance ai = new AllergyIntolerance();
        ListEntryComponent item = addItemToList(list, ai);
        // SHALL contain at least one [1..*] id (CONF:7472).
        for (Element e : cda.getChildren(concern, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
        // SHALL contain exactly one [1..1] statusCode, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.80.68 HITSPProblemStatus DYNAMIC (CONF:7485)
        // the status code is about the concern (e.g. the entry in the list)
        // possible values: active, suspended, aborted, completed, with an effective time
        String s = cda.getStatus(concern);
        item.setFlag(Factory.newCodeableConcept(s, "http://hl7.org/fhir/v3/ActStatus", s));
        if (// only on this condition?
        s.equals("aborted"))
            item.setDeleted(true);
        // SHALL contain exactly one [1..1] effectiveTime (CONF:7498)
        Period p = convert.makePeriodFromIVL(cda.getChild(concern, "effectiveTime"));
        item.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/list-period", p, false));
        if (p.getEnd() != null)
            item.setDate(p.getEnd());
        else
            item.setDate(p.getStart());
        // SHALL contain at least one [1..*] id (CONF:7382)
        for (Element e : cda.getChildren(obs, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
        // SHALL contain exactly one [1..1] effectiveTime (CONF:7387)
        ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergyintolerance-period", convert.makePeriodFromIVL(cda.getChild(obs, "effectiveTime")), false));
        // SHALL contain exactly one [1..1] value with @xsi:type="CD" (CONF:7390)
        CodeableConcept type = convert.makeCodeableConceptFromCD(cda.getChild(obs, "value"));
        // This value SHALL contain @code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.6.2 Allergy/Adverse Event Type
        String ss = type.getCoding().get(0).getCode();
        if (ss.equals("416098002") || ss.equals("414285001"))
            ai.setType(AllergyIntoleranceType.ALLERGY);
        else if (ss.equals("59037007") || ss.equals("235719002"))
            ai.setType(AllergyIntoleranceType.INTOLERANCE);
        ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergy-category", type, false));
        // SHOULD contain zero or one [0..1] participant (CONF:7402) such that it
        // ......This playingEntity SHALL contain exactly one [1..1] code
        ai.setCode(convert.makeCodeableConceptFromCD(cda.getDescendent(obs, "participant/participantRole/playingEntity/code")));
        // SHOULD contain zero or more [0..*] entryRelationship (CONF:7447) such that it SHALL contain exactly one [1..1] Reaction Observation (templateId:2.16.840.1.113883.10.20.22.4.9) (CONF:7450).
        for (Element e : cda.getChildren(obs, "entryRelationship")) {
            Element child = cda.getChild(e, "observation");
            if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.28") && ai.getClinicalStatus() == null) {
                // SHALL contain exactly one [1..1] value with @xsi:type="CE", where the @code SHALL be selected from ValueSet Problem Status Value Set 2.16.840.1.113883.3.88.12.80.68 DYNAMIC (CONF:7322).
                // 55561003  SNOMED CT  Active
                // 73425007  SNOMED CT  Inactive
                // 413322009  SNOMED CT  Resolved
                String sc = cda.getChild(child, "value").getAttribute("code");
                if (sc.equals("55561003")) {
                    ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
                    ai.setVerificationStatus(AllergyIntoleranceVerificationStatus.CONFIRMED);
                } else
                    ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
            } else if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.9")) {
                ai.getReaction().add(processAdverseReactionObservation(child));
            }
        }
        // SHOULD contain zero or one [0..1] entryRelationship (CONF:9961) such that it SHALL contain exactly one [1..1] Severity Observation (templateId:2.16.840.1.113883.10.20.22.4.8) (CONF:9963).
        ai.setCriticality(readCriticality(cda.getSeverity(obs)));
    }
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) Element(org.w3c.dom.Element) ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)

Example 88 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet in project org.hl7.fhir.core by hapifhir.

the class CCDAConverter method processProcedure.

protected void processProcedure(ListResource list, Element procedure, ProcedureType type) throws Exception {
    switch(type) {
        case Procedure:
            cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.14");
            break;
        case Observation:
            cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.13");
            break;
        case Act:
            cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.12");
    }
    checkNoNegationOrNullFlavor(procedure, "Procedure (" + type + ")");
    checkNoSubject(procedure, "Procedure (" + type + ")");
    Procedure p = new Procedure();
    addItemToList(list, p);
    // moodCode is either INT or EVN. INT is not handled yet. INT is deprecated anyway
    if (procedure.getAttribute("moodCode").equals("INT"))
        p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-planned", Factory.newBoolean(true), false));
    // SHALL contain at least one [1..*] id (CONF:7655).
    for (Element e : cda.getChildren(procedure, "id")) p.getIdentifier().add(convert.makeIdentifierFromII(e));
    // SHALL contain exactly one [1..1] code (CONF:7656).
    // This code @code in a procedure activity SHOULD be selected from LOINC or SNOMED CT and MAY be selected from CPT-4, ICD9 Procedures, ICD10 Procedures
    p.setCode(convert.makeCodeableConceptFromCD(cda.getChild(procedure, "code")));
    // SHALL contain exactly one [1..1] statusCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.11.20.9.22 ProcedureAct
    // completed | active | aborted | cancelled - not in FHIR
    p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-status", Factory.newCode(cda.getStatus(procedure)), false));
    // SHOULD contain zero or one [0..1] effectiveTime (CONF:7662).
    p.setPerformed(convert.makePeriodFromIVL(cda.getChild(procedure, "effectiveTime")));
    // MAY contain zero or one [0..1] priorityCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.1.11.16866 ActPriority DYNAMIC (CONF:7668)
    p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-priority", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "priorityCode")), false));
    // MAY contain zero or one [0..1] methodCode (CONF:7670).
    p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-method", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "methodCode")), false));
    if (type == ProcedureType.Observation) {
    // for Procedure-Observation:
    // 9.	SHALL contain exactly one [1..1] value (CONF:16846).
    // don't know what this is. It's not the actual result of the procedure (that goes in results "This section records ... procedure observations"), and there seems to be no value. The example as <value xsi:type="CD"/> which is not valid
    // so we ignore this for now
    }
    // SHOULD contain zero or more [0..*] targetSiteCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.8.9 Body site DYNAMIC (CONF:7683).
    for (Element e : cda.getChildren(procedure, "targetSiteCode")) p.addBodySite(convert.makeCodeableConceptFromCD(e));
    // SHOULD contain zero or more [0..*] performer (CONF:7718) such that it
    for (Element e : cda.getChildren(procedure, "performer")) {
        ProcedurePerformerComponent pp = new ProcedurePerformerComponent();
        p.getPerformer().add(pp);
        pp.setActor(makeReferenceToPractitionerForAssignedEntity(e, p));
    }
    for (Element participant : cda.getChildren(procedure, "participant")) {
        Element participantRole = cda.getlastChild(participant);
        if (type == ProcedureType.Procedure && cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.37")) {
            // MAY contain zero or more [0..*] participant (CONF:7751) such that it  SHALL contain exactly one [1..1] @typeCode="DEV" Device
            // implanted devices
            p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/implanted-devices", Factory.makeReference(processDevice(participantRole, p)), false));
        } else if (cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.32")) {
            // MAY contain zero or more [0..*] participant (CONF:7765) such that it SHALL contain exactly one [1..1] Service Delivery Location (templateId:2.16.840.1.113883.10.20.22.4.32) (CONF:7767)
            p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/location", Factory.makeReference(processSDLocation(participantRole, p)), false));
        }
    }
    for (Element e : cda.getChildren(procedure, "entryRelationship")) {
        Element a = /* act*/
        cda.getlastChild(e);
        if (a.getLocalName().equals("encounter")) {
        // MAY contain zero or more [0..*] entryRelationship (CONF:7768) such that it SHALL contain exactly one encounter which SHALL contain exactly one [1..1] id (CONF:7773).
        // todo - and process as a full encounter while we're at it
        } else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.20")) {
            // MAY contain zero or one [0..1] entryRelationship (CONF:7775) such that it SHALL contain exactly one [1..1] Instructions (templateId:2.16.840.1.113883.10.20.22.4.20) (CONF:7778).
            // had code for type, plus text for instructions
            Extension n = Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions", null, true);
            n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-type", convert.makeCodeableConceptFromCD(cda.getChild(a, "code")), false));
            n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-text", convert.makeStringFromED(cda.getChild(a, "text")), false));
            p.getExtension().add(n);
        } else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.19")) {
            // MAY contain zero or more [0..*] entryRelationship (CONF:7779) such that it SHALL contain exactly one [1..1] Indication (templateId:2.16.840.1.113883.10.20.22.4.19) (CONF:7781).
            p.addReasonCode(processIndication(a));
        } else if (cda.hasTemplateId(cda.getlastChild(e), "2.16.840.1.113883.10.20.22.4.16")) {
        // MAY contain zero or one [0..1] entryRelationship (CONF:7886) such that it SHALL contain exactly one [1..1] Medication Activity (templateId:2.16.840.1.113883.10.20.22.4.16) (CONF:7888).
        // todo
        }
    }
}
Also used : Element(org.w3c.dom.Element) ProcedurePerformerComponent(org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent)

Example 89 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet in project org.hl7.fhir.core by hapifhir.

the class ISO21090Importer method produceProperties.

private void produceProperties(List<ElementDefinition> elements, String name, List<Property> properties, boolean attrMode, boolean snapshot) throws FHIRFormatError {
    for (Property p : properties) {
        if (p.isIsattr() == attrMode) {
            ElementDefinition ed = new ElementDefinition();
            elements.add(ed);
            ed.setPath(name + "." + p.getName());
            if (p.getType().startsWith("xsd:"))
                ToolingExtensions.addStringExtension(ed.addType(), ToolingExtensions.EXT_XML_TYPE, p.getType());
            else
                ed.addType().setCode(p.getType());
            ed.setMin(p.getMin());
            ed.setMax(p.getMax() == Integer.MAX_VALUE ? "*" : Integer.toString(p.getMax()));
            ed.setDefinition(p.getDoco());
            if (p.isIsattr())
                ed.addRepresentation(PropertyRepresentation.XMLATTR);
            if (p.getBinding() != null)
                ed.getBinding().setStrength(BindingStrength.REQUIRED).setValueSet(new UriType("http://hl7.org/fhir/iso21090/ValueSet/" + p.getBinding()));
            if (snapshot)
                ed.getBase().setPath(ed.getPath()).setMin(ed.getMin()).setMax(ed.getMax());
        }
    }
}
Also used : ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) UriType(org.hl7.fhir.dstu3.model.UriType)

Example 90 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet in project org.hl7.fhir.core by hapifhir.

the class ISO21090Importer method generateValueSet.

private void generateValueSet(EnumValueSet evs) throws Exception {
    ValueSet bvs = ctxt.fetchResource(ValueSet.class, evs.getTemplate());
    if (bvs == null)
        throw new Exception("Did not find template value set " + evs.getTemplate());
    ValueSet vs = bvs.copy();
    vs.getCompose().getInclude().clear();
    vs.getIdentifier().clear();
    vs.setName("ISO 20190 " + evs.getName() + " Enumeration");
    vs.setId(evs.getName());
    vs.setUrl("http://hl7.org/fhir/iso21090/ValueSet/" + vs.getId());
    vs.setDate(new Date());
    vs.setExperimental(false);
    ConceptSetComponent inc = vs.getCompose().addInclude().setSystem(evs.getSystem());
    for (String code : evs.getCodes()) {
        inc.addConcept().setCode(code);
    }
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "iso21090\\ValueSet-" + evs.getName() + ".xml")), vs);
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

ValueSet (org.hl7.fhir.r5.model.ValueSet)159 ValueSet (org.hl7.fhir.r4.model.ValueSet)116 Test (org.junit.jupiter.api.Test)115 ArrayList (java.util.ArrayList)101 FHIRException (org.hl7.fhir.exceptions.FHIRException)100 IOException (java.io.IOException)97 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)59 ValueSet (org.hl7.fhir.r4b.model.ValueSet)59 FileNotFoundException (java.io.FileNotFoundException)58 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)56 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)46 HashMap (java.util.HashMap)45 Test (org.junit.Test)45 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)43 File (java.io.File)36 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)36 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)29 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)29 FileInputStream (java.io.FileInputStream)27