Skip to content

Commit

Permalink
Merge branch 'develop-6.0' into 6.0/2930-remove-isnested-type
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Hl7.Fhir.Base/CompatibilitySuppressions.xml
#	src/Hl7.Fhir.Base/FhirPath/FhirEvaluationContext.cs
#	src/Hl7.FhirPath.R4.Tests/PocoTests/FhirPathTest.cs
  • Loading branch information
Kasdejong committed Oct 23, 2024
2 parents 5479d86 + 581baec commit ab691a1
Show file tree
Hide file tree
Showing 15 changed files with 601 additions and 278 deletions.
84 changes: 84 additions & 0 deletions src/Hl7.Fhir.Base/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,41 @@
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.FhirPath.FhirEvaluationContext.get_TerminologyService</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.FhirPath.FhirEvaluationContext.WithResourceOverrides(Hl7.Fhir.ElementModel.ITypedElement,Hl7.Fhir.ElementModel.ITypedElement)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Model.Parameters.get_Item(System.String)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Rest.ContentType.BuildContentType(Hl7.Fhir.Rest.ResourceFormat,System.String)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Rest.ContentType.BuildMediaType(Hl7.Fhir.Rest.ResourceFormat,System.String)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Serialization.IFhirSerializationEngine.SerializeToXml(Hl7.Fhir.Model.Resource)</Target>
Expand Down Expand Up @@ -196,6 +231,20 @@
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Utility.ReflectionHelper.IsTypedCollection(System.Type)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.FhirPath.EvaluationContext.WithResourceOverrides(Hl7.Fhir.ElementModel.ITypedElement,Hl7.Fhir.ElementModel.ITypedElement)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.ElementModel.TypedElementExtensions.IsExactlyEqualTo``1(``0,``0,System.Boolean)</Target>
Expand Down Expand Up @@ -322,6 +371,41 @@
<Right>lib/netstandard2.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.FhirPath.FhirEvaluationContext.get_TerminologyService</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.FhirPath.FhirEvaluationContext.WithResourceOverrides(Hl7.Fhir.ElementModel.ITypedElement,Hl7.Fhir.ElementModel.ITypedElement)</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Model.Parameters.get_Item(System.String)</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Rest.ContentType.BuildContentType(Hl7.Fhir.Rest.ResourceFormat,System.String)</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Rest.ContentType.BuildMediaType(Hl7.Fhir.Rest.ResourceFormat,System.String)</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Serialization.IFhirSerializationEngine.SerializeToXml(Hl7.Fhir.Model.Resource)</Target>
Expand Down
6 changes: 3 additions & 3 deletions src/Hl7.Fhir.Base/FhirPath/FhirEvaluationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public FhirEvaluationContext(ScopedNode node)
{
RootResource = Resource is ScopedNode sn ? sn.ResourceContext : node;
}
public ITerminologyService? TerminologyService { get; set; }

public ICodeValidationTerminologyService? TerminologyService { get; set; }

private static ITypedElement toNearestResource(ScopedNode node)
{
Expand All @@ -88,4 +88,4 @@ public Func<string, ITypedElement>? ElementResolver
}
}

#nullable restore
#nullable restore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Hl7.Fhir.Rest;
using Hl7.Fhir.Utility;
using System;
using System.Collections.Generic;
Expand All @@ -19,7 +19,7 @@ namespace Hl7.Fhir.Specification.Snapshot
// This extension indicates snapshot elements with associated differential constraints in the profile.
// Note: extensions are persisted to XML/JSON, whereas annotations are ephemeral (in-memory only)

/// <summary>Helper methods for the <see cref="SnapshotGenerator"/> class to generate and inspect custom extensions.</summary>
/// <summary>Helper methods for the SnapshotGenerator class to generate and inspect custom extensions.</summary>
public static class SnapshotGeneratorExtensions
{
/// <summary>The canonical url of the extension definition that marks snapshot elements with associated differential constraints.</summary>
Expand Down Expand Up @@ -54,6 +54,7 @@ public static void RemoveConstrainedByDiffExtension(this IExtendable element)
}

