Search in sources :

Example 16 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(XhtmlNode ul, ConceptSetComponent inc, String type) {
    boolean hasExtensions = false;
    XhtmlNode li;
    li = ul.addTag("li");
    CodeSystem e = context.fetchCodeSystem(inc.getSystem());
    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.addTag("table");
            boolean hasComments = false;
            boolean hasDefinition = false;
            for (ConceptReferenceComponent c : inc.getConcept()) {
                hasComments = hasComments || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_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.addTag("tr");
                tr.addTag("td").addText(c.getCode());
                ConceptDefinitionComponent cc = getConceptForCode(e, c.getCode(), inc.getSystem());
                XhtmlNode td = tr.addTag("td");
                if (!Utilities.noString(c.getDisplay()))
                    td.addText(c.getDisplay());
                else if (cc != null && !Utilities.noString(cc.getDisplay()))
                    td.addText(cc.getDisplay());
                td = tr.addTag("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_COMMENT)) {
                    smartAddText(tr.addTag("td"), "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_COMMENT));
                }
            }
        }
        boolean first = true;
        for (ConceptSetFilterComponent f : inc.getFilter()) {
            if (first) {
                li.addText(type + " codes from ");
                first = false;
            } else
                li.addText(" and ");
            addCsRef(inc, li, e);
            li.addText(" where " + f.getProperty() + " " + describe(f.getOp()) + " ");
            if (e != null && codeExistsInValueSet(e, f.getValue())) {
                XhtmlNode a = li.addTag("a");
                a.addText(f.getValue());
                a.setAttribute("href", prefix + getCsRef(e) + "#" + Utilities.nmtokenize(f.getValue()));
            } else
                li.addText(f.getValue());
            String disp = ToolingExtensions.getDisplayHint(f);
            if (disp != null)
                li.addText(" (" + disp + ")");
        }
    }
    return hasExtensions;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent) CodeSystem(org.hl7.fhir.dstu2016may.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ConceptReferenceComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 17 with ConceptSetComponent

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

the class BaseWorkerContext method determineCacheId.

private String determineCacheId(ValueSet vs, boolean heirarchical) throws Exception {
    // just the content logical definition is hashed
    ValueSet vsid = new ValueSet();
    vsid.setCompose(vs.getCompose());
    JsonParser parser = new JsonParser();
    parser.setOutputStyle(OutputStyle.NORMAL);
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    parser.compose(b, vsid);
    b.close();
    String s = new String(b.toByteArray(), Constants.CHARSET_UTF8);
    // any code systems we can find, we add these too.
    for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
        CodeSystem cs = fetchCodeSystem(inc.getSystem());
        if (cs != null) {
            String css = cacheValue(cs);
            s = s + css;
        }
    }
    s = s + "-" + Boolean.toString(heirarchical);
    String r = Integer.toString(s.hashCode());
    // TextFile.stringToFile(s, Utilities.path(cache, r+".id.json"));
    return r;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) JsonParser(org.hl7.fhir.dstu3.formats.JsonParser)

Example 18 with ConceptSetComponent

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

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionComponent expandVS(ConceptSetComponent inc, boolean heirachical) throws TerminologyServiceException {
    ValueSet vs = new ValueSet();
    vs.setCompose(new ValueSetComposeComponent());
    vs.getCompose().getInclude().add(inc);
    ValueSetExpansionOutcome vse = expandVS(vs, true, heirachical);
    ValueSet valueset = vse.getValueset();
    if (valueset == null) {
        throw new TerminologyServiceException("Error Expanding ValueSet: " + vse.getError());
    }
    return valueset.getExpansion();
}
Also used : ValueSetExpansionOutcome(org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent)

Example 19 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(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.dstu3.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent) HashMap(java.util.HashMap) ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 20 with ConceptSetComponent

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

the class ProfileComparer method unite.

private ValueSet unite(ElementDefinition ed, ProfileComparison outcome, String path, ValueSet lvs, ValueSet rvs) {
    ValueSet vs = new ValueSet();
    if (lvs.hasCompose()) {
        for (ConceptSetComponent inc : lvs.getCompose().getInclude()) vs.getCompose().getInclude().add(inc);
        if (lvs.getCompose().hasExclude()) {
            outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "The value sets " + lvs.getUrl() + " has exclude statements, and no union involving it can be correctly determined", ValidationMessage.IssueSeverity.ERROR));
            status(ed, ProfileUtilities.STATUS_ERROR);
        }
    }
    if (rvs.hasCompose()) {
        for (ConceptSetComponent inc : rvs.getCompose().getInclude()) if (!mergeIntoExisting(vs.getCompose().getInclude(), inc))
            vs.getCompose().getInclude().add(inc);
        if (rvs.getCompose().hasExclude()) {
            outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "The value sets " + lvs.getUrl() + " has exclude statements, and no union involving it can be correctly determined", ValidationMessage.IssueSeverity.ERROR));
            status(ed, ProfileUtilities.STATUS_ERROR);
        }
    }
    return vs;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

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