Search in sources :

Example 6 with ConceptReferenceComponent

use of org.hl7.fhir.r4b.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");
    CodeSystem 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.dstu2016may.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent) CodeSystem(org.hl7.fhir.dstu2016may.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ConceptReferenceComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 7 with ConceptReferenceComponent

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

the class NarrativeGenerator method genInclude.

private boolean genInclude(ResourceContext rcontext, XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs) throws FHIRException {
    boolean hasExtensions = false;
    XhtmlNode li;
    li = ul.li();
    CodeSystem e = context.fetchCodeSystem(inc.getSystem());
    if (inc.hasSystem()) {
        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.table("none");
                boolean hasComments = false;
                boolean hasDefinition = false;
                for (ConceptReferenceComponent c : inc.getConcept()) {
                    hasComments = hasComments || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_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.tr();
                    XhtmlNode td = tr.td();
                    ConceptDefinitionComponent cc = getConceptForCode(e, c.getCode(), inc);
                    addCodeToTable(false, inc.getSystem(), c.getCode(), c.hasDisplay() ? c.getDisplay() : cc != null ? cc.getDisplay() : "", td);
                    td = tr.td();
                    if (!Utilities.noString(c.getDisplay()))
                        td.addText(c.getDisplay());
                    else if (cc != null && !Utilities.noString(cc.getDisplay()))
                        td.addText(cc.getDisplay());
                    td = tr.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_VS_COMMENT)) {
                        smartAddText(tr.td(), "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_VS_COMMENT));
                    }
                    for (ConceptReferenceDesignationComponent cd : c.getDesignation()) {
                        if (cd.hasLanguage() && !langs.contains(cd.getLanguage()))
                            langs.add(cd.getLanguage());
                    }
                }
            }
            boolean first = true;
            for (ConceptSetFilterComponent f : inc.getFilter()) {
                if (first) {
                    li.addText(type + " codes from ");
                    first = false;
                } else
                    li.tx(" and ");
                addCsRef(inc, li, e);
                li.tx(" where " + f.getProperty() + " " + describe(f.getOp()) + " ");
                if (e != null && codeExistsInValueSet(e, f.getValue())) {
                    String href = prefix + getCsRef(e);
                    if (href.contains("#"))
                        href = href + "-" + Utilities.nmtokenize(f.getValue());
                    else
                        href = href + "#" + e.getId() + "-" + Utilities.nmtokenize(f.getValue());
                    li.ah(href).addText(f.getValue());
                } else if ("concept".equals(f.getProperty()) && inc.hasSystem()) {
                    li.addText(f.getValue());
                    ValidationResult vr = context.validateCode(inc.getSystem(), f.getValue(), null);
                    if (vr.isOk()) {
                        li.tx(" (" + vr.getDisplay() + ")");
                    }
                } else
                    li.addText(f.getValue());
                String disp = ToolingExtensions.getDisplayHint(f);
                if (disp != null)
                    li.tx(" (" + disp + ")");
            }
        }
        if (inc.hasValueSet()) {
            li.tx(", where the codes are contained in ");
            boolean first = true;
            for (UriType vs : inc.getValueSet()) {
                if (first)
                    first = false;
                else
                    li.tx(", ");
                AddVsRef(rcontext, vs.asStringValue(), li);
            }
        }
    } else {
        li = ul.li();
        li.tx("Import all the codes that are contained in ");
        boolean first = true;
        for (UriType vs : inc.getValueSet()) {
            if (first)
                first = false;
            else
                li.tx(", ");
            AddVsRef(rcontext, vs.asStringValue(), li);
        }
    }
    return hasExtensions;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent) ConceptReferenceDesignationComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceDesignationComponent) ValidationResult(org.hl7.fhir.dstu3.context.IWorkerContext.ValidationResult) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) UriType(org.hl7.fhir.dstu3.model.UriType)

Example 8 with ConceptReferenceComponent

