Search in sources :

Example 91 with ValueSet

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

the class ICD11Generator method processMMSEntity.

private void processMMSEntity(CodeSystem cs, String base, String ref, org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent cc, String dest) throws IOException {
    System.out.print(".");
    JsonObject entity = fetchJson(url(base, ref));
    cc.setId(tail(ref));
    if (entity.has("code") && !Utilities.noString(entity.get("code").getAsString())) {
        cc.setCode(entity.get("code").getAsString());
    } else if (entity.has("blockId") && !Utilities.noString(entity.get("blockId").getAsString())) {
        cc.setCode(entity.get("blockId").getAsString());
    } else {
        cc.setCode(cc.getId());
        cc.addProperty().setCode("abstract").setValue(new BooleanType(true));
    }
    if (entity.has("classKind") && !Utilities.noString(entity.get("classKind").getAsString()) && !"category".equals(entity.get("classKind").getAsString())) {
        cc.addProperty().setCode("kind").setValue(new CodeType(entity.get("classKind").getAsString()));
    }
    cc.setDisplay(readString(entity, "title"));
    StringBuilder defn = new StringBuilder();
    String d = readString(entity, "definition");
    if (d != null) {
        defn.append(d);
    }
    if (d == null && (entity.has("inclusion") || entity.has("exclusion"))) {
        defn.append(cc.getDisplay());
    }
    if (entity.has("inclusion")) {
        defn.append(". Includes: ");
        boolean first = true;
        for (JsonElement child : entity.getAsJsonArray("inclusion")) {
            if (first)
                first = false;
            else
                defn.append(", ");
            defn.append(readString((JsonObject) child, "label"));
        }
    }
    if (entity.has("exclusion")) {
        defn.append(". Excludes: ");
        boolean first = true;
        for (JsonElement child : entity.getAsJsonArray("exclusion")) {
            if (first)
                first = false;
            else
                defn.append(", ");
            JsonObject co = (JsonObject) child;
            String v = readString(co, "label");
            if (v != null) {
                defn.append(v);
                if (co.has("linearizationReference")) {
                    cc.addProperty().setValue(new Coding().setSystem("http://id.who.int/icd11/mms").setCode(tail(co.get("linearizationReference").getAsString())).setDisplay(v)).setCode("exclusion");
                }
            }
        }
    }
    cc.setDefinition(defn.toString());
    addDesignation(readString(entity, "longDefinition"), cc, "http://id.who.int/icd11/mms/designation", "longDefinition");
    addDesignation(readString(entity, "fullySpecifiedName"), cc, "http://snomed.info/sct", "900000000000003001");
    addProperty(readString(entity, "codingNote"), cc, "codingNote");
    if (entity.has("indexTerm")) {
        // }
        for (JsonElement child : entity.getAsJsonArray("indexTerm")) {
            processIndexTerm(cc, (JsonObject) child);
        }
    }
    if (entity.has("postcoordinationScale")) {
        for (JsonElement child : entity.getAsJsonArray("postcoordinationScale")) {
            JsonObject o = (JsonObject) child;
            String name = tail(o.get("axisName").getAsString());
            ConceptPropertyComponent prop = cc.addProperty();
            prop.setCode("postcoordinationScale");
            prop.setValue(new CodeType(name));
            ToolingExtensions.addBooleanExtension(prop, "http://id.who.int/icd11/extensions/required", o.get("requiredPostcoordination").getAsBoolean());
            ToolingExtensions.addBooleanExtension(prop, "http://id.who.int/icd11/extensions/repeats", o.get("allowMultipleValues").getAsBoolean());
            if (o.has("scaleEntity")) {
                ToolingExtensions.addUriExtension(prop, "http://id.who.int/icd11/extensions/valueSet", buildValueSet(cs, cc.getCode(), name, o, dest));
            }
        }
    }
    if (entity.has("child")) {
        for (JsonElement child : entity.getAsJsonArray("child")) {
            processMMSEntity(cs, base, child.getAsString(), cc.addConcept(), dest);
        }
    }
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptPropertyComponent) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 92 with ValueSet

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

