Search in sources :

Example 21 with ConceptSetComponent

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

the class ProfileComparer method intersectByExpansion.

private ValueSet intersectByExpansion(ValueSet lvs, ValueSet rvs) {
    // this is pretty straight forward - we intersect the lists, and build a compose out of the intersection
    ValueSet vs = new ValueSet();
    vs.setStatus(ConformanceResourceStatus.DRAFT);
    Map<String, ValueSetExpansionContainsComponent> left = new HashMap<String, ValueSetExpansionContainsComponent>();
    scan(lvs.getExpansion().getContains(), left);
    Map<String, ValueSetExpansionContainsComponent> right = new HashMap<String, ValueSetExpansionContainsComponent>();
    scan(rvs.getExpansion().getContains(), right);
    Map<String, ConceptSetComponent> inc = new HashMap<String, ConceptSetComponent>();
    for (String s : left.keySet()) {
        if (right.containsKey(s)) {
            ValueSetExpansionContainsComponent cc = left.get(s);
            ConceptSetComponent c = inc.get(cc.getSystem());
            if (c == null) {
                c = vs.getCompose().addInclude().setSystem(cc.getSystem());
                inc.put(cc.getSystem(), c);
            }
            c.addConcept().setCode(cc.getCode()).setDisplay(cc.getDisplay());
        }
    }
    return vs;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent) HashMap(java.util.HashMap) ValueSet(org.hl7.fhir.dstu2.model.ValueSet)

Example 22 with ConceptSetComponent

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

the class ProfileComparer method intersectByExpansion.

private ValueSet intersectByExpansion(ValueSet lvs, ValueSet rvs) {
    // this is pretty straight forward - we intersect the lists, and build a compose out of the intersection
    ValueSet vs = new ValueSet();
    vs.setStatus(ConformanceResourceStatus.DRAFT);
    Map<String, ValueSetExpansionContainsComponent> left = new HashMap<String, ValueSetExpansionContainsComponent>();
    scan(lvs.getExpansion().getContains(), left);
    Map<String, ValueSetExpansionContainsComponent> right = new HashMap<String, ValueSetExpansionContainsComponent>();
    scan(rvs.getExpansion().getContains(), right);
    Map<String, ConceptSetComponent> inc = new HashMap<String, ConceptSetComponent>();
    for (String s : left.keySet()) {
        if (right.containsKey(s)) {
            ValueSetExpansionContainsComponent cc = left.get(s);
            ConceptSetComponent c = inc.get(cc.getSystem());
            if (c == null) {
                c = vs.getCompose().addInclude().setSystem(cc.getSystem());
                inc.put(cc.getSystem(), c);
            }
            c.addConcept().setCode(cc.getCode()).setDisplay(cc.getDisplay());
        }
    }
    return vs;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionContainsComponent) HashMap(java.util.HashMap) ValueSet(org.hl7.fhir.dstu2016may.model.ValueSet)

Example 23 with ConceptSetComponent

use of org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent 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 24 with ConceptSetComponent

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

the class ValueSetExpanderSimple method doServerIncludeCodes.

private void doServerIncludeCodes(ConceptSetComponent inc, boolean heirarchical, List<ValueSetExpansionParameterComponent> params, List<ValueSet> imports, Parameters expParams) throws FHIRException {
    ValueSetExpansionOutcome vso = context.expandVS(inc, heirarchical);
    if (vso.getError() != null)
        throw new TerminologyServiceException("Unable to expand imported value set: " + vso.getError());
    ValueSet vs = vso.getValueset();
    if (vs.hasVersion())
        if (!existsInParams(params, "version", new UriType(vs.getUrl() + "|" + vs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
    for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
        if (!existsInParams(params, p.getName(), p.getValue()))
            params.add(p);
    }
    for (ValueSetExpansionContainsComponent cc : vs.getExpansion().getContains()) {
        addCodeAndDescendents(cc, null, expParams, imports);
    }
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.r4.model.ValueSet) UriType(org.hl7.fhir.r4.model.UriType)

Example 25 with ConceptSetComponent

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

the class ValueSetExpanderSimple method includeCodes.

private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, Parameters expParams, boolean heirarchical) throws ETooCostly, FileNotFoundException, IOException, FHIRException {
    inc.checkNoModifiers("Compose.include", "expanding");
    List<ValueSet> imports = new ArrayList<ValueSet>();
    for (UriType imp : inc.getValueSet()) {
        imports.add(importValueSet(imp.getValue(), params, expParams));
    }
    if (!inc.hasSystem()) {
        if (// though this is not supposed to be the case
        imports.isEmpty())
            return;
        ValueSet base = imports.get(0);
        imports.remove(0);
        base.checkNoModifiers("Imported ValueSet", "expanding");
        copyImportContains(base.getExpansion().getContains(), null, expParams, imports);
    } else {
        CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
        if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE)) {
            doServerIncludeCodes(inc, heirarchical, params, imports, expParams);
        } else {
            doInternalIncludeCodes(inc, params, expParams, imports, cs);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ValueSet(org.hl7.fhir.r4.model.ValueSet) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) UriType(org.hl7.fhir.r4.model.UriType)

Aggregations

ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)25 ArrayList (java.util.ArrayList)22 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)21 IOException (java.io.IOException)20 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)20 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)19 FHIRException (org.hl7.fhir.exceptions.FHIRException)17 HashMap (java.util.HashMap)15 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)14 ConceptReferenceComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)14 ValueSet (org.hl7.fhir.r4.model.ValueSet)13 ValueSet (org.hl7.fhir.r5.model.ValueSet)13 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)12 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)12 ConceptSetComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent)12 FileNotFoundException (java.io.FileNotFoundException)10 NotImplementedException (org.apache.commons.lang3.NotImplementedException)10 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)10 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)10 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)9