From fab4eadf91a24e6d45597307b0a9f225d9c70dad Mon Sep 17 00:00:00 2001 From: Lina Roth Date: Thu, 12 Dec 2024 10:18:10 -0500 Subject: [PATCH 1/7] add to_json_string so it will bring periods with value --- data/Templates/eCR/Entry/SocialHistory/_entry.liquid | 2 ++ data/Templates/eCR/Utils/_ValueHelper.liquid | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/data/Templates/eCR/Entry/SocialHistory/_entry.liquid b/data/Templates/eCR/Entry/SocialHistory/_entry.liquid index fdd8c7db..3da4795b 100644 --- a/data/Templates/eCR/Entry/SocialHistory/_entry.liquid +++ b/data/Templates/eCR/Entry/SocialHistory/_entry.liquid @@ -17,6 +17,8 @@ {% include 'Resource/ObservationPregnancyStatus' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%} {% elsif entry.observation.code.code == '76690-7' -%} {% include 'Resource/ObservationSexualOrientation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%} + {% elsif entry.observation.code.code == '897148007' -%} + {% include 'Resource/Observation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%} {% else -%} {% include 'Resource/Observation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%} {% endif -%} diff --git a/data/Templates/eCR/Utils/_ValueHelper.liquid b/data/Templates/eCR/Utils/_ValueHelper.liquid index 37132838..5993fe2c 100644 --- a/data/Templates/eCR/Utils/_ValueHelper.liquid +++ b/data/Templates/eCR/Utils/_ValueHelper.liquid @@ -9,7 +9,7 @@ "valueBoolean" : {{ value.value }} {% elsif value.value -%} "valueQuantity": { - "value":{{ value.value }}, + "value":{{ value.value | to_json_string }}, {% if value.unit and value.unit != "null" -%} "unit":"{{ value.unit }}", {% endif -%} From 063b8a2d593c14515f908bd8f3804c670d947a2d Mon Sep 17 00:00:00 2001 From: Lina Roth Date: Thu, 12 Dec 2024 11:24:30 -0500 Subject: [PATCH 2/7] remove uneeded change --- data/Templates/eCR/Entry/SocialHistory/_entry.liquid | 2 -- 1 file changed, 2 deletions(-) diff --git a/data/Templates/eCR/Entry/SocialHistory/_entry.liquid b/data/Templates/eCR/Entry/SocialHistory/_entry.liquid index 3da4795b..fdd8c7db 100644 --- a/data/Templates/eCR/Entry/SocialHistory/_entry.liquid +++ b/data/Templates/eCR/Entry/SocialHistory/_entry.liquid @@ -17,8 +17,6 @@ {% include 'Resource/ObservationPregnancyStatus' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%} {% elsif entry.observation.code.code == '76690-7' -%} {% include 'Resource/ObservationSexualOrientation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%} - {% elsif entry.observation.code.code == '897148007' -%} - {% include 'Resource/Observation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%} {% else -%} {% include 'Resource/Observation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%} {% endif -%} From 267601cc90623ae7b9e6264a5e05572c58f38d39 Mon Sep 17 00:00:00 2001 From: Lina Roth Date: Tue, 17 Dec 2024 13:20:43 -0500 Subject: [PATCH 3/7] Add value helper unit tests --- data/Templates/eCR/Utils/_ValueHelper.liquid | 1 + .../Templates/eCR/Utils/ValueHelperTests.cs | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs diff --git a/data/Templates/eCR/Utils/_ValueHelper.liquid b/data/Templates/eCR/Utils/_ValueHelper.liquid index 5993fe2c..332ef4dd 100644 --- a/data/Templates/eCR/Utils/_ValueHelper.liquid +++ b/data/Templates/eCR/Utils/_ValueHelper.liquid @@ -1,3 +1,4 @@ +{{ value | print_object }} {% if value.code %} "valueCodeableConcept" : { {% assign translations = value.translation | to_array -%} diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs new file mode 100644 index 00000000..5abd774e --- /dev/null +++ b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using System.IO; +using DotLiquid; +using Xunit; + +namespace Microsoft.Health.Fhir.Liquid.Converter.UnitTests +{ + public class ValueHelperTests : BaseECRLiquidTests + { + private static readonly string ECRPath = Path.Join( + TestConstants.ECRTemplateDirectory, "Utils", "_ValueHelper.liquid" + ); + + [Fact] + public void GivenNoAttributeReturnsEmpty() + { + ConvertCheckLiquidTemplate(ECRPath, new Dictionary(), "\"valueString\": \"\","); + } + + [Fact] + public void GivenDecimalProperlyReturnsWithDecimal() + { + var attributes = new Dictionary{ + {"value", Hash.FromAnonymousObject(new { value = ".29"})} + }; + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":\".29\", },"); + } + + [Fact] + public void GivenIntProperlyReturnsInt() + { + var attributes = new Dictionary{ + {"value", Hash.FromAnonymousObject(new { value = "300"})} + }; + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":\"300\", },"); + } + + [Fact] + public void GivenDecimalProperlyReturnsDecimal() + { + var attributes = new Dictionary{ + {"value", Hash.FromAnonymousObject(new { value = "300.00"})} + }; + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":\"300.00\", },"); + } + + [Fact] + public void GivenNegativeValueProperlyReturnsNegativeValue() + { + var attributes = new Dictionary{ + {"value", Hash.FromAnonymousObject(new { value = "-300.00"})} + }; + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":\"-300.00\", },"); + } + + [Fact] + public void GivenValueUnitProperlyReturnsWithValueUnit() + { + var attributes = new Dictionary{ + {"value", Hash.FromAnonymousObject(new { value = ".29" , unit = "/d"})} + }; + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":\".29\", \"unit\":\"/d\", },"); + } + } +} From da245a22579c637dc442d508e289b1f10e1d902d Mon Sep 17 00:00:00 2001 From: Lina Roth Date: Tue, 17 Dec 2024 13:25:00 -0500 Subject: [PATCH 4/7] remove print --- data/Templates/eCR/Utils/_ValueHelper.liquid | 1 - 1 file changed, 1 deletion(-) diff --git a/data/Templates/eCR/Utils/_ValueHelper.liquid b/data/Templates/eCR/Utils/_ValueHelper.liquid index 332ef4dd..5993fe2c 100644 --- a/data/Templates/eCR/Utils/_ValueHelper.liquid +++ b/data/Templates/eCR/Utils/_ValueHelper.liquid @@ -1,4 +1,3 @@ -{{ value | print_object }} {% if value.code %} "valueCodeableConcept" : { {% assign translations = value.translation | to_array -%} From 5b1d86a623c9e664f479bc9d15b657cb7369cd5c Mon Sep 17 00:00:00 2001 From: Lina Roth Date: Tue, 17 Dec 2024 14:23:32 -0500 Subject: [PATCH 5/7] change to_json_string to_json_number --- data/Templates/eCR/Utils/_ValueHelper.liquid | 2 +- .../Templates/eCR/Utils/ValueHelperTests.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data/Templates/eCR/Utils/_ValueHelper.liquid b/data/Templates/eCR/Utils/_ValueHelper.liquid index 5993fe2c..0661fe60 100644 --- a/data/Templates/eCR/Utils/_ValueHelper.liquid +++ b/data/Templates/eCR/Utils/_ValueHelper.liquid @@ -9,7 +9,7 @@ "valueBoolean" : {{ value.value }} {% elsif value.value -%} "valueQuantity": { - "value":{{ value.value | to_json_string }}, + "value":{{ value.value | to_json_number }}, {% if value.unit and value.unit != "null" -%} "unit":"{{ value.unit }}", {% endif -%} diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs index 5abd774e..9ea6a684 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs @@ -23,7 +23,7 @@ public void GivenDecimalProperlyReturnsWithDecimal() var attributes = new Dictionary{ {"value", Hash.FromAnonymousObject(new { value = ".29"})} }; - ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":\".29\", },"); + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":.29, },"); } [Fact] @@ -32,7 +32,7 @@ public void GivenIntProperlyReturnsInt() var attributes = new Dictionary{ {"value", Hash.FromAnonymousObject(new { value = "300"})} }; - ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":\"300\", },"); + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":300, },"); } [Fact] @@ -41,7 +41,7 @@ public void GivenDecimalProperlyReturnsDecimal() var attributes = new Dictionary{ {"value", Hash.FromAnonymousObject(new { value = "300.00"})} }; - ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":\"300.00\", },"); + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":300.00, },"); } [Fact] @@ -50,7 +50,7 @@ public void GivenNegativeValueProperlyReturnsNegativeValue() var attributes = new Dictionary{ {"value", Hash.FromAnonymousObject(new { value = "-300.00"})} }; - ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":\"-300.00\", },"); + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":-300.00, },"); } [Fact] @@ -59,7 +59,7 @@ public void GivenValueUnitProperlyReturnsWithValueUnit() var attributes = new Dictionary{ {"value", Hash.FromAnonymousObject(new { value = ".29" , unit = "/d"})} }; - ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":\".29\", \"unit\":\"/d\", },"); + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":.29, \"unit\":\"/d\", },"); } } } From 41d7d11a90f480c8dfc807e3065edc145b6eec8b Mon Sep 17 00:00:00 2001 From: Lina Roth Date: Tue, 17 Dec 2024 14:59:03 -0500 Subject: [PATCH 6/7] ensure decimal is persisted by adding leading 0 if applicable --- data/Templates/eCR/Utils/_ValueHelper.liquid | 7 ++++++- .../Templates/eCR/Utils/ValueHelperTests.cs | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/data/Templates/eCR/Utils/_ValueHelper.liquid b/data/Templates/eCR/Utils/_ValueHelper.liquid index 0661fe60..736878f0 100644 --- a/data/Templates/eCR/Utils/_ValueHelper.liquid +++ b/data/Templates/eCR/Utils/_ValueHelper.liquid @@ -9,7 +9,12 @@ "valueBoolean" : {{ value.value }} {% elsif value.value -%} "valueQuantity": { - "value":{{ value.value | to_json_number }}, + "value": + {% if value.value startswith "." %} + {{ "0" | append: value.value | to_json_number }}, + {% else %} + {{ value.value | to_json_number }}, + {% endif %} {% if value.unit and value.unit != "null" -%} "unit":"{{ value.unit }}", {% endif -%} diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs index 9ea6a684..fa1a5d09 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/Utils/ValueHelperTests.cs @@ -23,7 +23,7 @@ public void GivenDecimalProperlyReturnsWithDecimal() var attributes = new Dictionary{ {"value", Hash.FromAnonymousObject(new { value = ".29"})} }; - ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":.29, },"); + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\": 0.29, },"); } [Fact] @@ -32,7 +32,7 @@ public void GivenIntProperlyReturnsInt() var attributes = new Dictionary{ {"value", Hash.FromAnonymousObject(new { value = "300"})} }; - ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":300, },"); + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\": 300, },"); } [Fact] @@ -41,7 +41,7 @@ public void GivenDecimalProperlyReturnsDecimal() var attributes = new Dictionary{ {"value", Hash.FromAnonymousObject(new { value = "300.00"})} }; - ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":300.00, },"); + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\": 300.00, },"); } [Fact] @@ -50,7 +50,7 @@ public void GivenNegativeValueProperlyReturnsNegativeValue() var attributes = new Dictionary{ {"value", Hash.FromAnonymousObject(new { value = "-300.00"})} }; - ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":-300.00, },"); + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\": -300.00, },"); } [Fact] @@ -59,7 +59,7 @@ public void GivenValueUnitProperlyReturnsWithValueUnit() var attributes = new Dictionary{ {"value", Hash.FromAnonymousObject(new { value = ".29" , unit = "/d"})} }; - ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":.29, \"unit\":\"/d\", },"); + ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\": 0.29, \"unit\":\"/d\", },"); } } } From 8aab0ebe23e5c94e272494c9e1e9726699ff8815 Mon Sep 17 00:00:00 2001 From: Lina Roth Date: Tue, 17 Dec 2024 15:18:13 -0500 Subject: [PATCH 7/7] final_final_copy_4 --- data/Templates/eCR/Utils/_ValueHelper.liquid | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/Templates/eCR/Utils/_ValueHelper.liquid b/data/Templates/eCR/Utils/_ValueHelper.liquid index 736878f0..e983bf53 100644 --- a/data/Templates/eCR/Utils/_ValueHelper.liquid +++ b/data/Templates/eCR/Utils/_ValueHelper.liquid @@ -11,9 +11,9 @@ "valueQuantity": { "value": {% if value.value startswith "." %} - {{ "0" | append: value.value | to_json_number }}, + {{ "0" | append: value.value }}, {% else %} - {{ value.value | to_json_number }}, + {{ value.value }}, {% endif %} {% if value.unit and value.unit != "null" -%} "unit":"{{ value.unit }}",