Search in sources :

Example 1 with ConceptSetFilterComponent

use of org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent in project kindling by HL7.

the class PageProcessor method getSnomedCTConceptList.

private String getSnomedCTConceptList() throws Exception {
    Map<String, SnomedConceptUsage> concepts = new HashMap<String, SnomedConceptUsage>();
    for (ValueSet vs : definitions.getValuesets().getList()) {
        if (!vs.hasUrl() || !vs.getUrl().startsWith("http://terminology.hl7.org")) {
            for (ConceptSetComponent cc : vs.getCompose().getInclude()) if (cc.hasSystem() && cc.getSystem().equals("http://snomed.info/sct")) {
                for (ConceptReferenceComponent c : cc.getConcept()) {
                    String d = c.hasDisplay() ? c.getDisplay() : workerContext.getCodeDefinition("http://snomed.info/sct", c.getCode()).getDisplay();
                    if (concepts.containsKey(c.getCode()))
                        concepts.get(c.getCode()).update(d, vs);
                    else
                        concepts.put(c.getCode(), new SnomedConceptUsage(c.getCode(), d, vs));
                }
                for (ConceptSetFilterComponent c : cc.getFilter()) {
                    if ("concept".equals(c.getProperty())) {
                        getSnomedCTConcept(concepts, vs, c);
                    }
                }
            }
        }
    }
    List<String> sorts = new ArrayList<String>();
    for (String s : concepts.keySet()) sorts.add(s);
    Collections.sort(sorts);
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"codes\">\r\n");
    b.append(" <tr><td><b>Code</b></td><td><b>Display</b></td><td>ValueSets</td></tr>\r\n");
    for (String s : sorts) {
        SnomedConceptUsage usage = concepts.get(s);
        b.append(" <tr>\r\n   <td>" + s + "</td>\r\n    <td>" + Utilities.escapeXml(usage.getDisplay()) + "</td>\r\n    <td>");
        boolean first = true;
        for (ValueSet vs : usage.getValueSets()) {
            if (first)
                first = false;
            else
                b.append("<br/>");
            String path = (String) vs.getUserData("path");
            b.append(" <a href=\"" + pathTail(Utilities.changeFileExt(path, ".html")) + "\">" + Utilities.escapeXml(vs.present()) + "</a>");
        }
        b.append("</td>\r\n  </tr>\r\n");
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ConceptSetFilterComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ValueSet(org.hl7.fhir.r5.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Example 2 with ConceptSetFilterComponent

use of org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent in project kindling by HL7.

the class PageProcessor method getSnomedCTConcept.

public void getSnomedCTConcept(Map<String, SnomedConceptUsage> concepts, ValueSet vs, ConceptSetFilterComponent c) throws Exception {
    ConceptDefinitionComponent def = workerContext.getCodeDefinition("http://snomed.info/sct", c.getValue());
    if (def == null) {
        throw new Exception("Unable to retrieve definition for SNOMED code: " + c.getValue());
    }
    String d = def.getDisplay();
    if (concepts.containsKey(c.getValue()))
        concepts.get(c.getValue()).update(d, vs);
    else
        concepts.put(c.getValue(), new SnomedConceptUsage(c.getValue(), d, vs));
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 3 with ConceptSetFilterComponent

use of org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpanderSimple method includeCodes.

private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params) throws TerminologyServiceException, ETooCostly {
    if (context.supportsSystem(inc.getSystem())) {
        addCodes(context.expandVS(inc), params);
        return;
    }
    ValueSet cs = context.fetchCodeSystem(inc.getSystem());
    if (cs == null)
        throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
    if (cs.hasVersion())
        if (!existsInParams(params, "version", new UriType(cs.getUrl() + "?version=" + cs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "?version=" + cs.getVersion())));
    if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
        // special case - add all the code system
        for (ConceptDefinitionComponent def : cs.getCodeSystem().getConcept()) {
            addCodeAndDescendents(inc.getSystem(), def);
        }
    }
    for (ConceptReferenceComponent c : inc.getConcept()) {
        addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay());
    }
    if (inc.getFilter().size() > 1)
        // need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
        throw new TerminologyServiceException("Multiple filters not handled yet");
    if (inc.getFilter().size() == 1) {
        ConceptSetFilterComponent fc = inc.getFilter().get(0);
        if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
            // special: all non-abstract codes in the target code system under the value
            ConceptDefinitionComponent def = getConceptForCode(cs.getCodeSystem().getConcept(), fc.getValue());
            if (def == null)
                throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            addCodeAndDescendents(inc.getSystem(), def);
        } else
            throw new NotImplementedException("not done yet");
    }
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionParameterComponent) NotImplementedException(org.apache.commons.lang3.NotImplementedException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent) UriType(org.hl7.fhir.dstu2.model.UriType)

Example 4 with ConceptSetFilterComponent

use of org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpanderSimple method includeCodes.

private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params) throws TerminologyServiceException, ETooCostly {
    if (context.supportsSystem(inc.getSystem())) {
        try {
            int i = codes.size();
            addCodes(context.expandVS(inc), params);
            if (codes.size() > i)
                return;
        } catch (Exception e) {
        // ok, we'll try locally
        }
    }
    CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
    if (cs == null)
        throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
    if (cs.hasVersion())
        if (!existsInParams(params, "version", new UriType(cs.getUrl() + "?version=" + cs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "?version=" + cs.getVersion())));
    if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
        // special case - add all the code system
        for (ConceptDefinitionComponent def : cs.getConcept()) {
            addCodeAndDescendents(cs, inc.getSystem(), def);
        }
    }
    for (ConceptReferenceComponent c : inc.getConcept()) {
        addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay());
    }
    if (inc.getFilter().size() > 1)
        // need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
        throw new TerminologyServiceException("Multiple filters not handled yet");
    if (inc.getFilter().size() == 1) {
        ConceptSetFilterComponent fc = inc.getFilter().get(0);
        if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
            // special: all non-abstract codes in the target code system under the value
            ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
            if (def == null)
                throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            addCodeAndDescendents(cs, inc.getSystem(), def);
        } else
            throw new NotImplementedException("not done yet");
    }
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionParameterComponent) NotImplementedException(org.apache.commons.lang3.NotImplementedException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) CodeSystem(org.hl7.fhir.dstu2016may.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ConceptReferenceComponent) NotImplementedException(org.apache.commons.lang3.NotImplementedException) IOException(java.io.IOException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) UriType(org.hl7.fhir.dstu2016may.model.UriType)

Example 5 with ConceptSetFilterComponent

use of org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent 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)

Aggregations

ConceptSetFilterComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 ArrayList (java.util.ArrayList)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 ConceptSetFilterComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent)5 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)5 ConceptReferenceComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)5 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)5 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)4 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)3 ConceptDefinitionComponent (org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent)3 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)3 UriType (org.hl7.fhir.r4b.model.UriType)3 ConceptReferenceComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent)3 UriType (org.hl7.fhir.r5.model.UriType)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)2