Skip to content
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
140 changes: 98 additions & 42 deletions src/Hl7.Fhir.Base/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,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 All @@ -105,6 +140,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 @@ -168,6 +217,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 All @@ -189,6 +273,20 @@
<Right>lib/netstandard2.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/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.FhirPath.EvaluationContext.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>CP0006</DiagnosticId>
<Target>M:Hl7.Fhir.ElementModel.ITypedElement.Children(System.String)</Target>
Expand Down Expand Up @@ -329,46 +427,4 @@
<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/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.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.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.Utility.ReflectionHelper.IsTypedCollection(System.Type)</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.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.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>
</Suppressions>
16 changes: 10 additions & 6 deletions src/Hl7.Fhir.Base/FhirPath/EvaluationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ public EvaluationContext(ITypedElement? resource, ITypedElement? rootResource, I
{
Environment = environment;
}

/// <summary>
/// Explicitly override the values of %resource and %rootResource in the evaluation context.
/// </summary>
public static EvaluationContext WithResourceOverrides(ITypedElement? resource, ITypedElement? rootResource = null) =>
new EvaluationContext { Resource = resource, RootResource = rootResource ?? resource };

/// <summary>
/// The data represented by <c>%rootResource</c>.
Expand All @@ -67,4 +61,14 @@ public static EvaluationContext WithResourceOverrides(ITypedElement? resource, I
/// A delegate that handles the output for the <c>trace()</c> function.
/// </summary>
public Action<string, IEnumerable<ITypedElement>>? Tracer { get; set; }
}

public static class EvaluationContextExtensions
{
public static T WithResourceOverrides<T>(this T context, ITypedElement? resource, ITypedElement? rootResource = null) where T : EvaluationContext
{
context.Resource = resource;
context.RootResource = rootResource ?? resource;
return context;
}
}
7 changes: 1 addition & 6 deletions src/Hl7.Fhir.Base/FhirPath/FhirEvaluationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ public FhirEvaluationContext(ScopedNode node)
RootResource = Resource is ScopedNode sn ? sn.ResourceContext : node;
}

/// <summary>
/// Explicitly override the values of %resource and %rootResource in the evaluation context.
/// </summary>
public static new FhirEvaluationContext WithResourceOverrides(ITypedElement? resource, ITypedElement? rootResource = null) =>
(FhirEvaluationContext)EvaluationContext.WithResourceOverrides(resource, rootResource);
public ICodeValidationTerminologyService? TerminologyService { get; set; }

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

#nullable restore
#nullable restore
6 changes: 3 additions & 3 deletions src/Hl7.Fhir.Base/Model/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void Remove(string name, bool matchPrefix = false)
/// Searches for a parameter with the given name, and returns the matching parameter(s)
/// </summary>
/// <param name="name">The name of the parameter</param>
/// <param name="matchPrefix">If true, will remove all parameters which begin with the string given in the "name" parameter</param>
/// <param name="matchPrefix">If true, will retrieve all parameters which begin with the string given in the "name" parameter</param>
public IEnumerable<ParameterComponent> Get(string name, bool matchPrefix = false)
{
if (name == null) throw new ArgumentNullException("name");
Expand All @@ -137,7 +137,7 @@ public IEnumerable<ParameterComponent> Get(string name, bool matchPrefix = false
/// Searches for a parameter with the given name, and returns the matching parameter(s)
/// </summary>
/// <param name="name">The name of the parameter</param>
/// <param name="matchPrefix">If true, will remove all parameters which begin with the string given in the "name" parameter</param>
/// <param name="matchPrefix">If true, will retrieve all parameters which begin with the string given in the "name" parameter</param>
public ParameterComponent GetSingle(string name, bool matchPrefix = false)
{
if (name == null) throw new ArgumentNullException("name");
Expand Down Expand Up @@ -174,4 +174,4 @@ private string DebuggerDisplay
}
}
}
}
}
15 changes: 9 additions & 6 deletions src/Hl7.Fhir.Base/Rest/ContentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,19 @@ public static ResourceFormat GetResourceFormatFromContentType(string? contentTyp
/// </summary>
/// <param name="format">Whether the body is xml or json.</param>
/// <param name="fhirVersion">Optional. The version of FHIR to add to the header.</param>
public static string BuildContentType(ResourceFormat format, string? fhirVersion = default) =>
BuildMediaType(format, fhirVersion).ToString();
/// <param name="excludeCharset">Optional. Whether exclude charset.</param>
public static string BuildContentType(ResourceFormat format, string? fhirVersion = default, bool excludeCharset = false) =>
BuildMediaType(format, fhirVersion, excludeCharset).ToString();

/// <summary>
/// Creates a <see cref="MediaTypeHeaderValue"/> for use in a Content-Type header,
/// given the serialization format and the fhir version in use.
/// </summary>
/// <param name="format">Whether the body is xml or json.</param>
/// <param name="fhirVersion">Optional. The version of FHIR to add to the header.</param>
/// <param name="excludeCharset">Optional. Whether exclude charset.</param>
/// <exception cref="ArgumentException">Unsupported serialization.</exception>
public static MediaTypeHeaderValue BuildMediaType(ResourceFormat format, string? fhirVersion = default)
public static MediaTypeHeaderValue BuildMediaType(ResourceFormat format, string? fhirVersion = default, bool excludeCharset = false)
{
var contentType = format switch
{
Expand All @@ -121,10 +123,11 @@ public static MediaTypeHeaderValue BuildMediaType(ResourceFormat format, string?
_ => throw new ArgumentException("Cannot determine content type for data format " + format),
};

var result = new MediaTypeHeaderValue(contentType)
var result = new MediaTypeHeaderValue(contentType);
if (!excludeCharset)
{
CharSet = Encoding.UTF8.WebName
};
result.CharSet = Encoding.UTF8.WebName;
}

if (fhirVersion is not null && SemVersion.TryParse(fhirVersion, out var version))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Hl7.Fhir.Base/Rest/HttpContentBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public static HttpRequestMessage WithAccept(this HttpRequestMessage message,
string? contentTypeFhirVersion,
bool requestCompressedResponse)
{
message.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse(
ContentType.BuildContentType(serialization, contentTypeFhirVersion)));
message.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse(ContentType.BuildContentType(serialization, contentTypeFhirVersion, true)));
message.Headers.AcceptCharset.Add(new StringWithQualityHeaderValue(Encoding.UTF8.WebName));

if (requestCompressedResponse)
{
Expand Down
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
Loading