/// <summary>Recursively removes all instances of the <see cref="CONSTRAINED_BY_DIFF_EXT"/> extension from the specified element definition and all it's child objects.</summary>
[Obsolete("Use RemoveAllNonInheritableExtensions(this Element element) instead.")]
public static void RemoveAllConstrainedByDiffExtensions(this Element element)
{
if (element == null) { throw Error.ArgumentNull(nameof(element)); }
Expand All @@ -65,6 +66,7 @@ public static void RemoveAllConstrainedByDiffExtensions(this Element element)
}

/// <summary>Recursively removes all instances of the <see cref="CONSTRAINED_BY_DIFF_EXT"/> extension from all the elements and their respective child objects.</summary>
[Obsolete("Use RemoveAllNonInheritableExtensions(this IEnumerable<T> elements) instead.")]
public static void RemoveAllConstrainedByDiffExtensions<T>(this IEnumerable<T> elements) where T : Element
{
if (elements == null) { throw Error.ArgumentNull(nameof(elements)); }
Expand All @@ -74,6 +76,47 @@ public static void RemoveAllConstrainedByDiffExtensions<T>(this IEnumerable<T> 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<Element>())
{
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<string> _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
Expand Down
18 changes: 18 additions & 0 deletions src/Hl7.Fhir.Conformance/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorExtensions</Target>
<Left>lib/net8.0/Hl7.Fhir.Conformance.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Conformance.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorExtensions</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.Conformance.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.Conformance.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
</Suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void merge(ElementDefinition snap, ElementDefinition diff, bool mergeElementId,
// Constraints are cumulative, so they are always "new" (hence a constant false for the comparer)
// [WMR 20160917] Note: constraint keys must be unique. The validator will detect duplicate keys, so the derived
// profile author can correct the conflicting constraint key.
// [WMR 20160918] MUST merge indentical constraints, otherwise each derived profile accumulates
// [WMR 20160918] MUST merge identical constraints, otherwise each derived profile accumulates
// additional identical constraints inherited from e.g. BackboneElement.
// snap.Constraint = mergeCollection(snap.Constraint, diff.Constraint, (a, b) => false);
// [WMR 20190723] R4 NEW: Initialize Constraint.source property
Expand Down Expand Up @@ -283,7 +283,7 @@ ElementDefinition.TypeRefComponent mergeElementType(ElementDefinition.TypeRefCom
// TODO: Move logic to MergeTo method on partial class TypeRefComponent

// TODO: Copy diff annotations...?
if (diff.ElementId != null) { result.ElementId = diff.ElementId; }
result.ElementId = mergeString(snap.ElementId, diff.ElementId);
result.Extension = mergeExtensions(snap.Extension, diff.Extension);
result.CodeElement = mergePrimitiveElement(snap.CodeElement, diff.CodeElement);

Expand Down Expand Up @@ -366,6 +366,7 @@ private ElementDefinition.ElementDefinitionBindingComponent mergeBinding(Element
snap.StrengthElement = mergePrimitiveElement(snap.StrengthElement, diff.StrengthElement);
snap.DescriptionElement = mergePrimitiveElement(snap.DescriptionElement, diff.DescriptionElement);
snap.ValueSetElement = mergeComplexAttribute(snap.ValueSetElement, diff.ValueSetElement);
snap.ElementId = mergeString(snap.ElementId, diff.ElementId);
snap.Extension = mergeExtensions(snap.Extension, diff.Extension);
snap.Additional = mergeCollection(snap.Additional, diff.Additional, matchExactly);
onConstraint(result);
Expand Down Expand Up @@ -670,7 +671,8 @@ T mergePrimitiveElement<T>(T snap, T diff, bool allowAppend = false) where T : P
{
result.ObjectValue = diffValue;
}
// Also merge extensions on primitives
// Also merge element id and extensions on primitives
result.ElementId = mergeString(snap.ElementId, diff.ElementId);
result.Extension = mergeExtensions(snap.Extension, diff.Extension);
onConstraint(result);
}
Expand All @@ -692,21 +694,21 @@ static string mergeId(ElementDefinition snap, ElementDefinition diff, bool merge
}
// Newly introduced named slices NEVER inherit element id
// Must always regenerate new unique identifier for named slices
else if (!IsEqualName(diff.SliceName, snap.SliceName))
if (!IsEqualName(diff.SliceName, snap.SliceName))
{
// Regenerate; don't inherit from snap
return null;
}
// Otherwise inherit existing element id from snap
return snap.ElementId;
}
else
{
// Don't merge elementId, e.g. for type profiles
return null;
}

// Don't merge elementId, e.g. for type profiles
return null;
}

static string mergeString(string snap, string diff) => diff ?? snap;

// Functions to match snap collection items to diff collection items
// Matching key depends on collection type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ private async Tasks.Task<List<ElementDefinition>> 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();
snapshot.RemoveAllNonInheritableExtensions();
snapshot.Element.RemoveAllConstrainedByDiffAnnotations();

// Notify observers
Expand Down Expand Up @@ -1487,7 +1487,7 @@ private static bool copyChildren(ElementDefinitionNavigator nav, ElementDefiniti
var elem = elems[pos];

// [WMR 20160826] Never inherit Changed extension from base profile!
elem.RemoveAllConstrainedByDiffExtensions();
elem.RemoveAllNonInheritableExtensions();
elem.RemoveAllConstrainedByDiffAnnotations();

// [WMR 20160902] Initialize empty ElementDefinition.Base components if necessary
Expand Down
14 changes: 14 additions & 0 deletions src/Hl7.Fhir.STU3/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorExtensions</Target>
<Left>lib/net8.0/Hl7.Fhir.STU3.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.STU3.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorExtensions</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.STU3.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.STU3.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:Hl7.Fhir.Model.ExplanationOfBenefit.ActInvoiceGroupCode.ActInvoiceInterGroupCode</Target>
Expand Down
16 changes: 9 additions & 7 deletions src/Hl7.Fhir.STU3/Specification/Snapshot/ElementDefnMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ T mergePrimitiveAttribute<T>(T snap, T diff, bool allowAppend = false) where T :

result.ObjectValue = diffText;
}
// Also merge extensions on primitives
// Also merge element id and extensions on primitives
// [Backported from R4]
result.ElementId = mergeString(snap?.ElementId, diff.ElementId);
result.Extension = mergeExtensions(snap?.Extension, diff.Extension);
onConstraint(result);
return result;
Expand Down Expand Up @@ -509,6 +510,7 @@ private ElementDefinition.ElementDefinitionBindingComponent mergeBinding(Element
snap.StrengthElement = mergePrimitiveAttribute(snap.StrengthElement, diff.StrengthElement);
snap.DescriptionElement = mergePrimitiveAttribute(snap.DescriptionElement, diff.DescriptionElement);
snap.ValueSet = mergeComplexAttribute(snap.ValueSet, diff.ValueSet);
snap.ElementId = mergeString(snap.ElementId, diff.ElementId);
snap.Extension = mergeExtensions(snap.Extension, diff.Extension);
onConstraint(result);
}
Expand All @@ -535,21 +537,21 @@ string mergeId(ElementDefinition snap, ElementDefinition diff, bool mergeElement
}
// Newly introduced named slices NEVER inherit element id
// Must always regenerate new unique identifier for named slices
else if (diff.SliceName != snap.SliceName)
if (diff.SliceName != snap.SliceName)
{
// Regenerate; don't inherit from snap
return null;
}
// Otherwise inherit existing element id from snap
return snap.ElementId;
}
else
{
// Don't merge elementId, e.g. for type profiles
return null;
}

// Don't merge elementId, e.g. for type profiles
return null;
}

static string mergeString(string snap, string diff) => diff ?? snap;

// [WMR 20180611] NEW
static bool isEqualCoding(Coding c, Coding d)
{
Expand Down
Loading

0 comments on commit ab691a1

Please sign in to comment.