public async Task <IList <ResourceStore> > GetSearch(Common.Enums.FhirVersion fhirVersion, Common.Enums.ResourceType resourceType, IList <ISearchQueryBase> searchQueryList)
        {
            ExpressionStarter <ResourceStore> Predicate = IPredicateFactory.CurrentMainResource(fhirVersion, resourceType);

            Predicate.Extend(await IPredicateFactory.GetResourceStoreIndexPredicate(fhirVersion, resourceType, searchQueryList), PredicateOperator.And);
            foreach (var exp in await IPredicateFactory.ChainEntry(_context, resourceType, searchQueryList))
            {
                Predicate.Extend(exp, PredicateOperator.And);
            }


            try
            {
                IQueryable <ResourceStore> Query = DbSet;
                Query = Query.AsExpandable().Where(Predicate);
                return(await Query.OrderBy(z => z.LastUpdated).ToListAsync());
            }
            catch (Exception Exec)
            {
                var mesg = Exec.Message;
                throw Exec;
            }

            //string Debug = Predicate.Expand().ToString();
            //return await Predicate2.AsExpandable().Where(Predicate).OrderBy(z => z.LastUpdated).ToListAsync();
        }
示例#2
0
        private static void IdSearchParameterPredicateProcessing(List <ISearchParameterBase> SearchParametersList, ResourceSearchExpressionTrees <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> MainPredicate)
        {
            var IdSearchParamerterList = SearchParametersList.Where(x => x.Resource == FHIRAllTypes.Resource.GetLiteral() && x.Name == "_id");

            if (IdSearchParamerterList != null)
            {
                ExpressionStarter <ResCurrentType> NewIdPredicate = null;
                foreach (var IdSearchParameter in IdSearchParamerterList)
                {
                    if (IdSearchParameter is SearchParameterToken SearchTypeToken)
                    {
                        NewIdPredicate = LinqKit.PredicateBuilder.New <ResCurrentType>();
                        foreach (var SearchValue in SearchTypeToken.ValueList)
                        {
                            if (!SearchTypeToken.Modifier.HasValue)
                            {
                                var Expression = Search.MainResourceFhirIdAny(SearchValue.Code);
                                NewIdPredicate = NewIdPredicate.Or(Expression);
                            }
                        }
                    }
                    MainPredicate.Extend <ResCurrentType>(NewIdPredicate, PredicateOperator.And);
                }
                SearchParametersList.RemoveAll(x => x.Resource == FHIRAllTypes.Resource.GetLiteral() && x.Name == "_id");
            }
        }
