Skip to content
This repository was archived by the owner on Jul 8, 2024. It is now read-only.
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
4 changes: 2 additions & 2 deletions src/Hl7.Fhir.ElementModel/Hl7.Fhir.ElementModel.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>net5.0;net45;netstandard1.6;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net5.0;net452;netstandard1.6;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\firely-net-common.props" />
Expand All @@ -15,7 +15,7 @@
<AssemblyName>Hl7.Fhir.ElementModel</AssemblyName>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'netstandard1.6'">
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' or '$(TargetFramework)' == 'netstandard1.6'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Hl7.Fhir.Serialization/Hl7.Fhir.Serialization.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0;net45;netstandard1.6;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net5.0;net452;netstandard1.6;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\firely-net-common.props" />
Expand Down
18 changes: 13 additions & 5 deletions src/Hl7.Fhir.Serialization/Utility/SerializationUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -51,9 +52,9 @@ private static XDocument XDocumentFromReaderInternal(XmlReader reader, bool igno

public static XDocument XDocumentFromReader(XmlReader reader, bool ignoreComments = true)
=> XDocumentFromReaderInternal(WrapXmlReader(reader, ignoreComments));

public static Task<XDocument> XDocumentFromReaderAsync(XmlReader reader, bool ignoreComments = true)
=> Task.FromResult(XDocumentFromReaderInternal(WrapXmlReader(reader, ignoreComments, async:true)));
=> Task.FromResult(XDocumentFromReaderInternal(WrapXmlReader(reader, ignoreComments, async: true)));

/// <inheritdoc cref="JObjectFromReaderAsync(JsonReader)" />
public static JObject JObjectFromReader(JsonReader reader)
Expand Down Expand Up @@ -125,9 +126,9 @@ public static async Task<JObject> JObjectFromJsonTextAsync(string json)

public static XmlReader XmlReaderFromXmlText(string xml, bool ignoreComments = true)
=> WrapXmlReader(XmlReader.Create(new StringReader(SerializationUtil.SanitizeXml(xml))), ignoreComments);

public static Task<XmlReader> XmlReaderFromXmlTextAsync(string xml, bool ignoreComments = true)
=> Task.FromResult(WrapXmlReader(XmlReader.Create(new StringReader(SerializationUtil.SanitizeXml(xml))), ignoreComments, async:true));
=> Task.FromResult(WrapXmlReader(XmlReader.Create(new StringReader(SerializationUtil.SanitizeXml(xml))), ignoreComments, async: true));

public static JsonReader JsonReaderFromJsonText(string json)
=> JsonReaderFromTextReader(new StringReader(json));
Expand Down Expand Up @@ -262,7 +263,7 @@ public static XDocument WriteXmlToDocument(Action<XmlWriter> serializer)

return doc;
}

public static async Task<XDocument> WriteXmlToDocumentAsync(Func<XmlWriter, Task> serializer)
{
var doc = new XDocument();
Expand Down Expand Up @@ -472,8 +473,15 @@ public static string[] RunFhirXhtmlSchemaValidation(XDocument doc)
if (!doc.Root.AtXhtmlDiv())
return new[] { $"Root element of XHTML is not a <div> from the XHTML namespace ({XmlNs.XHTML})." };

if (!hasContent(doc.Root))
return new[] { $"The narrative SHALL have some non-whitespace content." };

doc.Validate(_xhtmlSchemaSet.Value, (s, a) => result.Add(a.Message));
return result.ToArray();

// content consist of xml elements with non-whitespace content (text or an image)
static bool hasContent(XElement el)
=> el.DescendantsAndSelf().Any(e => !string.IsNullOrWhiteSpace(e.Value) || e.Name.LocalName == "img");
}

private static Lazy<XmlSchemaSet> _xhtmlSchemaSet = new Lazy<XmlSchemaSet>(compileXhtmlSchema, true);
Expand Down
6 changes: 3 additions & 3 deletions src/Hl7.Fhir.Support.Poco/Hl7.Fhir.Support.Poco.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net45;netstandard1.6;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net5.0;net452;netstandard1.6;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\firely-net-common.props" />
Expand All @@ -16,11 +16,11 @@
<AssemblyName>Hl7.Fhir.Support.Poco</AssemblyName>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net45'">
<ItemGroup Condition=" '$(TargetFramework)' != 'net452'">
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45'">
<ItemGroup Condition=" '$(TargetFramework)' == 'net452'">
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Net.Http"/>
</ItemGroup>
Expand Down
33 changes: 28 additions & 5 deletions src/Hl7.Fhir.Support.Tests/FhirPath/FhirPathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE
*/

