-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2582 from FirelyTeam/feature/VONK-5093-IScopedNode
VONK-5093: introducing IScopedNode
- Loading branch information
Showing
12 changed files
with
339 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Hl7.Fhir.Base/ElementModel/Adapters/ScopedNodeToTypedElementAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2023, Firely (info@fire.ly) and contributors | ||
* See the file CONTRIBUTORS for details. | ||
* | ||
* This file is licensed under the BSD 3-Clause license | ||
* available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE | ||
*/ | ||
|
||
#nullable enable | ||
|
||
using Hl7.Fhir.Specification; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Hl7.Fhir.ElementModel | ||
{ | ||
/// <summary> | ||
/// An adapter from <see cref="IScopedNode"/> to <see cref="ITypedElement"/>. | ||
/// </summary> | ||
/// <remarks>Be careful, this adapter does not implement the <see cref="ITypedElement.Location"/> and | ||
/// <see cref="ITypedElement.Definition"/> property. | ||
/// </remarks> | ||
internal class ScopedNodeToTypedElementAdapter : ITypedElement | ||
{ | ||
private readonly IScopedNode _adaptee; | ||
|
||
public ScopedNodeToTypedElementAdapter(IScopedNode adaptee) | ||
{ | ||
_adaptee = adaptee; | ||
} | ||
|
||
public string Location => throw new System.NotImplementedException(); | ||
|
||
public IElementDefinitionSummary Definition => throw new System.NotImplementedException(); | ||
|
||
public string Name => _adaptee.Name; | ||
|
||
public string InstanceType => _adaptee.InstanceType; | ||
|
||
public object Value => _adaptee.Value; | ||
|
||
public IEnumerable<ITypedElement> Children(string? name = null) => | ||
_adaptee.Children(name).Select(n => new ScopedNodeToTypedElementAdapter(n)); | ||
} | ||
} | ||
|
||
#nullable restore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2023, Firely (info@fire.ly) and contributors | ||
* See the file CONTRIBUTORS for details. | ||
* | ||
* This file is licensed under the BSD 3-Clause license | ||
* available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
#nullable enable | ||
|
||
namespace Hl7.Fhir.ElementModel | ||
{ | ||
/// <summary> | ||
/// The base interface for <see cref="ITypedElement"/> and <see cref="IScopedNode"/>."/> | ||
/// </summary> | ||
/// <typeparam name="TDerived"></typeparam> | ||
[Obsolete("WARNING! Intended for internal API usage exclusively, this interface ideally should be kept internal. " + | ||
"However, due to its derivation by the public interface ITypedElement, maintaining its internal status is impossible.")] | ||
public interface IBaseElementNavigator<TDerived> where TDerived : IBaseElementNavigator<TDerived> | ||
{ | ||
/// <summary> | ||
/// Enumerate the child nodes present in the source representation (if any) | ||
/// </summary> | ||
/// <param name="name">Return only the children with the given name.</param> | ||
/// <returns></returns> | ||
IEnumerable<TDerived> Children(string? name = null); | ||
|
||
/// <summary> | ||
/// Name of the node, e.g. "active", "value". | ||
/// </summary> | ||
string Name { get; } | ||
|
||
/// <summary> | ||
/// Type of the node. If a FHIR type, this is just a simple string, otherwise a StructureDefinition url for a type defined as a logical model. | ||
/// </summary> | ||
string InstanceType { get; } | ||
|
||
/// <summary> | ||
/// The value of the node (if it represents a primitive FHIR value) | ||
/// </summary> | ||
/// <remarks> | ||
/// FHIR primitives are mapped to underlying C# types as follows: | ||
/// | ||
/// instant Hl7.Fhir.ElementModel.Types.DateTime | ||
/// time Hl7.Fhir.ElementModel.Types.Time | ||
/// date Hl7.Fhir.ElementModel.Types.Date | ||
/// dateTime Hl7.Fhir.ElementModel.Types.DateTime | ||
/// decimal decimal | ||
/// boolean bool | ||
/// integer int | ||
/// unsignedInt int | ||
/// positiveInt int | ||
/// long/integer64 long (name will be finalized in R5) | ||
/// string string | ||
/// code string | ||
/// id string | ||
/// uri, oid, uuid, | ||
/// canonical, url string | ||
/// markdown string | ||
/// base64Binary string (uuencoded) | ||
/// xhtml string | ||
/// </remarks> | ||
object Value { get; } | ||
} | ||
} | ||
|
||
#nullable restore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2023, Firely (info@fire.ly) and contributors | ||
* See the file CONTRIBUTORS for details. | ||
* | ||
* This file is licensed under the BSD 3-Clause license | ||
* available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE | ||
*/ | ||
|
||
#nullable enable | ||
|
||
namespace Hl7.Fhir.ElementModel | ||
{ | ||
/// <summary> | ||
/// An element within a tree of typed FHIR data with also a parent element. | ||
/// </summary> | ||
/// <remarks> | ||
/// This interface represents FHIR data as a tree of elements, including type information either present in | ||
/// the instance or derived from fully aware of the FHIR definitions and types | ||
/// </remarks> | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
internal interface IScopedNode : IBaseElementNavigator<IScopedNode> | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
{ | ||
/// <summary> | ||
/// The parent node of this node, or null if this is the root node. | ||
/// </summary> | ||
IScopedNode? Parent { get; } | ||
} | ||
} | ||
|
||
#nullable restore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2023, Firely (info@fire.ly) and contributors | ||
* See the file CONTRIBUTORS for details. | ||
* | ||
* This file is licensed under the BSD 3-Clause license | ||
* available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE | ||
*/ | ||
|
||
#nullable enable | ||
|
||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Hl7.Fhir.ElementModel | ||
{ | ||
internal static class IScopedNodeExtensions | ||
{ | ||
/// <summary> | ||
/// Converts a <see cref="IScopedNode"/> to a <see cref="ITypedElement"/>. | ||
/// </summary> | ||
/// <param name="node">An <see cref="IScopedNode"/> node</param> | ||
/// <returns>An implementation of <see cref="ITypedElement"/></returns> | ||
/// <remarks>Be careful when using this method, the returned <see cref="ITypedElement"/> does not implement | ||
/// the methods <see cref="ITypedElement.Location"/> and <see cref="ITypedElement.Definition"/>. | ||
/// </remarks> | ||
[Obsolete("WARNING! For internal API use only. Turning an IScopedNode into an ITypedElement will cause problems for" + | ||
"Location and Definitions. Those properties are not implemented using this method and can cause problems " + | ||
"elsewhere. Please don't use this method unless you know what you are doing.")] | ||
public static ITypedElement AsTypedElement(this IScopedNode node) => | ||
node is ITypedElement ite ? ite : new ScopedNodeToTypedElementAdapter(node); | ||
|
||
/// <summary> | ||
/// Returns the parent resource of this node, or null if this node is not part of a resource. | ||
/// </summary> | ||
/// <param name="nodes"></param> | ||
/// <param name="name"></param> | ||
/// <returns></returns> | ||
public static IEnumerable<IScopedNode> Children(this IEnumerable<IScopedNode> nodes, string? name = null) => | ||
nodes.SelectMany(n => n.Children(name)); | ||
} | ||
} | ||
|
||
#nullable restore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.