Skip to content
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

Added Status and $Status operation to CapabilityStatement #3381

Merged
merged 12 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ internal static class RouteNames

internal const string PurgeHistoryDefinition = "PurgeHistoryDefinition";

internal const string SearchParameterStatusOperationDefinition = "SearchParameterStatusOperationDefinition";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low priority: You can replace the static string with nameof(SearchParameterStatusOperationDefinition).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add that as a fix in another PR.


internal const string SearchParameterState = "SearchParameterState";

internal const string PostSearchParameterState = "PostSearchParameterState";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ public Uri ResolveOperationDefinitionUrl(string operationName)
case OperationsConstants.PurgeHistory:
routeName = RouteNames.PurgeHistoryDefinition;
break;
case OperationsConstants.SearchParameterStatus:
routeName = RouteNames.SearchParameterStatusOperationDefinition;
break;

default:
throw new OperationNotImplementedException(string.Format(Resources.OperationNotImplemented, operationName));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"resourceType": "OperationDefinition",
"id": "status",
"url": "[base]/OperationDefinition/search-parameter-status",
"version": "1.0.0",
"name": "Selectable search parameters",
"status": "active",
"kind": "operation",
"description": "Allows for disabling of search parameters that are not being utilized in order to save space in the datastore. This operation is asynchronous as defined in the [FHIR Asynchronous Request Pattern](http://hl7.org/fhir/async.html)",
PTaladay marked this conversation as resolved.
Show resolved Hide resolved
"code": "status",
"system": false,
"type": true,
"instance": false,
"parameter": [
{
"name": "url",
"use": "in",
"min": 0,
"max": "1",
"documentation": "Url of the search parameter status to update.",
"type": "string"
},
{
"name": "status",
"use": "out",
"min": 0,
"max": "1",
"documentation": "Status to update search parameter to. Can be 'supported' or 'disabled'. Cannot update deleted search parameters with this operation.",
"type": "string"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using EnsureThat;
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using Microsoft.Extensions.Options;
using Microsoft.Health.Fhir.Core.Configs;
Expand All @@ -19,6 +22,7 @@
using Microsoft.Health.Fhir.Core.Features.Definition;
using Microsoft.Health.Fhir.Core.Features.Routing;
using Microsoft.Health.Fhir.Core.Features.Search;
using Microsoft.Health.Fhir.Core.Features.Search.Registry;
using Microsoft.Health.Fhir.Core.Features.Validation;
using Microsoft.Health.Fhir.Core.Features.Version;
using Microsoft.Health.Fhir.Core.Models;
Expand All @@ -35,28 +39,32 @@ internal class CapabilityStatementBuilder : ICapabilityStatementBuilder
private readonly ISearchParameterDefinitionManager _searchParameterDefinitionManager;
private readonly CoreFeatureConfiguration _configuration;
private readonly ISupportedProfilesStore _supportedProfiles;
private readonly SearchParameterStatusManager _searchParameterStatusManager;

private CapabilityStatementBuilder(
ListedCapabilityStatement statement,
IModelInfoProvider modelInfoProvider,
ISearchParameterDefinitionManager searchParameterDefinitionManager,
IOptions<CoreFeatureConfiguration> configuration,
ISupportedProfilesStore supportedProfiles)
ISupportedProfilesStore supportedProfiles,
SearchParameterStatusManager searchParameterStatusManager)
{
EnsureArg.IsNotNull(statement, nameof(statement));
EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider));
EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));
EnsureArg.IsNotNull(configuration, nameof(configuration));
EnsureArg.IsNotNull(supportedProfiles, nameof(supportedProfiles));
EnsureArg.IsNotNull(searchParameterStatusManager, nameof(searchParameterStatusManager));

_statement = statement;
_modelInfoProvider = modelInfoProvider;
_searchParameterDefinitionManager = searchParameterDefinitionManager;
_configuration = configuration.Value;
_supportedProfiles = supportedProfiles;
_searchParameterStatusManager = searchParameterStatusManager;
}

public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager, IOptions<CoreFeatureConfiguration> configuration, ISupportedProfilesStore supportedProfiles, IUrlResolver urlResolver)
public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager, IOptions<CoreFeatureConfiguration> configuration, ISupportedProfilesStore supportedProfiles, IUrlResolver urlResolver, SearchParameterStatusManager searchParameterStatusManager)
{
PTaladay marked this conversation as resolved.
Show resolved Hide resolved
EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider));
EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));
Expand Down Expand Up @@ -86,7 +94,7 @@ public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoPro
statement.Date = ProductVersionInfo.CreationTime.ToString("O");
statement.Url = urlResolver.ResolveMetadataUrl(false);

