Skip to content

Commit

Permalink
Merge pull request #2141 from FirelyTeam/feature/package-resolver-fac…
Browse files Browse the repository at this point in the history
…tory-methods-r5

Added factory method for creating a FHIR Core Package source [R5]
  • Loading branch information
marcovisserFurore authored Jul 5, 2022
2 parents 65f752e + 8eb28f5 commit df578ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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

0 comments on commit df578ca

Please sign in to comment.