Search in sources :

Example 76 with ValueSetExpansionContainsComponent

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

the class ValueSetExpanderSimple method addCodeAndDescendents.

private void addCodeAndDescendents(CodeSystem cs, String system, ConceptDefinitionComponent def, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters, ConceptDefinitionComponent exclusion, IConceptFilter filterFunc, boolean noInactive) throws FHIRException {
    def.checkNoModifiers("Code in Code System", "expanding");
    if (exclusion != null) {
        if (exclusion.getCode().equals(def.getCode()))
            // excluded.
            return;
    }
    if (!CodeSystemUtilities.isDeprecated(cs, def, false)) {
        ValueSetExpansionContainsComponent np = null;
        boolean abs = CodeSystemUtilities.isNotSelectable(cs, def);
        boolean inc = CodeSystemUtilities.isInactive(cs, def);
        if ((includeAbstract || !abs) && filterFunc.includeConcept(cs, def)) {
            np = addCode(system, def.getCode(), def.getDisplay(), parent, def.getDesignation(), expParams, abs, inc, filters, noInactive);
        }
        for (ConceptDefinitionComponent c : def.getConcept()) {
            addCodeAndDescendents(cs, system, c, np, expParams, filters, exclusion, filterFunc, noInactive);
        }
        if (def.hasUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK)) {
            List<ConceptDefinitionComponent> children = (List<ConceptDefinitionComponent>) def.getUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK);
            for (ConceptDefinitionComponent c : children) addCodeAndDescendents(cs, system, c, np, expParams, filters, exclusion, filterFunc, noInactive);
        }
    } else {
        for (ConceptDefinitionComponent c : def.getConcept()) {
            addCodeAndDescendents(cs, system, c, null, expParams, filters, exclusion, filterFunc, noInactive);
        }
        if (def.hasUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK)) {
            List<ConceptDefinitionComponent> children = (List<ConceptDefinitionComponent>) def.getUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK);
            for (ConceptDefinitionComponent c : children) addCodeAndDescendents(cs, system, c, null, expParams, filters, exclusion, filterFunc, noInactive);
        }
    }
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) ArrayList(java.util.ArrayList) List(java.util.List)

Example 77 with ValueSetExpansionContainsComponent

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

the class ValueSetCheckerSimple method findCodeInExpansion.

private ValidationResult findCodeInExpansion(Coding code, List<ValueSetExpansionContainsComponent> contains) {
    for (ValueSetExpansionContainsComponent containsComponent : contains) {
        if (containsComponent.getSystem().equals(code.getSystem()) && containsComponent.getCode().equals(code.getCode())) {
            ConceptDefinitionComponent ccd = new ConceptDefinitionComponent();
            ccd.setCode(containsComponent.getCode());
            ccd.setDisplay(containsComponent.getDisplay());
            ValidationResult res = new ValidationResult(code.getSystem(), ccd);
            return res;
        }
        if (containsComponent.hasContains()) {
            ValidationResult res = findCodeInExpansion(code, containsComponent.getContains());
            if (res != null) {
                return res;
            }
        }
    }
    return null;
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)

Example 78 with ValueSetExpansionContainsComponent

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

the class SpecDifferenceEvaluator method compareBindings.

