From 8eb28f57bf359044b56e7fef4a6a7e0a26cd735b Mon Sep 17 00:00:00 2001 From: Marten Smits Date: Mon, 30 May 2022 13:35:40 +0200 Subject: [PATCH] added factory method for creating an FHIR Core Package resolver --- .../Source/FhirPackageSourceTests.cs | 16 ++++++++++++++++ .../Specification/Source/FhirPackageSource.cs | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Hl7.Fhir.Specification.Tests/Source/FhirPackageSourceTests.cs b/src/Hl7.Fhir.Specification.Tests/Source/FhirPackageSourceTests.cs index d169ca81fe..bd50e97a9d 100644 --- a/src/Hl7.Fhir.Specification.Tests/Source/FhirPackageSourceTests.cs +++ b/src/Hl7.Fhir.Specification.Tests/Source/FhirPackageSourceTests.cs @@ -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() { diff --git a/src/Hl7.Fhir.Specification/Specification/Source/FhirPackageSource.cs b/src/Hl7.Fhir.Specification/Specification/Source/FhirPackageSource.cs index df0734df0d..aad53e428b 100644 --- a/src/Hl7.Fhir.Specification/Specification/Source/FhirPackageSource.cs +++ b/src/Hl7.Fhir.Specification/Specification/Source/FhirPackageSource.cs @@ -21,6 +21,10 @@ public static class CorePackageFileNames /// Reads FHIR version specific artifacts (Profiles, ValueSets, ...) from the FHIR Packages 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; /// Create a new instance to read FHIR artifacts from the referenced FHIR packages. @@ -40,6 +44,15 @@ public FhirPackageSource(string packageServer, string[] packageNames) _resolver = new CommonFhirPackageSource(inspector, packageServer, packageNames); } + /// + /// Create a new that includes the all Core FHIR artifacts including the expanded value sets. + /// + /// Needs an active internet connection for first installation, FHIR packages will be cached locally after + /// A new that includes all Core FHIR definitions/artifacts including the expanded value sets. + public static FhirPackageSource CreateFhirCorePackageSource() + { + return new FhirPackageSource(FHIR_PACKAGE_SERVER, new string[] { FHIR_CORE_PACKAGE_NAME, FHIR_CORE_EXPANSIONS_PACKAGE_NAME }); + } /// public async Task ResolveByCanonicalUriAsync(string uri)