예제 #1
0
        public async Task GivenASPStatusManager_WhenInitializing_ThenSearchParameterIsUpdatedFromRegistry()
        {
            await _manager.EnsureInitializedAsync(CancellationToken.None);

            var list = _searchParameterDefinitionManager.GetSearchParameters("Account").ToList();

            Assert.True(list[0].IsSearchable);
            Assert.True(list[0].IsSupported);
            Assert.False(list[0].IsPartiallySupported);

            Assert.True(list[1].IsSearchable);
            Assert.True(list[1].IsSupported);
            Assert.True(list[1].IsPartiallySupported);

            Assert.False(list[2].IsSearchable);
            Assert.False(list[2].IsSupported);
            Assert.False(list[2].IsPartiallySupported);

            Assert.False(list[3].IsSearchable);
            Assert.True(list[3].IsSupported);
            Assert.False(list[3].IsPartiallySupported);

            Assert.False(list[4].IsSearchable);
            Assert.True(list[4].IsSupported);
            Assert.False(list[4].IsPartiallySupported);
        }
        public void GivenAConformanceBuilder_WhenAddingDefaultSearchParameters_ThenDocumentationIsAdded()
        {
            string description = "Logical id of this artifact";

            _searchParameterDefinitionManager.GetSearchParameters("Account")
            .Returns(new[] { new SearchParameterInfo("_id", "_id", SearchParamType.Token, description: description), });

            _builder.AddDefaultSearchParameters();

            ITypedElement statement = _builder.Build();

            object idDocumentation = statement.Scalar($"{ResourceQuery("Account")}.searchParam.where(name = '_id').documentation");

            Assert.Equal(description, idDocumentation);
        }
예제 #3
0
        /// <inheritdoc />
        public IReadOnlyCollection <SearchIndexEntry> Extract(ResourceElement resource)
        {
            EnsureArg.IsNotNull(resource, nameof(resource));

            var poco = resource.ToPoco();

            var entries = new List <SearchIndexEntry>();

            var context = new FhirEvaluationContext(poco);

            IEnumerable <SearchParameterInfo> searchParameters = _searchParameterDefinitionManager.GetSearchParameters(resource.InstanceType);

            foreach (SearchParameterInfo searchParameter in searchParameters)
            {
                if (searchParameter.Name == SearchParameterNames.ResourceType)
                {
                    // We don't index the resource type value. We just use the property on the root document.

                    continue;
                }

                if (searchParameter.Type == SearchParamType.Composite)
                {
                    entries.AddRange(ProcessCompositeSearchParameter(searchParameter, poco, context));
                }
                else
                {
                    entries.AddRange(ProcessNonCompositeSearchParameter(searchParameter, poco, context));
                }
            }

            return(entries);
        }
        public ICapabilityStatementBuilder AddDefaultSearchParameters()
        {
            foreach (string resource in _modelInfoProvider.GetResourceTypeNames())
            {
                // Parameters is a non-persisted resource used to pass information into and back from an operation
                if (string.Equals(resource, KnownResourceTypes.Parameters, StringComparison.Ordinal))
                {
                    continue;
                }

                IEnumerable <SearchParameterInfo> searchParams = _searchParameterDefinitionManager.GetSearchParameters(resource);

                if (searchParams.Any())
                {
                    AddSearchParams(resource, searchParams.Select(x => new SearchParamComponent
                    {
                        Name          = x.Name,
                        Type          = x.Type,
                        Definition    = x.Url,
                        Documentation = x.Description,
                    }));

                    AddRestInteraction(resource, TypeRestfulInteraction.SearchType);
                }
            }

            return(this);
        }