use of org.hl7.fhir.r4b.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 new Error("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);
        ValueSet valueset = vse.getValueset();
        if (valueset == null)
            throw new TerminologyServiceException("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 new NotImplementedException("not done yet");
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) ValueSet(org.hl7.fhir.r4.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)

Example 9 with ConceptReferenceComponent

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

the class ValueSetCheckerSimple method inComponent.

private boolean inComponent(ConceptSetComponent vsi, String system, String code, boolean only) throws FHIRException {
    for (UriType uri : vsi.getValueSet()) {
        if (inImport(uri.getValue(), system, code))
            return true;
    }
    if (!vsi.hasSystem())
        return false;
    if (only && system == null) {
        // whether we know the system or not, we'll accept the stated codes at face value
        for (ConceptReferenceComponent cc : vsi.getConcept()) if (cc.getCode().equals(code))
            return true;
    }
    if (!system.equals(vsi.getSystem()))
        return false;
    if (vsi.hasFilter()) {
        boolean ok = true;
        for (ConceptSetFilterComponent f : vsi.getFilter()) if (!codeInFilter(system, f, code)) {
            ok = false;
            break;
        }
        if (ok)
            return true;
    }
    CodeSystem def = context.fetchCodeSystem(system);
    if (def.getContent() != CodeSystemContentMode.COMPLETE)
        throw new FHIRException("Unable to resolve system " + vsi.getSystem() + " - system is not complete");
    List<ConceptDefinitionComponent> list = def.getConcept();
    boolean ok = validateCodeInConceptList(code, def, list);
    if (ok && vsi.hasConcept()) {
        for (ConceptReferenceComponent cc : vsi.getConcept()) if (cc.getCode().equals(code))
            return true;
        return false;
    } else
        return ok;
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 10 with ConceptReferenceComponent

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

the class ValueSetComparer method addComposeRow.

private void addComposeRow(HierarchicalTableGenerator gen, List<Row> rows, StructuralMatch<Element> t, String name) {
    Row r = gen.new Row();
    rows.add(r);
    r.getCells().add(gen.new Cell(null, null, name, null, null));
    if (t.hasLeft() && t.hasRight()) {
        ConceptSetComponent csL = (ConceptSetComponent) t.getLeft();
        ConceptSetComponent csR = (ConceptSetComponent) t.getRight();
        if (csL.hasSystem() && csL.getSystem().equals(csR.getSystem())) {
            r.getCells().add(gen.new Cell(null, null, csL.getSystem(), null, null).span(2).center());
        } else {
            r.getCells().add(gen.new Cell(null, null, csL.getSystem(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
            r.getCells().add(gen.new Cell(null, null, csR.getSystem(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
        }
        if (csL.hasVersion() && csR.hasVersion()) {
            if (csL.getVersion().equals(csR.getVersion())) {
                r.getCells().add(gen.new Cell(null, null, csL.getVersion(), null, null).span(2).center());
            } else {
                r.getCells().add(gen.new Cell(null, null, csL.getVersion(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
                r.getCells().add(gen.new Cell(null, null, csR.getVersion(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
            }
        } else if (csL.hasVersion()) {
            r.getCells().add(gen.new Cell(null, null, csL.getVersion(), null, null));
            r.getCells().add(missingCell(gen, COLOR_NO_CELL_RIGHT));
        } else if (csR.hasVersion()) {
            r.getCells().add(missingCell(gen, COLOR_NO_CELL_LEFT));
            r.getCells().add(gen.new Cell(null, null, csR.getVersion(), null, null));
        } else {
            r.getCells().add(missingCell(gen).span(2).center());
        }
    } else if (t.hasLeft()) {
        r.setColor(COLOR_NO_ROW_RIGHT);
        ConceptSetComponent cs = (ConceptSetComponent) t.getLeft();
        r.getCells().add(gen.new Cell(null, null, cs.getSystem(), null, null));
        r.getCells().add(missingCell(gen));
        r.getCells().add(gen.new Cell(null, null, cs.hasVersion() ? "Version: " + cs.getVersion() : "", null, null));
        r.getCells().add(missingCell(gen));
    } else {
        r.setColor(COLOR_NO_ROW_LEFT);
        ConceptSetComponent cs = (ConceptSetComponent) t.getRight();
        r.getCells().add(missingCell(gen));
        r.getCells().add(gen.new Cell(null, null, cs.getSystem(), null, null));
        r.getCells().add(missingCell(gen));
        r.getCells().add(gen.new Cell(null, null, cs.hasVersion() ? "Version: " + cs.getVersion() : "", null, null));
    }
    r.getCells().add(cellForMessages(gen, t.getMessages()));
    for (StructuralMatch<Element> c : t.getChildren()) {
        if (c.either() instanceof ConceptReferenceComponent) {
            addSetConceptRow(gen, r.getSubRows(), c);
        } else {
            addSetFilterRow(gen, r.getSubRows(), c);
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent) Element(org.hl7.fhir.r4b.model.Element) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) ConceptReferenceComponent(org.hl7.fhir.r4b.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