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
13 changes: 6 additions & 7 deletions src/Benchmarks/SerializationBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ namespace Firely.Sdk.Benchmarks
public class SerializationBenchmarks
{
internal Patient Patient;
JsonSerializerOptions Options;
BaseFhirXmlPocoSerializer XmlSerializer;

private JsonSerializerOptions _options;
private FhirXmlSerializer _xmlSerializer;

[GlobalSetup]
public void BenchmarkSetup()
Expand All @@ -25,20 +24,20 @@ public void BenchmarkSetup()
// For now, deserialize with the existing deserializer, until we have completed
// the dynamicserializer too.
Patient = FhirJsonNode.Parse(data).ToPoco<Patient>();
Options = new JsonSerializerOptions().ForFhir();
XmlSerializer = new FhirXmlPocoSerializer();
_options = new JsonSerializerOptions().ForFhir();
_xmlSerializer = new FhirXmlSerializer();
}

[Benchmark]
public string JsonDictionarySerializer()
{
return JsonSerializer.Serialize(Patient, Options);
return JsonSerializer.Serialize(Patient, _options);
}

[Benchmark]
public string XmlDictionarySerializer()
{
return SerializationUtil.WriteXmlToString(Patient, (o, w) => XmlSerializer.Serialize(o, w));
return SerializationUtil.WriteXmlToString(w => _xmlSerializer.Serialize(Patient, w));
}

[Benchmark]
Expand Down
421 changes: 410 additions & 11 deletions src/Hl7.Fhir.Base/CompatibilitySuppressions.xml

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions src/Hl7.Fhir.Base/ElementModel/PocoBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ public static T ToPoco<T>(this ITypedElement element, ModelInspector inspector,
public static Base ToPoco(this ITypedElement element, ModelInspector inspector, PocoBuilderSettings settings = null) =>
new NewPocoBuilder(inspector, settings ?? new PocoBuilderSettings()).BuildFrom(element);

public static ISourceNode ToSourceNode(this Base @base, ModelInspector inspector, string rootName = null)
{
var node = @base.ToElementNode(rootName);
((IAnnotatable)node).AddAnnotation(inspector);

return node;
}
public static ISourceNode ToSourceNode(this Base @base, ModelInspector inspector, string rootName = null) =>
@base.ToPocoNode(inspector, rootName);
}
}
5 changes: 2 additions & 3 deletions src/Hl7.Fhir.Base/ElementModel/PocoNodeOrList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ Element when Poco.TypeName.Contains('.') => "Element",
_ => Name
};