예제 #5
0
        public IncludeExpression ParseInclude(string[] resourceTypes, string includeValue, bool isReversed, bool iterate)
        {
            var valueSpan = includeValue.AsSpan();

            if (!TrySplit(SearchSplitChar, ref valueSpan, out ReadOnlySpan <char> originalType))
            {
                throw new InvalidSearchOperationException(isReversed ? Resources.RevIncludeMissingType : Resources.IncludeMissingType);
            }

            if (resourceTypes.Length == 1 && resourceTypes[0].Equals(KnownResourceTypes.DomainResource, StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidSearchOperationException(Resources.IncludeCannotBeAgainstBase);
            }

            SearchParameterInfo refSearchParameter;
            List <string>       referencedTypes = null;
            bool   wildCard   = false;
            string targetType = null;

            if (valueSpan.Equals("*".AsSpan(), StringComparison.InvariantCultureIgnoreCase))
            {
                refSearchParameter = null;
                wildCard           = true;
            }
            else
            {
                if (!TrySplit(SearchSplitChar, ref valueSpan, out ReadOnlySpan <char> searchParam))
                {
                    searchParam = valueSpan;
                }
                else
                {
                    targetType = valueSpan.ToString();
                }

                refSearchParameter = _searchParameterDefinitionManager.GetSearchParameter(originalType.ToString(), searchParam.ToString());
            }

            if (wildCard)
            {
                referencedTypes = new List <string>();
                var searchParameters = resourceTypes.SelectMany(t => _searchParameterDefinitionManager.GetSearchParameters(t))
                                       .Where(p => p.Type == ValueSets.SearchParamType.Reference);

                foreach (var p in searchParameters)
                {
                    foreach (var t in p.TargetResourceTypes)
                    {
                        if (!referencedTypes.Contains(t))
                        {
                            referencedTypes.Add(t);
                        }
                    }
                }
            }

            return(new IncludeExpression(resourceTypes, refSearchParameter, originalType.ToString(), targetType, referencedTypes, wildCard, isReversed, iterate));
        }
예제 #6
0
        private ICapabilityStatementBuilder SyncSearchParams(string resourceType)
        {
            EnsureArg.IsNotNullOrEmpty(resourceType, nameof(resourceType));
            EnsureArg.IsTrue(_modelInfoProvider.IsKnownResource(resourceType), nameof(resourceType), x => GenerateTypeErrorMessage(x, resourceType));

            IEnumerable <SearchParameterInfo> searchParams = _searchParameterDefinitionManager.GetSearchParameters(resourceType);

            if (searchParams.Any())
            {
                ApplyToResource(resourceType, c =>
                {
                    c.SearchParam.Clear();
                    foreach (SearchParamComponent searchParam in searchParams.Select(x => new SearchParamComponent
                    {
                        Name = x.Name,
                        Type = x.Type,
                        Definition = x.Url,
                        Documentation = x.Description,
                    }))
                    {
                        // Exclude _type search param under resource
                        if (string.Equals("_type", searchParam.Name, StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        c.SearchParam.Add(searchParam);
                    }
                });
                AddResourceInteraction(resourceType, TypeRestfulInteraction.SearchType);
            }
            else
            {
                RemoveRestInteraction(resourceType, TypeRestfulInteraction.SearchType);
            }

            return(this);
        }
        public SearchParameterStatusManagerTests()
        {
            _searchParameterRegistry          = Substitute.For <ISearchParameterRegistry>();
            _searchParameterDefinitionManager = Substitute.For <ISearchParameterDefinitionManager>();
            _searchParameterSupportResolver   = Substitute.For <ISearchParameterSupportResolver>();
            _mediator = Substitute.For <IMediator>();

            _manager = new SearchParameterStatusManager(
                _searchParameterRegistry,
                _searchParameterDefinitionManager,
                _searchParameterSupportResolver,
                _mediator);

            _searchParameterRegistry.GetSearchParameterStatuses()
            .Returns(new[]
            {
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Enabled,
                    Uri    = new Uri(ResourceId),
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Enabled,
                    Uri    = new Uri(ResourceLastupdated),
                    IsPartiallySupported = true,
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Disabled,
                    Uri    = new Uri(ResourceProfile),
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Supported,
                    Uri    = new Uri(ResourceSecurity),
                },
            });

            _queryParameter       = new SearchParameterInfo("_query", SearchParamType.Token, new Uri(ResourceQuery));
            _searchParameterInfos = new[]
            {
                new SearchParameterInfo("_id", SearchParamType.Token, new Uri(ResourceId)),
                new SearchParameterInfo("_lastUpdated", SearchParamType.Token, new Uri(ResourceLastupdated)),
                new SearchParameterInfo("_profile", SearchParamType.Token, new Uri(ResourceProfile)),
                new SearchParameterInfo("_security", SearchParamType.Token, new Uri(ResourceSecurity)),
                _queryParameter,
            };

            _searchParameterDefinitionManager.GetSearchParameters("Account")
            .Returns(_searchParameterInfos);

            _searchParameterDefinitionManager.AllSearchParameters
            .Returns(_searchParameterInfos);

            _searchParameterDefinitionManager.GetSearchParameter(new Uri(ResourceQuery))
            .Returns(_queryParameter);

            _searchParameterSupportResolver
            .IsSearchParameterSupported(Arg.Any <SearchParameterInfo>())
            .Returns((false, false));

            _searchParameterSupportResolver
            .IsSearchParameterSupported(Arg.Is(_searchParameterInfos[4]))
            .Returns((true, false));
        }
 public IEnumerable <SearchParameterInfo> GetSearchParameters(string resourceType)
 {
     return(_inner.GetSearchParameters(resourceType)
            .Where(x => x.IsSupported));
 }
        public SearchParameterStatusManagerTests()
        {
            _searchParameterStatusDataStore   = Substitute.For <ISearchParameterStatusDataStore>();
            _searchParameterDefinitionManager = Substitute.For <ISearchParameterDefinitionManager>();
            _searchParameterSupportResolver   = Substitute.For <ISearchParameterSupportResolver>();
            _mediator = Substitute.For <IMediator>();

            _manager = new SearchParameterStatusManager(
                _searchParameterStatusDataStore,
                _searchParameterDefinitionManager,
                _searchParameterSupportResolver,
                _mediator);

            _resourceSearchParameterStatuses = new[]
            {
                new ResourceSearchParameterStatus
                {
                    Status      = SearchParameterStatus.Enabled,
                    Uri         = new Uri(ResourceId),
                    LastUpdated = Clock.UtcNow,
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Enabled,
                    Uri    = new Uri(ResourceLastupdated),
                    IsPartiallySupported = true,
                    LastUpdated          = Clock.UtcNow,
                },
                new ResourceSearchParameterStatus
                {
                    Status      = SearchParameterStatus.Disabled,
                    Uri         = new Uri(ResourceProfile),
                    LastUpdated = Clock.UtcNow,
                },
                new ResourceSearchParameterStatus
                {
                    Status      = SearchParameterStatus.Supported,
                    Uri         = new Uri(ResourceSecurity),
                    LastUpdated = Clock.UtcNow,
                },
            };

            _searchParameterStatusDataStore.GetSearchParameterStatuses().Returns(_resourceSearchParameterStatuses);

            List <string> baseResourceTypes = new List <string>()
            {
                "Resource"
            };
            List <string> targetResourceTypes = new List <string>()
            {
                "Patient"
            };

            _queryParameter       = new SearchParameterInfo("_query", SearchParamType.Token, new Uri(ResourceQuery));
            _searchParameterInfos = new[]
            {
                new SearchParameterInfo("_id", SearchParamType.Token, new Uri(ResourceId), targetResourceTypes: targetResourceTypes, baseResourceTypes: baseResourceTypes),
                new SearchParameterInfo("_lastUpdated", SearchParamType.Token, new Uri(ResourceLastupdated), targetResourceTypes: targetResourceTypes, baseResourceTypes: baseResourceTypes),
                new SearchParameterInfo("_profile", SearchParamType.Token, new Uri(ResourceProfile), targetResourceTypes: targetResourceTypes),
                new SearchParameterInfo("_security", SearchParamType.Token, new Uri(ResourceSecurity), targetResourceTypes: targetResourceTypes),
                _queryParameter,
            };

            _searchParameterDefinitionManager.GetSearchParameters("Account")
            .Returns(_searchParameterInfos);

            _searchParameterDefinitionManager.AllSearchParameters
            .Returns(_searchParameterInfos);

            _searchParameterDefinitionManager.GetSearchParameter(new Uri(ResourceQuery))
            .Returns(_queryParameter);

            _searchParameterSupportResolver
            .IsSearchParameterSupported(Arg.Any <SearchParameterInfo>())
            .Returns((false, false));

            _searchParameterSupportResolver
            .IsSearchParameterSupported(Arg.Is(_searchParameterInfos[4]))
            .Returns((true, false));
        }