public void GivenASPDefinitionManager_WhenInitialed_ThenSearchParametersHashHasValues()
        {
            var searchParams = _searchParameterDefinitionManager.GetSearchParameters("Patient");
            var patientHash  = SearchHelperUtilities.CalculateSearchParameterHash(searchParams);

            Assert.Equal(patientHash, _searchParameterDefinitionManager.GetSearchParameterHashForResourceType("Patient"));
        }
        public async Task GivenASPStatusManager_WhenInitializing_ThenSearchParametersHashUpdatedNotificationHasExpectedValues()
        {
            SearchParametersHashUpdated capturedMessage = null;
            await _mediator.Publish(Arg.Do <SearchParametersHashUpdated>(x => capturedMessage = x));

            await _manager.EnsureInitialized();

            await _mediator
            .Received()
            .Publish(
                Arg.Any <SearchParametersHashUpdated>(),
                Arg.Any <CancellationToken>());

            Assert.NotNull(capturedMessage);
            Assert.NotNull(capturedMessage.UpdatedHashMap["Patient"]);
            Assert.NotNull(capturedMessage.UpdatedHashMap["Resource"]);

            // Calculate expected hashes for Patient and Resource
            List <ResourceSearchParameterStatus> parametersForHash = new List <ResourceSearchParameterStatus>()
            {
                _resourceSearchParameterStatuses[0],
                _resourceSearchParameterStatuses[1],
                _resourceSearchParameterStatuses[3],
            };

            string patientHash = SearchHelperUtilities.CalculateSearchParameterHash(parametersForHash);

            parametersForHash.RemoveAt(2);
            string resourceHash = SearchHelperUtilities.CalculateSearchParameterHash(parametersForHash);

            Assert.Equal(patientHash, capturedMessage.UpdatedHashMap["Patient"]);
            Assert.Equal(resourceHash, capturedMessage.UpdatedHashMap["Resource"]);
        }
 private void CalculateSearchParameterHash()
 {
     foreach (string resourceName in TypeLookup.Keys)
     {
         string searchParamHash = SearchHelperUtilities.CalculateSearchParameterHash(TypeLookup[resourceName].Values);
         _resourceTypeSearchParameterHashMap.AddOrUpdate(
             resourceName,
             searchParamHash,
             (resourceType, existingValue) => searchParamHash);
     }
 }
 private void CalculateSearchParameterHash()
 {
     foreach (KeyValuePair <string, IDictionary <string, SearchParameterInfo> > kvp in TypeLookup)
     {
         string searchParamHash = SearchHelperUtilities.CalculateSearchParameterHash(kvp.Value.Values);
         _resourceTypeSearchParameterHashMap.AddOrUpdate(
             kvp.Key,
             searchParamHash,
             (resourceType, existingValue) => searchParamHash);
     }
 }
        public async Task EnsureInitialized()
        {
            var updated = new List <SearchParameterInfo>();

            var parameters = (await _searchParameterRegistry.GetSearchParameterStatuses())
                             .ToDictionary(x => x.Uri);

            // Set states of known parameters
            foreach (var p in _searchParameterDefinitionManager.AllSearchParameters)
            {
                if (parameters.TryGetValue(p.Url, out ResourceSearchParameterStatus result))
                {
                    bool isSearchable         = result.Status == SearchParameterStatus.Enabled;
                    bool isSupported          = result.Status != SearchParameterStatus.Disabled;
                    bool isPartiallySupported = result.IsPartiallySupported;

                    if (result.Status == SearchParameterStatus.Disabled)
                    {
                        // Re-check if this parameter is now supported.
                        (bool Supported, bool IsPartiallySupported)supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(p);
                        isSupported          = supportedResult.Supported;
                        isPartiallySupported = supportedResult.IsPartiallySupported;
                    }

                    if (p.IsSearchable != isSearchable ||
                        p.IsSupported != isSupported ||
                        p.IsPartiallySupported != isPartiallySupported)
                    {
                        p.IsSearchable         = isSearchable;
                        p.IsSupported          = isSupported;
                        p.IsPartiallySupported = isPartiallySupported;

                        updated.Add(p);
                    }
                }
                else
                {
                    p.IsSearchable = false;

                    // Check if this parameter is now supported.
                    (bool Supported, bool IsPartiallySupported)supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(p);
                    p.IsSupported          = supportedResult.Supported;
                    p.IsPartiallySupported = supportedResult.IsPartiallySupported;

                    updated.Add(p);
                }
            }

            var searchParameterHashValue = SearchHelperUtilities.CalculateSearchParameterHash(parameters.Values);
            await _mediator.Publish(new SearchParametersHashUpdated(searchParameterHashValue));

            await _mediator.Publish(new SearchParametersUpdated(updated));
        }
        public void GivenTwoDifferentListsOfResourceSearchParameterStatus_WhenCalculateSearchParameterHash_ThenHashIsDifferent()
        {
            DateTimeOffset lastUpdated = DateTimeOffset.UtcNow;
            var            param1      = GenerateSearchParameterInfo(_paramUri1, "patient");
            var            param2      = GenerateSearchParameterInfo(_paramUri2, "observation");

            string hash1 = SearchHelperUtilities.CalculateSearchParameterHash(new List <SearchParameterInfo>()
            {
                param1, param2
            });
            string hash2 = SearchHelperUtilities.CalculateSearchParameterHash(new List <SearchParameterInfo>()
            {
                param1
            });

            Assert.NotEqual(hash1, hash2);
        }