[TemporarilyChanged] // Parent should return PocoNode, not PocoNodeOrList. This will be solved in another branch.
IElementDefinitionSummary? ITypedElement.Definition
{
get
Expand Down Expand Up @@ -143,7 +142,7 @@ IEnumerable<IScopedNode> IScopedNode.Children(string? name) => name is null
? Children().SelectMany(node => node)
: Child(name) ?? [];

[TemporarilyChanged] // will be removed soon
[Obsolete("This is a temporary feature and will be removed before we publish SDK 6.0.")]
NodeType IScopedNode.Type => Poco switch
{
Bundle => NodeType.Bundle | NodeType.Resource,
Expand Down Expand Up @@ -219,7 +218,7 @@ IEnumerable<ISourceNode> ISourceNode.Children(string? name)

private AnnotationList? _annotations;

private AnnotationList Annotations => LazyInitializer.EnsureInitialized(ref _annotations, () => []);
private AnnotationList Annotations => LazyInitializer.EnsureInitialized(ref _annotations, () => [])!;

IEnumerable<object> IAnnotated.Annotations(Type type)
{
Expand Down
23 changes: 13 additions & 10 deletions src/Hl7.Fhir.Base/ElementModel/TypedElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,27 @@ public static ITypedElement ToTypedElementLegacy(this Base @base, ModelInspector
/// In the meantime, you can restore the old behaviour with a call to <see cref="ToTypedElementLegacy"/></remarks>
#if NETSTANDARD2_1
[Obsolete("The implementation of this method has changed to use our new model stack. If you want to try the new behaviour, "+
"either ignore this warning or call ToElementNode(). For reverting to the old behaviour, call .ToTypedElementLegacy()")]
"either ignore this warning or call ToPocoNode(). For reverting to the old behaviour, call .ToTypedElementLegacy()")]
#else
[Experimental("SDK0001")]
#endif
public static ITypedElement ToTypedElement(this Base @base, ModelInspector inspector, string? rootName = null)
{
var node = ToElementNode(@base, rootName);
((IAnnotatable)node).AddAnnotation(inspector);

return node;
}
public static ITypedElement ToTypedElement(this Base @base, ModelInspector inspector, string? rootName = null) =>
@base.ToPocoNode(inspector, rootName);

/// <summary>
/// Converts a Poco to a new PocoElementNode.
/// </summary>
/// <param name="base">The Poco that should be converted to an <see cref="ITypedElement"/>.</param>
/// <param name="rootName"></param>
public static PocoNode ToElementNode(this Base @base, string? rootName = null) => PocoNodeOrList.Root(@base, rootName);
/// <param name="inspector">An optional <see cref="ModelInspector"/> that should be used to access metadata about the resource.</param>
/// <param name="rootName">An optional nome for the node at the root of the tree.</param>
public static PocoNode ToPocoNode(this Base @base, ModelInspector? inspector = null, string? rootName = null)
{
var result = PocoNodeOrList.Root(@base, rootName);
if(inspector is not null)
((IAnnotatable)result).AddAnnotation(inspector);

return result;
}

/// <summary>
/// Determines whether the specified ITypedElement is equal to the current ITypedElement. You can discard the order of the elements
Expand Down
2 changes: 1 addition & 1 deletion src/Hl7.Fhir.Base/FhirPath/CompiledExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static bool Predicate(this CompiledExpression evaluator, IScopedNode inpu
/// <inheritdoc cref="Predicate(Hl7.FhirPath.CompiledExpression,Hl7.Fhir.Model.IScopedNode,Hl7.FhirPath.EvaluationContext)"/>
public static bool Predicate(this CompiledExpression evaluator, Base input, EvaluationContext ctx)
{
var result = evaluator(input.ToElementNode(), ctx).BooleanEval();
var result = evaluator(input.ToPocoNode(), ctx).BooleanEval();
return result is null || result.Value;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Hl7.Fhir.Base/FhirPath/Expressions/EvaluatorVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public EvaluatorVisitor(SymbolTable symbols)
}


[TemporarilyChanged] // we should investigate here. We will need a way to handle "object" without a fhir type, and try to infer it from the object
[TemporarilyChanged]
// we should investigate here. We will need a way to handle "object" without a fhir type,
// and try to infer it from the object. In the end we will remove the ToScopedNode.
public override Invokee VisitConstant(FP.ConstantExpression expression)
{
return InvokeeFactory.Return(ElementNode.ForPrimitive(expression.Value).ToScopedNode());
Expand Down Expand Up @@ -133,4 +135,4 @@ public static Invokee ToEvaluator(this FP.Expression expr, SymbolTable scope)
}
}

}
}
8 changes: 6 additions & 2 deletions src/Hl7.Fhir.Base/Model/Base.Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#nullable enable
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Introspection;
using Hl7.Fhir.Rest;
using Hl7.Fhir.Utility;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Hl7.Fhir.Model;

public static class BaseExtensions
{
[Obsolete("Use GetElementPairs() instead. Note that with GetElementPairs(), the elements are not guaranteed to " +
"be the same type, as they reflect the type in the actual POCO definition.")]
[Obsolete("Use EnumerateElements() instead. Note that with EnumerateElements(), the elements 'div' and 'id' are not FhirStrings, but XHtml and FhirUri respectively.")]
public static IEnumerable<Base> Children(this Base instance)
{
foreach (var element in instance.EnumerateElements())
Expand Down
Loading
Loading