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);
        }
示例#2
0
        public async Task GivenSupportedParams_WhenGettingSupported_ThenSupportedParamsReturned()
        {
            await _manager.EnsureInitializedAsync(CancellationToken.None);

            var supportedDefinitionManager = new SupportedSearchParameterDefinitionManager(_searchParameterDefinitionManager);
            var paramList = supportedDefinitionManager.GetSearchParametersRequiringReindexing();

            Assert.Collection(
                paramList,
                p =>
            {
                Assert.True(p.IsSupported);
                Assert.False(p.IsSearchable);
            },
                p2 =>
            {
                Assert.True(p2.IsSupported);
                Assert.False(p2.IsSearchable);
            });
        }
        public static async Task <SearchParameterDefinitionManager> CreateSearchParameterDefinitionManagerAsync(IModelInfoProvider modelInfoProvider, IMediator mediator)
        {
            var definitionManager = new SearchParameterDefinitionManager(modelInfoProvider, mediator);
            await definitionManager.StartAsync(CancellationToken.None);

            var statusRegistry = new FilebasedSearchParameterStatusDataStore(
                definitionManager,
                modelInfoProvider);
            var statusManager = new SearchParameterStatusManager(
                statusRegistry,
                definitionManager,
                new SearchParameterSupportResolver(await GetFhirTypedElementToSearchValueConverterManagerAsync()),
                Substitute.For <IMediator>());
            await statusManager.EnsureInitializedAsync(CancellationToken.None);

            return(definitionManager);
        }
        public async Task GivenExistingSearchParameters_WhenStartingSearchParameterDefinitionManager_ThenExistingParametersAdded()
        {
            // Create some existing search paramters that will be returned when searching for resources
            // of type SearchParameter
            var searchParam = new SearchParameter()
            {
                Id   = "id",
                Url  = "http://test/Patient-preexisting",
                Type = Hl7.Fhir.Model.SearchParamType.String,
                Base = new List <ResourceType?>()
                {
                    ResourceType.Patient
                },
                Expression = "Patient.name",
                Name       = "preexisting",
                Code       = "preexisting",
            };
            SearchResult result = GetSearchResultFromSearchParam(searchParam, "token");

            var searchParam2 = new SearchParameter()
            {
                Id   = "id2",
                Url  = "http://test/Patient-preexisting2",
                Type = Hl7.Fhir.Model.SearchParamType.String,
                Base = new List <ResourceType?>()
                {
                    ResourceType.Patient
                },
                Expression = "Patient.name",
                Name       = "preexisting2",
                Code       = "preexisting2",
            };
            SearchResult result2 = GetSearchResultFromSearchParam(searchParam2, "token2");

            var searchParam3 = new SearchParameter()
            {
                Id   = "QuestionnaireResponse-questionnaire2",
                Url  = "http://hl7.org/fhir/SearchParameter/QuestionnaireResponse-questionnaire2",
                Type = Hl7.Fhir.Model.SearchParamType.Reference,
                Base = new List <ResourceType?>()
                {
                    ResourceType.QuestionnaireResponse
                },
                Expression = "QuestionnaireResponse.questionnaire",
                Name       = "questionnaire2",
                Code       = "questionnaire2",
            };
            SearchResult result3 = GetSearchResultFromSearchParam(searchParam3, "token3");

            var searchParam4 = new SearchParameter()
            {
                Id   = "QuestionnaireResponse-questionnaire",
                Url  = "http://hl7.org/fhir/SearchParameter/QuestionnaireResponse-questionnaire",
                Type = Hl7.Fhir.Model.SearchParamType.Reference,
                Base = new List <ResourceType?>()
                {
                    ResourceType.QuestionnaireResponse
                },
                Expression = "QuestionnaireResponse.questionnaire",
                Name       = "questionnaire",
                Code       = "questionnaire",
            };
            SearchResult result4 = GetSearchResultFromSearchParam(searchParam4, null);

            var searchService = Substitute.For <ISearchService>();

            searchService.SearchAsync(Arg.Is <SearchOptions>(options => options.ContinuationToken == null), Arg.Any <CancellationToken>())
            .Returns(result);
            searchService.SearchAsync(
                Arg.Is <SearchOptions>(
                    options => options.ContinuationToken == "token"),
                Arg.Any <CancellationToken>())
            .Returns(result2);
            searchService.SearchAsync(
                Arg.Is <SearchOptions>(
                    options => options.ContinuationToken == "token2"),
                Arg.Any <CancellationToken>())
            .Returns(result3);
            searchService.SearchAsync(
                Arg.Is <SearchOptions>(
                    options => options.ContinuationToken == "token3"),
                Arg.Any <CancellationToken>())
            .Returns(result4);

            var dataStoreSearchParamValidator = Substitute.For <IDataStoreSearchParameterValidator>();

            dataStoreSearchParamValidator.ValidateSearchParameter(Arg.Any <SearchParameterInfo>(), out Arg.Any <string>()).Returns(true);

            _searchParameterSupportResolver
            .IsSearchParameterSupported(Arg.Is <SearchParameterInfo>(s => s.Name.StartsWith("preexisting")))
            .Returns((true, false));

            var searchParameterDefinitionManager = new SearchParameterDefinitionManager(ModelInfoProvider.Instance, _mediator, () => searchService.CreateMockScope(), NullLogger <SearchParameterDefinitionManager> .Instance);

            await searchParameterDefinitionManager.EnsureInitializedAsync(CancellationToken.None);

            var statusManager = new SearchParameterStatusManager(
                _searchParameterStatusDataStore,
                searchParameterDefinitionManager,
                _searchParameterSupportResolver,
                _mediator,
                NullLogger <SearchParameterStatusManager> .Instance);

            await statusManager.EnsureInitializedAsync(CancellationToken.None);

            var patientParams = searchParameterDefinitionManager.GetSearchParameters("Patient");

            Assert.False(patientParams.Where(p => p.Name == "preexisting").First().IsSearchable);
            Assert.True(patientParams.Where(p => p.Name == "preexisting2").First().IsSearchable);

            var questionnaireParams = searchParameterDefinitionManager.GetSearchParameters("QuestionnaireResponse");

            Assert.Single(questionnaireParams.Where(p => p.Name == "questionnaire2"));
        }