Exemple #7
0
        public void GivenTwoSameListsOfResourceSearchParameterStatus_WhenCalculateSearchParameterHash_ThenHashIsSame()
        {
            DateTimeOffset lastUpdated = DateTimeOffset.UtcNow;
            var            param1      = GenerateResourceSearchParameterStatus(_paramUri1, lastUpdated);
            var            param2      = GenerateResourceSearchParameterStatus(_paramUri2, lastUpdated);

            string hash1 = SearchHelperUtilities.CalculateSearchParameterHash(new List <ResourceSearchParameterStatus>()
            {
                param1, param2
            });
            string hash2 = SearchHelperUtilities.CalculateSearchParameterHash(new List <ResourceSearchParameterStatus>()
            {
                param1, param2
            });

            Assert.Equal(hash1, hash2);
        }
Exemple #8
0
        public void GivenTwoSameListsDifferentLastUpdatedResourceSearchParameterStatus_WhenCalculateSearchParameterHash_ThenHashIsDifferent()
        {
            DateTimeOffset lastUpdated  = DateTimeOffset.UtcNow.AddSeconds(-600);
            var            param1       = GenerateResourceSearchParameterStatus(_paramUri1, lastUpdated);
            var            param2       = GenerateResourceSearchParameterStatus(_paramUri2, lastUpdated);
            var            latestParam1 = GenerateResourceSearchParameterStatus(_paramUri1, DateTimeOffset.UtcNow);

            string hash1 = SearchHelperUtilities.CalculateSearchParameterHash(new List <ResourceSearchParameterStatus>()
            {
                param1, param2
            });
            string hash2 = SearchHelperUtilities.CalculateSearchParameterHash(new List <ResourceSearchParameterStatus>()
            {
                latestParam1, param2
            });

            Assert.NotEqual(hash1, hash2);
        }
 public void GivenEmptyResourceSearchParameterStatus_WhenCalculateSearchParameterHash_ThenThrowsException()
 {
     Assert.ThrowsAny <Exception>(() => SearchHelperUtilities.CalculateSearchParameterHash(new List <SearchParameterInfo>()));
 }
 public void GivenNullResourceSearchParameterStatus_WhenCalculateSearchParameterHash_ThenThrowsException()
 {
     Assert.ThrowsAny <Exception>(() => SearchHelperUtilities.CalculateSearchParameterHash(null));
 }
