Search in sources :

Example 36 with ConceptSetComponent

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

the class TerminologyCache method nameCacheToken.

public void nameCacheToken(ValueSet vs, CacheToken ct) {
    if (vs != null) {
        for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
            if (inc.hasSystem()) {
                ct.setName(getNameForSystem(inc.getSystem()));
                ct.hasVersion = inc.hasVersion();
            }
        }
        for (ConceptSetComponent inc : vs.getCompose().getExclude()) {
            if (inc.hasSystem()) {
                ct.setName(getNameForSystem(inc.getSystem()));
                ct.hasVersion = inc.hasVersion();
            }
        }
        for (ValueSetExpansionContainsComponent inc : vs.getExpansion().getContains()) {
            if (inc.hasSystem()) {
                ct.setName(getNameForSystem(inc.getSystem()));
                ct.hasVersion = inc.hasVersion();
            }
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent)

Example 37 with ConceptSetComponent

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

the class ValueSetCheckerSimple method findValueSetRef.

private ConceptReferenceComponent findValueSetRef(String system, String code) {
    if (valueset == null)
        return null;
    // if it has an expansion
    for (ValueSetExpansionContainsComponent exp : valueset.getExpansion().getContains()) {
        if (system.equals(exp.getSystem()) && code.equals(exp.getCode())) {
            ConceptReferenceComponent cc = new ConceptReferenceComponent();
            cc.setDisplay(exp.getDisplay());
            cc.setDesignation(exp.getDesignation());
            return cc;
        }
    }
    for (ConceptSetComponent inc : valueset.getCompose().getInclude()) {
        if (system.equals(inc.getSystem())) {
            for (ConceptReferenceComponent cc : inc.getConcept()) {
                if (cc.getCode().equals(code)) {
                    return cc;
                }
            }
        }
        for (CanonicalType url : inc.getValueSet()) {
            ConceptReferenceComponent cc = getVs(url.asStringValue()).findValueSetRef(system, code);
            if (cc != null) {
                return cc;
            }
        }
    }
    return null;
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) CanonicalType(org.hl7.fhir.r5.model.CanonicalType)

Example 38 with ConceptSetComponent

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

the class ValueSetExpanderSimple method includeCodes.

private void includeCodes(ConceptSetComponent inc, ValueSetExpansionComponent exp, Parameters expParams, boolean heirarchical, boolean noInactive, List<Extension> extensions, ValueSet valueSet) throws ETooCostly, FileNotFoundException, IOException, FHIRException {
    inc.checkNoModifiers("Compose.include", "expanding");
    List<ValueSet> imports = new ArrayList<ValueSet>();
    for (UriType imp : inc.getValueSet()) {
        imports.add(importValueSet(imp.getValue(), exp, expParams, noInactive, valueSet));
    }
    if (!inc.hasSystem()) {
        if (// though this is not supposed to be the case
        imports.isEmpty())
            return;
        ValueSet base = imports.get(0);
        imports.remove(0);
        base.checkNoModifiers("Imported ValueSet", "expanding");
        copyImportContains(base.getExpansion().getContains(), null, expParams, imports, noInactive);
    } else {
        CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
        if (isServerSide(inc.getSystem()) || (cs == null || (cs.getContent() != CodeSystemContentMode.COMPLETE && cs.getContent() != CodeSystemContentMode.FRAGMENT))) {
            doServerIncludeCodes(inc, heirarchical, exp, imports, expParams, extensions, noInactive);
        } else {
            doInternalIncludeCodes(inc, exp, expParams, imports, cs, noInactive);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ValueSet(org.hl7.fhir.r5.model.ValueSet) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) UriType(org.hl7.fhir.r5.model.UriType)

Example 39 with ConceptSetComponent

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

the class ValueSetExpanderSimple method handleCompose.

private void handleCompose(ValueSetComposeComponent compose, ValueSetExpansionComponent exp, Parameters expParams, String ctxt, List<Extension> extensions, ValueSet valueSet) throws ETooCostly, FileNotFoundException, IOException, FHIRException {
    compose.checkNoModifiers("ValueSet.compose", "expanding");
    // Exclude comes first because we build up a map of things to exclude
    for (ConceptSetComponent inc : compose.getExclude()) excludeCodes(inc, exp.getParameter(), ctxt);
    canBeHeirarchy = !expParams.getParameterBool("excludeNested") && excludeKeys.isEmpty() && excludeSystems.isEmpty();
    includeAbstract = !expParams.getParameterBool("excludeNotForUI");
    boolean first = true;
    for (ConceptSetComponent inc : compose.getInclude()) {
        if (first == true)
            first = false;
        else
            canBeHeirarchy = false;
        includeCodes(inc, exp, expParams, canBeHeirarchy, compose.hasInactive() && !compose.getInactive(), extensions, valueSet);
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)

Example 40 with ConceptSetComponent

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

the class ValueSetExpanderSimple method doInternalIncludeCodes.

public void doInternalIncludeCodes(ConceptSetComponent inc, ValueSetExpansionComponent exp, Parameters expParams, List<ValueSet> imports, CodeSystem cs, boolean noInactive) throws NoTerminologyServiceException, TerminologyServiceException, FHIRException {
    if (cs == null) {
        if (context.isNoTerminologyServer())
            throw failTSE("Unable to find code system " + inc.getSystem().toString());
        else
            throw failTSE("Unable to find code system " + inc.getSystem().toString());
    }
    cs.checkNoModifiers("Code System", "expanding");
    if (cs.getContent() != CodeSystemContentMode.COMPLETE && cs.getContent() != CodeSystemContentMode.FRAGMENT)
        throw failTSE("Code system " + inc.getSystem().toString() + " is incomplete");
    if (cs.hasVersion())
        if (!existsInParams(exp.getParameter(), "version", new UriType(cs.getUrl() + "|" + cs.getVersion())))
            exp.getParameter().add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "|" + 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, null, expParams, imports, null, new AllConceptsFilter(), noInactive);
        }
        if (cs.getContent() == CodeSystemContentMode.FRAGMENT) {
            addFragmentWarning(exp, cs);
        }
        if (cs.getContent() == CodeSystemContentMode.EXAMPLE) {
            addExampleWarning(exp, cs);
        }
    }
    if (!inc.getConcept().isEmpty()) {
        canBeHeirarchy = false;
        for (ConceptReferenceComponent c : inc.getConcept()) {
            c.checkNoModifiers("Code in Code System", "expanding");
            ConceptDefinitionComponent def = CodeSystemUtilities.findCode(cs.getConcept(), c.getCode());
            // default is true if we're a fragment and
            Boolean inactive = false;
            if (def == null) {
                if (cs.getContent() == CodeSystemContentMode.FRAGMENT) {
                    addFragmentWarning(exp, cs);
                } else if (cs.getContent() == CodeSystemContentMode.EXAMPLE) {
                    addExampleWarning(exp, cs);
                } else {
                    if (checkCodesWhenExpanding) {
                        throw failTSE("Unable to find code '" + c.getCode() + "' in code system " + cs.getUrl());
                    }
                }
            } else {
                inactive = CodeSystemUtilities.isInactive(cs, def);
            }
            addCode(inc.getSystem(), c.getCode(), !Utilities.noString(c.getDisplay()) ? c.getDisplay() : def == null ? null : def.getDisplay(), null, convertDesignations(c.getDesignation()), expParams, false, inactive, imports, noInactive);
        }
    }
    if (inc.getFilter().size() > 1) {
        // which will bt the case if we get around to supporting this
        canBeHeirarchy = false;
        // need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
        throw failTSE("Multiple filters not handled yet");
    }
    if (inc.getFilter().size() == 1) {
        if (cs.getContent() == CodeSystemContentMode.FRAGMENT) {
            addFragmentWarning(exp, cs);
        }
        ConceptSetFilterComponent fc = inc.getFilter().get(0);
        if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
            // special: all codes in the target code system under the value
            ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
            if (def == null)
                throw failTSE("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null, new AllConceptsFilter(), noInactive);
        } else if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISNOTA) {
            // special: all codes in the target code system that are not under the value
            ConceptDefinitionComponent defEx = getConceptForCode(cs.getConcept(), fc.getValue());
            if (defEx == null)
                throw failTSE("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            for (ConceptDefinitionComponent def : cs.getConcept()) {
                addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, defEx, new AllConceptsFilter(), noInactive);
            }
        } else if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.DESCENDENTOF) {
            // special: all codes in the target code system under the value
            ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
            if (def == null)
                throw failTSE("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            for (ConceptDefinitionComponent c : def.getConcept()) addCodeAndDescendents(cs, inc.getSystem(), c, null, expParams, imports, null, new AllConceptsFilter(), noInactive);
            if (def.hasUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK)) {
                List<ConceptDefinitionComponent> children = (List<ConceptDefinitionComponent>) def.getUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK);
                for (ConceptDefinitionComponent c : children) addCodeAndDescendents(cs, inc.getSystem(), c, null, expParams, imports, null, new AllConceptsFilter(), noInactive);
            }
        } else if ("display".equals(fc.getProperty()) && fc.getOp() == FilterOperator.EQUAL) {
            // gg; note: wtf is this: if the filter is display=v, look up the code 'v', and see if it's diplsay is 'v'?
            canBeHeirarchy = false;
            ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
            if (def != null) {
                if (isNotBlank(def.getDisplay()) && isNotBlank(fc.getValue())) {
                    if (def.getDisplay().contains(fc.getValue())) {
                        addCode(inc.getSystem(), def.getCode(), def.getDisplay(), null, def.getDesignation(), expParams, CodeSystemUtilities.isNotSelectable(cs, def), CodeSystemUtilities.isInactive(cs, def), imports, noInactive);
                    }
                }
            }
        } else if (isDefinedProperty(cs, fc.getProperty())) {
            for (ConceptDefinitionComponent def : cs.getConcept()) {
                addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null, new PropertyFilter(fc, getPropertyDefinition(cs, fc.getProperty())), noInactive);
            }
        } else {
            throw fail("Search by property[" + fc.getProperty() + "] and op[" + fc.getOp() + "] is not supported yet");
        }
    }
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent) ArrayList(java.util.ArrayList) List(java.util.List) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) UriType(org.hl7.fhir.r5.model.UriType)

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