Search in sources :

Example 46 with ConceptSetComponent

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

the class ValueSetComparer method compareCompose.

private void compareCompose(ValueSetComposeComponent left, ValueSetComposeComponent right, ValueSetComparison res, ValueSetComposeComponent union, ValueSetComposeComponent intersection) {
    // first, the includes
    List<ConceptSetComponent> matchR = new ArrayList<>();
    for (ConceptSetComponent l : left.getInclude()) {
        ConceptSetComponent r = findInList(right.getInclude(), l, left.getInclude());
        if (r == null) {
            union.getInclude().add(l);
            res.getIncludes().getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed Include", "ValueSet.compose.include")));
        } else {
            matchR.add(r);
            ConceptSetComponent csM = new ConceptSetComponent();
            ConceptSetComponent csI = new ConceptSetComponent();
            union.getInclude().add(csM);
            intersection.getInclude().add(csI);
            StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
            res.getIncludes().getChildren().add(sm);
            compareDefinitions(l, r, sm, csM, csI);
        }
    }
    for (ConceptSetComponent r : right.getInclude()) {
        if (!matchR.contains(r)) {
            union.getInclude().add(r);
            res.getIncludes().getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added Include", "ValueSet.compose.include"), r));
        }
    }
    // now. the excludes
    matchR.clear();
    for (ConceptSetComponent l : left.getExclude()) {
        ConceptSetComponent r = findInList(right.getExclude(), l, left.getExclude());
        if (r == null) {
            union.getExclude().add(l);
            res.getExcludes().getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed Exclude", "ValueSet.compose.exclude")));
        } else {
            matchR.add(r);
            ConceptSetComponent csM = new ConceptSetComponent();
            ConceptSetComponent csI = new ConceptSetComponent();
            union.getExclude().add(csM);
            intersection.getExclude().add(csI);
            StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
            res.getExcludes().getChildren().add(sm);
            compareDefinitions(l, r, sm, csM, csI);
        }
    }
    for (ConceptSetComponent r : right.getExclude()) {
        if (!matchR.contains(r)) {
            union.getExclude().add(r);
            res.getExcludes().getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added Exclude", "ValueSet.compose.exclude"), r));
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) Element(org.hl7.fhir.r5.model.Element) ArrayList(java.util.ArrayList)

Example 47 with ConceptSetComponent

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

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

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionOutcome expandVS(ConceptSetComponent inc, boolean heirachical) throws TerminologyServiceException {
    ValueSet vs = new ValueSet();
    vs.setCompose(new ValueSetComposeComponent());
    vs.getCompose().getInclude().add(inc);
    CacheToken cacheToken = txCache.generateExpandToken(vs, heirachical);
    ValueSetExpansionOutcome res;
    res = txCache.getExpansion(cacheToken);
    if (res != null)
        return res;
    Parameters p = expParameters.copy();
    p.setParameter("includeDefinition", false);
    p.setParameter("excludeNested", !heirachical);
    if (noTerminologyServer)
        return new ValueSetExpansionOutcome("Error expanding ValueSet: running without terminology services", TerminologyServiceErrorClass.NOSERVICE);
    Map<String, String> params = new HashMap<String, String>();
    params.put("_limit", Integer.toString(expandCodesLimit));
    params.put("_incomplete", "true");
    tlog("$expand on " + txCache.summary(vs));
    try {
        ValueSet result = txClient.expandValueset(vs, p, params);
        res = new ValueSetExpansionOutcome(result).setTxLink(txLog.getLastId());
    } catch (Exception e) {
        res = new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.UNKNOWN);
        if (txLog != null)
            res.setTxLink(txLog.getLastId());
    }
    txCache.cacheExpansion(cacheToken, res, TerminologyCache.PERMANENT);
    return res;
}
Also used : HashMap(java.util.HashMap) CacheToken(org.hl7.fhir.r4.context.TerminologyCache.CacheToken) ValueSetExpansionOutcome(org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 49 with ConceptSetComponent

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

the class TerminologyCache method getIncSummary.

private String getIncSummary(ConceptSetComponent cc) {
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    for (UriType vs : cc.getValueSet()) b.append(vs.asStringValue());
    String vsd = b.length() > 0 ? " where the codes are in the value sets (" + b.toString() + ")" : "";
    String system = cc.getSystem();
    if (cc.hasConcept())
        return Integer.toString(cc.getConcept().size()) + " codes from " + system + vsd;
    if (cc.hasFilter()) {
        String s = "";
        for (ConceptSetFilterComponent f : cc.getFilter()) {
            if (!Utilities.noString(s))
                s = s + " & ";
            s = s + f.getProperty() + " " + f.getOp().toCode() + " " + f.getValue();
        }
        return "from " + system + " where " + s + vsd;
    }
    return "All codes from " + system + vsd;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) UriType(org.hl7.fhir.r4.model.UriType)

Example 50 with ConceptSetComponent

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

the class NarrativeGenerator method addCsRef.

private <T extends Resource> void addCsRef(ConceptSetComponent inc, XhtmlNode li, T cs) {
    String ref = null;
    boolean addHtml = true;
    if (cs != null) {
        ref = (String) cs.getUserData("external.url");
        if (Utilities.noString(ref))
            ref = (String) cs.getUserData("filename");
        else
            addHtml = false;
        if (Utilities.noString(ref))
            ref = (String) cs.getUserData("path");
    }
    String spec = getSpecialReference(inc.getSystem());
    if (spec != null) {
        XhtmlNode a = li.ah(spec);
        a.code(inc.getSystem());
    } else if (cs != null && ref != null) {
        if (!Utilities.noString(prefix) && ref.startsWith("http://hl7.org/fhir/"))
            ref = ref.substring(20) + "/index.html";
        else if (addHtml && !ref.contains(".html"))
            ref = ref + ".html";
        XhtmlNode a = li.ah(prefix + ref.replace("\\", "/"));
        a.code(inc.getSystem());
    } else {
        li.code(inc.getSystem());
    }
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

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