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 factory method for creating a FHIR Core Package source [R5] #2141

Merged
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
16 changes: 16 additions & 0 deletions src/Hl7.Fhir.Specification.Tests/Source/FhirPackageSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ public async System.Threading.Tasks.Task TestResolveByCanonicalUri()
adm_gender.Expansion.Contains.Should().Contain(c => c.System == "http://hl7.org/fhir/administrative-gender" && c.Code == "other");
}

[TestMethod, TestCategory("IntegrationTest")]
public async System.Threading.Tasks.Task TestCorePackageSource()
{
var corePackageSource = FhirPackageSource.CreateFhirCorePackageSource();

//check StructureDefinitions
var pat = await corePackageSource.ResolveByCanonicalUriAsync("http://hl7.org/fhir/StructureDefinition/Patient").ConfigureAwait(false) as StructureDefinition;
pat.Should().NotBeNull();
pat.Url.Should().Be("http://hl7.org/fhir/StructureDefinition/Patient");

//check expansions
var adm_gender = await corePackageSource.ResolveByCanonicalUriAsync("http://hl7.org/fhir/ValueSet/administrative-gender").ConfigureAwait(false) as ValueSet;
adm_gender.Should().NotBeNull();
adm_gender.Expansion.Contains.Should().Contain(c => c.System == "http://hl7.org/fhir/administrative-gender" && c.Code == "other");
}

[TestMethod]
public void TestListFileNames()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public static class CorePackageFileNames
/// <summary>Reads FHIR version specific artifacts (Profiles, ValueSets, ...) from the FHIR Packages</summary>
public class FhirPackageSource : IAsyncResourceResolver, IArtifactSource, IConformanceSource
{
private const string FHIR_CORE_PACKAGE_NAME = "hl7.fhir.r5.core";
private const string FHIR_CORE_EXPANSIONS_PACKAGE_NAME = "hl7.fhir.r5.expansions";
private const string FHIR_PACKAGE_SERVER = "http://packages2.fhir.org/packages";

private CommonFhirPackageSource _resolver;

/// <summary>Create a new <see cref="FhirPackageSource"/> instance to read FHIR artifacts from the referenced FHIR packages.</summary>
Expand All @@ -40,6 +44,15 @@ public FhirPackageSource(string packageServer, string[] packageNames)
_resolver = new CommonFhirPackageSource(inspector, packageServer, packageNames);
}

/// <summary>
/// Create a new <see cref="FhirPackageSource"/> that includes the all Core FHIR artifacts including the expanded value sets.
/// </summary>
/// <remarks>Needs an active internet connection for first installation, FHIR packages will be cached locally after</remarks>
/// <returns>A new <see cref="FhirPackageSource"/> that includes all Core FHIR definitions/artifacts including the expanded value sets.</returns>
public static FhirPackageSource CreateFhirCorePackageSource()
{
return new FhirPackageSource(FHIR_PACKAGE_SERVER, new string[] { FHIR_CORE_PACKAGE_NAME, FHIR_CORE_EXPANSIONS_PACKAGE_NAME });
}

///<inheritdoc/>
public async Task<Resource?> ResolveByCanonicalUriAsync(string uri)
Expand Down