Search in sources :

Example 21 with ConceptSetFilterComponent

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

the class ValueSetExpanderSimple method doInternalIncludeCodes.

public void doInternalIncludeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, Parameters expParams, List<ValueSet> imports, CodeSystem cs) throws NoTerminologyServiceException, TerminologyServiceException, FHIRException {
    if (cs == null) {
        if (context.isNoTerminologyServer())
            throw new NoTerminologyServiceException("unable to find code system " + inc.getSystem().toString());
        else
            throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
    }
    cs.checkNoModifiers("Code System", "expanding");
    if (cs.getContent() != CodeSystemContentMode.COMPLETE)
        throw new TerminologyServiceException("Code system " + inc.getSystem().toString() + " is incomplete");
    if (cs.hasVersion())
        if (!existsInParams(params, "version", new UriType(cs.getUrl() + "|" + cs.getVersion())))
            params.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);
        }
    }
    if (!inc.getConcept().isEmpty()) {
        canBeHeirarchy = false;
        for (ConceptReferenceComponent c : inc.getConcept()) {
            c.checkNoModifiers("Code in Code System", "expanding");
            addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay(), null, convertDesignations(c.getDesignation()), expParams, false, CodeSystemUtilities.isInactive(cs, c.getCode()), imports);
        }
    }
    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 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 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, null, expParams, imports, null);
        } 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 new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            for (ConceptDefinitionComponent def : cs.getConcept()) {
                addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, defEx);
            }
        } 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 new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            for (ConceptDefinitionComponent c : def.getConcept()) addCodeAndDescendents(cs, inc.getSystem(), c, null, expParams, imports, null);
        } 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);
                    }
                }
            }
        } else
            throw new NotImplementedException("Search by property[" + fc.getProperty() + "] and op[" + fc.getOp() + "] is not supported yet");
    }
}
Also used : NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) ConceptSetFilterComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent) NotImplementedException(org.apache.commons.lang3.NotImplementedException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) UriType(org.hl7.fhir.r4.model.UriType)

Example 22 with ConceptSetFilterComponent

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

the class ValueSetCheckerSimple method inComponent.

private Boolean inComponent(ConceptSetComponent vsi, int vsiIndex, String system, String code, boolean only, List<String> warnings) throws FHIRException {
    if (isValueSetUnionImports()) {
        for (UriType uri : vsi.getValueSet()) {
            if (inImport(uri.getValue(), system, code)) {
                return true;
            }
        }
    } else {
        for (UriType uri : vsi.getValueSet()) {
            if (!inImport(uri.getValue(), system, code)) {
                return false;
            }
        }
    }
    if (!vsi.hasSystem()) {
        return false;
    }
    if (only && system == null) {
        // whether we know the system or not, we'll accept the stated codes at face value
        for (ConceptReferenceComponent cc : vsi.getConcept()) {
            if (cc.getCode().equals(code)) {
                return true;
            }
        }
    }
    if (!system.equals(vsi.getSystem()))
        return false;
    // ok, we need the code system
    CodeSystem cs = resolveCodeSystem(system);
    if (cs == null || (cs.getContent() != CodeSystemContentMode.COMPLETE && cs.getContent() != CodeSystemContentMode.FRAGMENT)) {
        // make up a transient value set with
        ValueSet vs = new ValueSet();
        vs.setStatus(PublicationStatus.ACTIVE);
        vs.setUrl(valueset.getUrl() + "--" + vsiIndex);
        vs.setVersion(valueset.getVersion());
        vs.getCompose().addInclude(vsi);
        ValidationResult res = context.validateCode(options.noClient(), new Coding(system, code, null), vs);
        if (res.getErrorClass() == TerminologyServiceErrorClass.UNKNOWN || res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED || res.getErrorClass() == TerminologyServiceErrorClass.VALUESET_UNSUPPORTED) {
            if (warnings != null && res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) {
                warnings.add(context.formatMessage(I18nConstants.TERMINOLOGY_TX_SYSTEM_NOTKNOWN, system));
            }
            return null;
        }
        if (res.getErrorClass() == TerminologyServiceErrorClass.NOSERVICE) {
            throw new NoTerminologyServiceException();
        }
        return res.isOk();
    } else {
        if (vsi.hasFilter()) {
            boolean ok = true;
            for (ConceptSetFilterComponent f : vsi.getFilter()) {
                if (!codeInFilter(cs, system, f, code)) {
                    ok = false;
                    break;
                }
            }
            return ok;
        }
        List<ConceptDefinitionComponent> list = cs.getConcept();
        boolean ok = validateCodeInConceptList(code, cs, list);
        if (ok && vsi.hasConcept()) {
            for (ConceptReferenceComponent cc : vsi.getConcept()) {
                if (cc.getCode().equals(code)) {
                    return true;
                }
            }
            return false;
        } else {
            return ok;
        }
    }
}
Also used : NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) ConceptSetFilterComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) Coding(org.hl7.fhir.r5.model.Coding) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ValueSet(org.hl7.fhir.r5.model.ValueSet) UriType(org.hl7.fhir.r5.model.UriType)

