Search in sources :

Example 41 with ConceptReferenceComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent in project kindling by HL7.

the class CodeListToValueSetParser method execute.

public void execute(String v2map, String v3map, boolean utg) throws Exception {
    boolean hasDefine = false;
    for (int row = 0; row < sheet.rows.size(); row++) {
        hasDefine = hasDefine || Utilities.noString(sheet.getColumn(row, "System"));
    }
    Map<String, ConceptDefinitionComponent> codes = new HashMap<String, ConceptDefinitionComponent>();
    Map<String, ConceptDefinitionComponent> codesById = new HashMap<String, ConceptDefinitionComponent>();
    Map<String, ConceptSetComponent> includes = new HashMap<String, ConceptSetComponent>();
    CodeSystem cs = null;
    if (hasDefine) {
        cs = new CodeSystem();
        if (utg)
            cs.setUrl("http://terminology.hl7.org/CodeSystem/" + sheetName);
        else
            cs.setUrl("http://hl7.org/fhir/" + sheetName);
        if (!valueSet.hasCompose())
            valueSet.setCompose(new ValueSetComposeComponent());
        valueSet.getCompose().addInclude().setSystem(cs.getUrl());
        cs.setVersion(version);
        cs.setCaseSensitive(true);
        cs.setContent(CodeSystemContentMode.COMPLETE);
        codeSystems.see(cs, packageInfo);
        for (int row = 0; row < sheet.rows.size(); row++) {
            if (Utilities.noString(sheet.getColumn(row, "System"))) {
                ConceptDefinitionComponent cc = new ConceptDefinitionComponent();
                cc.setUserData("id", sheet.getColumn(row, "Id"));
                cc.setCode(sheet.getColumn(row, "Code"));
                if (codes.containsKey(cc.getCode()))
                    throw new Exception("Duplicate Code " + cc.getCode());
                codes.put(cc.getCode(), cc);
                codesById.put(cc.getUserString("id"), cc);
                cc.setDisplay(sheet.getColumn(row, "Display"));
                if (sheet.getColumn(row, "Abstract").toUpperCase().equals("Y"))
                    CodeSystemUtilities.setNotSelectable(cs, cc);
                if (cc.hasCode() && !cc.hasDisplay())
                    cc.setDisplay(Utilities.humanize(cc.getCode()));
                cc.setDefinition(Utilities.appendPeriod(sheet.getColumn(row, "Definition")));
                if (!Utilities.noString(sheet.getColumn(row, "Comment")))
                    ToolingExtensions.addCSComment(cc, sheet.getColumn(row, "Comment"));
                cc.setUserData("v2", sheet.getColumn(row, "v2"));
                cc.setUserData("v3", sheet.getColumn(row, "v3"));
                for (String ct : sheet.columns) if (ct.startsWith("Display:") && !Utilities.noString(sheet.getColumn(row, ct)))
                    cc.addDesignation().setLanguage(ct.substring(8)).setValue(sheet.getColumn(row, ct));
                String parent = sheet.getColumn(row, "Parent");
                if (Utilities.noString(parent))
                    cs.addConcept(cc);
                else if (parent.startsWith("#") && codesById.containsKey(parent.substring(1)))
                    codesById.get(parent.substring(1)).addConcept(cc);
                else if (codes.containsKey(parent))
                    codes.get(parent).addConcept(cc);
                else
                    throw new Exception("Parent " + parent + " not resolved in " + sheetName);
            }
        }
    }
    for (int row = 0; row < sheet.rows.size(); row++) {
        if (!Utilities.noString(sheet.getColumn(row, "System"))) {
            String system = sheet.getColumn(row, "System");
            ConceptSetComponent t = includes.get(system);
            if (t == null) {
                if (!valueSet.hasCompose())
                    valueSet.setCompose(new ValueSetComposeComponent());
                t = valueSet.getCompose().addInclude();
                t.setSystem(system);
                includes.put(system, t);
            }
            ConceptReferenceComponent cc = t.addConcept();
            cc.setCode(sheet.getColumn(row, "Code"));
            if (codes.containsKey(cc.getCode()))
                throw new Exception("Duplicate Code " + cc.getCode());
            codes.put(cc.getCode(), null);
            cc.setDisplay(sheet.getColumn(row, "Display"));
            if (!Utilities.noString(sheet.getColumn(row, "Definition")))
                ToolingExtensions.addDefinition(cc, sheet.getColumn(row, "Definition"));
            if (!Utilities.noString(sheet.getColumn(row, "Comment")))
                ToolingExtensions.addVSComment(cc, sheet.getColumn(row, "Comment"));
            cc.setUserDataINN("v2", sheet.getColumn(row, "v2"));
            cc.setUserDataINN("v3", sheet.getColumn(row, "v3"));
            for (String ct : sheet.columns) if (ct.startsWith("Display:") && !Utilities.noString(sheet.getColumn(row, ct)))
                cc.addDesignation().setLanguage(ct.substring(8)).setValue(sheet.getColumn(row, ct));
        }
    }
    if (!Utilities.noString(v2map)) {
        generateConceptMapV2(v2map, valueSet, cs);
    }
    if (!Utilities.noString(v3map)) {
        generateConceptMapV3(v3map, valueSet, cs);
    }
    if (cs != null)
        CodeSystemConvertor.populate(cs, valueSet);
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) HashMap(java.util.HashMap) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ValueSetComposeComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Example 42 with ConceptReferenceComponent

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