Exemple #11
0
        public async Task EnsureInitialized()
        {
            var updated = new List <SearchParameterInfo>();
            var resourceTypeSearchParamStatusMap = new Dictionary <string, List <ResourceSearchParameterStatus> >();

            var parameters = (await _searchParameterStatusDataStore.GetSearchParameterStatuses())
                             .ToDictionary(x => x.Uri);

            // Set states of known parameters
            foreach (SearchParameterInfo p in _searchParameterDefinitionManager.AllSearchParameters)
            {
                if (parameters.TryGetValue(p.Url, out ResourceSearchParameterStatus result))
                {
                    bool isSearchable         = result.Status == SearchParameterStatus.Enabled;
                    bool isSupported          = result.Status != SearchParameterStatus.Disabled;
                    bool isPartiallySupported = result.IsPartiallySupported;

                    if (result.Status == SearchParameterStatus.Disabled)
                    {
                        // Re-check if this parameter is now supported.
                        (bool Supported, bool IsPartiallySupported)supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(p);
                        isSupported          = supportedResult.Supported;
                        isPartiallySupported = supportedResult.IsPartiallySupported;
                    }

                    if (p.IsSearchable != isSearchable ||
                        p.IsSupported != isSupported ||
                        p.IsPartiallySupported != isPartiallySupported)
                    {
                        p.IsSearchable         = isSearchable;
                        p.IsSupported          = isSupported;
                        p.IsPartiallySupported = isPartiallySupported;

                        updated.Add(p);
                    }
                }
                else
                {
                    p.IsSearchable = false;

                    // Check if this parameter is now supported.
                    (bool Supported, bool IsPartiallySupported)supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(p);
                    p.IsSupported          = supportedResult.Supported;
                    p.IsPartiallySupported = supportedResult.IsPartiallySupported;

                    updated.Add(p);
                }

                // We need to keep track of supported or partially supported parameters.
                // These parameters will be used to calculate the search parameter hash below.
                if (p.IsPartiallySupported || p.IsSupported)
                {
                    if (result == null)
                    {
                        result = new ResourceSearchParameterStatus()
                        {
                            Uri         = p.Url,
                            Status      = SearchParameterStatus.Supported,
                            LastUpdated = Clock.UtcNow,
                        };
                    }

                    if (p.TargetResourceTypes != null)
                    {
                        foreach (string resourceType in p.TargetResourceTypes)
                        {
                            if (resourceTypeSearchParamStatusMap.ContainsKey(resourceType))
                            {
                                resourceTypeSearchParamStatusMap[resourceType].Add(result);
                            }
                            else
                            {
                                resourceTypeSearchParamStatusMap.Add(resourceType, new List <ResourceSearchParameterStatus>()
                                {
                                    result
                                });
                            }
                        }
                    }

                    if (p.BaseResourceTypes != null)
                    {
                        foreach (string resourceType in p.BaseResourceTypes)
                        {
                            if (resourceTypeSearchParamStatusMap.ContainsKey(resourceType))
                            {
                                resourceTypeSearchParamStatusMap[resourceType].Add(result);
                            }
                            else
                            {
                                resourceTypeSearchParamStatusMap.Add(resourceType, new List <ResourceSearchParameterStatus>()
                                {
                                    result
                                });
                            }
                        }
                    }
                }
            }

            var resourceHashMap = new Dictionary <string, string>();

            foreach (KeyValuePair <string, List <ResourceSearchParameterStatus> > kvp in resourceTypeSearchParamStatusMap)
            {
                string searchParamHash = SearchHelperUtilities.CalculateSearchParameterHash(kvp.Value);
                resourceHashMap.Add(kvp.Key, searchParamHash);
            }

            await _mediator.Publish(new SearchParametersHashUpdated(resourceHashMap));

            await _mediator.Publish(new SearchParametersUpdated(updated));
        }