private boolean compareBindings(Document doc, Element element, ElementDefinitionBindingComponent rev, ElementDefinitionBindingComponent orig) {
    boolean res = false;
    if (rev.getStrength() != orig.getStrength()) {
        element.setAttribute("binding-strength-changed", "true");
        res = true;
    }
    if (!Base.compareDeep(rev.getValueSet(), orig.getValueSet(), false)) {
        element.setAttribute("binding-valueset-changed", "true");
        res = true;
    }
    if (!maxValueSetsMatch(rev, orig)) {
        element.setAttribute("max-valueset-changed", "true");
        res = true;
    }
    if (rev.getStrength() == BindingStrength.REQUIRED && orig.getStrength() == BindingStrength.REQUIRED) {
        ValueSet vrev = getValueSet(rev.getValueSet(), revision.getExpansions());
        ValueSet vorig = getValueSet(rev.getValueSet(), original.getExpansions());
        boolean changed = false;
        if (vrev != null && vorig != null) {
            for (ValueSetExpansionContainsComponent cc : vorig.getExpansion().getContains()) {
                if (!hasCode(vrev, cc)) {
                    element.appendChild(makeElementWithAttribute(doc, "removed-code", "code", cc.getCode()));
                    changed = true;
                }
            }
            for (ValueSetExpansionContainsComponent cc : vrev.getExpansion().getContains()) {
                if (!hasCode(vorig, cc)) {
                    element.appendChild(makeElementWithAttribute(doc, "added-code", "code", cc.getCode()));
                    changed = true;
                }
            }
        }
        if (changed) {
            element.setAttribute("binding-codes-changed", "true");
            res = true;
        }
    }
    return res;
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent)

Example 79 with ValueSetExpansionContainsComponent

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

the class SpecDifferenceEvaluator method compareBindings.

private String compareBindings(ElementDefinitionBindingComponent rev, ElementDefinitionBindingComponent orig) {
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder("\r\n");
    if (rev.getStrength() != orig.getStrength())
        b.append("Change binding strength from " + orig.getStrength().toCode() + " to " + rev.getStrength().toCode());
    if (!canonicalsMatch(rev.getValueSet(), orig.getValueSet())) {
        b.append("Change value set from " + describeReference(orig.getValueSet()) + " to " + describeReference(rev.getValueSet()));
    }
    if (!maxValueSetsMatch(rev, orig))
        b.append("Change max value set from " + describeMax(orig) + " to " + describeMax(rev));
    if (rev.getStrength() == BindingStrength.REQUIRED && orig.getStrength() == BindingStrength.REQUIRED) {
        ValueSet vrev = getValueSet(rev.getValueSet(), revision.getExpansions());
        ValueSet vorig = getValueSet(rev.getValueSet(), original.getExpansions());
        CommaSeparatedStringBuilder br = new CommaSeparatedStringBuilder();
        int ir = 0;
        CommaSeparatedStringBuilder bo = new CommaSeparatedStringBuilder();
        int io = 0;
        if (vrev != null && vorig != null) {
            for (ValueSetExpansionContainsComponent cc : vorig.getExpansion().getContains()) {
                if (!hasCode(vrev, cc)) {
                    io++;
                    bo.append("`" + Utilities.escapeXml(cc.getCode()) + "`");
                }
            }
            for (ValueSetExpansionContainsComponent cc : vrev.getExpansion().getContains()) {
                if (!hasCode(vorig, cc)) {
                    ir++;
                    br.append("`" + Utilities.escapeXml(cc.getCode()) + "`");
                }
            }
        }
        if (io > 0)
            b.append("Remove " + Utilities.pluralize("Code", io) + " " + bo);
        if (ir > 0)
            b.append("Add " + Utilities.pluralize("Code", ir) + "  " + br);
    }
    if (rev.getStrength() == BindingStrength.EXTENSIBLE && orig.getStrength() == BindingStrength.EXTENSIBLE) {
        ValueSet vrev = getValueSet(rev.getValueSet(), revision.getValuesets());
        ValueSet vorig = getValueSet(orig.getValueSet(), original.getValuesets());
        if (vrev != null && vrev.hasCompose() && vrev.getCompose().getInclude().size() == 1 && vrev.getCompose().getIncludeFirstRep().hasSystem() && vorig != null && vorig.hasCompose() && vorig.getCompose().getInclude().size() == 1 && vorig.getCompose().getIncludeFirstRep().hasSystem()) {
            if (!vorig.getCompose().getIncludeFirstRep().getSystem().equals(vrev.getCompose().getIncludeFirstRep().getSystem())) {
                b.append("Change code system for extensibly bound codes from \"" + vorig.getCompose().getIncludeFirstRep().getSystem() + "\" to \"" + vrev.getCompose().getIncludeFirstRep().getSystem() + "\"");
            }
        }
    }
    return b.toString();
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent)

