public void TestCompositeType()
        {
            //Prepare
            Setup();
            List <SearchParameter> SearchParameterListForResource = ISearchParameterCacheMock !.Object.GetForIndexingAsync(Common.Enums.FhirVersion.R4, Common.Enums.ResourceType.Observation).Result;
            SearchParameter        SearchParameter = SearchParameterListForResource.SingleOrDefault(x => x.Name == "code-value-concept");

            var Parameter = new KeyValuePair <string, StringValues>("code-value-concept", new StringValues("SystemOne|CodeOne$SystemTwo|CodeTwo"));

            //Act
            IList <ISearchQueryBase> ISearchQueryBaseList = SearchQueryFactory !.Create(Common.Enums.ResourceType.Observation, SearchParameter, Parameter, false).Result;

            //Assert
            Assert.Equal(1, ISearchQueryBaseList.Count);
            ISearchQueryBase SearchQueryResult = ISearchQueryBaseList[0];

            Assert.Null(SearchQueryResult.ChainedSearchParameter);
            Assert.NotNull(SearchQueryResult.ComponentList);
            Assert.Equal(2, SearchQueryResult.ComponentList.Count);
            Assert.Equal(Bug.Common.Enums.FhirVersion.R4, SearchQueryResult.FhirVersionId);
            Assert.False(SearchQueryResult.HasLogicalOrProperties);
            Assert.Equal(string.Empty, SearchQueryResult.InvalidMessage);
            Assert.True(SearchQueryResult.IsValid);
            Assert.Null(SearchQueryResult.Modifier);
            Assert.Equal("code-value-concept", SearchQueryResult.Name);
            Assert.Equal("code-value-concept=SystemOne|CodeOne$SystemTwo|CodeTwo", SearchQueryResult.RawValue);
            Assert.Equal(Common.Enums.ResourceType.Observation, SearchQueryResult.ResourceContext);
            Assert.Equal(1, SearchQueryResult.ResourceTypeList.Count);
            Assert.Equal(Common.Enums.ResourceType.Observation, SearchQueryResult.ResourceTypeList.ToArray()[0].ResourceTypeId);
            Assert.Equal(Common.Enums.SearchParamType.Composite, SearchQueryResult.SearchParamTypeId);
            Assert.Equal(0, SearchQueryResult.TargetResourceTypeList.Count);
            Assert.False(SearchQueryResult.TypeModifierResource.HasValue);
            Assert.Equal("http://hl7.org/fhir/SearchParameter/Observation-code-value-concept", SearchQueryResult.Url);
        }
 public List <Expression <Func <IndexToken, bool> > > TokenIndex(ISearchQueryBase SearchQueryBase)
 {
     if (SearchQueryBase is SearchQueryToken SearchQueryToken)
     {
         return(IIndexTokenPredicateFactory.TokenIndex(SearchQueryToken));
     }
     else
     {
         throw new InvalidCastException($"Unable to cast a {nameof(ISearchQueryBase)} of type {SearchQueryBase.GetType().Name} to a {typeof(SearchQueryToken).Name}");
     }
 }
 public List <Expression <Func <IndexQuantity, bool> > > NumberIndex(ISearchQueryBase SearchQueryBase)
 {
     if (SearchQueryBase is SearchQueryNumber SearchQueryNumber)
     {
         return(IIndexNumberPredicateFactory.NumberIndex(SearchQueryNumber));
     }
     else
     {
         throw new InvalidCastException($"Unable to cast a {nameof(ISearchQueryBase)} of type {SearchQueryBase.GetType().Name} to a {typeof(SearchQueryNumber).Name}");
     }
 }
 public List <Expression <Func <IndexString, bool> > > StringIndex(ISearchQueryBase SearchQueryBase)
 {
     if (SearchQueryBase is SearchQueryString SearchQueryString)
     {
         return(IIndexStringPredicateFactory.StringIndex(SearchQueryString));
     }
     else
     {
         throw new InvalidCastException($"Unable to cast a {nameof(ISearchQueryBase)} of type {SearchQueryBase.GetType().Name} to a {typeof(SearchQueryString).Name}");
     }
 }
