Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update fhir net api version to 2.0.3 #97

Merged
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<Version>2.1.0</Version>
<Version>2.2.0</Version>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hl7.Fhir.R4" Version="1.7.0" />
<PackageReference Include="Hl7.FhirPath" Version="1.7.0" />
<PackageReference Include="Hl7.Fhir.R4" Version="2.0.3" />
<PackageReference Include="Hl7.FhirPath" Version="2.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<ItemGroup>
<PackageReference Include="Ensure.That" Version="9.2.0" />
<PackageReference Include="Hl7.Fhir.R4" Version="1.7.0" />
<PackageReference Include="Hl7.FhirPath" Version="1.7.0" />
<PackageReference Include="Hl7.Fhir.R4" Version="2.0.3" />
<PackageReference Include="Hl7.FhirPath" Version="2.0.3" />
<PackageReference Include="MathNet.Numerics" Version="4.11.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hl7.Fhir.R4" Version="1.7.0" />
<PackageReference Include="Hl7.FhirPath" Version="1.7.0" />
<PackageReference Include="Hl7.Fhir.R4" Version="2.0.3" />
<PackageReference Include="Hl7.FhirPath" Version="2.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using Hl7.FhirPath;
using Hl7.Fhir.ElementModel;
using Microsoft.Health.Fhir.Anonymizer.Core;
using Microsoft.Health.Fhir.Anonymizer.Core.Extensions;
using Xunit;
Expand Down Expand Up @@ -29,9 +30,14 @@ public static IEnumerable<object[]> GetR4OnlyResources()
yield return new object[] { "R4OnlyResource/ServiceRequest.json", "R4OnlyResource/ServiceRequest-target.json" };
}

public static IEnumerable<object[]> GetCommonResourcesWithStu3OnlyField()
public static IEnumerable<object[]> GetCommonResourcesWithStu3OnlyValue()
{
yield return new object[] { "Stu3OnlyResource/Claim-Stu3.json" };

}

public static IEnumerable<object[]> GetCommonResourcesWithStu3OnlyElement()
BoyaWu10 marked this conversation as resolved.
Show resolved Hide resolved
{
yield return new object[] { "Stu3OnlyResource/Account-Stu3.json" };
yield return new object[] { "Stu3OnlyResource/Contract-Stu3.json" };
}
Expand Down Expand Up @@ -72,15 +78,25 @@ public void GivenCommonResourceWithR4OnlyField_WhenAnonymizing_AnonymizedJsonSho
}

[Theory]
[MemberData(nameof(GetCommonResourcesWithStu3OnlyField))]
public void GivenCommonResourceWithStu3OnlyField_WhenAnonymizing_ExceptionShouldBeThrown(string testFile)
[MemberData(nameof(GetCommonResourcesWithStu3OnlyValue))]
public void GivenCommonResourceWithStu3OnlyValue_WhenAnonymizing_ExceptionShouldBeThrown(string testFile)
{
AnonymizerEngine engine = new AnonymizerEngine("r4-configuration-sample.json");
string testContent = File.ReadAllText(ResourceTestsFile(testFile));

Assert.Throws<FormatException>(() => engine.AnonymizeJson(testContent));
}

[Theory]
[MemberData(nameof(GetCommonResourcesWithStu3OnlyElement))]
public void GivenCommonResourceWithStu3OnlyElement_WhenAnonymizing_ExceptionShouldBeThrown(string testFile)
{
AnonymizerEngine engine = new AnonymizerEngine("r4-configuration-sample.json");
string testContent = File.ReadAllText(ResourceTestsFile(testFile));

Assert.Throws<StructuralTypeException>(() => engine.AnonymizeJson(testContent));
}