Example 80 with ValueSetExpansionContainsComponent

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

the class NarrativeGenerator method addExpansionRowToTable.

private void addExpansionRowToTable(XhtmlNode t, ValueSetExpansionContainsComponent c, int i, boolean doSystem, boolean doDefinition, Map<ConceptMap, String> mymaps, CodeSystem allCS) {
    XhtmlNode tr = t.addTag("tr");
    XhtmlNode td = tr.addTag("td");
    String tgt = makeAnchor(c.getSystem(), c.getCode());
    td.addTag("a").setAttribute("name", tgt).addText(" ");
    String s = Utilities.padLeft("", '.', i * 2);
    td.addText(s);
    Resource e = context.fetchCodeSystem(c.getSystem());
    if (e == null)
        td.addText(c.getCode());
    else {
        XhtmlNode a = td.addTag("a");
        a.addText(c.getCode());
        a.setAttribute("href", prefix + getCsRef(e) + "#" + Utilities.nmtokenize(c.getCode()));
    }
    if (doSystem) {
        td = tr.addTag("td");
        td.addText(c.getSystem());
    }
    td = tr.addTag("td");
    if (c.hasDisplayElement())
        td.addText(c.getDisplay());
    if (doDefinition) {
        CodeSystem cs = allCS;
        if (cs == null)
            cs = context.fetchCodeSystem(c.getSystem());
        td = tr.addTag("td");
        if (cs != null)
            td.addText(CodeSystemUtilities.getCodeDefinition(cs, c.getCode()));
    }
    for (ConceptMap m : mymaps.keySet()) {
        td = tr.addTag("td");
        List<TargetElementComponent> mappings = findMappingsForCode(c.getCode(), m);
        boolean first = true;
        for (TargetElementComponent mapping : mappings) {
            if (!first)
                td.addTag("br");
            first = false;
            XhtmlNode span = td.addTag("span");
            span.setAttribute("title", mapping.getEquivalence().toString());
            span.addText(getCharForEquivalence(mapping));
            XhtmlNode a = td.addTag("a");
            a.setAttribute("href", prefix + mymaps.get(m) + "#" + mapping.getCode());
            a.addText(mapping.getCode());
            if (!Utilities.noString(mapping.getComments()))
                td.addTag("i").addText("(" + mapping.getComments() + ")");
        }
    }
    for (ValueSetExpansionContainsComponent cc : c.getContains()) {
        addExpansionRowToTable(t, cc, i + 1, doSystem, doDefinition, mymaps, allCS);
    }
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionContainsComponent) Resource(org.hl7.fhir.dstu2016may.model.Resource) DomainResource(org.hl7.fhir.dstu2016may.model.DomainResource) TargetElementComponent(org.hl7.fhir.dstu2016may.model.ConceptMap.TargetElementComponent) ConceptMap(org.hl7.fhir.dstu2016may.model.ConceptMap) CodeSystem(org.hl7.fhir.dstu2016may.model.CodeSystem) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

ValueSetExpansionContainsComponent (org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent)32 ValueSetExpansionContainsComponent (org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionContainsComponent)22 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)20 ValueSetExpansionContainsComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent)17 ValueSet (org.hl7.fhir.r4.model.ValueSet)9 HashMap (java.util.HashMap)8 ValueSet (org.hl7.fhir.r5.model.ValueSet)8 ArrayList (java.util.ArrayList)7 ValueSetExpansionContainsComponent (org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent)7 ValueSetExpansionContainsComponent (org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionContainsComponent)7 IOException (java.io.IOException)6 ValueSetExpansionContainsComponent (org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent)6 ValueSetExpansionComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)5 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)5 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)5 ValueSet (org.hl7.fhir.dstu2016may.model.ValueSet)4 ValueSet (org.hl7.fhir.r4b.model.ValueSet)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)3