using FluentAssertions;
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.FhirPath;
using Hl7.FhirPath;
using Hl7.FhirPath.Expressions;
Expand All @@ -17,19 +19,40 @@ namespace Hl7.Fhir.Support.Tests
[TestClass]
public class FhirPathTests
{
[TestMethod]
public void ResolveOnEmptyTest()
private static FhirPathCompiler _compiler;

[ClassInitialize]
public static void ClassSetup(TestContext context)
{
// resolve should handle an empty collection as input
var symbolTable = new SymbolTable();
symbolTable.AddStandardFP();
symbolTable.AddFhirExtensions();
var compiler = new FhirPathCompiler(symbolTable);
var evaluator = compiler.Compile("{}.resolve()");
_compiler = new FhirPathCompiler(symbolTable);
}

[TestMethod]
public void ResolveOnEmptyTest()
{
// resolve should handle an empty collection as input
var evaluator = _compiler.Compile("{}.resolve()");
var result = evaluator(null, FhirEvaluationContext.CreateDefault());

Assert.IsFalse(result.Any());
}

[DataTestMethod]
[DataRow("<div>Not empty</div>", false, "no XHTML namespace")]
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\"> </div>", false, "containing only whitespace")]
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\">\t\n</div>", false, "containing only whitespace")]
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\"></div>", false, "empty div element")]
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\">Not empty</div>", true, "non empty div element with XHTML namespace")]
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\"><img src=\"fhir.gif\" alt=\"Fhir gif\"></img></div>", true, "containing an image element")]
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b><i> </i></b></p></div>", false, "no text")]
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b><i> </i></b><img src=\"fhir.gif\" alt=\"Fhir gif\"></img></p></div>", true, "containing an image element")]
public void HtmlChecks(string xml, bool expected, string because)
{
var evaluator = _compiler.Compile("htmlChecks()");
evaluator.Predicate(ElementNode.ForPrimitive(xml), FhirEvaluationContext.CreateDefault()).Should().Be(expected, because);
}
}
}
2 changes: 1 addition & 1 deletion src/Hl7.Fhir.Support.Tests/Hl7.Fhir.Support.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net40' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace Hl7.Fhir.Support.Tests
{
[Obsolete("The class `ObjectListExtensions` is obsolete and will be removed in the next major release. Obsolete since 2021-09-22")]
[TestClass]

public class ObjectListExtensionTests
{
[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions src/Hl7.Fhir.Support/Hl7.Fhir.Support.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0;net45;netstandard1.6;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net5.0;net452;netstandard1.6;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\firely-net-common.props" />
Expand All @@ -15,7 +15,7 @@
<AssemblyName>Hl7.Fhir.Support</AssemblyName>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net45'">
<ItemGroup Condition=" '$(TargetFramework)' != 'net452'">
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion src/Hl7.Fhir.Support/Utility/ObjectList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Hl7.Fhir.Utility
{
public static class ObjectListExtensions
{
[Obsolete("This method is obsolete and will be removed in the next major release. Obsolete since 2021-09-22")]
public static IEnumerable<object> OfType(this IEnumerable<object> me, Type t)
{
return me.Where(e => e.GetType() == t);
}

[Obsolete("This method is obsolete and will be removed in the next major release. Obsolete since 2021-09-22")]
public static void RemoveOfType(this IList<object> me, Type t)
{
var annotations = me.OfType(t).ToArray();
Expand Down
8 changes: 4 additions & 4 deletions src/Hl7.Fhir.Support/Utility/SemVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Hl7.Fhir.Utility
/// A semantic version implementation.
/// Conforms with v2.0.0 of http://semver.org
/// </summary>
#if !NET45
#if !NET452
public sealed class SemVersion : IComparable<SemVersion>, IComparable
#else
[Serializable]
Expand All @@ -27,14 +27,14 @@ public sealed class SemVersion : IComparable<SemVersion>, IComparable, ISerializ
@"(?>\.(?<patch>\d+))?" +
@"(?>\-(?<pre>[0-9A-Za-z\-\.]+))?" +
@"(?>\+(?<build>[0-9A-Za-z\-\.]+))?$",
#if !NET45
#if !NET452
RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture
#else
RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.ExplicitCapture
#endif
);

#if NET45
#if NET452
#pragma warning disable CA1801 // Parameter unused
/// <summary>
/// Deserialize a <see cref="SemVersion"/>.
Expand Down Expand Up @@ -479,7 +479,7 @@ public override int GetHashCode()
}
}

#if NET45
#if NET452
/// <summary>
/// Populates a <see cref="SerializationInfo"/> with the data needed to serialize the target object.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Hl7.FhirPath/Hl7.FhirPath.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0;net45;netstandard1.6;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net5.0;net452;netstandard1.6;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\firely-net-common.props" />
Expand Down