the class NarrativeGenerator method generateComposition.

private boolean generateComposition(XhtmlNode x, ValueSet vs, boolean header) {
    boolean hasExtensions = false;
    if (!vs.hasCodeSystem()) {
        if (header) {
            XhtmlNode h = x.addTag("h2");
            h.addText(vs.getName());
            XhtmlNode p = x.addTag("p");
            smartAddText(p, vs.getDescription());
            if (vs.hasCopyrightElement())
                generateCopyright(x, vs);
        }
        XhtmlNode p = x.addTag("p");
        p.addText("This value set includes codes from the following code systems:");
    } else {
        XhtmlNode p = x.addTag("p");
        p.addText("In addition, this value set includes codes from other code systems:");
    }
    XhtmlNode ul = x.addTag("ul");
    XhtmlNode li;
    for (UriType imp : vs.getCompose().getImport()) {
        li = ul.addTag("li");
        li.addText("Import all the codes that are contained in ");
        AddVsRef(imp.getValue(), li);
    }
    for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
        hasExtensions = genInclude(ul, inc, "Include") || hasExtensions;
    }
    for (ConceptSetComponent exc : vs.getCompose().getExclude()) {
        hasExtensions = genInclude(ul, exc, "Exclude") || hasExtensions;
    }
    return hasExtensions;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) UriType(org.hl7.fhir.dstu2.model.UriType)

Example 93 with ValueSet

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

the class NarrativeGenerator method countMembership.

private Integer countMembership(ValueSet vs) {
    int count = 0;
    if (vs.hasExpansion())
        count = count + conceptCount(vs.getExpansion().getContains());
    else {
        if (vs.hasCodeSystem())
            count = count + countConcepts(vs.getCodeSystem().getConcept());
        if (vs.hasCompose()) {
            if (vs.getCompose().hasExclude()) {
                try {
                    ValueSetExpansionOutcome vse = context.expandVS(vs, true);
                    count = 0;
                    count += conceptCount(vse.getValueset().getExpansion().getContains());
                    return count;
                } catch (Exception e) {
                    return null;
                }
            }
            for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
                if (inc.hasFilter())
                    return null;
                if (!inc.hasConcept())
                    return null;
                count = count + inc.getConcept().size();
            }
        }
    }
    return count;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent) ValueSetExpansionOutcome(org.hl7.fhir.dstu2.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ContactPoint(org.hl7.fhir.dstu2.model.ContactPoint) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 94 with ValueSet

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

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionOutcome expandVS(ValueSet vs, boolean cacheOk) {
    try {
        Map<String, String> params = new HashMap<String, String>();
        params.put("_limit", "10000");
        params.put("_incomplete", "true");
        params.put("profile", "http://www.healthintersections.com.au/fhir/expansion/no-details");
        ValueSet result = txServer.expandValueset(vs, null, params);
        return new ValueSetExpansionOutcome(result);
    } catch (Exception e) {
        return new ValueSetExpansionOutcome("Error expanding ValueSet \"" + vs.getUrl() + ": " + e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) ValueSetExpansionOutcome(org.hl7.fhir.dstu2.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 95 with ValueSet

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

the class BaseWorkerContext method validateCode.

@Override
public ValidationResult validateCode(String system, String code, String display, ConceptSetComponent vsi) {
    try {
        ValueSet vs = new ValueSet().setUrl(Utilities.makeUuidUrn());
        vs.getCompose().addInclude(vsi);
        return verifyCodeExternal(vs, new Coding().setSystem(system).setCode(code).setDisplay(display), true);
    } catch (Exception e) {
        return new ValidationResult(IssueSeverity.FATAL, "Error validating code \"" + code + "\" in system \"" + system + "\": " + e.getMessage());
    }
}
Also used : Coding(org.hl7.fhir.dstu2.model.Coding) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

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