the class NarrativeGenerator method genInclude.

private boolean genInclude(XhtmlNode ul, ConceptSetComponent inc, String type) {
    boolean hasExtensions = false;
    XhtmlNode li;
    li = ul.addTag("li");
    ValueSet e = context.fetchCodeSystem(inc.getSystem());
    if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
        li.addText(type + " all codes defined in ");
        addCsRef(inc, li, e);
    } else {
        if (inc.getConcept().size() > 0) {
            li.addText(type + " these codes as defined in ");
            addCsRef(inc, li, e);
            XhtmlNode t = li.addTag("table");
            boolean hasComments = false;
            boolean hasDefinition = false;
            for (ConceptReferenceComponent c : inc.getConcept()) {
                hasComments = hasComments || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_COMMENT);
                hasDefinition = hasDefinition || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION);
            }
            if (hasComments || hasDefinition)
                hasExtensions = true;
            addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false);
            for (ConceptReferenceComponent c : inc.getConcept()) {
                XhtmlNode tr = t.addTag("tr");
                tr.addTag("td").addText(c.getCode());
                ConceptDefinitionComponent cc = getConceptForCode(e, c.getCode(), inc.getSystem());
                XhtmlNode td = tr.addTag("td");
                if (!Utilities.noString(c.getDisplay()))
                    td.addText(c.getDisplay());
                else if (cc != null && !Utilities.noString(cc.getDisplay()))
                    td.addText(cc.getDisplay());
                td = tr.addTag("td");
                if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION))
                    smartAddText(td, ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_DEFINITION));
                else if (cc != null && !Utilities.noString(cc.getDefinition()))
                    smartAddText(td, cc.getDefinition());
                if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_COMMENT)) {
                    smartAddText(tr.addTag("td"), "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_COMMENT));
                }
            }
        }
        boolean first = true;
        for (ConceptSetFilterComponent f : inc.getFilter()) {
            if (first) {
                li.addText(type + " codes from ");
                first = false;
            } else
                li.addText(" and ");
            addCsRef(inc, li, e);
            li.addText(" where " + f.getProperty() + " " + describe(f.getOp()) + " ");
            if (e != null && codeExistsInValueSet(e, f.getValue())) {
                XhtmlNode a = li.addTag("a");
                a.addText(f.getValue());
                a.setAttribute("href", prefix + getCsRef(e) + "#" + Utilities.nmtokenize(f.getValue()));
            } else
                li.addText(f.getValue());
            String disp = ToolingExtensions.getDisplayHint(f);
            if (disp != null)
                li.addText(" (" + disp + ")");
        }
    }
    return hasExtensions;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 43 with ConceptReferenceComponent

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

the class ValueSetExpanderSimple method doInternalIncludeCodes.

public void doInternalIncludeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, Parameters expParams, List<ValueSet> imports, CodeSystem cs) throws NoTerminologyServiceException, TerminologyServiceException, FHIRException {
    if (cs == null) {
        if (context.isNoTerminologyServer())
            throw new NoTerminologyServiceException("unable to find code system " + inc.getSystem().toString());
        else
            throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
    }
    cs.checkNoModifiers("Code System", "expanding");
    if (cs.getContent() != CodeSystemContentMode.COMPLETE)
        throw new TerminologyServiceException("Code system " + inc.getSystem().toString() + " is incomplete");
    if (cs.hasVersion())
        if (!existsInParams(params, "version", new UriType(cs.getUrl() + "|" + cs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "|" + cs.getVersion())));
    if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
        // special case - add all the code system
        for (ConceptDefinitionComponent def : cs.getConcept()) {
            addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null);
        }
    }
    if (!inc.getConcept().isEmpty()) {
        canBeHeirarchy = false;
        for (ConceptReferenceComponent c : inc.getConcept()) {
            c.checkNoModifiers("Code in Code System", "expanding");
            addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay(), null, convertDesignations(c.getDesignation()), expParams, false, CodeSystemUtilities.isInactive(cs, c.getCode()), imports);
        }
    }
    if (inc.getFilter().size() > 1) {
        // which will bt the case if we get around to supporting this
        canBeHeirarchy = false;
        // need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
        throw new TerminologyServiceException("Multiple filters not handled yet");
    }
    if (inc.getFilter().size() == 1) {
        ConceptSetFilterComponent fc = inc.getFilter().get(0);
        if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
            // special: all codes in the target code system under the value
            ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
            if (def == null)
                throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null);
        } else if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISNOTA) {
            // special: all codes in the target code system that are not under the value
            ConceptDefinitionComponent defEx = getConceptForCode(cs.getConcept(), fc.getValue());
            if (defEx == null)
                throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            for (ConceptDefinitionComponent def : cs.getConcept()) {
                addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, defEx);
            }
        } else if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.DESCENDENTOF) {
            // special: all codes in the target code system under the value
            ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
            if (def == null)
                throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            for (ConceptDefinitionComponent c : def.getConcept()) addCodeAndDescendents(cs, inc.getSystem(), c, null, expParams, imports, null);
        } else if ("display".equals(fc.getProperty()) && fc.getOp() == FilterOperator.EQUAL) {
            // gg; note: wtf is this: if the filter is display=v, look up the code 'v', and see if it's diplsay is 'v'?
            canBeHeirarchy = false;
            ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
            if (def != null) {
                if (isNotBlank(def.getDisplay()) && isNotBlank(fc.getValue())) {
                    if (def.getDisplay().contains(fc.getValue())) {
                        addCode(inc.getSystem(), def.getCode(), def.getDisplay(), null, def.getDesignation(), expParams, CodeSystemUtilities.isNotSelectable(cs, def), CodeSystemUtilities.isInactive(cs, def), imports);
                    }
                }
            }
        } else
            throw new NotImplementedException("Search by property[" + fc.getProperty() + "] and op[" + fc.getOp() + "] is not supported yet");
    }
}
Also used : NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) ConceptSetFilterComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent) NotImplementedException(org.apache.commons.lang3.NotImplementedException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) UriType(org.hl7.fhir.r4.model.UriType)