return new CapabilityStatementBuilder(statement, modelInfoProvider, searchParameterDefinitionManager, configuration, supportedProfiles);
return new CapabilityStatementBuilder(statement, modelInfoProvider, searchParameterDefinitionManager, configuration, supportedProfiles, searchParameterStatusManager);
}

public ICapabilityStatementBuilder Apply(Action<ListedCapabilityStatement> action)
Expand Down Expand Up @@ -159,7 +167,6 @@ public ICapabilityStatementBuilder AddGlobalInteraction(string systemInteraction
EnsureArg.IsNotNullOrEmpty(systemInteraction, nameof(systemInteraction));

_statement.Rest.Server().Interaction.Add(new ResourceInteractionComponent { Code = systemInteraction });

return this;
}

Expand All @@ -171,12 +178,13 @@ public ICapabilityStatementBuilder AddGlobalSearchParameters()
return this;
}

private ICapabilityStatementBuilder SyncSearchParams(string resourceType)
private async Task<ICapabilityStatementBuilder> SyncSearchParamsAsync(string resourceType, CancellationToken cancellationToken)
{
EnsureArg.IsNotNullOrEmpty(resourceType, nameof(resourceType));
EnsureArg.IsTrue(_modelInfoProvider.IsKnownResource(resourceType), nameof(resourceType), x => GenerateTypeErrorMessage(x, resourceType));

List<SearchParameterInfo> searchParams = _searchParameterDefinitionManager.GetSearchParameters(resourceType).ToList();
var searchParamStatuses = await _searchParameterStatusManager.GetAllSearchParameterStatus(cancellationToken);

if (searchParams.Any())
{
Expand All @@ -197,6 +205,8 @@ private ICapabilityStatementBuilder SyncSearchParams(string resourceType)
continue;
}

string status = string.Format("Current status of search parameter is {0}. ", searchParamStatuses.SingleOrDefault(x => x.Uri == searchParam.Definition)?.Status.ToString());
searchParam.Documentation = status = status + searchParam.Documentation;
c.SearchParam.Add(searchParam);
}
});
Expand Down Expand Up @@ -324,8 +334,10 @@ public ICapabilityStatementBuilder PopulateDefaultResourceInteractions()
return this;
}

public ICapabilityStatementBuilder SyncSearchParameters()
public async Task<ICapabilityStatementBuilder> SyncSearchParametersAsync(CancellationToken cancellationToken)
{
EnsureArg.IsNotNull(_searchParameterStatusManager, nameof(_searchParameterStatusManager));

foreach (string resource in _modelInfoProvider.GetResourceTypeNames())
{
ApplyToResource(resource, c => c.SearchRevInclude.Clear());
Expand All @@ -339,7 +351,7 @@ public ICapabilityStatementBuilder SyncSearchParameters()
continue;
}

SyncSearchParams(resource);
await SyncSearchParamsAsync(resource, cancellationToken);
}

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// -------------------------------------------------------------------------------------------------

using System;
using System.Threading;
using System.Threading.Tasks;
using Hl7.Fhir.ElementModel;
using Microsoft.Health.Fhir.Core.Features.Conformance.Models;

Expand Down Expand Up @@ -45,7 +47,8 @@ public interface ICapabilityStatementBuilder
/// <summary>
/// Updates capability statement to latest supported search paramaters by checkin in memory storage for search parameters.
/// </summary>
ICapabilityStatementBuilder SyncSearchParameters();
/// <param name="cancellationToken">Cancellation token.</param>
Task<ICapabilityStatementBuilder> SyncSearchParametersAsync(CancellationToken cancellationToken);

/// <summary>
/// Updates capability statement to lastest supported profiles by pulling them from database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.Health.Fhir.Core.Features.Conformance.Models;
using Microsoft.Health.Fhir.Core.Features.Definition;
using Microsoft.Health.Fhir.Core.Features.Routing;
using Microsoft.Health.Fhir.Core.Features.Search.Registry;
using Microsoft.Health.Fhir.Core.Features.Validation;
using Microsoft.Health.Fhir.Core.Messages.CapabilityStatement;
using Microsoft.Health.Fhir.Core.Models;
Expand All @@ -43,6 +44,7 @@ public sealed class SystemConformanceProvider
private readonly IOptions<CoreFeatureConfiguration> _configuration;
private readonly ISupportedProfilesStore _supportedProfiles;
private readonly ILogger _logger;
private readonly SearchParameterStatusManager _searchParameterStatusManager;