Example 23 with ConceptSetFilterComponent

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

the class ValueSetRenderer method genInclude.

private boolean genInclude(XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs, boolean doLangs, List<UsedConceptMap> maps) throws FHIRException, IOException {
    boolean hasExtensions = false;
    XhtmlNode li;
    li = ul.li();
    CodeSystem e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
    if (inc.hasSystem()) {
        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);
                if (inc.hasVersion()) {
                    li.addText(" version ");
                    li.code(inc.getVersion());
                }
                // for performance reasons, we do all the fetching in one batch
                Map<String, ConceptDefinitionComponent> definitions = getConceptsForCodes(e, inc);
                XhtmlNode t = li.table("none");
                boolean hasComments = false;
                boolean hasDefinition = false;
                for (ConceptReferenceComponent c : inc.getConcept()) {
                    hasComments = hasComments || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT);
                    ConceptDefinitionComponent cc = definitions.get(c.getCode());
                    hasDefinition = hasDefinition || ((cc != null && cc.hasDefinition()) || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION));
                }
                if (hasComments || hasDefinition)
                    hasExtensions = true;
                addMapHeaders(addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false, false, null, langs, doLangs), maps);
                for (ConceptReferenceComponent c : inc.getConcept()) {
                    XhtmlNode tr = t.tr();
                    XhtmlNode td = tr.td();
                    ConceptDefinitionComponent cc = definitions.get(c.getCode());
                    addCodeToTable(false, inc.getSystem(), c.getCode(), c.hasDisplay() ? c.getDisplay() : cc != null ? cc.getDisplay() : "", td);
                    td = tr.td();
                    if (!Utilities.noString(c.getDisplay()))
                        td.addText(c.getDisplay());
                    else if (cc != null && !Utilities.noString(cc.getDisplay()))
                        td.addText(cc.getDisplay());
                    if (hasDefinition) {
                        td = tr.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 (hasComments) {
                        td = tr.td();
                        if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT)) {
                            smartAddText(td, "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_VS_COMMENT));
                        }
                    }
                    if (doLangs) {
                        addLangaugesToRow(c, langs, tr);
                    }
                }
            }
            if (inc.getFilter().size() > 0) {
                li.addText(type + " codes from ");
                addCsRef(inc, li, e);
                li.tx(" where ");
                for (int i = 0; i < inc.getFilter().size(); i++) {
                    ConceptSetFilterComponent f = inc.getFilter().get(i);
                    if (i > 0) {
                        if (i == inc.getFilter().size() - 1) {
                            li.tx(" and ");
                        } else {
                            li.tx(", ");
                        }
                    }
                    if (f.getOp() == FilterOperator.EXISTS) {
                        if (f.getValue().equals("true")) {
                            li.tx(f.getProperty() + " exists");
                        } else {
                            li.tx(f.getProperty() + " doesn't exist");
                        }
                    } else {
                        li.tx(f.getProperty() + " " + describe(f.getOp()) + " ");
                        if (e != null && codeExistsInValueSet(e, f.getValue())) {
                            String href = getContext().fixReference(getCsRef(e));
                            if (href.contains("#"))
                                href = href + "-" + Utilities.nmtokenize(f.getValue());
                            else
                                href = href + "#" + e.getId() + "-" + Utilities.nmtokenize(f.getValue());
                            li.ah(href).addText(f.getValue());
                        } else if ("concept".equals(f.getProperty()) && inc.hasSystem()) {
                            li.addText(f.getValue());
                            ValidationResult vr = getContext().getWorker().validateCode(getContext().getTerminologyServiceOptions(), inc.getSystem(), inc.getVersion(), f.getValue(), null);
                            if (vr.isOk()) {
                                li.tx(" (" + vr.getDisplay() + ")");
                            }
                        } else
                            li.addText(f.getValue());
                        String disp = ToolingExtensions.getDisplayHint(f);
                        if (disp != null)
                            li.tx(" (" + disp + ")");
                    }
                }
            }
        }
        if (inc.hasValueSet()) {
            li.tx(", where the codes are contained in ");
            boolean first = true;
            for (UriType vs : inc.getValueSet()) {
                if (first)
                    first = false;
                else
                    li.tx(", ");
                AddVsRef(vs.asStringValue(), li);
            }
        }
    } else {
        li.tx("Import all the codes that are contained in ");
        if (inc.getValueSet().size() < 4) {
            boolean first = true;
            for (UriType vs : inc.getValueSet()) {
                if (first)
                    first = false;
                else
                    li.tx(", ");
                AddVsRef(vs.asStringValue(), li);
            }
        } else {
            XhtmlNode xul = li.ul();
            for (UriType vs : inc.getValueSet()) {
                AddVsRef(vs.asStringValue(), xul.li());
            }
        }
    }
    return hasExtensions;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent) ValidationResult(org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) UriType(org.hl7.fhir.r4b.model.UriType)

