Пример #1
0
 public ReindexUtilitiesTests(ITestOutputHelper output)
 {
     _output = output;
     _searchParameterHashMap = new Dictionary<string, string>() { { "Patient", "hash1" } };
     Func<Health.Extensions.DependencyInjection.IScoped<IFhirDataStore>> fhirDataStoreScope = () => _fhirDataStore.CreateMockScope();
     _searchParameterStatusManager = new SearchParameterStatusManager(_searchParameterStatusDataStore, _searchParameterDefinitionManager, _searchParameterSupportResolver, _mediator, NullLogger<SearchParameterStatusManager>.Instance);
     _reindexUtilities = new ReindexUtilities(fhirDataStoreScope, _searchIndexer, _resourceDeserializer, _searchParameterDefinitionManager, _searchParameterStatusManager, _resourceWrapperFactory);
 }
Пример #2
0
        public async Task InitializeAsync()
        {
            _fhirOperationDataStore         = _fixture.OperationDataStore;
            _fhirStorageTestHelper          = _fixture.TestHelper;
            _scopedOperationDataStore       = _fixture.OperationDataStore.CreateMockScope();
            _scopedDataStore                = _fixture.DataStore.CreateMockScope();
            _searchParameterStatusDataStore = _fixture.SearchParameterStatusDataStore;

            _jobConfiguration = new ReindexJobConfiguration();
            IOptions <ReindexJobConfiguration> optionsReindexConfig = Substitute.For <IOptions <ReindexJobConfiguration> >();

            optionsReindexConfig.Value.Returns(_jobConfiguration);

            _searchParameterDefinitionManager = new SearchParameterDefinitionManager(ModelInfoProvider.Instance);
            await _searchParameterDefinitionManager.StartAsync(CancellationToken.None);

            _supportedSearchParameterDefinitionManager = new SupportedSearchParameterDefinitionManager(_searchParameterDefinitionManager);
            var fhirRequestContextAccessor = Substitute.For <IFhirRequestContextAccessor>();

            _searchableSearchParameterDefinitionManager = new SearchableSearchParameterDefinitionManager(_searchParameterDefinitionManager, fhirRequestContextAccessor);

            ResourceWrapperFactory wrapperFactory = Mock.TypeWithArguments <ResourceWrapperFactory>(
                new RawResourceFactory(new FhirJsonSerializer()),
                _searchIndexer,
                _searchableSearchParameterDefinitionManager,
                Deserializers.ResourceDeserializer);

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

            _createReindexRequestHandler = new CreateReindexRequestHandler(
                _fhirOperationDataStore,
                DisabledFhirAuthorizationService.Instance,
                optionsReindexConfig,
                _searchParameterDefinitionManager);
            _reindexUtilities = new ReindexUtilities(
                () => _scopedDataStore,
                _searchIndexer,
                Deserializers.ResourceDeserializer,
                _supportedSearchParameterDefinitionManager,
                _searchParameterStatusManager,
                wrapperFactory);

            coreOptions.Value.Returns(new CoreFeatureConfiguration());

            var searchParameterExpressionParser = new SearchParameterExpressionParser(new ReferenceSearchValueParser(fhirRequestContextAccessor));
            var expressionParser     = new ExpressionParser(() => _searchableSearchParameterDefinitionManager, searchParameterExpressionParser);
            var searchOptionsFactory = new SearchOptionsFactory(expressionParser, () => _searchableSearchParameterDefinitionManager, coreOptions, fhirRequestContextAccessor, _sortingValidator, NullLogger <SearchOptionsFactory> .Instance);
            var cosmosSearchService  = new FhirCosmosSearchService(searchOptionsFactory, _fixture.DataStore as CosmosFhirDataStore, new QueryBuilder(), _searchParameterDefinitionManager, fhirRequestContextAccessor) as ISearchService;

            _searchService = cosmosSearchService.CreateMockScope();

            await _fhirStorageTestHelper.DeleteAllReindexJobRecordsAsync(CancellationToken.None);
        }
