Search in sources :

Example 16 with ConceptSetFilterComponent

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

the class ValueSetCheckerSimple method codeInConceptIsAFilter.

private boolean codeInConceptIsAFilter(CodeSystem cs, ConceptSetFilterComponent f, String code, boolean rootOnly) {
    if (!rootOnly && code.equals(f.getProperty())) {
        return true;
    }
    ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), f.getValue());
    if (cc == null) {
        return false;
    }
    cc = findCodeInConcept(cc, code);
    return cc != null;
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)

Example 17 with ConceptSetFilterComponent

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

the class ValueSetRenderer method genInclude.

private boolean genInclude(XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs, boolean doDesignations, List<UsedConceptMap> maps, Map<String, String> designations, int index) throws FHIRException, IOException {
    boolean hasExtensions = false;
    XhtmlNode li;
    li = ul.li();
    CodeSystem e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
    Map<String, ConceptDefinitionComponent> definitions = new HashMap<>();
    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);
                if (inc.hasVersion()) {
                    li.addText(" version ");
                    li.code(inc.getVersion());
                }
                // for performance reasons, we do all the fetching in one batch
                definitions = getConceptsForCodes(e, inc);
                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);
                    ConceptDefinitionComponent cc = definitions.get(c.getCode());
                    hasDefinition = hasDefinition || ((cc != null && cc.hasDefinition()) || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION));
                }
                if (hasComments || hasDefinition)
                    hasExtensions = true;
                addMapHeaders(addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false, false, null, langs, designations, doDesignations), maps);
                for (ConceptReferenceComponent c : inc.getConcept()) {
                    XhtmlNode tr = t.tr();
                    XhtmlNode td = tr.td();
                    ConceptDefinitionComponent cc = definitions.get(c.getCode());
                    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());
                    if (hasDefinition) {
                        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 (hasComments) {
                        td = tr.td();
                        if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT)) {
                            smartAddText(td, "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_VS_COMMENT));
                        }
                    }
                    if (doDesignations) {
                        addDesignationsToRow(c, designations, tr);
                        addLangaugesToRow(c, langs, tr);
                    }
                }
            }
            if (inc.getFilter().size() > 0) {
                li.addText(type + " codes from ");
                addCsRef(inc, li, e);
                li.tx(" where ");
                for (int i = 0; i < inc.getFilter().size(); i++) {
                    ConceptSetFilterComponent f = inc.getFilter().get(i);
                    if (i > 0) {
                        if (i == inc.getFilter().size() - 1) {
                            li.tx(" and ");
                        } else {
                            li.tx(", ");
                        }
                    }
                    if (f.getOp() == FilterOperator.EXISTS) {
                        if (f.getValue().equals("true")) {
                            li.tx(f.getProperty() + " exists");
                        } else {
                            li.tx(f.getProperty() + " doesn't exist");
                        }
                    } else {
                        li.tx(f.getProperty() + " " + describe(f.getOp()) + " ");
                        if (e != null && codeExistsInValueSet(e, f.getValue())) {
                            String href = getContext().fixReference(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 = getContext().getWorker().validateCode(getContext().getTerminologyServiceOptions(), inc.getSystem(), inc.getVersion(), 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(vs.asStringValue(), li);
            }
        }
        if (inc.hasExtension(ToolingExtensions.EXT_EXPAND_RULES) || inc.hasExtension(ToolingExtensions.EXT_EXPAND_GROUP)) {
            hasExtensions = true;
            renderExpansionRules(li, inc, index, definitions);
        }
    } else {
        li.tx("Import all the codes that are contained in ");
        if (inc.getValueSet().size() < 4) {
            boolean first = true;
            for (UriType vs : inc.getValueSet()) {
                if (first)
                    first = false;
                else
                    li.tx(", ");
                AddVsRef(vs.asStringValue(), li);
            }
        } else {
            XhtmlNode xul = li.ul();
            for (UriType vs : inc.getValueSet()) {
                AddVsRef(vs.asStringValue(), xul.li());
            }
        }
    }
    return hasExtensions;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) HashMap(java.util.HashMap) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) UriType(org.hl7.fhir.r5.model.UriType)

Example 18 with ConceptSetFilterComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent in project snowstorm by IHTSDO.

the class FHIRHelper method convertFilterToECL.

public String convertFilterToECL(ConceptSetComponent setDefn, boolean firstItem) throws FHIROperationException {
    StringBuilder eclBuilder = new StringBuilder();
    for (ConceptSetFilterComponent filter : setDefn.getFilter()) {
        if (firstItem) {
            firstItem = false;
        } else {
            eclBuilder.append(" OR ");
        }
        if (filter.getProperty().equals("concept")) {
            eclBuilder.append(convertOperationToECL(filter.getOp()));
            eclBuilder.append(filter.getValue());
        } else if (filter.getProperty().equals("constraint")) {
            if (filter.getOp().toCode() != "=") {
                throw new FHIROperationException(IssueType.NOTSUPPORTED, "ValueSet compose filter 'constaint' operation - only '=' currently implemented");
            }
            eclBuilder.append(filter.getValue());
        } else {
            throw new FHIROperationException(IssueType.NOTSUPPORTED, "ValueSet compose filter property - only 'concept' and 'constraint' currently implemented");
        }
    }
    return eclBuilder.toString();
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent)

Example 19 with ConceptSetFilterComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent 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 20 with ConceptSetFilterComponent

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

the class BaseWorkerContext method getIncSummary.

private String getIncSummary(ConceptSetComponent cc) {
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    for (UriType vs : cc.getValueSet()) {
        b.append(vs.asStringValue());
    }
    String vsd = b.length() > 0 ? " where the codes are in the value sets (" + b.toString() + ")" : "";
    String system = cc.getSystem();
    if (cc.hasConcept()) {
        return Integer.toString(cc.getConcept().size()) + " codes from " + system + vsd;
    }
    if (cc.hasFilter()) {
        String s = "";
        for (ConceptSetFilterComponent f : cc.getFilter()) {
            if (!Utilities.noString(s)) {
                s = s + " & ";
            }
            s = s + f.getProperty() + " " + f.getOp().toCode() + " " + f.getValue();
        }
        return "from " + system + " where " + s + vsd;
    }
    return "All codes from " + system + vsd;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) UriType(org.hl7.fhir.dstu3.model.UriType)

Aggregations

ConceptSetFilterComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 ArrayList (java.util.ArrayList)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 ConceptSetFilterComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent)5 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)5 ConceptReferenceComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)5 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)5 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)4 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)3 ConceptDefinitionComponent (org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent)3 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)3 UriType (org.hl7.fhir.r4b.model.UriType)3 ConceptReferenceComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent)3 UriType (org.hl7.fhir.r5.model.UriType)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)2