diff --git a/src/Hl7.Fhir.Conformance/Specification/Snapshot/SnapshotGeneratorExtensions.cs b/src/Hl7.Fhir.Conformance/Specification/Snapshot/SnapshotGeneratorExtensions.cs index b1b8688e5c..278a121572 100644 --- a/src/Hl7.Fhir.Conformance/Specification/Snapshot/SnapshotGeneratorExtensions.cs +++ b/src/Hl7.Fhir.Conformance/Specification/Snapshot/SnapshotGeneratorExtensions.cs @@ -7,9 +7,8 @@ */ using Hl7.Fhir.Model; -using Hl7.Fhir.Support; +using Hl7.Fhir.Rest; using Hl7.Fhir.Utility; -using System; using System.Collections.Generic; using System.Linq; @@ -74,6 +73,47 @@ public static void RemoveAllConstrainedByDiffExtensions(this IEnumerable e } } + + internal static void RemoveAllNonInheritableExtensions(this Element element) + { + if (element == null) { throw Error.ArgumentNull(nameof(element)); } + element.RemoveNonInheritableExtensions(); + foreach (var child in element.Children.OfType()) + { + child.RemoveAllNonInheritableExtensions(); + } + } + + internal static void RemoveNonInheritableExtensions(this IExtendable element) + { + if (element == null) { throw Error.ArgumentNull(nameof(element)); } + foreach (var ext in _nonInheritableExtensions) + { + element.RemoveExtension(ext); + } + } + + private static readonly List _nonInheritableExtensions = [ + ResourceIdentity.CORE_BASE_URL + "elementdefinition-isCommonBinding", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-fmm", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-fmm-no-warnings", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-hierarchy", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-interface", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-normative-version", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-applicable-version", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-category", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-codegen-super", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-security-category", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-standards-status", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-summary", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-wg", + ResourceIdentity.CORE_BASE_URL + "replaces", + ResourceIdentity.CORE_BASE_URL + "resource-approvalDate", + ResourceIdentity.CORE_BASE_URL + "resource-effectivePeriod", + ResourceIdentity.CORE_BASE_URL + "resource-lastReviewDate", + CONSTRAINED_BY_DIFF_EXT //this is our own extension to define differences compared to the base, this can't be inherited from the base profile + ]; + // ========== For internal use only ========== // [WMR 20170209] OBSOLETE #if false diff --git a/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGenerator.cs b/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGenerator.cs index 662f8531ea..01b7264441 100644 --- a/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGenerator.cs +++ b/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGenerator.cs @@ -399,7 +399,8 @@ private async Tasks.Task> generate(StructureDefinition s // [WMR 20170208] Moved to *AFTER* ensureBaseComponents - emits annotations... // [WMR 20160915] Derived profiles should never inherit the ChangedByDiff extension from the base structure - snapshot.Element.RemoveAllConstrainedByDiffExtensions(); + // Also remove core extensions that are not supposed to be inherited by derived profiles + snapshot.RemoveAllNonInheritableExtensions(); snapshot.Element.RemoveAllConstrainedByDiffAnnotations(); // Notify observers diff --git a/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGeneratorExtensions.cs b/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGeneratorExtensions.cs index 2c13de5f28..9663245562 100644 --- a/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGeneratorExtensions.cs +++ b/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGeneratorExtensions.cs @@ -7,9 +7,8 @@ */ using Hl7.Fhir.Model; -using Hl7.Fhir.Support; +using Hl7.Fhir.Rest; using Hl7.Fhir.Utility; -using System; using System.Collections.Generic; using System.Linq; @@ -73,6 +72,47 @@ public static void RemoveAllConstrainedByDiffExtensions(this IEnumerable e } } + internal static void RemoveAllNonInheritableExtensions(this Element element) + { + if (element == null) { throw Error.ArgumentNull(nameof(element)); } + element.RemoveNonInheritableExtensions(); + foreach (var child in element.Children.OfType()) + { + child.RemoveAllNonInheritableExtensions(); + } + } + + internal static void RemoveNonInheritableExtensions(this IExtendable element) + { + if (element == null) { throw Error.ArgumentNull(nameof(element)); } + foreach (var ext in _nonInheritableExtensions) + { + element.RemoveExtension(ext); + } + } + + private static readonly List _nonInheritableExtensions = [ + ResourceIdentity.CORE_BASE_URL + "elementdefinition-isCommonBinding", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-fmm", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-fmm-no-warnings", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-hierarchy", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-interface", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-normative-version", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-applicable-version", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-category", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-codegen-super", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-security-category", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-standards-status", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-summary", + ResourceIdentity.CORE_BASE_URL + "structuredefinition-wg", + ResourceIdentity.CORE_BASE_URL + "replaces", + ResourceIdentity.CORE_BASE_URL + "resource-approvalDate", + ResourceIdentity.CORE_BASE_URL + "resource-effectivePeriod", + ResourceIdentity.CORE_BASE_URL + "resource-lastReviewDate", + CONSTRAINED_BY_DIFF_EXT //this is our own extension to define differences compared to the base, this can't be inherited from the base profile + ]; + + // ========== For internal use only ========== // [WMR 20170209] OBSOLETE #if false diff --git a/src/Hl7.Fhir.Specification.STU3.Tests/Snapshot/SnapshotGeneratorTest.cs b/src/Hl7.Fhir.Specification.STU3.Tests/Snapshot/SnapshotGeneratorTest.cs index 04c280575f..ba3bc9c1e3 100644 --- a/src/Hl7.Fhir.Specification.STU3.Tests/Snapshot/SnapshotGeneratorTest.cs +++ b/src/Hl7.Fhir.Specification.STU3.Tests/Snapshot/SnapshotGeneratorTest.cs @@ -21,8 +21,8 @@ using Hl7.Fhir.Support; using Hl7.Fhir.Utility; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; using NSubstitute; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -2433,8 +2433,8 @@ private static bool isAlmostExactly(ElementDefinition elem, ElementDefinition ba } // Also ignore any Changed extensions on base and diff - elemClone.RemoveAllConstrainedByDiffExtensions(); - baseClone.RemoveAllConstrainedByDiffExtensions(); + elemClone.RemoveAllNonInheritableExtensions(); + baseClone.RemoveAllNonInheritableExtensions(); elemClone.RemoveAllConstrainedByDiffAnnotations(); baseClone.RemoveAllConstrainedByDiffAnnotations(); diff --git a/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorTest.cs b/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorTest.cs index 48fb3b9acd..8ff23d24b7 100644 --- a/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorTest.cs +++ b/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorTest.cs @@ -10060,6 +10060,37 @@ private StructureDefinition createVeryNestedExtension() } + [TestMethod] + public void RemoveNonInhertitableSnapshotsTest() + { + var profile = new StructureDefinition + { + Url = "http://fire.ly/StructureDefinition/example", + Snapshot = new() + { + Element = new() { + new("Example") + { + Binding = new() + { + Strength = BindingStrength.Required, + ValueSet = "http://fire.ly/ValueSet/example" + } + }, + } + } + }; + + profile.Snapshot.Element[0].AddExtension(ResourceIdentity.CORE_BASE_URL + "structuredefinition-hierarchy", new FhirString("foo")); + profile.Snapshot.Element[0].Binding.AddExtension(ResourceIdentity.CORE_BASE_URL + "elementdefinition-isCommonBinding", new FhirBoolean(true)); + + profile.Snapshot.RemoveAllNonInheritableExtensions(); + + profile.Snapshot.Element[0].Extension.Should().BeEmpty(); + profile.Snapshot.Element[0].Binding.Extension.Should().BeEmpty(); + } + + [TestMethod] public async Tasks.Task TestNewR5Elements() {