Пример #3
0
        public ReindexUtilitiesTests(ITestOutputHelper output)
        {
            _output = output;
            _searchParameterHashMap = new Dictionary <string, string>()
            {
                { "Patient", "hash1" }
            };
            Func <Health.Extensions.DependencyInjection.IScoped <IFhirDataStore> > fhirDataStoreScope = () => _fhirDataStore.CreateMockScope();

            _reindexUtilities = new ReindexUtilities(fhirDataStoreScope, _searchIndexer, _resourceDeserializer, _searchParameterDefinitionManager, _searchParameterRegistry);
        }
Пример #4
0
        public async Task InitializeAsync()
        {
            _fhirOperationDataStore   = _fixture.OperationDataStore;
            _fhirStorageTestHelper    = _fixture.TestHelper;
            _scopedOperationDataStore = _fhirOperationDataStore.CreateMockScope();
            _scopedDataStore          = _fixture.DataStore.CreateMockScope();

            _jobConfiguration = new ReindexJobConfiguration();
            IOptions <ReindexJobConfiguration> optionsReindexConfig = Substitute.For <IOptions <ReindexJobConfiguration> >();

            optionsReindexConfig.Value.Returns(_jobConfiguration);

            _searchParameterDefinitionManager          = _fixture.SearchParameterDefinitionManager;
            _supportedSearchParameterDefinitionManager = _fixture.SupportedSearchParameterDefinitionManager;

            ResourceWrapperFactory wrapperFactory = Mock.TypeWithArguments <ResourceWrapperFactory>(
                new RawResourceFactory(new FhirJsonSerializer()),
                new FhirRequestContextAccessor(),
                _searchIndexer,
                _searchParameterDefinitionManager,
                Deserializers.ResourceDeserializer);

            _searchParameterStatusManager = _fixture.SearchParameterStatusManager;

            _createReindexRequestHandler = new CreateReindexRequestHandler(
                _fhirOperationDataStore,
                DisabledFhirAuthorizationService.Instance,
                optionsReindexConfig,
                _searchParameterDefinitionManager,
                _searchParameterOperations);

            _reindexUtilities = new ReindexUtilities(
                () => _scopedDataStore,
                _searchIndexer,
                Deserializers.ResourceDeserializer,
                _supportedSearchParameterDefinitionManager,
                _searchParameterStatusManager,
                wrapperFactory);

            _searchService = _fixture.SearchService.CreateMockScope();

            await _fhirStorageTestHelper.DeleteAllReindexJobRecordsAsync(CancellationToken.None);

            _throttleController.GetThrottleBasedDelay().Returns(0);
            _throttleController.GetThrottleBatchSize().Returns(100U);
        }
