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

Fix: URL under Capability Statement not Absolute Uri #3265

Merged
merged 3 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -17,6 +17,7 @@
using Microsoft.Health.Fhir.Core.Features.Conformance.Models;
using Microsoft.Health.Fhir.Core.Features.Conformance.Serialization;
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.Validation;
using Microsoft.Health.Fhir.Core.Features.Version;
Expand Down Expand Up @@ -55,10 +56,11 @@ private CapabilityStatementBuilder(
_supportedProfiles = supportedProfiles;
}

public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager, IOptions<CoreFeatureConfiguration> configuration, ISupportedProfilesStore supportedProfiles)
public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager, IOptions<CoreFeatureConfiguration> configuration, ISupportedProfilesStore supportedProfiles, IUrlResolver urlResolver)
{
EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider));
EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));
EnsureArg.IsNotNull(urlResolver, nameof(urlResolver));

using Stream resourceStream = modelInfoProvider.OpenVersionedFileStream("BaseCapabilities.json");
using var reader = new StreamReader(resourceStream);
Expand All @@ -82,6 +84,9 @@ public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoPro

statement.FhirVersion = modelInfoProvider.SupportedVersion.VersionString;
statement.Date = ProductVersionInfo.CreationTime.ToString("O");

Uri baseUri = new Uri(urlResolver.ResolveMetadataUrl(false).ToString());
statement.Url = new Uri(baseUri, "metadata");
abiisnn marked this conversation as resolved.
Show resolved Hide resolved
return new CapabilityStatementBuilder(statement, modelInfoProvider, searchParameterDefinitionManager, configuration, supportedProfiles);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.Health.Fhir.Core.Extensions;
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.Validation;
using Microsoft.Health.Fhir.Core.Messages.CapabilityStatement;
using Microsoft.Health.Fhir.Core.Models;
Expand All @@ -36,6 +37,7 @@ public sealed class SystemConformanceProvider
private readonly int _rebuildDelay = 240; // 4 hours in minutes
private readonly IModelInfoProvider _modelInfoProvider;
private readonly ISearchParameterDefinitionManager _searchParameterDefinitionManager;
private readonly IUrlResolver _urlResolver;
private readonly Func<IScoped<IEnumerable<IProvideCapability>>> _capabilityProviders;
private readonly List<Action<ListedCapabilityStatement>> _configurationUpdates = new List<Action<ListedCapabilityStatement>>();
private readonly IOptions<CoreFeatureConfiguration> _configuration;
Expand All @@ -54,14 +56,16 @@ public SystemConformanceProvider(
Func<IScoped<IEnumerable<IProvideCapability>>> capabilityProviders,
IOptions<CoreFeatureConfiguration> configuration,
ISupportedProfilesStore supportedProfiles,
ILogger<SystemConformanceProvider> logger)
ILogger<SystemConformanceProvider> logger,
IUrlResolver urlResolver)
{
EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider));
EnsureArg.IsNotNull(searchParameterDefinitionManagerResolver, nameof(searchParameterDefinitionManagerResolver));
EnsureArg.IsNotNull(capabilityProviders, nameof(capabilityProviders));
EnsureArg.IsNotNull(configuration, nameof(configuration));
EnsureArg.IsNotNull(supportedProfiles, nameof(supportedProfiles));
EnsureArg.IsNotNull(logger, nameof(logger));
EnsureArg.IsNotNull(urlResolver, nameof(urlResolver));

_modelInfoProvider = modelInfoProvider;
_searchParameterDefinitionManager = searchParameterDefinitionManagerResolver();
Expand All @@ -70,6 +74,7 @@ public SystemConformanceProvider(
_supportedProfiles = supportedProfiles;
_logger = logger;
_disposed = false;
_urlResolver = urlResolver;
}

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

using (IScoped<IEnumerable<IProvideCapability>> providerFactory = _capabilityProviders())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.Health.Fhir.Core.Features.Conformance;
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.Validation;
using Microsoft.Health.Fhir.Core.Models;
using Microsoft.Health.Fhir.Tests.Common;
Expand All @@ -36,6 +37,7 @@ public partial class ConformanceBuilderTests
private readonly ICapabilityStatementBuilder _builder;
private readonly ISearchParameterDefinitionManager _searchParameterDefinitionManager;
private readonly ISupportedProfilesStore _supportedProfiles;
private readonly IUrlResolver _urlResolver;

public ConformanceBuilderTests()
{
Expand All @@ -44,11 +46,15 @@ public ConformanceBuilderTests()

_searchParameterDefinitionManager = Substitute.For<ISearchParameterDefinitionManager>();
_supportedProfiles = Substitute.For<ISupportedProfilesStore>();
_urlResolver = Substitute.For<IUrlResolver>();
_urlResolver.ResolveMetadataUrl(Arg.Any<bool>()).Returns(new System.Uri("https://test.com"));

_builder = CapabilityStatementBuilder.Create(
ModelInfoProvider.Instance,
_searchParameterDefinitionManager,
configuration,
_supportedProfiles);
_supportedProfiles,
_urlResolver);
}

[Fact]
Expand Down Expand Up @@ -88,7 +94,8 @@ public void GivenAConformanceBuilder_WhenVersionofResourceIsDifferentFromDefault
ModelInfoProvider.Instance,
_searchParameterDefinitionManager,
configuration,
supportedProfiles);
supportedProfiles,
_urlResolver);
ICapabilityStatementBuilder capabilityStatement = builder.ApplyToResource("Patient", c =>
{
c.Interaction.Add(new ResourceInteractionComponent
Expand Down Expand Up @@ -118,7 +125,8 @@ public void GivenAConformanceBuilder_WhenResourceTypeOverridesContainsResourcesT
ModelInfoProvider.Instance,
_searchParameterDefinitionManager,
configuration,
supportedProfiles);
supportedProfiles,
_urlResolver);
ICapabilityStatementBuilder capabilityStatement = builder.ApplyToResource("Patient", c =>
{
c.Interaction.Add(new ResourceInteractionComponent
Expand Down Expand Up @@ -147,7 +155,8 @@ public void GivenAConformanceBuilder_WhenResourceTypeOverridesIsEmpty_ThenResour
ModelInfoProvider.Instance,
_searchParameterDefinitionManager,
configuration,
supportedProfiles);
supportedProfiles,
_urlResolver);
ICapabilityStatementBuilder capabilityStatement = builder.ApplyToResource("Patient", c =>
{
c.Interaction.Add(new ResourceInteractionComponent
Expand Down