From 29fbc6b7189f02cde6f151f210ef82634b670105 Mon Sep 17 00:00:00 2001 From: YanhuiHong Date: Mon, 22 Feb 2021 16:47:35 +0800 Subject: [PATCH 1/3] update fhir net api version to 2.0.3 --- Directory.Build.props | 2 +- README.md | 2 +- ...h.Fhir.Anonymizer.R4.Core.UnitTests.csproj | 4 +- ...soft.Health.Fhir.Anonymizer.R4.Core.csproj | 4 +- ....Fhir.Anonymizer.R4.FunctionalTests.csproj | 4 +- .../VersionSpecificTests.cs | 22 +++++- .../FhirPathSymbolExtensionsTests.cs | 2 +- .../Processors/GeneralizeProcessorTests.cs | 67 +++++++++++++------ .../Processors/PerturbProcessorTests.cs | 4 +- .../Settings/GeneralizeSettingTests.cs | 2 +- .../Visitors/AnonymizationVisitorTests.cs | 4 +- .../Processors/GeneralizeProcessor.cs | 3 - ...Fhir.Anonymizer.Stu3.Core.UnitTests.csproj | 4 +- ...ft.Health.Fhir.Anonymizer.Stu3.Core.csproj | 4 +- ...hir.Anonymizer.Stu3.FunctionalTests.csproj | 4 +- .../VersionSpecificTests.cs | 27 ++++++-- 16 files changed, 107 insertions(+), 52 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 131fdbcf..56cf7036 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 2.1.0 + 2.2.0 diff --git a/README.md b/README.md index 1648fd45..a7526699 100644 --- a/README.md +++ b/README.md @@ -493,7 +493,7 @@ There are a few parameters that can help you customize the noise amount for diff - [optional] **rangeType** Define whether the *span* value is *fixed* or *proportional*. The default value is *fixed*. - [optional] **roundTo** A value from 0 to 28 that specifies the number of decimal places to round to. The default value is *0* for integer types and *2* for decimal types. -Note that the target field should be of either a numeric type (integer, decimal, unsignedInt, positiveInt) or a quantity type (Quantity, SimpleQuantity, Money, etc.). +Note that the target field should be of either a numeric type (integer, decimal, unsignedInt, positiveInt) or a quantity type (Quantity). ## Generalize method As one of the anonymization methods, generalization means mapping values to the higher level of generalization. It is the process of abstracting distinguishing value into a more general, less distinguishing value. Generalization attempts to preserve data utility while also reducing the identifiability of the data. diff --git a/src/Microsoft.Health.Fhir.Anonymizer.R4.Core.UnitTests/Microsoft.Health.Fhir.Anonymizer.R4.Core.UnitTests.csproj b/src/Microsoft.Health.Fhir.Anonymizer.R4.Core.UnitTests/Microsoft.Health.Fhir.Anonymizer.R4.Core.UnitTests.csproj index ee8ec38a..9912e4c2 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.R4.Core.UnitTests/Microsoft.Health.Fhir.Anonymizer.R4.Core.UnitTests.csproj +++ b/src/Microsoft.Health.Fhir.Anonymizer.R4.Core.UnitTests/Microsoft.Health.Fhir.Anonymizer.R4.Core.UnitTests.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/Microsoft.Health.Fhir.Anonymizer.R4.Core/Microsoft.Health.Fhir.Anonymizer.R4.Core.csproj b/src/Microsoft.Health.Fhir.Anonymizer.R4.Core/Microsoft.Health.Fhir.Anonymizer.R4.Core.csproj index 55b4d42e..ba30b716 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.R4.Core/Microsoft.Health.Fhir.Anonymizer.R4.Core.csproj +++ b/src/Microsoft.Health.Fhir.Anonymizer.R4.Core/Microsoft.Health.Fhir.Anonymizer.R4.Core.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/src/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests.csproj b/src/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests.csproj index 7307c1a0..d1a9bb9f 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests.csproj +++ b/src/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests/VersionSpecificTests.cs b/src/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests/VersionSpecificTests.cs index 35f3d064..c9048dee 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests/VersionSpecificTests.cs +++ b/src/Microsoft.Health.Fhir.Anonymizer.R4.FunctionalTests/VersionSpecificTests.cs @@ -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; @@ -29,9 +30,14 @@ public static IEnumerable GetR4OnlyResources() yield return new object[] { "R4OnlyResource/ServiceRequest.json", "R4OnlyResource/ServiceRequest-target.json" }; } - public static IEnumerable GetCommonResourcesWithStu3OnlyField() + public static IEnumerable GetCommonResourcesWithStu3OnlyValue() { yield return new object[] { "Stu3OnlyResource/Claim-Stu3.json" }; + + } + + public static IEnumerable GetCommonResourcesWithStu3OnlyElement() + { yield return new object[] { "Stu3OnlyResource/Account-Stu3.json" }; yield return new object[] { "Stu3OnlyResource/Contract-Stu3.json" }; } @@ -72,8 +78,8 @@ 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)); @@ -81,6 +87,16 @@ public void GivenCommonResourceWithStu3OnlyField_WhenAnonymizing_ExceptionShould Assert.Throws(() => 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(() => engine.AnonymizeJson(testContent)); + } + private string ResourceTestsFile(string fileName) { return Path.Combine("TestResources", fileName); diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Extensions/FhirPathSymbolExtensionsTests.cs b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Extensions/FhirPathSymbolExtensionsTests.cs index a75e50c9..e329c6ba 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Extensions/FhirPathSymbolExtensionsTests.cs +++ b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Extensions/FhirPathSymbolExtensionsTests.cs @@ -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); diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/GeneralizeProcessorTests.cs b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/GeneralizeProcessorTests.cs index e1e6e0f0..8b4c5e32 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/GeneralizeProcessorTests.cs +++ b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/GeneralizeProcessorTests.cs @@ -24,24 +24,24 @@ public static IEnumerable GetEmptyNodesToGeneralize() public static IEnumerable 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 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 GetStringNodesToGeneralizeWithValueSet() @@ -67,11 +67,14 @@ public static IEnumerable 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, "Redact" }; + 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" }; } @@ -88,10 +91,11 @@ public static IEnumerable 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 GetTimeNodesToGeneralizeWithRangeMapping() @@ -127,14 +131,18 @@ public static IEnumerable GetDateTimeNodesToGeneralizeWithOmitDay() public static IEnumerable 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 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 GetNodesToGeneralizeWithConflictSettings() { yield return new object[] { new Integer(18), 20 }; @@ -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() + }; + var settings = new Dictionary { { "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") diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/PerturbProcessorTests.cs b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/PerturbProcessorTests.cs index dbaf2dde..06e042fe 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/PerturbProcessorTests.cs +++ b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/PerturbProcessorTests.cs @@ -90,7 +90,7 @@ public static IEnumerable 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, @@ -134,7 +134,7 @@ public static IEnumerable 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, diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/Settings/GeneralizeSettingTests.cs b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/Settings/GeneralizeSettingTests.cs index b16503f8..3ac9bb70 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/Settings/GeneralizeSettingTests.cs +++ b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/Settings/GeneralizeSettingTests.cs @@ -14,6 +14,7 @@ public static IEnumerable GetGeneralizeFhirRuleConfigs() yield return new object[] { new Dictionary() { { "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() { { "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() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"\": \"\"}" }, { "otherValues", "Redact" } }, "{\r\n \"\": \"\"\r\n}", "Redact" }; + yield return new object[] { new Dictionary() { { "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 GetInvalidGeneralizeFhirRuleConfigs() @@ -23,7 +24,6 @@ public static IEnumerable GetInvalidGeneralizeFhirRuleConfigs() yield return new object[] { new Dictionary() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this sub 1\": \"10\"}" } } }; yield return new object[] { new Dictionary() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this<10\"+ \"10++\"}" } } }; yield return new object[] { new Dictionary() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this<10\": \"10\"}" }, { "otherValues", "unknown" } } }; - yield return new object[] { new Dictionary() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"$this = @2015-01-01T00:00\": \"@2015-01-01T00:00:00Z\"}" }} }; yield return new object[] { new Dictionary() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "cases", "{\"\": \"\"}" }, { "otherValues", "Redact" } } }; yield return new object[] { new Dictionary() { { "path", "Patient.birthDate" }, { "method", "generalize" }, { "otherValues", "Keep" } } }; yield return new object[] { new Dictionary() { { "path", "Patient.birthDate" }, { "cases", "{\"$this<10\": \"10\"}" }, { "otherValues", "Keep" } } }; diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Visitors/AnonymizationVisitorTests.cs b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Visitors/AnonymizationVisitorTests.cs index b609852a..236b6381 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Visitors/AnonymizationVisitorTests.cs +++ b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Visitors/AnonymizationVisitorTests.cs @@ -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; } diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core/Processors/GeneralizeProcessor.cs b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core/Processors/GeneralizeProcessor.cs index 68b24099..3a21c2fc 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core/Processors/GeneralizeProcessor.cs +++ b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core/Processors/GeneralizeProcessor.cs @@ -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; @@ -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 diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.UnitTests/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.UnitTests.csproj b/src/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.UnitTests/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.UnitTests.csproj index a618f1dc..218c702a 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.UnitTests/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.UnitTests.csproj +++ b/src/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.UnitTests/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.UnitTests.csproj @@ -11,8 +11,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Stu3.Core/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.csproj b/src/Microsoft.Health.Fhir.Anonymizer.Stu3.Core/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.csproj index 8604c55a..19adf75c 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Stu3.Core/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.csproj +++ b/src/Microsoft.Health.Fhir.Anonymizer.Stu3.Core/Microsoft.Health.Fhir.Anonymizer.Stu3.Core.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests.csproj b/src/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests.csproj index ef8956b5..4e11e7c5 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests.csproj +++ b/src/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests.csproj @@ -11,8 +11,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests/VersionSpecificTests.cs b/src/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests/VersionSpecificTests.cs index 6a9d2e1a..a2f6e131 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests/VersionSpecificTests.cs +++ b/src/Microsoft.Health.Fhir.Anonymizer.Stu3.FunctionalTests/VersionSpecificTests.cs @@ -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; @@ -36,12 +37,17 @@ public static IEnumerable GetCommonResourcesWithStu3OnlyField() yield return new object[] { "Stu3OnlyResource/Contract-Stu3.json", "Stu3OnlyResource/Contract-Stu3-target.json" }; } - public static IEnumerable GetCommonResourcesWithR4OnlyField() + public static IEnumerable GetCommonResourcesWithR4OnlyValue() { yield return new object[] { "R4OnlyResource/Claim-R4.json" }; - yield return new object[] { "R4OnlyResource/Account-R4.json" }; + } + + public static IEnumerable GetCommonResourcesWithR4OnlyElement() + { yield return new object[] { "R4OnlyResource/Contract-R4.json" }; - } + yield return new object[] { "R4OnlyResource/Account-R4.json" }; + + } [Theory] [MemberData(nameof(GetR4OnlyResources))] @@ -72,14 +78,23 @@ public void GivenCommonResourceWithStu3OnlyField_WhenAnonymizing_AnonymizedJsonS } [Theory] - [MemberData(nameof(GetCommonResourcesWithR4OnlyField))] - public void GivenCommonResourceWithR4OnlyField_WhenAnonymizing_ExceptionShouldBeThrown(string testFile) - { + [MemberData(nameof(GetCommonResourcesWithR4OnlyValue))] + public void GivenCommonResourceWithR4OnlyValue_WhenAnonymizing_ExceptionShouldBeThrown(string testFile) + { AnonymizerEngine engine = new AnonymizerEngine("stu3-configuration-sample.json"); string testContent = File.ReadAllText(ResourceTestsFile(testFile)); Assert.Throws(() => engine.AnonymizeJson(testContent)); } + [Theory] + [MemberData(nameof(GetCommonResourcesWithR4OnlyElement))] + public void GivenCommonResourceWithR4OnlyElement_WhenAnonymizing_ExceptionShouldBeThrown(string testFile) + { + AnonymizerEngine engine = new AnonymizerEngine("stu3-configuration-sample.json"); + string testContent = File.ReadAllText(ResourceTestsFile(testFile)); + Assert.Throws(() => engine.AnonymizeJson(testContent)); + } + private string ResourceTestsFile(string fileName) { return Path.Combine("TestResources", fileName); From eea0edca2afac7b0eff52fa46341f0ff88cade68 Mon Sep 17 00:00:00 2001 From: YanhuiHong Date: Tue, 23 Feb 2021 18:31:31 +0800 Subject: [PATCH 2/3] fix bug --- .../Processors/GeneralizeProcessorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/GeneralizeProcessorTests.cs b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/GeneralizeProcessorTests.cs index 8b4c5e32..43d6ea3d 100644 --- a/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/GeneralizeProcessorTests.cs +++ b/src/Microsoft.Health.Fhir.Anonymizer.Shared.Core.UnitTests/Processors/GeneralizeProcessorTests.cs @@ -68,7 +68,7 @@ public static IEnumerable GetDateNodesToGeneralizeWithRangeMapping() 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"), "1990", "Redact" }; - yield return new object[] { new Date("2000-01-01"), null, "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" }; From 7b46f4a07af8a47e13852c248f6d15df66460625 Mon Sep 17 00:00:00 2001 From: YanhuiHong Date: Tue, 9 Mar 2021 16:11:31 +0800 Subject: [PATCH 3/3] unchange readme.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a7526699..1648fd45 100644 --- a/README.md +++ b/README.md @@ -493,7 +493,7 @@ There are a few parameters that can help you customize the noise amount for diff - [optional] **rangeType** Define whether the *span* value is *fixed* or *proportional*. The default value is *fixed*. - [optional] **roundTo** A value from 0 to 28 that specifies the number of decimal places to round to. The default value is *0* for integer types and *2* for decimal types. -Note that the target field should be of either a numeric type (integer, decimal, unsignedInt, positiveInt) or a quantity type (Quantity). +Note that the target field should be of either a numeric type (integer, decimal, unsignedInt, positiveInt) or a quantity type (Quantity, SimpleQuantity, Money, etc.). ## Generalize method As one of the anonymization methods, generalization means mapping values to the higher level of generalization. It is the process of abstracting distinguishing value into a more general, less distinguishing value. Generalization attempts to preserve data utility while also reducing the identifiability of the data.