Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/nuget/MSTest.TestFramework-3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsmits authored Jan 31, 2024
2 parents 2d36b89 + 43e2df4 commit 02bbb29
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 9 deletions.
28 changes: 20 additions & 8 deletions src/Hl7.Fhir.Base/ElementModel/TypedElementParseExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
#nullable enable

/*
* Copyright (c) 2018, Firely (info@fire.ly) and contributors
* See the file CONTRIBUTORS for details.
*
Expand Down Expand Up @@ -33,27 +35,34 @@ public static class TypedElementParseExtensions
/// 'string' => code
/// 'uri' => code
/// </remarks>
public static Element ParseBindable(this ITypedElement instance)
public static Element? ParseBindable(this ITypedElement instance)
#pragma warning disable CS0618 // Type or member is obsolete
=> 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>
internal static Element? ParseBindableInternal<T>(this IBaseElementNavigator<T> instance) where T : IBaseElementNavigator<T>
{
return instance.InstanceType switch
{
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.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(),
FhirTypeConstants.CODEABLEREFERENCE => parseCodeableReference(),
_ => null,
};

CodeableConcept? parseCodeableReference()
{
var valueChild = instance.Children("concept").FirstOrDefault();
return valueChild?.ParseCodeableConceptInternal();
}

Coding parseQuantity()
{
var newCoding = new Coding();
Expand All @@ -62,7 +71,8 @@ Coding parseQuantity()
newCoding.System = q.System ?? "http://unitsofmeasure.org";
return newCoding;
}
Element parseExtension()

Element? parseExtension()
{
var valueChild = instance.Children("value").FirstOrDefault();
return valueChild?.ParseBindableInternal();
Expand All @@ -71,7 +81,7 @@ Element parseExtension()
#endregion

#region ParseQuantity
public static Model.Quantity ParseQuantity(this ITypedElement instance)
public static Quantity ParseQuantity(this ITypedElement instance)
#pragma warning disable CS0618 // Type or member is obsolete
=> ParseQuantityInternal(instance);
#pragma warning restore CS0618 // Type or member is obsolete
Expand Down Expand Up @@ -169,8 +179,10 @@ public static CodeableConcept ParseCodeableConceptInternal<T>(this IBaseElementN
#endregion

#pragma warning disable CS0618 // Type or member is obsolete
public static string GetString<T>(this IEnumerable<T> instance) where T : IBaseElementNavigator<T>
public static string? GetString<T>(this IEnumerable<T> instance) where T : IBaseElementNavigator<T>
#pragma warning restore CS0618 // Type or member is obsolete
=> instance.SingleOrDefault()?.Value as string;
}
}

#nullable restore
1 change: 1 addition & 0 deletions src/Hl7.Fhir.Base/Model/FhirTypeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal class FhirTypeConstants
// Special Purpose Data types
public const string EXTENSION = "Extension";
public const string REFERENCE = "Reference";
public const string CODEABLEREFERENCE = "CodeableReference";
public const string XHTML = "xhtml";

// Resource type
Expand Down
1 change: 1 addition & 0 deletions src/Hl7.Fhir.Base/Rest/FhirClientSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved

namespace Hl7.Fhir.Rest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
#pragma warning disable CS1580 // Invalid type for parameter in XML comment cref attribute
#pragma warning disable CS1584 // XML comment has syntactically incorrect cref attribute

namespace Hl7.Fhir.Serialization
{
Expand Down
27 changes: 27 additions & 0 deletions src/Hl7.Fhir.ElementModel.R4B.Tests/ParseExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using FluentAssertions;
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Specification.Terminology;
using System.Collections.Generic;
using Xunit;

namespace Hl7.Fhir.Validation
{
public partial class ParseExtensionsTests
{
[Fact]
public void TestParseCodeableReference()
{
var i = new CodeableReference
{
Reference = new ResourceReference("http://example.org/fhir/Patient/1"),
Concept = new CodeableConcept("http://nu.nl", "bla")
};

var node = i.ToTypedElement();
var p = node.ParseBindable();

p.Should().BeEquivalentTo(new { Coding = new List<Coding> { new Coding("http://nu.nl", "bla") } });
}
}
}
26 changes: 26 additions & 0 deletions src/Hl7.Fhir.ElementModel.R5.Tests/ParseExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using FluentAssertions;
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using System.Collections.Generic;
using Xunit;

namespace Hl7.Fhir.Validation
{
public partial class ParseExtensionsTests
{
[Fact]
public void TestParseCodeableReference()
{
var i = new CodeableReference
{
Reference = new ResourceReference("http://example.org/fhir/Patient/1"),
Concept = new CodeableConcept("http://nu.nl", "bla")
};

var node = i.ToTypedElement();
var p = node.ParseBindable();

p.Should().BeEquivalentTo(new { Coding = new List<Coding> { new Coding("http://nu.nl", "bla") } });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Hl7.Fhir.Validation
{
public class ParseExtensionsTests
public partial class ParseExtensionsTests
{
[Fact]
public void TestParseQuantity()
Expand Down
18 changes: 18 additions & 0 deletions src/Hl7.Fhir.R4B/Model/CodeableReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2024, 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.Introspection;

namespace Hl7.Fhir.Model
{
[Bindable(true)]
public partial class CodeableReference
{
}
}
18 changes: 18 additions & 0 deletions src/Hl7.Fhir.R5/Model/CodeableReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2024, 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.Introspection;

namespace Hl7.Fhir.Model
{
[Bindable(true)]
public partial class CodeableReference
{
}
}

0 comments on commit 02bbb29

Please sign in to comment.