示例#3
0
        public async Task <ExpressionStarter <ResourceStore> > GetResourceStoreIndexPredicate(Common.Enums.FhirVersion fhirVersion, Common.Enums.ResourceType resourceType, IList <ISearchQueryBase> SearchQueryList)
        {
            IEnumerable <ISearchQueryBase> ChainedSearchQueryList   = SearchQueryList.Where(x => x.ChainedSearchParameter is object);
            IEnumerable <ISearchQueryBase> NoChainedSearchQueryList = SearchQueryList.Where(x => x.ChainedSearchParameter is null);

            //Below must be true 'PredicateBuilder.New<ResourceStore>(true)' in order to get all resource when no query string
            ExpressionStarter <ResourceStore> Predicate = PredicateBuilder.New <ResourceStore>(true);

            foreach (var Search in NoChainedSearchQueryList)
            {
                switch (Search.SearchParamTypeId)
                {
                case Common.Enums.SearchParamType.Number:
                    IResourceStorePredicateFactory.NumberIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.QuantityIndexList.Any(x.Compile())));
                    break;

                case Common.Enums.SearchParamType.Date:
                    IResourceStorePredicateFactory.DateTimeIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.DateTimeIndexList.Any(x.Compile())));
                    break;

                case Common.Enums.SearchParamType.String:
                    IResourceStorePredicateFactory.StringIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.StringIndexList.Any(x.Compile())));
                    break;

                case Common.Enums.SearchParamType.Token:
                    IResourceStorePredicateFactory.TokenIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.TokenIndexList.Any(x.Compile())));
                    break;

                case Common.Enums.SearchParamType.Reference:
                    (await IResourceStorePredicateFactory.ReferenceIndex(Search)).ForEach(x => Predicate = Predicate.Or(y => y.ReferenceIndexList.Any(x.Compile())));
                    break;

                case Common.Enums.SearchParamType.Composite:
                    Predicate = await IResourceStorePredicateFactory.CompositeIndex(this, Search);

                    break;

                case Common.Enums.SearchParamType.Quantity:
                    IResourceStorePredicateFactory.QuantityIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.QuantityIndexList.Any(x.Compile())));
                    break;

                case Common.Enums.SearchParamType.Uri:
                    IResourceStorePredicateFactory.UriIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.UriIndexList.Any(x.Compile())));
                    break;

                case Common.Enums.SearchParamType.Special:
                    throw new Common.Exceptions.FhirFatalException(System.Net.HttpStatusCode.InternalServerError, new string[] { $"Attempt to search with a SearchParameter of type: {Common.Enums.SearchParamType.Special.GetCode()} which is not supported by this server." });

                default:
                    break;
                }
                Predicate = Predicate.Extend(Predicate, PredicateOperator.And);
            }
            return(Predicate);
        }
        public static void Build(List <ISearchParameterBase> SearchParametersList, ResourceSearch <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> MainPredicate)
        {
            var LastUpdatedSearchParamerterList = SearchParametersList.Where(x => x.Resource == FHIRAllTypes.Resource.GetLiteral() && x.Name == "_lastUpdated");

            if (LastUpdatedSearchParamerterList != null)
            {
                ExpressionStarter <ResCurrentType> NewLastUpdatedPredicate = null;
                foreach (var LastUpdatedSearchParameter in LastUpdatedSearchParamerterList)
                {
                    if (LastUpdatedSearchParameter is SearchParameterDateTime SearchTypeToken)
                    {
                        NewLastUpdatedPredicate = LinqKit.PredicateBuilder.New <ResCurrentType>();
                        foreach (var SearchValue in SearchTypeToken.ValueList)
                        {
                            if (!SearchTypeToken.Modifier.HasValue)
                            {
                                if (SearchValue.Prefix.HasValue == false)
                                {
                                    NewLastUpdatedPredicate = Equals(Search, NewLastUpdatedPredicate, SearchValue);
                                }
                                else
                                {
                                    switch (SearchValue.Prefix)
                                    {
                                    case SearchParameter.SearchComparator.Eq:
                                        NewLastUpdatedPredicate = Equals(Search, NewLastUpdatedPredicate, SearchValue);
                                        break;

                                    case SearchParameter.SearchComparator.Ne:
                                        throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter _lastUpdated.");

                                    case SearchParameter.SearchComparator.Gt:
                                        var ExpressionGreaterThan = Search.LastUpdatedPropertyGreaterThan(FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision));
                                        NewLastUpdatedPredicate = NewLastUpdatedPredicate.Or(ExpressionGreaterThan);
                                        break;

                                    case SearchParameter.SearchComparator.Lt:
                                        var ExpressionLessThan = Search.LastUpdatedPropertyLessThan(SearchValue.Value);
                                        NewLastUpdatedPredicate = NewLastUpdatedPredicate.Or(ExpressionLessThan);
                                        break;

                                    case SearchParameter.SearchComparator.Ge:
                                        var ExpressionGreaterThanOrEqualTo = Search.LastUpdatedPropertyGreaterThanOrEqualTo(SearchValue.Value);
                                        NewLastUpdatedPredicate = NewLastUpdatedPredicate.Or(ExpressionGreaterThanOrEqualTo);
                                        break;

                                    case SearchParameter.SearchComparator.Le:
                                        var ExpressionLessThanOrEqualTo = Search.LastUpdatedPropertyLessThanOrEqualTo(FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision));
                                        NewLastUpdatedPredicate = NewLastUpdatedPredicate.Or(ExpressionLessThanOrEqualTo);
                                        break;

                                    case SearchParameter.SearchComparator.Sa:
                                        throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter _lastUpdated.");

                                    case SearchParameter.SearchComparator.Eb:
                                        throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter _lastUpdated.");

                                    case SearchParameter.SearchComparator.Ap:
                                        throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter _lastUpdated.");

                                    default:
                                        throw new System.ComponentModel.InvalidEnumArgumentException(SearchValue.Prefix.Value.GetLiteral(), (int)SearchValue.Prefix, typeof(SearchParameter.SearchComparator));
                                    }
                                }
                            }
                            else
                            {
                                throw new FormatException($"The search Modifiers are not supported for search parameter _lastUpdated. Found modifier {SearchTypeToken.Modifier.Value.GetLiteral()}");
                            }
                        }
                    }
                    MainPredicate.Extend <ResCurrentType>(NewLastUpdatedPredicate, PredicateOperator.And);
                }
                SearchParametersList.RemoveAll(x => x.Resource == FHIRAllTypes.Resource.GetLiteral() && x.Name == "_lastUpdated");
            }
        }