private string ResourceTestsFile(string fileName)
{
return Path.Combine("TestResources", fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void GivenListOfPrimitiveElementNodes_WhenGetDecendantsByType_AllNodesSho
FhirBoolean boolean = new FhirBoolean();
FhirString fhirString = new FhirString();

var nodes = new Primitive[] { date, instant, boolean, fhirString }.Select(n => ElementNode.FromElement(n.ToTypedElement()));
var nodes = new PrimitiveType[] { date, instant, boolean, fhirString }.Select(n => ElementNode.FromElement(n.ToTypedElement()));

var results = FhirPathSymbolExtensions.NodesByType(nodes, "string").Select(n => n.Location);
Assert.Single(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ public static IEnumerable<object[]> GetEmptyNodesToGeneralize()

public static IEnumerable<object[]> GetIntegerNodesToGeneralizeWithRangeMapping()
{
yield return new object[] { new Integer(5), (long)20 };
yield return new object[] { new Integer(20), (long)40 };
yield return new object[] { new Integer(43), (long)60 };
yield return new object[] { new Integer(78), (long)80 };
yield return new object[] { new Integer(5), 20 };
yield return new object[] { new Integer(20), 40 };
yield return new object[] { new Integer(43), 60 };
yield return new object[] { new Integer(78), 80 };
yield return new object[] { new Integer(110), null, "Redact"};
yield return new object[] { new Integer(110), 110, "Keep" };
}

public static IEnumerable<object[]> GetIntegerNodesToGeneralizeWithApproximate()
{
yield return new object[] { new Integer(5), (long)-10 };
yield return new object[] { new Integer(20), (long)10 };
yield return new object[] { new Integer(43), (long)30 };
yield return new object[] { new Integer(78), (long)60 };
yield return new object[] { new Integer(5), -10 };
yield return new object[] { new Integer(20), 10 };
yield return new object[] { new Integer(43), 30 };
yield return new object[] { new Integer(78), 60 };
yield return new object[] { new Integer(110), null, "Redact" };
yield return new object[] { new Integer(110), 110, "Keep" };
yield return new object[] { new PositiveInt(24), (long)10 };
yield return new object[] { new UnsignedInt(24), (long)10 };
yield return new object[] { new PositiveInt(24), 10 };
yield return new object[] { new UnsignedInt(24), 10 };
}

public static IEnumerable<object[]> GetStringNodesToGeneralizeWithValueSet()
Expand All @@ -67,11 +67,14 @@ public static IEnumerable<object[]> GetDateNodesToGeneralizeWithRangeMapping()
yield return new object[] { new Date("1990-01-01"), "1990" };
yield return new object[] { new Date("2000-01-01"), null, "Redact" };
yield return new object[] { new Date("1990"), "1990", "Redact" };
yield return new object[] { new Date("2000"), null, "Redact" };
yield return new object[] { new Date("2010"), "2010-01-01", "Redact" };
yield return new object[] { new Date("2010-01-01"), null, "Redact" };
yield return new object[] { new Date("2000"), "1990", "Redact" };
yield return new object[] { new Date("2000-01-01"), null};
yield return new object[] { new Date("2010"), "2010-01-01"};
yield return new object[] { new Date("2010-01-01"), "2010-01-01" };
yield return new object[] { new Date("2010-01-02"), "2010-01-01" };
yield return new object[] { new Date("2020"), "2020-01-01" };
yield return new object[] { new Date("2020-05-20"), "2020-01-01" };
yield return new object[] { new Date("2020-01-01"), null, "Redact" };
yield return new object[] { new Date("2020-05-20"), null, "Redact" };
yield return new object[] { new Date("2021-05-20"), "2021-05-20", "Keep" };
}

Expand All @@ -88,10 +91,11 @@ public static IEnumerable<object[]> GetDateTimeNodesToGeneralizeWithRangeMapping
yield return new object[] { new FhirDateTime("2010-01-01"), null };
yield return new object[] { new FhirDateTime("2010-01-01T00:00:00Z"), null };
yield return new object[] { new FhirDateTime("2010-01-01T00:00:00+08:00"), "2010-01-01" };
yield return new object[] { new FhirDateTime("2010-01-01T00:00:00+08:00"), "2010-01-01" };
yield return new object[] { new FhirDateTime("2010-01-01T00:00:00+09:00"), null };
yield return new object[] { new FhirDateTime("2009-12-31T16:00:00Z"), "2010-01-01" };
yield return new object[] { new FhirDateTime("2020-01-01T00:00:00+08:00"), "2020-01-01" };
yield return new object[] { new FhirDateTime("2020-01-01"), "2020-01-01" };
yield return new object[] { new FhirDateTime("2020-01-01T00:00:00"), "2020-01-01" };
yield return new object[] { new FhirDateTime("2020-01-01T00:00:00+08:00"), null};
yield return new object[] { new FhirDateTime("2020-01-01"), null };
}

public static IEnumerable<object[]> GetTimeNodesToGeneralizeWithRangeMapping()
Expand Down Expand Up @@ -127,14 +131,18 @@ public static IEnumerable<object[]> GetDateTimeNodesToGeneralizeWithOmitDay()

public static IEnumerable<object[]> GetInvalidCasesExpressions()
{
yield return new object[] { new Integer(5), "{\"$this>='0' and $this<'20'\":\"20\"}" };
yield return new object[] { new Integer(5), "{\"$this>=0 and $this<20\":\"$this / 2\"}" };
yield return new object[] { new Integer(5), "{\"$this<5.5\":\"$this\"}" };
yield return new object[] { new Integer(5), "{\"$this>='0' and $this<'20'\":\"20\"}" };
yield return new object[] { new FhirDateTime("2015-01-01T00:00:00Z"), "{\"$this > @2015-1-1\":\"@2015-01-01\"}" };
yield return new object[] { new Date("2015-01-01"), "{\"$this > @2015-1-1\":\"@2015-01-01\"}" };
yield return new object[] { new FhirString("2015-01-01"), "{\"$this > @2015-01-01\":\"@2015-01-01\"}" };
}

public static IEnumerable<object[]> GetIntegerDecimalComparingCases()
{
yield return new object[] { new Integer(5), "{\"$this>=0 and $this<20\":\"$this / 2\"}", (decimal)2.5 };
yield return new object[] { new Integer(5), "{\"$this<5.5\":\"$this\"}", 5 };
}

public static IEnumerable<object[]> GetNodesToGeneralizeWithConflictSettings()
{
yield return new object[] { new Integer(18), 20 };
Expand Down Expand Up @@ -263,6 +271,25 @@ public void GivenAnIntegerNode_WhenGeneralizedWithApproximate_GeneralizedNodeSho
Assert.Equal(target, node.Value);
}


[Theory]
[MemberData(nameof(GetIntegerDecimalComparingCases))]
public void GivenIntegerDecimalComparingCases_WhenGeneralized_GeneralizedNodeShouldBeReturned(Base data, string cases, object target)
{
var node = ElementNode.FromElement(data.ToTypedElement());

GeneralizeProcessor processor = new GeneralizeProcessor();
var context = new ProcessContext
{
VisitedNodes = new HashSet<ElementNode>()
};
var settings = new Dictionary<string, object> { { "cases", cases } };

var processResult = processor.Process(node, context, settings);
Assert.True(processResult.IsGeneralized);
Assert.Equal(target, node.Value);
}

[Theory]
[MemberData(nameof(GetStringNodesToGeneralizeWithValueSet))]
public void GivenAStringNode_WhenGeneralizedWithValueSet_GeneralizedNodeShouldBeReturned(Base data, object target, string otherValues = "redact")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static IEnumerable<object[]> GetQuantityNodesToPerturbFixedSpan()
};
yield return new object[]
{
new SimpleQuantity { Value = decimal.Parse("25,162.1378") },
new Quantity { Value = decimal.Parse("25,162.1378") },
2.26,
2,
25161.01,
Expand Down Expand Up @@ -134,7 +134,7 @@ public static IEnumerable<object[]> GetQuantityNodesToPerturbProportionalSpan()
};
yield return new object[]
{
new SimpleQuantity { Value = decimal.Parse("25,162.1378") },
new Quantity { Value = decimal.Parse("25,162.1378") },
1,
2,
12581.07,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static IEnumerable<object[]> GetGeneralizeFhirRuleConfigs()
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this<=10 and $this>=0\": \"10\"}" }, { "otherValues", "Keep" } }, "{\r\n \"$this<=10 and $this>=0\": \"10\"\r\n}", "Keep" };
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this<=10 and $this>=0\": \"10\"}" }, { "otherValues", "Redact" } }, "{\r\n \"$this<=10 and $this>=0\": \"10\"\r\n}", "Redact" };
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"\": \"\"}" }, { "otherValues", "Redact" } }, "{\r\n \"\": \"\"\r\n}", "Redact" };
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this = @2015-01-01T00:00\": \"@2015-01-01T00:00:00Z\"}" } }, "{\r\n \"$this = @2015-01-01T00:00\": \"@2015-01-01T00:00:00Z\"\r\n}", "Redact" };
}