Пример #5
0
        public ReindexJobTests(FhirStorageTestsFixture fixture)
        {
            _fhirOperationDataStore   = fixture.OperationDataStore;
            _fhirStorageTestHelper    = fixture.TestHelper;
            _scopedOperationDataStore = fixture.OperationDataStore.CreateMockScope();
            _scopedOperationDataStore = fixture.OperationDataStore.CreateMockScope();
            _scopedDataStore          = fixture.DataStore.CreateMockScope();

            _jobConfiguration = new ReindexJobConfiguration();
            IOptions <ReindexJobConfiguration> optionsReindexConfig = Substitute.For <IOptions <ReindexJobConfiguration> >();

            optionsReindexConfig.Value.Returns(_jobConfiguration);

            _searchParameterDefinitionManager = new SearchParameterDefinitionManager(ModelInfoProvider.Instance);
            _searchParameterDefinitionManager.Start();
            _searchParameterDefinitionManager.UpdateSearchParameterHashMap(new Dictionary <string, string>()
            {
                { "Patient", "newHash" }
            });
            _supportedSearchParameterDefinitionManager = new SupportedSearchParameterDefinitionManager(_searchParameterDefinitionManager);
            var fhirRequestContextAccessor = Substitute.For <IFhirRequestContextAccessor>();

            _searchableSearchParameterDefinitionManager = new SearchableSearchParameterDefinitionManager(_searchParameterDefinitionManager, fhirRequestContextAccessor);

            _createReindexRequestHandler = new CreateReindexRequestHandler(
                _fhirOperationDataStore,
                DisabledFhirAuthorizationService.Instance,
                optionsReindexConfig,
                _searchParameterDefinitionManager);
            _reindexUtilities = new ReindexUtilities(
                () => _scopedDataStore,
                _searchIndexer,
                Deserializers.ResourceDeserializer,
                _supportedSearchParameterDefinitionManager,
                _searchParameterRegistry);

            coreOptions.Value.Returns(new CoreFeatureConfiguration());

            var searchParameterExpressionParser = new SearchParameterExpressionParser(() => _searchParameterDefinitionManager, new ReferenceSearchValueParser(fhirRequestContextAccessor));
            var expressionParser     = new ExpressionParser(() => _searchableSearchParameterDefinitionManager, searchParameterExpressionParser);
            var searchOptionsFactory = new SearchOptionsFactory(expressionParser, () => _searchableSearchParameterDefinitionManager, coreOptions, fhirRequestContextAccessor, NullLogger <SearchOptionsFactory> .Instance);
            var cosmosSearchService  = new FhirCosmosSearchService(searchOptionsFactory, fixture.DataStore as CosmosFhirDataStore, new QueryBuilder()) as ISearchService;

            _searchService = cosmosSearchService.CreateMockScope();
        }
Пример #6
0
        public async System.Threading.Tasks.Task GivenResourcesWithUnchangedOrChangedIndices_WhenResultsProcessed_ThenCorrectResourcesHaveIndicesUpdated()
        {
            Func <Health.Extensions.DependencyInjection.IScoped <IFhirDataStore> > fhirDataStoreScope = () => _fhirDataStore.CreateMockScope();
            var utilities = new ReindexUtilities(fhirDataStoreScope, _searchIndexer, _resourceDeserializer);

            var searchIndices1 = new List <SearchIndexEntry>()
            {
                new SearchIndexEntry(new Core.Models.SearchParameterInfo("param1"), new StringSearchValue("value1"))
            };
            var searchIndices2 = new List <SearchIndexEntry>()
            {
                new SearchIndexEntry(new Core.Models.SearchParameterInfo("param2"), new StringSearchValue("value2"))
            };

            _searchIndexer.Extract(Arg.Any <Core.Models.ResourceElement>()).Returns(searchIndices1);

            var entry1 = CreateSearchResultEntry("Patient", searchIndices1);

            _output.WriteLine($"Loaded Patient with id: {entry1.Resource.ResourceId}");
            var entry2 = CreateSearchResultEntry("Observation-For-Patient-f001", searchIndices2);

            _output.WriteLine($"Loaded Observation with id: {entry2.Resource.ResourceId}");
            var resultList = new List <SearchResultEntry>();

            resultList.Add(entry1);
            resultList.Add(entry2);
            var result = new SearchResult(resultList, new List <Tuple <string, string> >(), new List <(string, string)>(), "token");

            await utilities.ProcessSearchResultsAsync(result, "hash", CancellationToken.None);

            await _fhirDataStore.Received().UpdateSearchParameterHashBatchAsync(
                Arg.Is <IReadOnlyCollection <ResourceWrapper> >(
                    c => c.Where(r => r.SearchIndices == searchIndices1 && r.ResourceTypeName.Equals("Patient")).Count() == 1),
                Arg.Any <CancellationToken>());

            await _fhirDataStore.Received().UpdateSearchParameterIndicesBatchAsync(
                Arg.Is <IReadOnlyCollection <ResourceWrapper> >(
                    c => c.Where(r => r.SearchIndices == searchIndices1 && r.ResourceTypeName.Equals("Observation")).Count() == 1),
                Arg.Any <CancellationToken>());
        }