Search in sources :

Example 21 with ConceptReferenceComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent 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.r5.model.ValueSet.ConceptSetFilterComponent) Element(org.hl7.fhir.r5.model.Element) ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Example 22 with ConceptReferenceComponent

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

the class NarrativeGenerator method generateComposition.

private boolean generateComposition(ResourceContext rcontext, XhtmlNode x, ValueSet vs, boolean header) throws FHIRException, IOException {
    boolean hasExtensions = false;
    List<String> langs = new ArrayList<String>();
    if (header) {
        XhtmlNode h = x.h2();
        h.addText(vs.getName());
        addMarkdown(x, vs.getDescription());
        if (vs.hasCopyrightElement())
            generateCopyright(x, vs);
    }
    XhtmlNode p = x.para();
    p.tx("This value set includes codes from the following code systems:");
    XhtmlNode ul = x.ul();
    XhtmlNode li;
    for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
        hasExtensions = genInclude(rcontext, ul, inc, "Include", langs) || hasExtensions;
    }
    for (ConceptSetComponent exc : vs.getCompose().getExclude()) {
        hasExtensions = genInclude(rcontext, ul, exc, "Exclude", langs) || hasExtensions;
    }
    if (langs.size() > 0) {
        Collections.sort(langs);
        x.para().b().tx("Additional Language Displays");
        XhtmlNode t = x.table("codes");
        XhtmlNode tr = t.tr();
        tr.td().b().tx("Code");
        for (String lang : langs) tr.td().b().addText(describeLang(lang));
        for (ConceptSetComponent c : vs.getCompose().getInclude()) {
            for (ConceptReferenceComponent cc : c.getConcept()) {
                addLanguageRow(cc, t, langs);
            }
        }
    }
    return hasExtensions;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ArrayList(java.util.ArrayList) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 23 with ConceptReferenceComponent

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

the class NarrativeGenerator method describeLang.

private String describeLang(String lang) {
    ValueSet v = context.fetchResource(ValueSet.class, "http://hl7.org/fhir/ValueSet/languages");
    if (v != null) {
        ConceptReferenceComponent l = null;
        for (ConceptReferenceComponent cc : v.getCompose().getIncludeFirstRep().getConcept()) {
            if (cc.getCode().equals(lang))
                l = cc;
        }
        if (l == null) {
            if (lang.contains("-"))
                lang = lang.substring(0, lang.indexOf("-"));
            for (ConceptReferenceComponent cc : v.getCompose().getIncludeFirstRep().getConcept()) {
                if (cc.getCode().equals(lang) || cc.getCode().startsWith(lang + "-"))
                    l = cc;
            }
        }
        if (l != null) {
            if (lang.contains("-"))
                lang = lang.substring(0, lang.indexOf("-"));
            String en = l.getDisplay();
            String nativelang = null;
            for (ConceptReferenceDesignationComponent cd : l.getDesignation()) {
                if (cd.getLanguage().equals(lang))
                    nativelang = cd.getValue();
            }
            if (nativelang == null)
                return en + " (" + lang + ")";
            else
                return nativelang + " (" + en + ", " + lang + ")";
        }
    }
    return lang;
}
Also used : ValueSet(org.hl7.fhir.r4.model.ValueSet)

Example 24 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 = cs.hasUserData("tx.cs.special") ? ((SpecialCodeSystem) cs.getUserData("tx.cs.special")).findConcept(code) : findCodeInConcept(cs.getConcept(), code.getCode());
    if (cc == null) {
        if (cs.getContent() == CodeSystemContentMode.FRAGMENT) {
            return new ValidationResult(IssueSeverity.WARNING, context.formatMessage(I18nConstants.UNKNOWN_CODE__IN_FRAGMENT, gen(code), cs.getUrl()));
        } else {
            return new ValidationResult(IssueSeverity.ERROR, context.formatMessage(I18nConstants.UNKNOWN_CODE__IN_, gen(code), cs.getUrl()));
        }
    }
    if (code.getDisplay() == null) {
        return new ValidationResult(code.getSystem(), cc);
    }
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    if (cc.hasDisplay()) {
        b.append(cc.getDisplay());
        if (code.getDisplay().equalsIgnoreCase(cc.getDisplay())) {
            return new ValidationResult(code.getSystem(), cc);
        }
    }
    for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
        b.append(ds.getValue());
        if (code.getDisplay().equalsIgnoreCase(ds.getValue())) {
            return new ValidationResult(code.getSystem(), 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(code.getSystem(), cc);
            }
        }
        for (ConceptReferenceDesignationComponent ds : vs.getDesignation()) {
            b.append(ds.getValue());
            if (code.getDisplay().equalsIgnoreCase(ds.getValue())) {
                return new ValidationResult(code.getSystem(), cc);
            }
        }
    }
    return new ValidationResult(IssueSeverity.WARNING, context.formatMessage(I18nConstants.DISPLAY_NAME_FOR__SHOULD_BE_ONE_OF__INSTEAD_OF_, code.getSystem(), code.getCode(), b.toString(), code.getDisplay()), code.getSystem(), cc);
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent) ConceptDefinitionDesignationComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionDesignationComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ConceptReferenceDesignationComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceDesignationComponent) ValidationResult(org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult) ConceptReferenceComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent)

Example 25 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);
        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.r4b.model.CodeSystem) ValueSet(org.hl7.fhir.r4b.model.ValueSet) 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