Skip to content

Commit

Permalink
Merge branch 'develop-6.0' into 6.0/parse-elements-for-xml-parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasdejong authored Nov 13, 2024
2 parents 4f5a17d + a935d3c commit 7319e72
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 238 deletions.
28 changes: 28 additions & 0 deletions src/Hl7.Fhir.Base/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Hl7.Fhir.ElementModel.ScopedNodeExtensions</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>CP0001</DiagnosticId>
<Target>T:Hl7.Fhir.ElementModel.Types.MetricConfiguration</Target>
Expand All @@ -22,6 +29,20 @@
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:Hl7.Fhir.ElementModel.ScopedNode.Parent</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.ScopedNode.Children(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.ElementModel.TypedElementExtensions.IsExactlyEqualTo``1(``0,``0,System.Boolean)</Target>
Expand Down Expand Up @@ -85,6 +106,13 @@
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.FhirPath.FhirEvaluationContext.get_ElementResolver</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>
Expand Down
36 changes: 31 additions & 5 deletions src/Hl7.Fhir.Base/ElementModel/ScopedNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
* available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE
*/

using Hl7.Fhir.Model;
using Hl7.Fhir.Specification;
using Hl7.Fhir.Support.Poco;
using Hl7.Fhir.Utility;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

#nullable enable

namespace Hl7.Fhir.ElementModel
{
public class ScopedNode : ITypedElement, IAnnotated, IExceptionSource
public class ScopedNode : IScopedNode, IAnnotated, IExceptionSource
{
private class Cache
{
Expand Down Expand Up @@ -54,7 +56,6 @@ private ScopedNode(ScopedNode parentNode, ScopedNode? parentResource, ITypedElem

if (Current.Name == "entry")
_fullUrl = Current.Children("fullUrl").FirstOrDefault()?.Value as string ?? _fullUrl;

}

public ExceptionNotificationHandler? ExceptionHandler { get; set; }
Expand All @@ -72,7 +73,7 @@ private ScopedNode(ScopedNode parentNode, ScopedNode? parentResource, ITypedElem
/// <summary>
/// The resource or element which is the direct parent of this node.
/// </summary>
public readonly ScopedNode? Parent;
public IScopedNode? Parent { get; }

/// <summary>
/// Returns the location of the current element within its most direct parent resource or datatype.
Expand All @@ -87,6 +88,19 @@ private ScopedNode(ScopedNode parentNode, ScopedNode? parentResource, ITypedElem
/// <inheritdoc/>
public string Name => Current.Name;

/// <summary>
/// Will be replaced by a different implementation in the future.
/// </summary>
public NodeType Type => this switch
{
{ AtResource: true } when Current.Children("contained").Any() => NodeType.DomainResource | NodeType.Resource,
{ InstanceType: FhirTypeConstants.BUNDLE } => NodeType.Bundle | NodeType.Resource,
{ AtResource: true } => NodeType.Resource,
{ InstanceType: FhirTypeConstants.REFERENCE or FhirTypeConstants.CANONICAL or FhirTypeConstants.CODEABLEREFERENCE } => NodeType.Reference,
{ Value: not null } => NodeType.Primitive,
_ => 0
};

/// <inheritdoc/>
public string? InstanceType => Current.InstanceType;

Expand All @@ -96,6 +110,12 @@ private ScopedNode(ScopedNode parentNode, ScopedNode? parentResource, ITypedElem
/// <inheritdoc/>
public string Location => Current.Location;

public bool TryResolveBundleEntry(string fullUrl, [NotNullWhen(true)] out IScopedNode? result)
=> (result = ((ReferencedResourceCache)this.BundledResources()).ResolveReference(fullUrl)) is not null;

public bool TryResolveContainedEntry(string id, [NotNullWhen(true)] out IScopedNode? result)
=> (result = (this.ContainedResourcesWithId()).ResolveReference(id)) is not null;

/// <summary>
/// Whether this node is a root element of a Resource.
/// </summary>
Expand Down Expand Up @@ -264,7 +284,13 @@ private set
public IEnumerable<object> Annotations(Type type) => type == typeof(ScopedNode) ? (new[] { this }) : Current.Annotations(type);

/// <inheritdoc />
public IEnumerable<ITypedElement> Children(string? name = null) =>
IEnumerable<ITypedElement> ITypedElement.Children(string? name) =>
Current.Children(name).Select(c => new ScopedNode(this, ParentResource, c, _fullUrl));

/// <inheritdoc />
public IEnumerable<IScopedNode> Children(string? name = null) =>
Current.Children(name).Select(c => new ScopedNode(this, ParentResource, c, _fullUrl));

public string ShortPath => Current is ElementNode en ? en.ShortPath : Current.Location;
}
}
145 changes: 0 additions & 145 deletions src/Hl7.Fhir.Base/ElementModel/ScopedNodeExtensions.cs

This file was deleted.

6 changes: 3 additions & 3 deletions src/Hl7.Fhir.Base/FhirPath/ElementNavFhirExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static void PrepareFhirSymbolTableFunctions()
public static SymbolTable AddFhirExtensions(this SymbolTable t)
{
t.Add("hasValue", (ITypedElement f) => f.HasValue(), doNullProp: false);
t.Add("resolve", (ITypedElement f, EvaluationContext ctx) => resolver(f, ctx), doNullProp: false);
t.Add("resolve", (IEnumerable<ITypedElement> f, EvaluationContext ctx) => f.Select(fi => resolver(fi, ctx)), doNullProp: false);
t.Add("resolve", (IScopedNode f, EvaluationContext ctx) => resolver(f, ctx), doNullProp: false);
t.Add("resolve", (IEnumerable<IScopedNode> f, EvaluationContext ctx) => f.Select(fi => resolver(fi, ctx)), doNullProp: false);

t.Add("memberOf", (ITypedElement input, string valueset, EvaluationContext ctx) => MemberOf(input, valueset, ctx), doNullProp: false);

Expand Down Expand Up @@ -69,7 +69,7 @@ public static SymbolTable AddFhirExtensions(this SymbolTable t)

return t;

static ITypedElement? resolver(ITypedElement f, EvaluationContext ctx)
static IScopedNode? resolver(IScopedNode f, EvaluationContext ctx)
{
return ctx is FhirEvaluationContext fctx ? f.Resolve(fctx.ElementResolver) : f.Resolve();
}
Expand Down
5 changes: 3 additions & 2 deletions src/Hl7.Fhir.Base/FhirPath/FhirEvaluationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Specification.Terminology;
using Hl7.FhirPath;
using System;
Expand Down Expand Up @@ -78,9 +79,9 @@ private static ITypedElement toNearestResource(ScopedNode node)
return scan;
}

private Func<string, ITypedElement>? _elementResolver;
private Func<string, IScopedNode>? _elementResolver;

public Func<string, ITypedElement>? ElementResolver
public Func<string, IScopedNode>? ElementResolver
{
get { return _elementResolver; }
set { _elementResolver = value; }
Expand Down
1 change: 1 addition & 0 deletions src/Hl7.Fhir.Base/Hl7.Fhir.Base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 7319e72

Please sign in to comment.