Esempio n. 5
0
        private async Task LoadCompositeSubSearchParameters(Common.Enums.ResourceType ResourceContext, SearchParameter searchParameter, string ParameterValue, string RawValue, ISearchQueryBase SearchQueryBase)
        {
            if (SearchQueryBase is SearchQueryComposite SearchQueryComposite)
            {
                List <ISearchQueryBase> SearchParameterBaseList = new List <ISearchQueryBase>();

                //Note we OrderBy SequentialOrder as they must be processed in this specific order
                foreach (SearchParameterComponent Component in SearchQueryComposite.ComponentList) //Should this be ordered by sentinel?
                {
                    SearchParameter?CompositeSearchParamter = await ISearchParameterRepository.GetByCanonicalUrlAsync(SearchQueryComposite.FhirVersionId, ResourceContext, Component.Definition);

                    if (CompositeSearchParamter is object)
                    {
                        ISearchQueryBase CompositeSubSearchQueryBase = InitalizeSearchQueryEntity(CompositeSearchParamter, ResourceContext, false, RawValue);
                        SearchParameterBaseList.Add(CompositeSubSearchQueryBase);
                    }
                    else
                    {
                        //This should not ever happen, but have message in case it does. We should never have a Composite
                        //search parameter loaded like this as on load it is checked, but you never know!
                        string Message =
                            $"Unable to locate one of the SearchParameters referenced in a Composite SearchParametrer type. " +
                            $"The Composite SearchParametrer Url was: {SearchQueryComposite.Url} for the resource type '{ResourceContext.GetCode()}'. " +
                            $"This SearchParamter references another SearchParamter with the Canonical Url of {Component.Definition}. " +
                            $"This SearchParamter can not be located in the FHIR Server. This is most likely a server error that will require investigation to resolve";
                        SearchQueryComposite.InvalidMessage = Message;
                        SearchQueryComposite.IsValid        = false;
                        break;
                    }
                }
                SearchQueryComposite.ParseCompositeValue(SearchParameterBaseList, ParameterValue);
            }
            else
            {
                throw new InvalidCastException($"Unable to cast a {nameof(SearchQueryBase)} to {typeof(SearchQueryComposite).Name} when the {nameof(SearchQueryBase)}.{nameof(SearchQueryBase.SearchParamTypeId)} = {SearchQueryBase.SearchParamTypeId.GetCode()}");
            }
        }
