Skip to content

Commit

Permalink
Move IScopedNode to firely-validation-api
Browse files Browse the repository at this point in the history
  • Loading branch information
marcovisserFurore committed Dec 12, 2023
1 parent 60ab0e9 commit 2e82a50
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 220 deletions.

This file was deleted.

7 changes: 0 additions & 7 deletions src/Hl7.Fhir.Base/ElementModel/ElementNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ public static IReadOnlyCollection<IElementDefinitionSummary> ChildDefinitions(th

public static ScopedNode ToScopedNode(this ITypedElement node) =>
node as ScopedNode ?? new ScopedNode(node);

/// <summary>
/// Convert a <see cref="ITypedElement"/> to a <see cref="IScopedNode"/>.
/// </summary>
/// <param name="node">An <see cref="ITypedElement"/></param>
/// <returns></returns>
internal static IScopedNode AsScopedNode(this ITypedElement node) => ToScopedNode(node);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Hl7.Fhir.Base/ElementModel/IBaseElementNavigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Hl7.Fhir.ElementModel
{
/// <summary>
/// The base interface for <see cref="ITypedElement"/> and <see cref="IScopedNode"/>."/>
/// The base interface for <see cref="ITypedElement"/>."/>
/// </summary>
/// <typeparam name="TDerived"></typeparam>
[Obsolete("WARNING! Intended for internal API usage exclusively, this interface ideally should be kept internal. " +
Expand Down
31 changes: 0 additions & 31 deletions src/Hl7.Fhir.Base/ElementModel/IScopedNode.cs

This file was deleted.

45 changes: 0 additions & 45 deletions src/Hl7.Fhir.Base/ElementModel/IScopedNodeExtensions.cs

This file was deleted.

19 changes: 2 additions & 17 deletions src/Hl7.Fhir.Base/ElementModel/ScopedNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Hl7.Fhir.ElementModel
{
public class ScopedNode : ITypedElement, IScopedNode, IAnnotated, IExceptionSource
public class ScopedNode : ITypedElement, IAnnotated, IExceptionSource
{
private class Cache
{
Expand All @@ -32,7 +32,6 @@ private class Cache
private readonly Cache _cache = new();

public readonly ITypedElement Current;
private readonly ScopedNode? _parent;

public ScopedNode(ITypedElement wrapped, string? instanceUri = null)
{
Expand All @@ -46,7 +45,6 @@ public ScopedNode(ITypedElement wrapped, string? instanceUri = null)
private ScopedNode(ScopedNode parentNode, ScopedNode? parentResource, ITypedElement wrapped, string? fullUrl)
{
Current = wrapped;
_parent = parentNode;
ExceptionHandler = parentNode.ExceptionHandler;
ParentResource = parentNode.AtResource ? parentNode : parentResource;

Expand Down Expand Up @@ -230,24 +228,11 @@ private set
}
}

/// <inheritdoc />


IScopedNode? IScopedNode.Parent => _parent;

/// <inheritdoc />
public IEnumerable<object> Annotations(Type type) => type == typeof(ScopedNode) ? (new[] { this }) : Current.Annotations(type);

private IEnumerable<ScopedNode> childrenInternal(string? name = null) =>
Current.Children(name).Select(c => new ScopedNode(this, ParentResource, c, _fullUrl));

/// <inheritdoc />
public IEnumerable<ITypedElement> Children(string? name = null) =>
childrenInternal(name);

IEnumerable<IScopedNode> IBaseElementNavigator<IScopedNode>.Children(string? name) =>
childrenInternal(name);
Current.Children(name).Select(c => new ScopedNode(this, ParentResource, c, _fullUrl));
}
}

#nullable restore
100 changes: 46 additions & 54 deletions src/Hl7.Fhir.Base/ElementModel/TypedElementParseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

using Hl7.Fhir.Model;
using Hl7.Fhir.Support.Poco;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Hl7.Fhir.ElementModel
{
public static class TypedElementParseExtensions
{
# region ParseBindable
#region ParseBindable
/// <summary>
/// Parses a bindeable type (code, Coding, CodeableConcept, Quantity, string, uri) into a FHIR coded datatype.
/// Extensions will be parsed from the 'value' of the (simple) extension.
Expand All @@ -32,37 +33,22 @@ public static class TypedElementParseExtensions
/// 'string' => code
/// 'uri' => code
/// </remarks>
public static Element ParseBindable(this ITypedElement instance) => instance.parseBindable();

/// <summary>
/// Parses a bindeable type (code, Coding, CodeableConcept, Quantity, string, uri) into a FHIR coded datatype.
/// Extensions will be parsed from the 'value' of the (simple) extension.
/// </summary>
/// <param name="instance"></param>
/// <returns>An Element of a coded type (code, Coding or CodeableConcept) dependin on the instance type,
/// or null if no bindable instance data was found</returns>
/// <remarks>The instance type is mapped to a codable type as follows:
/// 'code' => code
/// 'Coding' => Coding
/// 'CodeableConcept' => CodeableConcept
/// 'Quantity' => Coding
/// 'Extension' => depends on value[x]
/// 'string' => code
/// 'uri' => code
/// </remarks>
internal static Element ParseBindable(this IScopedNode instance) => instance.parseBindable();

public static Element ParseBindable(this ITypedElement instance)
#pragma warning disable CS0618 // Type or member is obsolete
private static Element parseBindable<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
=> instance.ParseBindableInternal();
#pragma warning restore CS0618 // Type or member is obsolete

[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static Element ParseBindableInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
{
return instance.InstanceType switch
{
FhirTypeConstants.CODE => instance.parsePrimitive<Code, T>(),
FhirTypeConstants.STRING => new Code(instance.parsePrimitive<FhirString, T>()?.Value),
FhirTypeConstants.URI => new Code(instance.parsePrimitive<FhirUri, T>()?.Value),
FhirTypeConstants.CODING => instance.parseCoding(),
FhirTypeConstants.CODEABLE_CONCEPT => instance.parseCodeableConcept(),
FhirTypeConstants.CODE => instance.ParsePrimitiveInternal<Code, T>(),
FhirTypeConstants.STRING => new Code(instance.ParsePrimitiveInternal<FhirString, T>()?.Value),
FhirTypeConstants.URI => new Code(instance.ParsePrimitiveInternal<FhirUri, T>()?.Value),
FhirTypeConstants.CODING => instance.ParseCodingInternal(),
FhirTypeConstants.CODEABLE_CONCEPT => instance.ParseCodeableConceptInternal(),
FhirTypeConstants.QUANTITY => parseQuantity(),
FhirTypeConstants.EXTENSION => parseExtension(),
_ => null,
Expand All @@ -71,27 +57,28 @@ private static Element parseBindable<T>(this IBaseElementNavigator<T> instance)
Coding parseQuantity()
{
var newCoding = new Coding();
var q = instance.parseQuantity();
var q = instance.ParseQuantityInternal();
newCoding.Code = q.Code;
newCoding.System = q.System ?? "http://unitsofmeasure.org";
return newCoding;
}
Element parseExtension()
{
var valueChild = instance.Children("value").FirstOrDefault();
return valueChild?.parseBindable();
return valueChild?.ParseBindableInternal();
}
}
#endregion

#region ParseQuantity
public static Model.Quantity ParseQuantity(this ITypedElement instance) => parseQuantity(instance);

internal static Model.Quantity ParseQuantity(this IScopedNode instance) => parseQuantity(instance);

public static Model.Quantity ParseQuantity(this ITypedElement instance)
#pragma warning disable CS0618 // Type or member is obsolete
private static Quantity parseQuantity<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
=> ParseQuantityInternal(instance);
#pragma warning restore CS0618 // Type or member is obsolete

[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static Quantity ParseQuantityInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
{
var newQuantity = new Quantity
{
Expand All @@ -111,26 +98,27 @@ private static Quantity parseQuantity<T>(this IBaseElementNavigator<T> instance)

#region ParsePrimitive
public static T ParsePrimitive<T>(this ITypedElement instance) where T : PrimitiveType, new()
=> parsePrimitive<T, ITypedElement>(instance);

internal static T ParsePrimitive<T>(this IScopedNode instance) where T : PrimitiveType, new()
=> parsePrimitive<T, IScopedNode>(instance);

#pragma warning disable CS0618 // Type or member is obsolete
private static T parsePrimitive<T, U>(this IBaseElementNavigator<U> instance) where T : PrimitiveType, new() where U : IBaseElementNavigator<U>
=> ParsePrimitiveInternal<T, ITypedElement>(instance);
#pragma warning restore CS0618 // Type or member is obsolete

[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static T ParsePrimitiveInternal<T, U>(this IBaseElementNavigator<U> instance) where T : PrimitiveType, new() where U : IBaseElementNavigator<U>
=> new() { ObjectValue = instance.Value };

#endregion

#region ParseCoding
public static Coding ParseCoding(this ITypedElement instance) => parseCoding(instance);

internal static Coding ParseCoding(this IScopedNode instance) => parseCoding(instance);

public static Coding ParseCoding(this ITypedElement instance)
#pragma warning disable CS0618 // Type or member is obsolete
private static Coding parseCoding<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
=> ParseCodingInternal(instance);
#pragma warning restore CS0618 // Type or member is obsolete


[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static Coding ParseCodingInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
{
return new Coding()
{
Expand All @@ -144,13 +132,14 @@ private static Coding parseCoding<T>(this IBaseElementNavigator<T> instance) whe
#endregion

#region ParseResourceReference
public static ResourceReference ParseResourceReference(this ITypedElement instance) => instance.parseResourceReference();

internal static ResourceReference ParseResourceReference(this IScopedNode instance) => instance.parseResourceReference();

public static ResourceReference ParseResourceReference(this ITypedElement instance)
#pragma warning disable CS0618 // Type or member is obsolete
private static ResourceReference parseResourceReference<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
=> instance.ParseResourceReferenceInternal();
#pragma warning restore CS0618 // Type or member is obsolete

[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static ResourceReference ParseResourceReferenceInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
{
return new ResourceReference()
{
Expand All @@ -161,16 +150,19 @@ private static ResourceReference parseResourceReference<T>(this IBaseElementNavi
#endregion

#region ParseCodeableConcept
public static CodeableConcept ParseCodeableConcept(this ITypedElement instance) => instance.parseCodeableConcept();
internal static CodeableConcept ParseCodeableConcept(this IScopedNode instance) => instance.parseCodeableConcept();
public static CodeableConcept ParseCodeableConcept(this ITypedElement instance)
#pragma warning disable CS0618 // Type or member is obsolete
private static CodeableConcept parseCodeableConcept<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
=> instance.ParseCodeableConceptInternal();
#pragma warning restore CS0618 // Type or member is obsolete

[Obsolete("WARNING! Intended for internal API usage exclusively, interface IBaseElementNavigator can be changed in " +
"the near future.")]
public static CodeableConcept ParseCodeableConceptInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
{
return new CodeableConcept()
{
Coding =
instance.Children("coding").Select(codingNav => codingNav.parseCoding()).ToList(),
instance.Children("coding").Select(codingNav => codingNav.ParseCodingInternal()).ToList(),
Text = instance.Children("text").GetString()
};
}
Expand Down
Loading

0 comments on commit 2e82a50

Please sign in to comment.