public static IEnumerable<object[]> GetInvalidGeneralizeFhirRuleConfigs()
Expand All @@ -23,7 +24,6 @@ public static IEnumerable<object[]> GetInvalidGeneralizeFhirRuleConfigs()
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this sub 1\": \"10\"}" } } };
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this<10\"+ \"10++\"}" } } };
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this<10\": \"10\"}" }, { "otherValues", "unknown" } } };
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this = @2015-01-01T00:00\": \"@2015-01-01T00:00:00Z\"}" }} };
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"\": \"\"}" }, { "otherValues", "Redact" } } };
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "otherValues", "Keep" } } };
yield return new object[] { new Dictionary<string, object>() { { "path", "Patient.birthDate" }, { "cases", "{\"$this<10\": \"10\"}" }, { "otherValues", "Keep" } } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ private Observation CreateTestObservation()
observation.ReferenceRange.Add(
new Observation.ReferenceRangeComponent
{
Low = new SimpleQuantity { Value = 10, Unit = "TestUnit" },
High = new SimpleQuantity { Value = 100},
Low = new Quantity { Value = 10, Unit = "TestUnit" },
High = new Quantity { Value = 100},
});
return observation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.FhirPath;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Support.Model;
using Microsoft.Health.Fhir.Anonymizer.Core.Models;
using Microsoft.Health.Fhir.Anonymizer.Core.Processors.Settings;
using Microsoft.Health.Fhir.Anonymizer.Core.AnonymizerConfigurations;
Expand All @@ -27,7 +25,6 @@ public ProcessResult Process(ElementNode node, ProcessContext context = null, Di
}

var generalizeSetting = GeneralizeSetting.CreateFromRuleSettings(settings);
node.Value = PrimitiveTypeConverter.ConvertTo(node.Value, Primitives.GetNativeRepresentation(node.InstanceType));
foreach (var eachCase in generalizeSetting.Cases)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Hl7.Fhir.STU3" Version="1.7.0" />
<PackageReference Include="Hl7.FhirPath" Version="1.7.0" />
<PackageReference Include="Hl7.Fhir.STU3" Version="2.0.3" />
<PackageReference Include="Hl7.FhirPath" Version="2.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<ItemGroup>
<PackageReference Include="Ensure.That" Version="9.2.0" />
<PackageReference Include="Hl7.Fhir.STU3" Version="1.7.0" />
<PackageReference Include="Hl7.FhirPath" Version="1.7.0" />
<PackageReference Include="Hl7.Fhir.STU3" Version="2.0.3" />
<PackageReference Include="Hl7.FhirPath" Version="2.0.3" />
<PackageReference Include="MathNet.Numerics" Version="4.11.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Hl7.Fhir.STU3" Version="1.7.0" />
<PackageReference Include="Hl7.FhirPath" Version="1.7.0" />
<PackageReference Include="Hl7.Fhir.STU3" Version="2.0.3" />
<PackageReference Include="Hl7.FhirPath" Version="2.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
Loading