Esempio n. 6
0
        public async Task <IList <ISearchQueryBase> > Create(Bug.Common.Enums.ResourceType ResourceContext, SearchParameter searchParameter, KeyValuePair <string, StringValues> Parameter, bool IsChainedReferance = false)
        {
            var    Result        = new List <ISearchQueryBase>();
            string ParameterName = Parameter.Key.Trim();

            foreach (var ParameterValue in Parameter.Value)
            {
                string RawValue;
                if (IsChainedReferance)
                {
                    RawValue = $"{ParameterName}{FhirSearchQuery.TermChainDelimiter}";
                }
                else
                {
                    RawValue = $"{ParameterName}={ParameterValue}";
                }

                ISearchQueryBase SearchQueryBase = InitalizeSearchQueryEntity(searchParameter, ResourceContext, IsChainedReferance, RawValue);
                Result.Add(SearchQueryBase);

                SearchQueryBase.ParseModifier(ParameterName, this.IResourceTypeSupport, this.IKnownResource);

                if (SearchQueryBase.Modifier == SearchModifierCode.Type && !IsChainedReferance)
                {
                    SearchQueryBase.ParseValue($"{SearchQueryBase.TypeModifierResource.GetCode()}/{ParameterValue}");
                }
                else if (SearchQueryBase.SearchParamTypeId == Common.Enums.SearchParamType.Composite)
                {
                    await LoadCompositeSubSearchParameters(ResourceContext, searchParameter, ParameterValue, RawValue, SearchQueryBase);
                }
                else
                {
                    SearchQueryBase.ParseValue(ParameterValue);
                }
            }
            return(Result);
        }
 public async Task <Expression <Func <ResourceStore, bool> > > CompositeIndex(IPredicateFactory IPredicateFactory, ISearchQueryBase SearchQueryBase)
 {
     if (SearchQueryBase is SearchQueryComposite SearchQueryComposite)
     {
         return(await IIndexCompositePredicateFactory.CompositeIndex(IPredicateFactory, SearchQueryComposite));
     }
     else
     {
         throw new InvalidCastException($"Unable to cast a {nameof(ISearchQueryBase)} of type {SearchQueryBase.GetType().Name} to a {typeof(SearchQueryComposite).Name}");
     }
 }
 public async Task <List <Expression <Func <IndexReference, bool> > > > ReferenceIndex(ISearchQueryBase SearchQueryBase)
 {
     if (SearchQueryBase is SearchQueryReference SearchQueryReference)
     {
         return(await IIndexReferencePredicateFactory.ReferenceIndex(SearchQueryReference));
     }
     else
     {
         throw new InvalidCastException($"Unable to cast a {nameof(ISearchQueryBase)} of type {SearchQueryBase.GetType().Name} to a {typeof(SearchQueryReference).Name}");
     }
 }
        public void TestQueryTypesPositive(Common.Enums.FhirVersion fhirVersion, Common.Enums.ResourceType ResourceContext, Common.Enums.SearchParamType SearchParamType, string searchParameterName, string queryValue)
        {
            //Prepare
            Setup();
            List <SearchParameter> SearchParameterListForResource = ISearchParameterCacheMock !.Object.GetForIndexingAsync(fhirVersion, ResourceContext).Result;
            SearchParameter        SearchParameter = SearchParameterListForResource.SingleOrDefault(x => x.Name == searchParameterName);

            var Parameter = new KeyValuePair <string, StringValues>(searchParameterName, new StringValues(queryValue));

            //Act
            IList <ISearchQueryBase> ISearchQueryBaseList = SearchQueryFactory !.Create(ResourceContext, SearchParameter, Parameter, false).Result;

            //Assert
            Assert.Equal(1, ISearchQueryBaseList.Count);
            ISearchQueryBase SearchQueryResult = ISearchQueryBaseList[0];

            Assert.Null(SearchQueryResult.ChainedSearchParameter);
            if (SearchParamType == Common.Enums.SearchParamType.Composite)
            {
                Assert.NotNull(SearchQueryResult.ComponentList);
                //We are only assuming all Composite have only two components here, which is not always true
                Assert.Equal(2, SearchQueryResult.ComponentList.Count);
            }
            else
            {
                Assert.Equal(0, SearchQueryResult.ComponentList.Count);
            }

            Assert.Equal(fhirVersion, SearchQueryResult.FhirVersionId);
            Assert.Equal(queryValue.Contains(','), SearchQueryResult.HasLogicalOrProperties);
            Assert.Equal(string.Empty, SearchQueryResult.InvalidMessage);
            Assert.True(SearchQueryResult.IsValid);
            Assert.Null(SearchQueryResult.Modifier);
            Assert.Equal(searchParameterName, SearchQueryResult.Name);
            Assert.Equal($"{searchParameterName}={queryValue}", SearchQueryResult.RawValue);
            Assert.Equal(ResourceContext, SearchQueryResult.ResourceContext);
            Assert.True(SearchQueryResult.ResourceTypeList.Count > 0);
            Assert.Contains(SearchQueryResult.ResourceTypeList.ToArray(), x => x.ResourceTypeId == ResourceContext);
            Assert.Equal(SearchParamType, SearchQueryResult.SearchParamTypeId);
            if (SearchParamType == Common.Enums.SearchParamType.Reference)
            {
                Assert.True(SearchQueryResult.TargetResourceTypeList.Count > 0);
            }
            else
            {
                Assert.True(SearchQueryResult.TargetResourceTypeList.Count == 0);
            }
            Assert.False(SearchQueryResult.TypeModifierResource.HasValue);


            if (SearchQueryResult is SearchQueryComposite SearchQueryComposite)
            {
                Assert.Equal(2, SearchQueryResult.ComponentList.Count);
                Assert.True(SearchQueryComposite.ValueList.Count == 1);
                Assert.True(SearchQueryComposite.ValueList[0].SearchQueryBaseList.Count == 2);
                if (SearchQueryComposite.ValueList[0].SearchQueryBaseList[0] is SearchQueryToken SearchQueryToken)
                {
                    Assert.True(SearchQueryToken.ValueList.Count == 1);
                    Assert.Equal(queryValue.Split('$')[0].Split('|')[0], SearchQueryToken.ValueList[0].System);
                    Assert.Equal(queryValue.Split('$')[0].Split('|')[1], SearchQueryToken.ValueList[0].Code);
                }
            }
            else if (SearchQueryResult is SearchQueryString SearchQueryString)
            {
                if (queryValue.Contains(','))
                {
                    Assert.Equal(StringSupport.ToLowerTrimRemoveDiacriticsTruncate(queryValue.Split(',')[0], DatabaseMetaData.FieldLength.StringMaxLength), SearchQueryString.ValueList[0].Value);
                    Assert.Equal(StringSupport.ToLowerTrimRemoveDiacriticsTruncate(queryValue.Split(',')[1], DatabaseMetaData.FieldLength.StringMaxLength), SearchQueryString.ValueList[1].Value);
                }
                else
                {
                    Assert.Equal(StringSupport.ToLowerTrimRemoveDiacriticsTruncate(queryValue, DatabaseMetaData.FieldLength.StringMaxLength), SearchQueryString.ValueList[0].Value);
                }
            }
            else if (SearchQueryResult is SearchQueryReference SearchQueryReference)
            {
                Assert.NotNull(SearchQueryReference.ValueList[0].FhirUri);
                if (queryValue.StartsWith(TestData.BaseUrlServer))
                {
                    Assert.Equal(Common.Enums.ResourceType.Patient.GetCode(), SearchQueryReference.ValueList[0].FhirUri !.ResourseName);
                    Assert.Equal("11", SearchQueryReference.ValueList[0].FhirUri !.ResourceId);
                    Assert.True(SearchQueryReference.ValueList[0].FhirUri !.IsRelativeToServer);
                }
                else if (queryValue.StartsWith(TestData.BaseUrlRemote))
                {
                    Assert.Equal(Common.Enums.ResourceType.Patient.GetCode(), SearchQueryReference.ValueList[0].FhirUri !.ResourseName);
                    Assert.Equal("11", SearchQueryReference.ValueList[0].FhirUri !.ResourceId);
                    Assert.False(SearchQueryReference.ValueList[0].FhirUri !.IsRelativeToServer);
                }
                else if (queryValue.Contains('/'))
                {
                    Assert.Equal(queryValue.Split('/')[0], SearchQueryReference.ValueList[0].FhirUri !.ResourseName);
                    Assert.Equal(queryValue.Split('/')[1], SearchQueryReference.ValueList[0].FhirUri !.ResourceId);
                }
                else
                {
                    Assert.Equal(Common.Enums.ResourceType.Encounter.GetCode(), SearchQueryReference.ValueList[0].FhirUri !.ResourseName);
                    Assert.Equal(queryValue, SearchQueryReference.ValueList[0].FhirUri !.ResourceId);
                }
            }
            else if (SearchQueryResult is SearchQueryToken SearchQueryToken)
            {
                if (queryValue.StartsWith("code"))
                {
                    Assert.Null(SearchQueryToken.ValueList[0].System);
                    Assert.Equal(queryValue, SearchQueryToken.ValueList[0].Code);
                }
                else if (queryValue.EndsWith("|"))
                {
                    Assert.Null(SearchQueryToken.ValueList[0].Code);
                    Assert.Equal(queryValue.TrimEnd('|'), SearchQueryToken.ValueList[0].System);
                }
                else
                {
                    Assert.Equal(queryValue.Split('|')[0], SearchQueryToken.ValueList[0].System);
                    Assert.Equal(queryValue.Split('|')[1], SearchQueryToken.ValueList[0].Code);
                }
            }
            else if (SearchQueryResult is SearchQueryQuantity SearchQueryQuantity)
            {
                Assert.Equal(queryValue.Split('|')[1], SearchQueryQuantity.ValueList[0].System);
                Assert.Equal(queryValue.Split('|')[2], SearchQueryQuantity.ValueList[0].Code);
                if (queryValue.Split('|')[0].Contains("e+10") && queryValue.Split('|')[0].StartsWith('-'))
                {
                    Assert.Equal(-54000000000m, SearchQueryQuantity.ValueList[0].Value);
                    Assert.Equal(0, SearchQueryQuantity.ValueList[0].Scale);
                    Assert.Equal(11, SearchQueryQuantity.ValueList[0].Precision);
                }
                else if (queryValue.Split('|')[0].Contains("e-3"))
                {
                    Assert.Equal(0.00540m, SearchQueryQuantity.ValueList[0].Value);
                    Assert.Equal(5, SearchQueryQuantity.ValueList[0].Scale);
                    Assert.Equal(5, SearchQueryQuantity.ValueList[0].Precision);
                }
                else if (queryValue.Split('|')[0].Contains("e+10"))
                {
                    Assert.Equal(54000000000m, SearchQueryQuantity.ValueList[0].Value);
                    Assert.Equal(0, SearchQueryQuantity.ValueList[0].Scale);
                    Assert.Equal(11, SearchQueryQuantity.ValueList[0].Precision);
                }
                else
                {
                    Assert.Equal(Decimal.Parse(queryValue.Split('|')[0]), SearchQueryQuantity.ValueList[0].Value);
                    Assert.Equal(1, SearchQueryQuantity.ValueList[0].Scale);
                    Assert.Equal(2, SearchQueryQuantity.ValueList[0].Precision);
                }
            }
            else if (SearchQueryResult is SearchQueryNumber SearchQueryNumber)
            {
                if (queryValue.StartsWith("gt"))
                {
                    Assert.Equal(100, SearchQueryNumber.ValueList[0].Value);
                    Assert.Equal(0, SearchQueryNumber.ValueList[0].Scale);
                    Assert.Equal(3, SearchQueryNumber.ValueList[0].Precision);
                    Assert.Equal(SearchComparator.Gt, SearchQueryNumber.ValueList[0].Prefix);
                }
                else if (queryValue.StartsWith("lt"))
                {
                    Assert.Equal(100, SearchQueryNumber.ValueList[0].Value);
                    Assert.Equal(0, SearchQueryNumber.ValueList[0].Scale);
                    Assert.Equal(3, SearchQueryNumber.ValueList[0].Precision);
                    Assert.Equal(SearchComparator.Lt, SearchQueryNumber.ValueList[0].Prefix);
                }
                else if (queryValue == "100")
                {
                    Assert.Equal(100, SearchQueryNumber.ValueList[0].Value);
                    Assert.Equal(0, SearchQueryNumber.ValueList[0].Scale);
                    Assert.Equal(3, SearchQueryNumber.ValueList[0].Precision);
                    Assert.Null(SearchQueryNumber.ValueList[0].Prefix);
                }
                else if (queryValue == "100.00")
                {
                    Assert.Equal(100.00m, SearchQueryNumber.ValueList[0].Value);
                    Assert.Equal(2, SearchQueryNumber.ValueList[0].Scale);
                    Assert.Equal(5, SearchQueryNumber.ValueList[0].Precision);
                    Assert.Null(SearchQueryNumber.ValueList[0].Prefix);
                }
            }
            else if (SearchQueryResult is SearchQueryDateTime SearchQueryDateTime)
            {
                if (queryValue.StartsWith("gt"))
                {
                    var testDate = new DateTimeOffset(new DateTime(2020, 04, 07), TimeSpan.FromHours(10));
                    Assert.Equal(testDate.ToUniversalTime().DateTime, SearchQueryDateTime.ValueList[0].Value);
                    Assert.Equal(DateTimePrecision.Day, SearchQueryDateTime.ValueList[0].Precision);
                    Assert.Equal(SearchComparator.Gt, SearchQueryDateTime.ValueList[0].Prefix);
                }
                else if (queryValue.Length == 16)
                {
                    var testDate = new DateTimeOffset(new DateTime(2020, 04, 07, 10, 00, 00), TimeSpan.FromHours(10));
                    Assert.Equal(testDate.ToUniversalTime().DateTime, SearchQueryDateTime.ValueList[0].Value);
                    Assert.Equal(DateTimePrecision.HourMin, SearchQueryDateTime.ValueList[0].Precision);
                }
                else if (queryValue.Length == 4)
                {
                    var testDate = new DateTimeOffset(new DateTime(2020, 01, 01), TimeSpan.FromHours(10));
                    Assert.Equal(testDate.ToUniversalTime().DateTime, SearchQueryDateTime.ValueList[0].Value);
                    Assert.Equal(DateTimePrecision.Year, SearchQueryDateTime.ValueList[0].Precision);
                }
                else if (queryValue.Length == 7)
                {
                    var testDate = new DateTimeOffset(new DateTime(2020, 04, 01), TimeSpan.FromHours(10));
                    Assert.Equal(testDate.ToUniversalTime().DateTime, SearchQueryDateTime.ValueList[0].Value);
                    Assert.Equal(DateTimePrecision.Month, SearchQueryDateTime.ValueList[0].Precision);
                }
                else if (queryValue.Length == 10)
                {
                    var testDate = new DateTimeOffset(new DateTime(2020, 04, 07), TimeSpan.FromHours(10));
                    Assert.Equal(testDate.ToUniversalTime().DateTime, SearchQueryDateTime.ValueList[0].Value);
                    Assert.Equal(DateTimePrecision.Day, SearchQueryDateTime.ValueList[0].Precision);
                }
                else if (queryValue.Length == 19)
                {
                    var testDate = new DateTimeOffset(new DateTime(2020, 04, 07, 10, 00, 10), TimeSpan.FromHours(10));
                    Assert.Equal(testDate.ToUniversalTime().DateTime, SearchQueryDateTime.ValueList[0].Value);
                    Assert.Equal(DateTimePrecision.Sec, SearchQueryDateTime.ValueList[0].Precision);
                }
                else if (queryValue.Length == 25)
                {
                    var testDate = new DateTimeOffset(new DateTime(2020, 04, 07, 10, 00, 10), TimeSpan.FromHours(5));
                    Assert.Equal(testDate.ToUniversalTime().DateTime, SearchQueryDateTime.ValueList[0].Value);
                    Assert.Equal(DateTimePrecision.Sec, SearchQueryDateTime.ValueList[0].Precision);
                }
            }
            else if (SearchQueryResult is SearchQueryUri SearchQueryUri)
            {
                Assert.Equal(new Uri(queryValue), SearchQueryUri.ValueList[0].Value);
            }
            else
            {
                Assert.Null(SearchQueryResult.ComponentList);
            }
        }
