コード例 #1
0
        public OperationOutcome ValidateCode(string uri, string code, string system, string display = null, bool abstractAllowed = false)
        {
            var result = new OperationOutcome();
            var vs     = _resolver.FindValueSet(uri);

            if (vs == null)
            {
                result.AddIssue($"Cannot retrieve valueset '{uri}'", Issue.UNAVAILABLE_VALUESET);
                return(result);
            }

            // We might have a cached or pre-expanded version brought to us by the _source
            if (!vs.HasExpansion)
            {
                // This will expand te vs - since we do not deepcopy() it, it will change the instance
                // as it was passed to us from the source
                try
                {
                    _expander.Expand(vs);
                }
                catch (Exception e)
                {
                    var tooComplex = e is NotSupportedException || e is ValueSetExpansionTooBigException;

                    result.AddIssue($"ValueSet cannot be expanded: {e.Message}",
                                    tooComplex ? Issue.TERMINOLOGY_VALUESET_TOO_COMPLEX : Issue.TERMINOLOGY_EXPANSION_FAILED);
                    return(result);
                }
            }

            // No fallback necessary, just do a direct check for now

            var component = vs.FindInExpansion(code, system);
            var codeLabel = $"Code '{code}' from system '{system}'";

            if (component == null)
            {
                result.AddIssue($"{codeLabel} does not exists in valueset '{uri}'", Issue.TERMINOLOGY_CODE_NOT_IN_VALUESET);
            }
            else
            {
                if (component.Abstract == true && !abstractAllowed)
                {
                    result.AddIssue($"{codeLabel} is abstract, which is not allowed here", Issue.TERMINOLOGY_ABSTRACT_CODE_NOT_ALLOWED);
                }

                if (display != null && component.Display != null && display != component.Display)
                {
                    result.AddIssue($"{codeLabel} has incorrect display '{display}', should be '{component.Display}'", Issue.TERMINOLOGY_INCORRECT_DISPLAY);
                }
            }

            return(result);
        }
コード例 #2
0
        private OperationOutcome validateCodeVS(ValueSet vs, string code, string system, string display, bool?abstractAllowed)
        {
            if (code == null)
            {
                return(Issue.TERMINOLOGY_NO_CODE_IN_INSTANCE.NewOutcomeWithIssue($"No code supplied."));
            }

            lock (vs.SyncLock)
            {
                // We might have a cached or pre-expanded version brought to us by the _source
                if (!vs.HasExpansion)
                {
                    // This will expand te vs - since we do not deepcopy() it, it will change the instance
                    // as it was passed to us from the source
                    _expander.Expand(vs);
                }
            }

            var component = vs.FindInExpansion(code, system);
            var codeLabel = $"Code '{code}' from system '{system}'";
            var result    = new OperationOutcome();

            if (component == null)
            {
                result.AddIssue($"{codeLabel} does not exist in valueset '{vs.Url}'", Issue.TERMINOLOGY_CODE_NOT_IN_VALUESET);
            }
            else
            {
                if (component.Abstract == true && abstractAllowed == false)  // will be ignored if abstractAllowed == null
                {
                    result.AddIssue($"{codeLabel} is abstract, which is not allowed here", Issue.TERMINOLOGY_ABSTRACT_CODE_NOT_ALLOWED);
                }

                if (display != null && component.Display != null && display != component.Display)
                {
                    result.AddIssue($"{codeLabel} has incorrect display '{display}', should be '{component.Display}'", Issue.TERMINOLOGY_INCORRECT_DISPLAY);
                }
            }

            return(result);
        }