private ResourceElement _listedCapabilityStatement;
private ResourceElement _metadata;
Expand All @@ -57,7 +59,8 @@ public SystemConformanceProvider(
IOptions<CoreFeatureConfiguration> configuration,
ISupportedProfilesStore supportedProfiles,
ILogger<SystemConformanceProvider> logger,
IUrlResolver urlResolver)
IUrlResolver urlResolver,
SearchParameterStatusManager searchParameterStatusManager)
{
EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider));
EnsureArg.IsNotNull(searchParameterDefinitionManagerResolver, nameof(searchParameterDefinitionManagerResolver));
Expand All @@ -66,6 +69,7 @@ public SystemConformanceProvider(
EnsureArg.IsNotNull(supportedProfiles, nameof(supportedProfiles));
EnsureArg.IsNotNull(logger, nameof(logger));
EnsureArg.IsNotNull(urlResolver, nameof(urlResolver));
EnsureArg.IsNotNull(searchParameterStatusManager, nameof(searchParameterStatusManager));

_modelInfoProvider = modelInfoProvider;
_searchParameterDefinitionManager = searchParameterDefinitionManagerResolver();
Expand All @@ -75,6 +79,7 @@ public SystemConformanceProvider(
_logger = logger;
_disposed = false;
_urlResolver = urlResolver;
_searchParameterStatusManager = searchParameterStatusManager;
}

public override async Task<ResourceElement> GetCapabilityStatementOnStartup(CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -94,7 +99,7 @@ public SystemConformanceProvider(
{
if (_listedCapabilityStatement == null)
{
_builder = CapabilityStatementBuilder.Create(_modelInfoProvider, _searchParameterDefinitionManager, _configuration, _supportedProfiles, _urlResolver);
_builder = CapabilityStatementBuilder.Create(_modelInfoProvider, _searchParameterDefinitionManager, _configuration, _supportedProfiles, _urlResolver, _searchParameterStatusManager);

using (IScoped<IEnumerable<IProvideCapability>> providerFactory = _capabilityProviders())
{
Expand Down Expand Up @@ -169,7 +174,7 @@ public async Task BackgroudLoop()
if (_builder != null)
{
// Update search params;
_builder.SyncSearchParameters();
await _builder.SyncSearchParametersAsync(CancellationToken.None);

// Update supported profiles;
_builder.SyncProfiles();
Expand Down Expand Up @@ -241,7 +246,7 @@ public async Task Handle(RebuildCapabilityStatement notification, CancellationTo
{
case RebuildPart.SearchParameter:
// Update search params;
_builder.SyncSearchParameters();
await _builder.SyncSearchParametersAsync(cancellationToken);
break;

case RebuildPart.Profiles:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<None Remove="Data\OperationDefinition\member-match.json" />
<None Remove="Data\OperationDefinition\search-parameter-status.json" />
<None Remove="Features\Security\roles.schema.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Data\OperationDefinition\convert-data.json" />
<EmbeddedResource Include="Data\OperationDefinition\member-match.json" />
<EmbeddedResource Include="Data\OperationDefinition\purge-history.json" />
<EmbeddedResource Include="Data\OperationDefinition\search-parameter-status.json" />
<EmbeddedResource Include="Data\R4\BaseCapabilities.json" />
<EmbeddedResource Include="Data\R4\compartment.json" />
<EmbeddedResource Include="Data\R4\search-parameters.json" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,9 @@ public void Build(ICapabilityStatementBuilder builder)
try
{
watch = Stopwatch.StartNew();
builder = builder.SyncSearchParameters();
var builderTask = Task.Run(() => builder.SyncSearchParametersAsync(CancellationToken.None));
builderTask.Wait();
builder = builderTask.Result;
_logger.LogInformation("CosmosFhirDataStore. 'Search Parameters' built. Elapsed: {ElapsedTime}. Memory: {MemoryInUse}.", watch.Elapsed, GC.GetTotalMemory(forceFullCollection: false));
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ public class OperationDefinitionController : Controller
private readonly IMediator _mediator;
private readonly OperationsConfiguration _operationConfiguration;
private readonly FeatureConfiguration _featureConfiguration;
private readonly CoreFeatureConfiguration _coreFeatureConfiguration;

public OperationDefinitionController(
IMediator mediator,
IOptions<OperationsConfiguration> operationsConfig,
IOptions<FeatureConfiguration> featureConfig)
IOptions<FeatureConfiguration> featureConfig,
IOptions<CoreFeatureConfiguration> coreFeatureConfig)
PTaladay marked this conversation as resolved.
Show resolved Hide resolved
{
EnsureArg.IsNotNull(mediator, nameof(mediator));
EnsureArg.IsNotNull(operationsConfig?.Value, nameof(operationsConfig));
EnsureArg.IsNotNull(featureConfig?.Value, nameof(featureConfig));
EnsureArg.IsNotNull(coreFeatureConfig?.Value, nameof(coreFeatureConfig));

_mediator = mediator;
_operationConfiguration = operationsConfig.Value;
_featureConfiguration = featureConfig.Value;
_coreFeatureConfiguration = coreFeatureConfig.Value;
}

[HttpGet]
Expand Down Expand Up @@ -120,6 +124,14 @@ public async Task<IActionResult> PurgeHistoryOperationDefinition()
return await GetOperationDefinitionAsync(OperationsConstants.PurgeHistory);
}

[HttpGet]
[Route(KnownRoutes.SearchParametersStatusQuery, Name = RouteNames.SearchParameterStatusOperationDefinition)]
[AllowAnonymous]
public async Task<IActionResult> SearchParameterStatusOperationDefintion()
{
return await GetOperationDefinitionAsync(OperationsConstants.SearchParameterStatus);
}

private async Task<IActionResult> GetOperationDefinitionAsync(string operationName)
{
CheckIfOperationIsEnabledAndRespond(operationName);
Expand Down Expand Up @@ -153,6 +165,9 @@ private void CheckIfOperationIsEnabledAndRespond(string operationName)
case OperationsConstants.PurgeHistory:
operationEnabled = true;
break;
case OperationsConstants.SearchParameterStatus:
operationEnabled = _coreFeatureConfiguration.SupportsSelectableSearchParameters;
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ public partial class OperationsCapabilityProvider : IProvideCapability
{
private readonly OperationsConfiguration _operationConfiguration;
private readonly FeatureConfiguration _featureConfiguration;
private readonly CoreFeatureConfiguration _coreFeatureConfiguration;
private readonly IUrlResolver _urlResolver;

public OperationsCapabilityProvider(
IOptions<OperationsConfiguration> operationConfiguration,
IOptions<FeatureConfiguration> featureConfiguration,
IOptions<CoreFeatureConfiguration> coreFeatureConfiguration,
IUrlResolver urlResolver)
{
EnsureArg.IsNotNull(operationConfiguration?.Value, nameof(operationConfiguration));
EnsureArg.IsNotNull(featureConfiguration?.Value, nameof(featureConfiguration));
EnsureArg.IsNotNull(coreFeatureConfiguration?.Value, nameof(coreFeatureConfiguration));
EnsureArg.IsNotNull(urlResolver, nameof(urlResolver));

_operationConfiguration = operationConfiguration.Value;
_featureConfiguration = featureConfiguration.Value;
_coreFeatureConfiguration = coreFeatureConfiguration.Value;
_urlResolver = urlResolver;
}

Expand Down Expand Up @@ -66,6 +70,11 @@ public void Build(ICapabilityStatementBuilder builder)

builder.Apply(AddMemberMatchDetails);
builder.Apply(AddPatientEverythingDetails);

if (_coreFeatureConfiguration.SupportsSelectableSearchParameters)
{
builder.Apply(AddSelectableSearchParameterDetails);
}
}

private void AddExportDetailsHelper(ICapabilityStatementBuilder builder)
Expand Down Expand Up @@ -125,5 +134,10 @@ public void AddMemberMatchDetails(ListedCapabilityStatement capabilityStatement)
{
GetAndAddOperationDefinitionUriToCapabilityStatement(capabilityStatement, OperationsConstants.MemberMatch);
}

public void AddSelectableSearchParameterDetails(ListedCapabilityStatement capabilityStatement)
{
GetAndAddOperationDefinitionUriToCapabilityStatement(capabilityStatement, OperationsConstants.SearchParameterStatus);
}
}
}
Loading