コード例 #1
0
        private void _PopulateResourceEntity(ResCurrentType ResourceEntity, Resource Resource, IPyroRequestUri FhirRequestUri, IList <DtoServiceSearchParameterLight> SearchParametersList)
        {
            Hl7.Fhir.ElementModel.PocoNavigator Navigator = new Hl7.Fhir.ElementModel.PocoNavigator(Resource);
            string Resource_ResourceName = FHIRAllTypes.Resource.GetLiteral();

            foreach (DtoServiceSearchParameterLight SearchParameter in SearchParametersList)
            {
                //Todo: Composite searchParameters are not supported as yet, need to do work to read
                // the sub search parameters of the composite directly fro the SearchParameter resources.
                if (SearchParameter.Type != SearchParamType.Composite)
                {
                    bool SetSearchParameterIndex = true;
                    if ((SearchParameter.Resource == Resource_ResourceName && SearchParameter.Name == "_id") ||
                        (SearchParameter.Resource == Resource_ResourceName && SearchParameter.Name == "_lastUpdated"))
                    {
                        SetSearchParameterIndex = false;
                    }

                    if (SetSearchParameterIndex)
                    {
                        string Expression = SearchParameter.Expression;
                        if (SearchParameter.Resource == Resource_ResourceName)
                        {
                            //If the Expression is one with a parent resource of Resource then swap it for the actual current resource name
                            //For example make 'Resource._tag' be 'Observation._tag' for Observation resources.
                            Expression = Resource.TypeName + SearchParameter.Expression.TrimStart(Resource_ResourceName.ToCharArray());
                        }

                        IEnumerable <IElementNavigator> ResultList = Navigator.Select(Expression, new EvaluationContext(Navigator));
                        //Upgrade of FHRI .NET API
                        //IEnumerable<IElementNavigator> ResultList = Navigator.Select(Expression, Navigator);

                        foreach (IElementNavigator oElement in ResultList)
                        {
                            if (oElement != null)
                            {
                                switch (SearchParameter.Type)
                                {
                                case SearchParamType.Number:
                                {
                                    ICollection <ResIndexQuantityType> ResourceIndexQuantity = IIndexSetterFactory.CreateNumberSetter().Set(oElement, SearchParameter);
                                    if (ResourceIndexQuantity != null)
                                    {
                                        ResourceEntity.IndexQuantityList.AddRange(ResourceIndexQuantity);
                                    }
                                    break;
                                }

                                case SearchParamType.Date:
                                {
                                    ICollection <ResIndexDateTimeType> ResourceIndexDateTime = IIndexSetterFactory.CreateDateTimeSetter().Set(oElement, SearchParameter);
                                    if (ResourceIndexDateTime != null)
                                    {
                                        ResourceEntity.IndexDateTimeList.AddRange(ResourceIndexDateTime);
                                    }
                                    break;
                                }

                                case SearchParamType.String:
                                {
                                    ICollection <ResIndexStringType> ResourceIndexString = IIndexSetterFactory.CreateStringSetter().Set(oElement, SearchParameter);
                                    if (ResourceIndexString != null)
                                    {
                                        ResourceEntity.IndexStringList.AddRange(ResourceIndexString);
                                    }
                                    break;
                                }

                                case SearchParamType.Token:
                                {
                                    ICollection <ResIndexTokenType> ResourceIndexToken = IIndexSetterFactory.CreateTokenSetter().Set(oElement, SearchParameter);
                                    if (ResourceIndexToken != null)
                                    {
                                        ResourceEntity.IndexTokenList.AddRange(ResourceIndexToken);
                                    }
                                    break;
                                }

                                case SearchParamType.Reference:
                                {
                                    ICollection <ResIndexReferenceType> ResourceIndexReference = IIndexSetterFactory.CreateReferenceSetter().Set(oElement, SearchParameter);
                                    if (ResourceIndexReference != null)
                                    {
                                        ResourceEntity.IndexReferenceList.AddRange(ResourceIndexReference);
                                    }
                                    break;
                                }

                                case SearchParamType.Composite:
                                {
                                    break;
                                }

                                case SearchParamType.Quantity:
                                {
                                    ICollection <ResIndexQuantityType> ResourceIndexQuantity = IIndexSetterFactory.CreateQuantitySetter().Set(oElement, SearchParameter);
                                    if (ResourceIndexQuantity != null)
                                    {
                                        ResourceEntity.IndexQuantityList.AddRange(ResourceIndexQuantity);
                                    }
                                    break;
                                }

                                case SearchParamType.Uri:
                                {
                                    ICollection <ResIndexUriType> ResourceIndexUri = IIndexSetterFactory.CreateUriSetter().Set(oElement, SearchParameter);
                                    if (ResourceIndexUri != null)
                                    {
                                        ResourceEntity.IndexUriList.AddRange(ResourceIndexUri);
                                    }
                                    break;
                                }

                                default:
                                    throw new System.ComponentModel.InvalidEnumArgumentException(SearchParameter.Type.ToString(), (int)SearchParameter.Type, typeof(SearchParamType));
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void Index(Resource Resource, PyroSearchParameters DtoSearchParameters = null)
        {
            this.ResourceType = Resource.ResourceType;
            this.FhirID       = Resource.Id;
            string ResourceName = Resource.ResourceType.GetLiteral();
            IList <DtoServiceSearchParameterLight> SearchParametersList = IServiceSearchParameterCache.GetSearchParameterForResource(ResourceName);

            //Filter the list by only the searech parameters provided, do not inex for all
            if (DtoSearchParameters != null)
            {
                SearchParametersList = SearchParametersList.Where(x => DtoSearchParameters.SearchParametersList.Any(d => d.Id == x.Id)).ToList();
            }

            PocoNavigator Navigator = new PocoNavigator(Resource);

            string Resource_ResourceName = FHIRAllTypes.Resource.GetLiteral();

            foreach (DtoServiceSearchParameterLight SearchParameter in SearchParametersList)
            {
                //Todo: Composite searchParameters are not supported as yet, need to do work to read
                // the sub search parameters of the composite directly fro the SearchParameter resources.
                if (SearchParameter.Type != SearchParamType.Composite)
                {
                    bool SetSearchParameterIndex = true;
                    //if ((SearchParameter.Resource == Resource_ResourceName && SearchParameter.Name == "_id") ||
                    //  (SearchParameter.Resource == Resource_ResourceName && SearchParameter.Name == "_lastUpdated"))
                    //{
                    //  SetSearchParameterIndex = false;
                    //}

                    if (SetSearchParameterIndex)
                    {
                        string Expression = SearchParameter.Expression;
                        if (SearchParameter.Resource == Resource_ResourceName)
                        {
                            //If the Expression is one with a parent resource of Resource then swap it for the actual current resource name
                            //For example make 'Resource._tag' be 'Observation._tag' for Observation resources.
                            Expression = Resource.TypeName + SearchParameter.Expression.TrimStart(Resource_ResourceName.ToCharArray());
                        }

                        IEnumerable <IElementNavigator> ResultList = Navigator.Select(Expression, new EvaluationContext(Navigator));
                        foreach (IElementNavigator oElement in ResultList)
                        {
                            if (oElement != null)
                            {
                                switch (SearchParameter.Type)
                                {
                                case SearchParamType.Number:
                                {
                                    this.IndexQuantityList.AddRange(IIndexSetterFactory.CreateNumberSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.Date:
                                {
                                    this.IndexDateTimeList.AddRange(IIndexSetterFactory.CreateDateTimeSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.String:
                                {
                                    this.IndexStringList.AddRange(IIndexSetterFactory.CreateStringSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.Token:
                                {
                                    this.IndexTokenList.AddRange(IIndexSetterFactory.CreateTokenSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.Reference:
                                {
                                    this.IndexReferenceList.AddRange(IIndexSetterFactory.CreateReferenceSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.Composite:
                                {
                                    break;
                                }

                                case SearchParamType.Quantity:
                                {
                                    this.IndexQuantityList.AddRange(IIndexSetterFactory.CreateQuantitySetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.Uri:
                                {
                                    this.IndexUriList.AddRange(IIndexSetterFactory.CreateUriSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                default:
                                    throw new System.ComponentModel.InvalidEnumArgumentException(SearchParameter.Type.ToString(), (int)SearchParameter.Type, typeof(SearchParamType));
                                }
                            }
                        }
                    }
                }
            }
        }