Search in sources :

Example 1 with ConceptSetComponent

use of org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent in project bunsen by cerner.

the class ValueSets method expandValuesIterator.

private static Iterator<Value> expandValuesIterator(ValueSet valueSet) {
    List<Value> values = new ArrayList<>();
    ValueSetComposeComponent compose = valueSet.getCompose();
    for (ConceptSetComponent inclusion : compose.getInclude()) {
        for (ConceptReferenceComponent concept : inclusion.getConcept()) {
            Value value = new Value();
            value.setValueSetUri(valueSet.getUrl());
            value.setValueSetVersion(valueSet.getVersion());
            value.setSystem(inclusion.getSystem());
            value.setVersion(inclusion.getVersion());
            value.setValue(concept.getCode());
            values.add(value);
        }
    }
    return values.iterator();
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ArrayList(java.util.ArrayList) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 2 with ConceptSetComponent

use of org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent in project bunsen by cerner.

the class ValueSets method addToValueSet.

/**
 * Adds the given values to the given value set instance.
 */
private void addToValueSet(ValueSet valueSet, Dataset<Value> values) {
    ValueSetComposeComponent composeComponent = valueSet.getCompose();
    ConceptSetComponent currentInclusion = null;
    ConceptReferenceComponent concept = null;
    List<Value> sortedValues = values.sort("system", "version", "value").collectAsList();
    // Workaround for the decoder producing an immutable array by replacing it with a mutable one
    composeComponent.setInclude(new ArrayList<>(composeComponent.getInclude()));
    for (Value value : sortedValues) {
        if (currentInclusion == null || !value.getSystem().equals(currentInclusion.getSystem()) || !value.getVersion().equals(currentInclusion.getVersion())) {
            // Find a matching inclusion
            for (ConceptSetComponent candidate : composeComponent.getInclude()) {
                if (value.getSystem().equals(candidate.getSystem()) && value.getVersion().equals(candidate.getVersion())) {
                    currentInclusion = candidate;
                    // Workaround for the decoder producing an immutable array by replacing it with a
                    // mutable one
                    currentInclusion.setConcept(new ArrayList<>(currentInclusion.getConcept()));
                }
            }
            // No matching inclusion found, so add one
            if (currentInclusion == null) {
                currentInclusion = composeComponent.addInclude();
                currentInclusion.setSystem(value.getSystem());
                currentInclusion.setVersion(value.getVersion());
                concept = null;
            }
        }
        // Create concept if not exists
        if (concept == null || !value.getValue().equals(concept.getCode())) {
            concept = currentInclusion.addConcept();
            concept.setCode(value.getValue());
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 3 with ConceptSetComponent

use of org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent in project bunsen by cerner.

the class ValueSetsTest method valueSet.

private static ValueSet valueSet(String valueSetUrl, String valueSetVersion, String... codes) {
    ValueSet valueSet = new ValueSet();
    valueSet.setUrl(valueSetUrl);
    valueSet.setVersion(valueSetVersion);
    valueSet.setExperimental(true);
    ConceptSetComponent inclusion = valueSet.getCompose().addInclude();
    inclusion.setSystem("urn:cerner:system").setVersion("1");
    for (String code : codes) {
        inclusion.addConcept().setCode(code);
    }
    return valueSet;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 4 with ConceptSetComponent

use of org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent in project kindling by HL7.

the class PageProcessor method summariseSCTCLD.

private String summariseSCTCLD(ValueSet vs) {
    boolean hasNonSCT = false;
    for (ConceptSetComponent cc : vs.getCompose().getInclude()) {
        if (!"http://snomed.info/sct".equals(cc.getSystem()))
            hasNonSCT = true;
    }
    StringBuilder b = new StringBuilder();
    b.append("<ul>");
    for (ConceptSetComponent cc : vs.getCompose().getInclude()) {
        if ("http://snomed.info/sct".equals(cc.getSystem())) {
            if (!cc.hasConcept() && !cc.hasFilter()) {
                b.append("<li>any SCT concept</li>");
            } else if (cc.hasConcept()) {
                b.append("<li>" + Integer.toString(cc.getConcept().size()) + " enumerated concepts</li>");
            } else {
                if (cc.getFilter().size() != 1 || !cc.getFilter().get(0).getProperty().equals("concept"))
                    b.append("<li>ERROR!</li>");
                else {
                    ConceptDefinitionComponent def = workerContext.getCodeDefinition("http://snomed.info/sct", cc.getFilter().get(0).getValue());
                    b.append("<li>" + cc.getFilter().get(0).getOp().toCode() + " " + (def == null ? cc.getFilter().get(0).getValue() : Utilities.escapeXml(def.getDisplay())) + "</li>");
                }
            }
        }
    }
    if (hasNonSCT)
        b.append("<li>other code systems</li>");
    b.append("</ul>");
    return b.toString();
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)

Example 5 with ConceptSetComponent

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

Aggregations

ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)25 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)20 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)20 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)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.r5.model.ValueSet)13 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)12 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)12 ValueSet (org.hl7.fhir.r4.model.ValueSet)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