Example 24 with ConceptSetFilterComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetFilterComponent 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) 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());
        }
        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);
        }
    }
    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());
        } 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());
            }
        } 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());
            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());
            }
        } 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);
                    }
                }
            }
        } 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())));
            }
        } else {
            throw fail("Search by property[" + fc.getProperty() + "] and op[" + fc.getOp() + "] is not supported yet");
        }
    }
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionParameterComponent) ArrayList(java.util.ArrayList) List(java.util.List) ConceptReferenceComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent) UriType(org.hl7.fhir.r4b.model.UriType)

Example 25 with ConceptSetFilterComponent

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

the class ValueSetCheckerSimple method inComponent.

private Boolean inComponent(ConceptSetComponent vsi, int vsiIndex, String system, String code, boolean only, List<String> warnings) throws FHIRException {
    for (UriType uri : vsi.getValueSet()) {
        if (inImport(uri.getValue(), system, code)) {
            return true;
        }
    }
    if (!vsi.hasSystem()) {
        return false;
    }
    if (only && system == null) {
        // whether we know the system or not, we'll accept the stated codes at face value
        for (ConceptReferenceComponent cc : vsi.getConcept()) {
            if (cc.getCode().equals(code)) {
                return true;
            }
        }
    }
    if (!system.equals(vsi.getSystem()))
        return false;
    // ok, we need the code system
    CodeSystem cs = resolveCodeSystem(system);
    if (cs == null || (cs.getContent() != CodeSystemContentMode.COMPLETE && cs.getContent() != CodeSystemContentMode.FRAGMENT)) {
        // make up a transient value set with
        ValueSet vs = new ValueSet();
        vs.setStatus(PublicationStatus.ACTIVE);
        vs.setUrl(valueset.getUrl() + "--" + vsiIndex);
        vs.setVersion(valueset.getVersion());
        vs.getCompose().addInclude(vsi);
        ValidationResult res = context.validateCode(options.noClient(), new Coding(system, code, null), vs);
        if (res.getErrorClass() == TerminologyServiceErrorClass.UNKNOWN || res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED || res.getErrorClass() == TerminologyServiceErrorClass.VALUESET_UNSUPPORTED) {
            if (warnings != null && res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) {
                warnings.add(context.formatMessage(I18nConstants.TERMINOLOGY_TX_SYSTEM_NOTKNOWN, system));
            }
            return null;
        }
        if (res.getErrorClass() == TerminologyServiceErrorClass.NOSERVICE) {
            throw new NoTerminologyServiceException();
        }
        return res.isOk();
    } else {
        if (vsi.hasFilter()) {
            boolean ok = true;
            for (ConceptSetFilterComponent f : vsi.getFilter()) {
                if (!codeInFilter(cs, system, f, code)) {
                    ok = false;
                    break;
                }
            }
            return ok;
        }
        List<ConceptDefinitionComponent> list = cs.getConcept();
        boolean ok = validateCodeInConceptList(code, cs, list);
        if (ok && vsi.hasConcept()) {
            for (ConceptReferenceComponent cc : vsi.getConcept()) {
                if (cc.getCode().equals(code)) {
                    return true;
                }
            }
            return false;
        } else {
            return ok;
        }
    }
}
Also used : NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) ConceptSetFilterComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent) Coding(org.hl7.fhir.r4b.model.Coding) ValidationResult(org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult) ConceptReferenceComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem) ValueSet(org.hl7.fhir.r4b.model.ValueSet) UriType(org.hl7.fhir.r4b.model.UriType)

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