Пример #1
0
 public static Argument Create(SearchParamType type)
 {
     return(type switch
     {
         SearchParamType.Number => new IntArgument(),
         SearchParamType.String => new StringArgument(),
         SearchParamType.Date => new DateArgument(),
         SearchParamType.Token => new TokenArgument(),
         SearchParamType.Reference => new ReferenceArgument(),
         SearchParamType.Composite =>
         //TODO: Implement Composite arguments
         new Argument(),
         _ => new Argument()
     });
Пример #2
0
 public SearchParameterInfo(
     string name,
     SearchParamType searchParamType,
     Uri url = null,
     IReadOnlyList <SearchParameterComponentInfo> components = null,
     string expression = null,
     IReadOnlyCollection <string> targetResourceTypes = null)
     : this(name)
 {
     Url                 = url;
     Type                = searchParamType;
     Component           = components;
     Expression          = expression;
     TargetResourceTypes = targetResourceTypes;
 }
 public SearchParameterInfo(
     string name,
     string code,
     SearchParamType searchParamType,
     Uri url = null,
     IReadOnlyList <SearchParameterComponentInfo> components = null,
     string expression = null,
     IReadOnlyList <string> targetResourceTypes = null,
     IReadOnlyList <string> baseResourceTypes   = null,
     string description = null)
     : this(name, code)
 {
     Url                 = url;
     Type                = searchParamType;
     Component           = components;
     Expression          = expression;
     TargetResourceTypes = targetResourceTypes;
     BaseResourceTypes   = baseResourceTypes;
     Description         = description;
 }
Пример #4
0
 public static SearchComparator[] GetPrefixListForSearchType(SearchParamType SearchParamType)
 {
     return(SearchParamType switch
     {
         SearchParamType.Number => new SearchComparator[] {
             SearchComparator.Ne,
             SearchComparator.Eq,
             SearchComparator.Gt,
             SearchComparator.Ge,
             SearchComparator.Lt,
             SearchComparator.Le
         },
         SearchParamType.Date => new SearchComparator[] {
             SearchComparator.Ne,
             SearchComparator.Eq,
             SearchComparator.Gt,
             SearchComparator.Ge,
             SearchComparator.Lt,
             SearchComparator.Le
         },
         SearchParamType.String => new SearchComparator[] { },    //Any search parameter that's value is a string will not have prefixes
         SearchParamType.Token => new SearchComparator[] { },     //Any search parameter that's value is a string will not have prefixes
         SearchParamType.Reference => new SearchComparator[] { }, //Any search parameter that's value is a string will not have prefixes
         SearchParamType.Composite => new SearchComparator[] { }, //Any search parameter that's value is a string will not have prefixes
         SearchParamType.Quantity => new SearchComparator[] {
             SearchComparator.Ne,
             SearchComparator.Eq,
             SearchComparator.Gt,
             SearchComparator.Ge,
             SearchComparator.Lt,
             SearchComparator.Le
         },
         SearchParamType.Uri => new SearchComparator[] { },//Any search parameter that's value is a string will not have prefixes
         SearchParamType.Special => new SearchComparator[] { },
         _ => throw new System.ComponentModel.InvalidEnumArgumentException(SearchParamType.GetCode(), (int)SearchParamType, typeof(SearchParamType)),
     });
Пример #5
0
 public void GivenMultipleValuesWithPrefix_WhenBuilding_ThenInvalidSearchOperationExceptionShouldBeThrown(SearchParamType searchParameterType, string value)
 {
     // Parse the expression.
     Assert.Throws <InvalidSearchOperationException>(() => _parser.Parse(
                                                         CreateSearchParameter(searchParameterType),
                                                         null,
                                                         value));
 }
Пример #6
0
        public void GivenASearchParameterThatDoesNotSupportTextModifier_WhenBuilt_ThenCorrectExpressionShouldBeCreated(SearchParamType searchParameterType)
        {
            var searchParameter = new SearchParameter()
            {
                Name = "test",
                Type = searchParameterType,
            };

            Assert.Throws <InvalidSearchOperationException>(() => _parser.Parse(searchParameter, SearchModifierCode.Text, "test"));
        }
        public void GivenUnsupportedSortParametersType_WhenValidating_ThenReturnsFalse(SearchParamType searchParamType)
        {
            SearchParameterInfo paramInfo = new SearchParameterInfo(name: "paramName", code: "paramName", searchParamType);
            IReadOnlyList <(SearchParameterInfo, SortOrder)> searchList = new List <(SearchParameterInfo, SortOrder)>()
            {
                { (paramInfo, SortOrder.Ascending) },
            };

            bool sortingValid = _sqlServerSortingValidator.ValidateSorting(searchList, out IReadOnlyList <string> errorMessage);

            Assert.False(sortingValid);
            Assert.NotEmpty(errorMessage);
        }
        public void GivenSupportedSortParametersTypeForSchemaOlderThanV17_WhenValidating_ThenReturnsFalse(SearchParamType searchParamType)
        {
            SearchParameterInfo paramInfo = new SearchParameterInfo(name: "paramName", code: "paramName", searchParamType);
            IReadOnlyList <(SearchParameterInfo, SortOrder)> searchList = new List <(SearchParameterInfo, SortOrder)>()
            {
                { (paramInfo, SortOrder.Ascending) },
            };

            _schemaInformation.Current = (int)SchemaVersion.V16;
            bool sortingValid = _sqlServerSortingValidator.ValidateSorting(searchList, out IReadOnlyList <string> errorMessage);

            Assert.False(sortingValid);
            Assert.NotEmpty(errorMessage);
        }
Пример #9
0
        private IReadOnlyList <ISearchValue> ExtractSearchValues(
            string searchParameterDefinitionUrl,
            SearchParamType searchParameterType,
            IEnumerable <ResourceType?> allowedReferenceResourceTypes,
            Base element,
            string fhirPathExpression,
            FhirEvaluationContext context)
        {
            Debug.Assert(searchParameterType != SearchParamType.Composite, "The search parameter must be non-composite.");

            var results = new List <ISearchValue>();

            // For simple value type, we can parse the expression directly.
            IEnumerable <Base> extractedValues = Enumerable.Empty <Base>();

            try
            {
                extractedValues = element.Select(fhirPathExpression, context);
            }
            catch (Exception ex)
            {
                _logger.LogWarning(
                    ex,
                    "Failed to extract the values using '{FhirPathExpression}' against '{ElementType}'.",
                    fhirPathExpression,
                    element.GetType());
            }

            Debug.Assert(extractedValues != null, "The extracted values should not be null.");

            // If there is target set, then filter the extracted values to only those types.
            if (searchParameterType == SearchParamType.Reference &&
                allowedReferenceResourceTypes != null &&
                allowedReferenceResourceTypes.Any())
            {
                List <string> targetResourceTypes = _targetTypesLookup.GetOrAdd(searchParameterDefinitionUrl, _ =>
                {
                    return(allowedReferenceResourceTypes.Select(t => t.ToString()).ToList());
                });

                // TODO: The expression for reference search parameters in STU3 has issues.
                // The reference search parameter could be pointing to an element that can be multiple types. For example,
                // the Appointment.participant.actor can be type of Patient, Practitioner, Related Person, Location, and so on.
                // Some search parameter could refer to this property but restrict to certain types. For example,
                // Appointment's location search parameter is returned only when Appointment.participant.actor is Location element.
                // The STU3 expressions don't have this restriction so everything is being returned. This is addressed in R4 release (see
                // http://community.fhir.org/t/expression-seems-incorrect-for-reference-search-parameter-thats-only-applicable-to-certain-types/916/2).
                // Therefore, for now, we will need to compare the reference value itself (which can be internal or external references), and restrict
                // the values ourselves.
                extractedValues = extractedValues.Where(ev =>
                                                        ev is ResourceReference rr &&
                                                        rr.Reference != null &&
                                                        targetResourceTypes.Any(trt => rr.Reference.Contains(trt, StringComparison.Ordinal)));
            }

            foreach (var extractedValue in extractedValues)
            {
                if (!_fhirElementTypeConverterManager.TryGetConverter(extractedValue.GetType(), GetSearchValueTypeForSearchParamType(searchParameterType), out IFhirElementToSearchValueTypeConverter converter))
                {
                    _logger.LogWarning(
                        "The FHIR element '{ElementType}' is not supported.",
                        extractedValue.TypeName);

                    continue;
                }

                _logger.LogDebug(
                    "The FHIR element '{ElementType}' will be converted using '{ElementTypeConverter}'.",
                    extractedValue.TypeName,
                    converter.GetType().FullName);

                results.AddRange(converter.ConvertTo(extractedValue) ?? Enumerable.Empty <ISearchValue>());
            }

            return(results);
        }
Пример #10
0
 public static ValueSets.SearchParamType ToValueSet(this SearchParamType searchParam)
 {
     return(Enum.Parse <ValueSets.SearchParamType>(searchParam.ToString()));
 }
Пример #11
0
        private async Task <SearchParameter> CreatePatientSearchParam(string searchParamName, SearchParamType type, string expression)
        {
            var searchParam = new SearchParameter
            {
                Url  = $"http://hl7.org/fhir/SearchParameter/Patient-{searchParamName}",
                Type = type,
                Base = new List <ResourceType?> {
                    ResourceType.Patient
                },
                Expression = expression,
                Name       = searchParamName,
                Code       = searchParamName,
            };

            _searchParameterDefinitionManager.AddNewSearchParameters(new List <ITypedElement> {
                searchParam.ToTypedElement()
            });

            // Add the search parameter to the datastore
            await _fixture.SearchParameterStatusManager.UpdateSearchParameterStatusAsync(new List <string> {
                searchParam.Url
            }, SearchParameterStatus.Supported);

            return(searchParam);
        }
Пример #12
0
        public static IList <SearchParameter.SearchModifierCode> GetModifiersForSearchType(SearchParamType SearchParamType)
        {
            IList <SearchParameter.SearchModifierCode> ReturnList = new List <SearchParameter.SearchModifierCode>();

            switch (SearchParamType)
            {
            case SearchParamType.Number:
                ReturnList.Add(SearchParameter.SearchModifierCode.Missing);
                return(ReturnList);

            case SearchParamType.Date:
                ReturnList.Add(SearchParameter.SearchModifierCode.Missing);
                return(ReturnList);

            case SearchParamType.String:
                ReturnList.Add(SearchParameter.SearchModifierCode.Missing);
                ReturnList.Add(SearchParameter.SearchModifierCode.Contains);
                ReturnList.Add(SearchParameter.SearchModifierCode.Exact);
                return(ReturnList);

            case SearchParamType.Token:
                ReturnList.Add(SearchParameter.SearchModifierCode.Missing);
                //The modifiers below are supported in the spec for token but not
                //implemented by this server as yet

                //ReturnList.Add(Conformance.SearchModifierCode.Text.ToString());
                //ReturnList.Add(Conformance.SearchModifierCode.In.ToString());
                //ReturnList.Add(Conformance.SearchModifierCode.Below.ToString());
                //ReturnList.Add(Conformance.SearchModifierCode.Above.ToString());
                //ReturnList.Add(Conformance.SearchModifierCode.In.ToString());
                //ReturnList.Add(Conformance.SearchModifierCode.NotIn.ToString());
                return(ReturnList);

            case SearchParamType.Reference:
                ReturnList.Add(SearchParameter.SearchModifierCode.Type);
                ReturnList.Add(SearchParameter.SearchModifierCode.Missing);
                return(ReturnList);

            case SearchParamType.Composite:
                return(ReturnList);

            case SearchParamType.Quantity:
                ReturnList.Add(SearchParameter.SearchModifierCode.Missing);
                return(ReturnList);

            case SearchParamType.Uri:
                ReturnList.Add(SearchParameter.SearchModifierCode.Missing);
                ReturnList.Add(SearchParameter.SearchModifierCode.Below);
                ReturnList.Add(SearchParameter.SearchModifierCode.Above);
                ReturnList.Add(SearchParameter.SearchModifierCode.Contains);
                ReturnList.Add(SearchParameter.SearchModifierCode.Exact);
                return(ReturnList);

            default:
                throw new System.ComponentModel.InvalidEnumArgumentException(SearchParamType.ToString(), (int)SearchParamType, typeof(SearchParamType));
            }
        }
Пример #13
0
            public static bool TryParse(string value, out SearchParamType result)
            {
                result = default(SearchParamType);

                if( value=="integer")
                    result = SearchParamType.Integer;
                else if( value=="string")
                    result = SearchParamType.String;
                else if( value=="text")
                    result = SearchParamType.Text;
                else if( value=="date")
                    result = SearchParamType.Date;
                else if( value=="token")
                    result = SearchParamType.Token;
                else if( value=="reference")
                    result = SearchParamType.Reference;
                else if( value=="composite")
                    result = SearchParamType.Composite;
                else
                    return false;

                return true;
            }
Пример #14
0
 public static string ToString(SearchParamType value)
 {
     if( value==SearchParamType.Integer )
         return "integer";
     else if( value==SearchParamType.String )
         return "string";
     else if( value==SearchParamType.Text )
         return "text";
     else if( value==SearchParamType.Date )
         return "date";
     else if( value==SearchParamType.Token )
         return "token";
     else if( value==SearchParamType.Reference )
         return "reference";
     else if( value==SearchParamType.Composite )
         return "composite";
     else
         throw new ArgumentException("Unrecognized SearchParamType value: " + value.ToString());
 }