Skip to content

Commit

Permalink
CapabilityStatement generation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
GinoCanessa committed Jan 29, 2025
1 parent cc1e00d commit bdd950d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
22 changes: 13 additions & 9 deletions src/FhirStore.CommonVersioned/Storage/ResourceStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public class ResourceStore<T> : IVersionedResourceStore
private Dictionary<string, ExecutableSubscriptionInfo> _executableSubscriptions = new();

/// <summary>The supported includes.</summary>
private string[] _supportedIncludes = Array.Empty<string>();
private string[] _supportedIncludes = [];

/// <summary>The supported reverse includes.</summary>
private string[] _supportedRevIncludes = Array.Empty<string>();
private string[] _supportedRevIncludes = [];

/// <summary>Gets the keys.</summary>
/// <typeparam name="string"> Type of the string.</typeparam>
Expand Down Expand Up @@ -525,7 +525,7 @@ public bool TryResolveIdentifier(string system, string value, out Hl7.Fhir.Model

ParsedSubscriptionTopic? parsedSubscriptionTopic = null;
ParsedSubscription? parsedSubscription = null;

// perform any mandatory validation
switch (source.TypeName)
{
Expand Down Expand Up @@ -585,7 +585,7 @@ public bool TryResolveIdentifier(string system, string value, out Hl7.Fhir.Model
source.Meta.Tag = new List<Coding>();
}

if (!source.Meta.Tag.Any(c =>
if (!source.Meta.Tag.Any(c =>
c.System.Equals("http://hl7.org/fhir/us/core/CodeSystem/us-core-tags", StringComparison.Ordinal) &&
c.Code.Equals("patient-supplied")))
{
Expand Down Expand Up @@ -701,8 +701,8 @@ public bool TryResolveIdentifier(string system, string value, out Hl7.Fhir.Model
/// <param name="outcome"> [out] The outcome.</param>
/// <returns>The updated resource, or null if it could not be performed.</returns>
public Resource? InstanceUpdate(
Resource source,
bool allowCreate,
Resource source,
bool allowCreate,
string ifMatch,
string ifNoneMatch,
HashSet<string> protectedResources,
Expand Down Expand Up @@ -1409,7 +1409,7 @@ private void PerformSubscriptionTest(
{
additionalContext.AddRange(reverses);
}
}
}

SubscriptionEvent subEvent = new()
{
Expand Down Expand Up @@ -1648,7 +1648,7 @@ public void RemoveExecutableSearchParameter(string name)

if (_searchParameters.TryGetValue(name, out ModelInfo.SearchParamDefinition? spd))
{
if ((!string.IsNullOrEmpty(spd.Url)) &&
if ((!string.IsNullOrEmpty(spd.Url)) &&
_searchParamUrlsToNames.ContainsKey(spd.Url))
{
_ = _searchParamUrlsToNames.Remove(spd.Url);
Expand Down Expand Up @@ -1757,7 +1757,11 @@ public bool TryGetSearchParamDefinition(string name, [NotNullWhen(true)] out Mod
/// An enumerator that allows foreach to be used to process the search includes in this
/// collection.
/// </returns>
public IEnumerable<string> GetSearchIncludes() => _supportedIncludes;
public IEnumerable<string> GetSearchIncludes() => _searchParameters.Values
.Where(sp => sp.Type == SearchParamType.Reference)
.Where(sp => sp.Name != null)
.Select(sp => this._resourceName + ":" + sp.Name!)
.Order();

/// <summary>Gets the search reverse includes supported by this store.</summary>
/// <returns>
Expand Down
23 changes: 11 additions & 12 deletions src/FhirStore.CommonVersioned/Storage/VersionedFhirStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public void Init(TenantConfiguration config)
DiscoverInteractionHooks();

// generate our initial capability statement
_ = GenerateCapabilities(new FhirRequestContext(this, "GET", _config.BaseUrl + "/metadata"));
_ = generateCapabilities(new FhirRequestContext(this, "GET", _config.BaseUrl + "/metadata"));

// create a timer to check max resource count if we are monitoring that
_maxResourceCount = config.MaxResourceCount;
Expand Down Expand Up @@ -5572,7 +5572,7 @@ private CapabilityStatement GetCapabilities(FhirRequestContext? ctx)
{
if (_capabilitiesAreStale || (ctx?.Forwarded != null))
{
return GenerateCapabilities(ctx);
return generateCapabilities(ctx);
}

// bypass read to avoid instance read hooks (firing meta hooks)
Expand All @@ -5581,9 +5581,8 @@ private CapabilityStatement GetCapabilities(FhirRequestContext? ctx)

/// <summary>Updates the current capabilities of this store.</summary>
/// <param name="ctx"> The request context.</param>
/// <param name="store">(Optional) The store.</param>
/// <returns>The capability statement.</returns>
private CapabilityStatement GenerateCapabilities(FhirRequestContext? ctx)
private CapabilityStatement generateCapabilities(FhirRequestContext? ctx)
{
string root = getBaseUrl(ctx);
string smartRoot = fhirUrlToSmart(root);
Expand Down Expand Up @@ -5624,7 +5623,7 @@ private CapabilityStatement GenerateCapabilities(FhirRequestContext? ctx)
new() { Code = Hl7.Fhir.Model.CapabilityStatement.SystemRestfulInteraction.SearchSystem },
new() { Code = Hl7.Fhir.Model.CapabilityStatement.SystemRestfulInteraction.Transaction },
},
//SearchParam = new(), // currently, search parameters are expanded out to all-resource
//SearchParam = new(), // search parameters are expanded out to each resource
Operation = _operations.Values
.Where(o => o.AllowSystemLevel)
.Select(o => new CapabilityStatement.OperationComponent()
Expand Down Expand Up @@ -5688,19 +5687,19 @@ private CapabilityStatement GenerateCapabilities(FhirRequestContext? ctx)
Versioning = CapabilityStatement.ResourceVersionPolicy.NoVersion,
//ReadHistory = true,
UpdateCreate = true,
//ConditionalCreate = true,
ConditionalRead = CapabilityStatement.ConditionalReadStatus.NotSupported,
//ConditionalUpdate = true,
ConditionalCreate = true,
ConditionalRead = CapabilityStatement.ConditionalReadStatus.FullSupport,
ConditionalUpdate = true,
//ConditionalPatch = true,
ConditionalDelete = CapabilityStatement.ConditionalDeleteStatus.NotSupported,
ReferencePolicy = new CapabilityStatement.ReferenceHandlingPolicy?[]
{
ReferencePolicy =
[
CapabilityStatement.ReferenceHandlingPolicy.Literal,
//CapabilityStatement.ReferenceHandlingPolicy.Logical,
CapabilityStatement.ReferenceHandlingPolicy.Logical,
//CapabilityStatement.ReferenceHandlingPolicy.Resolves,
//CapabilityStatement.ReferenceHandlingPolicy.Enforced,
CapabilityStatement.ReferenceHandlingPolicy.Local,
},
],
SearchInclude = resourceStore.GetSearchIncludes(),
SearchRevInclude = resourceStore.GetSearchRevIncludes(),
SearchParam = resourceStore.GetSearchParamDefinitions().Select(sp => new CapabilityStatement.SearchParamComponent()
Expand Down

0 comments on commit bdd950d

Please sign in to comment.