Example 44 with ConceptReferenceComponent

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

the class ValueSetCheckerSimple method validateCode.

private ValidationResult validateCode(Coding code, CodeSystem cs) {
    ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code.getCode());
    if (cc == null)
        return new ValidationResult(IssueSeverity.ERROR, "Unknown Code " + gen(code) + " in " + cs.getUrl());
    if (code.getDisplay() == null)
        return new ValidationResult(cc);
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    if (cc.hasDisplay()) {
        b.append(cc.getDisplay());
        if (code.getDisplay().equalsIgnoreCase(cc.getDisplay()))
            return new ValidationResult(cc);
    }
    for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
        b.append(ds.getValue());
        if (code.getDisplay().equalsIgnoreCase(ds.getValue()))
            return new ValidationResult(cc);
    }
    // also check to see if the value set has another display
    ConceptReferenceComponent vs = findValueSetRef(code.getSystem(), code.getCode());
    if (vs != null && (vs.hasDisplay() || vs.hasDesignation())) {
        if (vs.hasDisplay()) {
            b.append(vs.getDisplay());
            if (code.getDisplay().equalsIgnoreCase(vs.getDisplay()))
                return new ValidationResult(cc);
        }
        for (ConceptReferenceDesignationComponent ds : vs.getDesignation()) {
            b.append(ds.getValue());
            if (code.getDisplay().equalsIgnoreCase(ds.getValue()))
                return new ValidationResult(cc);
        }
    }
    return new ValidationResult(IssueSeverity.WARNING, "Display Name for " + code.getSystem() + "#" + code.getCode() + " should be one of '" + b.toString() + "' instead of " + code.getDisplay(), cc);
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) ConceptDefinitionDesignationComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionDesignationComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ValidationResult(org.hl7.fhir.r4.context.IWorkerContext.ValidationResult)

Example 45 with ConceptReferenceComponent

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

the class ValueSetExpanderSimple method excludeCodes.

private void excludeCodes(ConceptSetComponent exc, List<ValueSetExpansionParameterComponent> params, String ctxt) throws FHIRException {
    exc.checkNoModifiers("Compose.exclude", "expanding");
    if (exc.hasSystem() && exc.getConcept().size() == 0 && exc.getFilter().size() == 0) {
        excludeSystems.add(exc.getSystem());
    }
    if (exc.hasValueSet())
        throw fail("Processing Value set references in exclude is not yet done in " + ctxt);
    // importValueSet(imp.getValue(), params, expParams);
    CodeSystem cs = context.fetchCodeSystem(exc.getSystem());
    if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(exc.getSystem())) {
        ValueSetExpansionOutcome vse = context.expandVS(exc, false, false);
        ValueSet valueset = vse.getValueset();
        if (valueset == null)
            throw failTSE("Error Expanding ValueSet: " + vse.getError());
        excludeCodes(valueset.getExpansion(), params);
        return;
    }
    for (ConceptReferenceComponent c : exc.getConcept()) {
        excludeCode(exc.getSystem(), c.getCode());
    }
    if (exc.getFilter().size() > 0)
        throw fail("not done yet - multiple filters");
}
Also used : CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ValueSet(org.hl7.fhir.r5.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Aggregations

ConceptReferenceComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)17 ArrayList (java.util.ArrayList)14 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)14 ConceptReferenceComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent)12 ConceptReferenceComponent (org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)10 HashMap (java.util.HashMap)7 ConceptReferenceComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)7 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)7 ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)7 ValueSet (org.hl7.fhir.r4.model.ValueSet)6 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)5 ConceptReferenceDesignationComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceDesignationComponent)5 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)4 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)4 ConceptReferenceDesignationComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceDesignationComponent)4 ValueSet (org.hl7.fhir.r5.model.ValueSet)4 ConceptSetFilterComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent)4