Esempio n. 10
0
        private async Task <IQueryable <ResourceStore> > ChainRecursion(AppDbContext AppDbContext, IQueryable <ResourceStore> OtherResourceStoreQuery, ISearchQueryBase ChainSearchQuery)
        {
            if (ChainSearchQuery.ChainedSearchParameter is object)
            {
                //Recursively move through each child chain search query until at the end and child is null
                //The last one is the root search at the end of the chain, performer:Organization.name from the example.
                Bug.Common.Enums.ResourceType ChainedResourceTypeContext = ChainSearchQuery.ChainedSearchParameter.ResourceContext;
                IQueryable <ResourceStore>    ResCurrentTypeContext      = AppDbContext.Set <ResourceStore>();

                IQueryable <IndexReference> IndexReferenceContext = AppDbContext.Set <IndexReference>();
                IQueryable <IndexString>    IndexStringContext    = AppDbContext.Set <IndexString>();

                ResCurrentTypeContext = await ChainRecursion(AppDbContext, ResCurrentTypeContext, ChainSearchQuery.ChainedSearchParameter);

                Bug.Common.Enums.ResourceType ReferenceResourceType = ChainSearchQuery.TypeModifierResource.Value;
                int ReferenceSearchParameterId = ChainSearchQuery.ChainedSearchParameter.Id;
                //need to get the Key of the Primary Base URL somehow as hard coded here
                //int ReferencePrimaryServiceRootUrlId = IServiceBaseUrlCache.GetPrimaryAsync.Id;
                int ReferencePrimaryServiceRootUrlId = 1;


                OtherResourceStoreQuery = OtherResourceStoreQuery.Where(x =>
                                                                        x.ReferenceIndexList.Any(y =>
                                                                                                 y.ServiceBaseUrlId == 1 &
                                                                                                 y.SearchParameterId == 1000 &
                                                                                                 y.ResourceTypeId == Common.Enums.ResourceType.Observation &
                                                                                                 y.CanonicalVersionId == null &
                                                                                                 y.VersionId == null &
                                                                                                 IndexReferenceContext.Where(g =>
                                                                                                                             g.ServiceBaseUrlId == 1 &
                                                                                                                             g.SearchParameterId == 2000 &
                                                                                                                             g.ResourceTypeId == Common.Enums.ResourceType.DiagnosticReport &
                                                                                                                             g.CanonicalVersionId == null &
                                                                                                                             g.VersionId == null &
                                                                                                                             IndexStringContext.Where(l =>
                                                                                                                                                      l.SearchParameterId == 3000 &
                                                                                                                                                      l.String == "Value").Select(s => s.ResourceStoreId).Contains(g.ResourceStoreId)).Select(q => q.ResourceStoreId).Contains(y.ResourceStoreId)));



                OtherResourceStoreQuery = OtherResourceStoreQuery
                                          .Where(x =>
                                                 x.ReferenceIndexList.Any(c =>
                                                                          ResCurrentTypeContext.Where(a =>
                                                                                                      a.IsCurrent == true &
                                                                                                      a.IsDeleted == false &
                                                                                                      a.ContainedId == null &
                                                                                                      a.ReferenceIndexList.Any(f =>
                                                                                                                               f.ResourceTypeId == ReferenceResourceType &
                                                                                                                               f.SearchParameterId == ReferenceSearchParameterId &
                                                                                                                               f.VersionId == null &
                                                                                                                               f.CanonicalVersionId == null &
                                                                                                                               f.ServiceBaseUrlId == ReferencePrimaryServiceRootUrlId)).Select(v => v.Id).Contains(c.Id)));
                return(OtherResourceStoreQuery);
            }
            else
            {
                switch (ChainSearchQuery.SearchParamTypeId)
                {
                case Common.Enums.SearchParamType.Number:
                    var Predicate2 = IResourceStorePredicateFactory.NumberIndex(ChainSearchQuery);
                    IQueryable <IndexQuantity>        IndexQuantity = AppDbContext.Set <IndexQuantity>();
                    ExpressionStarter <IndexQuantity> PredicateGus  = PredicateBuilder.New <IndexQuantity>(true);
                    foreach (var Pred in Predicate2)
                    {
                        PredicateGus = PredicateGus.Or(Pred);
                    }
                    IndexQuantity = IndexQuantity.Where(PredicateGus);

                    break;

                case Common.Enums.SearchParamType.Date:
                    break;

                case Common.Enums.SearchParamType.String:
                    break;

                case Common.Enums.SearchParamType.Token:
                    break;

                case Common.Enums.SearchParamType.Reference:
                    break;

                case Common.Enums.SearchParamType.Composite:
                    break;

                case Common.Enums.SearchParamType.Quantity:
                    break;

                case Common.Enums.SearchParamType.Uri:
                    break;

                case Common.Enums.SearchParamType.Special:
                    break;

                default:
                    break;
                }


                var Predicate = await GetResourceStoreIndexPredicate(ChainSearchQuery.FhirVersionId, ChainSearchQuery.ResourceContext, new List <ISearchQueryBase>() { ChainSearchQuery });

                IQueryable <ResourceStore> ResCurrentTypeContext = AppDbContext.Set <ResourceStore>();
                ResCurrentTypeContext = ResCurrentTypeContext.AsExpandable().Where(Predicate);

                OtherResourceStoreQuery = OtherResourceStoreQuery
                                          .Where(x => x.ReferenceIndexList.Any(c => ResCurrentTypeContext.Select(v => v.Id).Contains(c.Id)));

                return(OtherResourceStoreQuery);
            }
        }
