Search in sources :

Example 61 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent 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(PublicationStatus.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.r4.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) HashMap(java.util.HashMap) ValueSet(org.hl7.fhir.r4.model.ValueSet)

Example 62 with ValueSetExpansionContainsComponent

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

the class Element method getAsICoding.

public ICoding getAsICoding() throws FHIRException {
    if ("code".equals(fhirType())) {
        if (property.getDefinition().getBinding().getStrength() != BindingStrength.REQUIRED)
            return null;
        ICodingImpl c = new ICodingImpl(true, true, false, false);
        c.code = primitiveValue();
        ValueSetExpansionOutcome vse = property.getContext().expandVS(property.getDefinition().getBinding(), true, false);
        if (vse.getValueset() == null)
            return null;
        for (ValueSetExpansionContainsComponent cc : vse.getValueset().getExpansion().getContains()) {
            if (cc.getCode().equals(c.code)) {
                c.system = cc.getSystem();
                if (cc.hasVersion()) {
                    c.doesVersion = true;
                    c.version = cc.getVersion();
                }
                if (cc.hasDisplay()) {
                    c.doesDisplay = true;
                    c.display = cc.getDisplay();
                }
            }
        }
        if (c.system == null)
            return null;
        return c;
    } else if ("Coding".equals(fhirType())) {
        ICodingImpl c = new ICodingImpl(true, true, true, true);
        c.system = getNamedChildValue("system");
        c.code = getNamedChildValue("code");
        c.display = getNamedChildValue("display");
        c.version = getNamedChildValue("version");
        return c;
    } else if ("Quantity".equals(fhirType())) {
        ICodingImpl c = new ICodingImpl(true, true, false, false);
        c.system = getNamedChildValue("system");
        c.code = getNamedChildValue("code");
        return c;
    } else
        return null;
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionOutcome(org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome)

Example 63 with ValueSetExpansionContainsComponent

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

the class TerminologyCache method generateExpandToken.

public CacheToken generateExpandToken(ValueSet vs, boolean heirarchical) {
    CacheToken ct = new CacheToken();
    ValueSet vsc = getVSEssense(vs);
    for (ConceptSetComponent inc : vs.getCompose().getInclude()) if (inc.hasSystem())
        ct.setName(getNameForSystem(inc.getSystem()));
    for (ConceptSetComponent inc : vs.getCompose().getExclude()) if (inc.hasSystem())
        ct.setName(getNameForSystem(inc.getSystem()));
    for (ValueSetExpansionContainsComponent inc : vs.getExpansion().getContains()) if (inc.hasSystem())
        ct.setName(getNameForSystem(inc.getSystem()));
    JsonParser json = new JsonParser();
    json.setOutputStyle(OutputStyle.PRETTY);
    try {
        ct.request = "{\"hierarchical\" : " + (heirarchical ? "true" : "false") + ", \"valueSet\" :" + json.composeString(vsc) + "}\r\n";
    } catch (IOException e) {
        throw new Error(e);
    }
    ct.key = String.valueOf(hashNWS(ct.request));
    return ct;
}
Also used : ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) IOException(java.io.IOException) ValueSet(org.hl7.fhir.r4.model.ValueSet) JsonParser(org.hl7.fhir.r4.formats.JsonParser)

Example 64 with ValueSetExpansionContainsComponent

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

the class NarrativeGenerator method generateExpansion.

private boolean generateExpansion(XhtmlNode x, ValueSet vs, ValueSet src, boolean header) {
    boolean hasExtensions = false;
    Map<ConceptMap, String> mymaps = new HashMap<ConceptMap, String>();
    for (ConceptMap a : context.findMapsForSource(vs.getUrl())) {
        String url = "";
        ValueSet vsr = context.fetchResource(ValueSet.class, ((Reference) a.getTarget()).getReference());
        if (vsr != null)
            url = (String) vsr.getUserData("filename");
        mymaps.put(a, url);
    }
    if (header) {
        XhtmlNode h = x.addTag("h3");
        h.addText("Value Set Contents");
        if (IsNotFixedExpansion(vs))
            x.addTag("p").addText(vs.getDescription());
        if (vs.hasCopyright())
            generateCopyright(x, vs);
    }
    if (ToolingExtensions.hasExtension(vs.getExpansion(), "http://hl7.org/fhir/StructureDefinition/valueset-toocostly"))
        x.addTag("p").setAttribute("style", "border: maroon 1px solid; background-color: #FFCCCC; font-weight: bold; padding: 8px").addText(tooCostlyNote);
    else {
        Integer count = countMembership(vs);
        if (count == null)
            x.addTag("p").addText("This value set does not contain a fixed number of concepts");
        else
            x.addTag("p").addText("This value set contains " + count.toString() + " concepts");
    }
    boolean doSystem = checkDoSystem(vs, src);
    if (doSystem && allFromOneSystem(vs)) {
        doSystem = false;
        XhtmlNode p = x.addTag("p");
        p.addText("All codes from system ");
        p.addTag("code").addText(vs.getExpansion().getContains().get(0).getSystem());
    }
    XhtmlNode t = x.addTag("table").setAttribute("class", "codes");
    XhtmlNode tr = t.addTag("tr");
    tr.addTag("td").addTag("b").addText("Code");
    if (doSystem)
        tr.addTag("td").addTag("b").addText("System");
    tr.addTag("td").addTag("b").addText("Display");
    addMapHeaders(tr, mymaps);
    for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
        addExpansionRowToTable(t, c, 0, doSystem, mymaps);
    }
    return hasExtensions;
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent) HashMap(java.util.HashMap) ConceptMap(org.hl7.fhir.dstu2.model.ConceptMap) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 65 with ValueSetExpansionContainsComponent

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

the class ValueSetExpanderSimple method addCode.

private void addCode(String system, String code, String display) {
    ValueSetExpansionContainsComponent n = new ValueSet.ValueSetExpansionContainsComponent();
    n.setSystem(system);
    n.setCode(code);
    n.setDisplay(display);
    String s = key(n);
    if (!map.containsKey(s)) {
        codes.add(n);
        map.put(s, n);
    }
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent)

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