Search in sources :

Example 6 with ConceptSetFilterComponent

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

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

use of org.hl7.fhir.dstu2016may.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) {
    if (code.equals(f.getProperty()))
        return true;
    ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), f.getValue());
    if (cc == null)
        return false;
    cc = findCodeInConcept(cc.getConcept(), code);
    return cc != null;
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent)

Example 9 with ConceptSetFilterComponent

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

the class TerminologyCache 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.hasOp() ? f.getOp().toCode() : "?") + " " + f.getValue();
        }
        return "from " + system + " where " + s + vsd;
    }
    return "All codes from " + system + vsd;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) UriType(org.hl7.fhir.r4b.model.UriType)

Example 10 with ConceptSetFilterComponent

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

the class ValueSetComparer method compareDefinitions.

private void compareDefinitions(ConceptSetComponent left, ConceptSetComponent right, StructuralMatch<Element> combined, ConceptSetComponent union, ConceptSetComponent intersection) {
    // system must match, but the rest might not. we're going to do the full comparison whatever, so the outcome looks consistent to the user
    List<CanonicalType> matchVSR = new ArrayList<>();
    for (CanonicalType l : left.getValueSet()) {
        CanonicalType r = findInList(right.getValueSet(), l, left.getValueSet());
        if (r == null) {
            union.getValueSet().add(l);
            combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed ValueSet", "ValueSet.compose.include.valueSet")));
        } else {
            matchVSR.add(r);
            if (l.getValue().equals(r.getValue())) {
                union.getValueSet().add(l);
                intersection.getValueSet().add(l);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, null);
                combined.getChildren().add(sm);
            } else {
                union.getValueSet().add(l);
                union.getValueSet().add(r);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Values are different", "ValueSet.compose.include.valueSet"));
                combined.getChildren().add(sm);
            }
        }
    }
    for (CanonicalType r : right.getValueSet()) {
        if (!matchVSR.contains(r)) {
            union.getValueSet().add(r);
            combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Add ValueSet", "ValueSet.compose.include.valueSet"), r));
        }
    }
    List<ConceptReferenceComponent> matchCR = new ArrayList<>();
    for (ConceptReferenceComponent l : left.getConcept()) {
        ConceptReferenceComponent r = findInList(right.getConcept(), l, left.getConcept());
        if (r == null) {
            union.getConcept().add(l);
            combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed this Concept", "ValueSet.compose.include.concept")));
        } else {
            matchCR.add(r);
            if (l.getCode().equals(r.getCode())) {
                ConceptReferenceComponent cu = new ConceptReferenceComponent();
                ConceptReferenceComponent ci = new ConceptReferenceComponent();
                union.getConcept().add(cu);
                intersection.getConcept().add(ci);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
                combined.getChildren().add(sm);
                compareConcepts(l, r, sm, cu, ci);
            } else {
                union.getConcept().add(l);
                union.getConcept().add(r);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Concepts are different", "ValueSet.compose.include.concept"));
                combined.getChildren().add(sm);
                compareConcepts(l, r, sm, null, null);
            }
        }
    }
    for (ConceptReferenceComponent r : right.getConcept()) {
        if (!matchCR.contains(r)) {
            union.getConcept().add(r);
            combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added this Concept", "ValueSet.compose.include.concept"), r));
        }
    }
    List<ConceptSetFilterComponent> matchFR = new ArrayList<>();
    for (ConceptSetFilterComponent l : left.getFilter()) {
        ConceptSetFilterComponent r = findInList(right.getFilter(), l, left.getFilter());
        if (r == null) {
            union.getFilter().add(l);
            combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed this item", "ValueSet.compose.include.filter")));
        } else {
            matchFR.add(r);
            if (l.getProperty().equals(r.getProperty()) && l.getOp().equals(r.getOp())) {
                ConceptSetFilterComponent cu = new ConceptSetFilterComponent();
                ConceptSetFilterComponent ci = new ConceptSetFilterComponent();
                union.getFilter().add(cu);
                intersection.getFilter().add(ci);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
                combined.getChildren().add(sm);
                compareFilters(l, r, sm, cu, ci);
            } else {
                union.getFilter().add(l);
                union.getFilter().add(r);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Codes are different", "ValueSet.compose.include.filter"));
                combined.getChildren().add(sm);
                compareFilters(l, r, sm, null, null);
            }
        }
    }
    for (ConceptSetFilterComponent r : right.getFilter()) {
        if (!matchFR.contains(r)) {
            union.getFilter().add(r);
            combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added this item", "ValueSet.compose.include.filter"), r));
        }
    }
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent) Element(org.hl7.fhir.r4b.model.Element) ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r4b.model.CanonicalType) ConceptReferenceComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent)

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