Esempio n. 11
0
        private async Task <Expression <Func <IndexReference, bool> > > ChainRecursion2(AppDbContext AppDbContext, Expression <Func <IndexReference, bool> > OtherIndexRefQuery, ISearchQueryBase ChainSearchQuery)
        {
            if (ChainSearchQuery.ChainedSearchParameter.ChainedSearchParameter is null)
            {
                switch (ChainSearchQuery.ChainedSearchParameter.SearchParamTypeId)
                {
                case Common.Enums.SearchParamType.String:
                    List <Expression <Func <IndexString, bool> > > PredicateList = IResourceStorePredicateFactory.StringIndex(ChainSearchQuery.ChainedSearchParameter);
                    IQueryable <IndexString>        IndexString  = AppDbContext.Set <IndexString>();
                    ExpressionStarter <IndexString> PredicateGus = PredicateBuilder.New <IndexString>(true);
                    foreach (var Pred in PredicateList)
                    {
                        Expression <Func <IndexString, bool> > Temp = Pred;
                        PredicateGus = PredicateGus.Or(Temp);
                    }

                    OtherIndexRefQuery = OtherIndexRefQuery.And(x =>
                                                                x.SearchParameterId == 1 &
                                                                x.ResourceTypeId == ChainSearchQuery.TypeModifierResource !.Value &
                                                                x.SearchParameterId == ChainSearchQuery.Id &
                                                                x.VersionId == null &
                                                                x.CanonicalVersionId == null &
                                                                x.ResourceStore.ContainedId == null &
                                                                IndexString.Where(PredicateGus).Select(ss => ss.ResourceStore.ResourceId).Contains(x.ResourceId));

                    return(OtherIndexRefQuery);

                default:
                    throw new NotImplementedException();
                }
            }
            else
            {
                ExpressionStarter <IndexReference> Resultx = await ChainRecursion2(AppDbContext, OtherIndexRefQuery, ChainSearchQuery.ChainedSearchParameter);

                IQueryable <IndexReference> IndexReference = AppDbContext.Set <IndexReference>();

                OtherIndexRefQuery = OtherIndexRefQuery.And(x =>
                                                            x.SearchParameterId == 1 &
                                                            x.ResourceTypeId == ChainSearchQuery.TypeModifierResource !.Value &
                                                            x.SearchParameterId == ChainSearchQuery.Id &
                                                            x.VersionId == null &
                                                            x.CanonicalVersionId == null &
                                                            x.ResourceStore.ContainedId == null &
                                                            IndexReference.Where(Resultx).Select(ss => ss.ResourceStore.ResourceId).Contains(x.ResourceId));

                return(OtherIndexRefQuery);
            }
        }