-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for duplicate search parameters #3790
Open
feordin
wants to merge
13
commits into
main
Choose a base branch
from
personal/jaerwin/search-params
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d4e4852
Initial work to accept dup SearchParams
feordin 58e8001
More updates to check conditional codes
feordin 5a1fe12
Initial implementation of duplicate SearchParameters
feordin 07dee0a
Update reindex tests
feordin 8eb43b7
Revert appsettings change
feordin 039d72b
Fix status check for duplicated status
feordin 1b49bdc
Initial creation of E2E tests for duplicate params
feordin 5ed7eb5
Unit tests and fixes
feordin b8c299e
Fix unit tests
feordin 4d06425
Fix text case in unit test path
feordin 24d79c8
Update test files for validation
feordin ac129b3
CodeQL updates
feordin 3e8908f
More CodeQL updates
feordin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Health.Fhir.Core.Features.Search.Parameters | ||
{ | ||
public static class Constants | ||
{ | ||
public const string DuplicateSearchParameterUrl = "DuplicateSearchParameterUrl"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,11 @@ | |
using EnsureThat; | ||
using Hl7.Fhir.ElementModel; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Health.Core.Features.Context; | ||
using Microsoft.Health.Extensions.DependencyInjection; | ||
using Microsoft.Health.Fhir.Core.Exceptions; | ||
using Microsoft.Health.Fhir.Core.Extensions; | ||
using Microsoft.Health.Fhir.Core.Features.Context; | ||
using Microsoft.Health.Fhir.Core.Features.Definition; | ||
using Microsoft.Health.Fhir.Core.Features.Definition.BundleWrappers; | ||
using Microsoft.Health.Fhir.Core.Features.Persistence; | ||
|
@@ -30,6 +32,7 @@ public class SearchParameterOperations : ISearchParameterOperations | |
private readonly ISearchParameterSupportResolver _searchParameterSupportResolver; | ||
private readonly IDataStoreSearchParameterValidator _dataStoreSearchParameterValidator; | ||
private readonly Func<IScoped<ISearchService>> _searchServiceFactory; | ||
private readonly RequestContextAccessor<IFhirRequestContext> _contextAccessor; | ||
private readonly ILogger _logger; | ||
|
||
public SearchParameterOperations( | ||
|
@@ -39,6 +42,7 @@ public SearchParameterOperations( | |
ISearchParameterSupportResolver searchParameterSupportResolver, | ||
IDataStoreSearchParameterValidator dataStoreSearchParameterValidator, | ||
Func<IScoped<ISearchService>> searchServiceFactory, | ||
RequestContextAccessor<IFhirRequestContext> contextAccessor, | ||
ILogger<SearchParameterOperations> logger) | ||
{ | ||
EnsureArg.IsNotNull(searchParameterStatusManager, nameof(searchParameterStatusManager)); | ||
|
@@ -47,6 +51,7 @@ public SearchParameterOperations( | |
EnsureArg.IsNotNull(searchParameterSupportResolver, nameof(searchParameterSupportResolver)); | ||
EnsureArg.IsNotNull(dataStoreSearchParameterValidator, nameof(dataStoreSearchParameterValidator)); | ||
EnsureArg.IsNotNull(searchServiceFactory, nameof(searchServiceFactory)); | ||
EnsureArg.IsNotNull(contextAccessor, nameof(contextAccessor)); | ||
EnsureArg.IsNotNull(logger, nameof(logger)); | ||
|
||
_searchParameterStatusManager = searchParameterStatusManager; | ||
|
@@ -55,42 +60,51 @@ public SearchParameterOperations( | |
_searchParameterSupportResolver = searchParameterSupportResolver; | ||
_dataStoreSearchParameterValidator = dataStoreSearchParameterValidator; | ||
_searchServiceFactory = searchServiceFactory; | ||
_contextAccessor = contextAccessor; | ||
_logger = logger; | ||
} | ||
|
||
public async Task AddSearchParameterAsync(ITypedElement searchParam, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
// verify the parameter is supported before continuing | ||
var searchParameterWrapper = new SearchParameterWrapper(searchParam); | ||
var searchParameterInfo = new SearchParameterInfo(searchParameterWrapper); | ||
bool duplicateSearchParameter = IsSearchParameterDuplicate(); | ||
|
||
if (searchParameterInfo.Component?.Any() == true) | ||
if (!duplicateSearchParameter) | ||
{ | ||
foreach (SearchParameterComponentInfo c in searchParameterInfo.Component) | ||
// verify the parameter is supported before continuing | ||
var searchParameterInfo = new SearchParameterInfo(searchParameterWrapper); | ||
|
||
if (searchParameterInfo.Component?.Any() == true) | ||
{ | ||
c.ResolvedSearchParameter = _searchParameterDefinitionManager.GetSearchParameter(c.DefinitionUrl.OriginalString); | ||
foreach (SearchParameterComponentInfo c in searchParameterInfo.Component) | ||
{ | ||
c.ResolvedSearchParameter = _searchParameterDefinitionManager.GetSearchParameter(c.DefinitionUrl.OriginalString); | ||
} | ||
} | ||
} | ||
|
||
(bool Supported, bool IsPartiallySupported) supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(searchParameterInfo); | ||
(bool Supported, bool IsPartiallySupported) supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(searchParameterInfo); | ||
|
||
if (!supportedResult.Supported) | ||
{ | ||
throw new SearchParameterNotSupportedException(searchParameterInfo.Url); | ||
} | ||
if (!supportedResult.Supported) | ||
{ | ||
throw new SearchParameterNotSupportedException(searchParameterInfo.Url); | ||
} | ||
|
||
// check data store specific support for SearchParameter | ||
if (!_dataStoreSearchParameterValidator.ValidateSearchParameter(searchParameterInfo, out var errorMessage)) | ||
{ | ||
throw new SearchParameterNotSupportedException(errorMessage); | ||
// check data store specific support for SearchParameter | ||
if (!_dataStoreSearchParameterValidator.ValidateSearchParameter(searchParameterInfo, out var errorMessage)) | ||
{ | ||
throw new SearchParameterNotSupportedException(errorMessage); | ||
} | ||
} | ||
|
||
_logger.LogTrace("Adding the search parameter '{Url}'", searchParameterWrapper.Url); | ||
_searchParameterDefinitionManager.AddNewSearchParameters(new List<ITypedElement> { searchParam }); | ||
|
||
await _searchParameterStatusManager.AddSearchParameterStatusAsync(new List<string> { searchParameterWrapper.Url }, cancellationToken); | ||
await _searchParameterStatusManager.AddSearchParameterStatusAsync( | ||
new List<string> { searchParameterWrapper.Url }, | ||
cancellationToken, | ||
duplicateSearchParameter ? SearchParameterStatus.Duplicate : SearchParameterStatus.Supported); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are introducing a new status Duplicate here. How is it going to impact reindex and $status operation? |
||
} | ||
catch (FhirException fex) | ||
{ | ||
|
@@ -167,18 +181,23 @@ public async Task UpdateSearchParameterAsync(ITypedElement searchParam, RawResou | |
await GetAndApplySearchParameterUpdates(cancellationToken); | ||
|
||
var searchParameterWrapper = new SearchParameterWrapper(searchParam); | ||
var searchParameterInfo = new SearchParameterInfo(searchParameterWrapper); | ||
(bool Supported, bool IsPartiallySupported) supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(searchParameterInfo); | ||
bool duplicateSearchParameter = IsSearchParameterDuplicate(); | ||
|
||
if (!supportedResult.Supported) | ||
if (!duplicateSearchParameter) | ||
{ | ||
throw new SearchParameterNotSupportedException(searchParameterInfo.Url); | ||
} | ||
var searchParameterInfo = new SearchParameterInfo(searchParameterWrapper); | ||
(bool Supported, bool IsPartiallySupported) supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(searchParameterInfo); | ||
|
||
// check data store specific support for SearchParameter | ||
if (!_dataStoreSearchParameterValidator.ValidateSearchParameter(searchParameterInfo, out var errorMessage)) | ||
{ | ||
throw new SearchParameterNotSupportedException(errorMessage); | ||
if (!supportedResult.Supported) | ||
{ | ||
throw new SearchParameterNotSupportedException(searchParameterInfo.Url); | ||
} | ||
|
||
// check data store specific support for SearchParameter | ||
if (!_dataStoreSearchParameterValidator.ValidateSearchParameter(searchParameterInfo, out var errorMessage)) | ||
{ | ||
throw new SearchParameterNotSupportedException(errorMessage); | ||
} | ||
} | ||
|
||
var prevSearchParam = _modelInfoProvider.ToTypedElement(previousSearchParam); | ||
|
@@ -193,7 +212,10 @@ public async Task UpdateSearchParameterAsync(ITypedElement searchParam, RawResou | |
|
||
_logger.LogTrace("Adding the search parameter '{Url}' (update step 2/2)", searchParameterWrapper.Url); | ||
_searchParameterDefinitionManager.AddNewSearchParameters(new List<ITypedElement>() { searchParam }); | ||
await _searchParameterStatusManager.AddSearchParameterStatusAsync(new List<string>() { searchParameterWrapper.Url }, cancellationToken); | ||
await _searchParameterStatusManager.AddSearchParameterStatusAsync( | ||
new List<string>() { searchParameterWrapper.Url }, | ||
cancellationToken, | ||
duplicateSearchParameter ? SearchParameterStatus.Duplicate : SearchParameterStatus.Supported); | ||
} | ||
catch (FhirException fex) | ||
{ | ||
|
@@ -302,5 +324,10 @@ private async Task<ITypedElement> GetSearchParameterByUrl(string url, Cancellati | |
|
||
return null; | ||
} | ||
|
||
private bool IsSearchParameterDuplicate() | ||
{ | ||
return _contextAccessor.RequestContext.Properties.TryGetValue(Constants.DuplicateSearchParameterUrl, out _); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,6 @@ public enum SearchParameterStatus | |
PendingDelete = 5, | ||
PendingDisable = 6, | ||
Unsupported = 7, | ||
Duplicate = 8, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Customer sees this message "The search parameter with definition URL '{0}' is not supported.". I know this change is not related to this PR but in this scenario, error is thrown if definition has any issues. Do you think we can use better error message to indicate customer that something is wrong with the definition they have sent?