diff --git a/data/Templates/eCR/DataType/_Address.liquid b/data/Templates/eCR/DataType/_Address.liquid index 587ae4eb..72bcac36 100644 --- a/data/Templates/eCR/DataType/_Address.liquid +++ b/data/Templates/eCR/DataType/_Address.liquid @@ -1,16 +1,16 @@ {% assign lines = Address.streetAddressLine | to_array -%} {% if lines.first._ or Address.city._ or Address.state._ or Address.country._ or Address.postalCode._ or Address.county._ -%} "use": "{{ Address.use | get_property: 'ValueSet/AddressUse' }}", - "line": [ - {% assign lines = Address.streetAddressLine | to_array -%} - {% for l in lines -%} + {%- assign lines = Address.streetAddressLine | to_array -%} + {%- for l in lines -%} "{{l._}}", - {% endfor -%} + {%- endfor -%} ], "city": "{{Address.city._}}", "state": "{{Address.state._}}", "country": "{{Address.country._}}", "postalCode": "{{Address.postalCode._}}", "district": "{{Address.county._}}", -{% endif -%} \ No newline at end of file + "period": { {% include 'DataType/Period' Period: Address.useablePeriod %} }, +{% endif -%} diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/BaseECRLiquidTests.cs b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/BaseECRLiquidTests.cs index 91e18c80..bb2a8689 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/BaseECRLiquidTests.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/BaseECRLiquidTests.cs @@ -11,14 +11,16 @@ namespace Microsoft.Health.Fhir.Liquid.Converter.UnitTests { - public class BaseConvertLiquidTemplate + public class BaseECRLiquidTests { - /// /// Given a path to an eCR template, and attributes. Check that the rendered template /// matches the expected contents. /// - protected void ConvertCheckLiquidTemplate(string templatePath, Dictionary attributes, string expectedContent) + /// Path to the template being tested + /// Dictionary of attributes to hydrate the template + /// Serialized string that ought to be returned + protected static void ConvertCheckLiquidTemplate(string templatePath, Dictionary attributes, string expectedContent) { var templateContent = File.ReadAllText(templatePath); var template = TemplateUtility.ParseLiquidTemplate(templatePath, templateContent); @@ -53,7 +55,8 @@ protected void ConvertCheckLiquidTemplate(string templatePath, Dictionary(), string.Empty); + } + + [Fact] + public void GivenSingleStreetAddresReturnsLines() + { + var attributes = new Dictionary{ + {"Address", Hash.FromAnonymousObject(new { streetAddressLine = new { _ = "132 Main St" }})} + }; + ConvertCheckLiquidTemplate( + ECRPath, + attributes, + @"""use"": """", ""line"": [ ""132 Main St"", ], ""city"": """", ""state"": """", ""country"": """", ""postalCode"": """", ""district"": """", ""period"": { ""start"":"""", ""end"":"""", },"); + } + + [Fact] + public void GivenArrayStreetAddresReturnsLines() + { + var attributes = new Dictionary{ + {"Address", Hash.FromAnonymousObject(new { streetAddressLine = new List {new {_ = "132 Main St"}, new { _ ="Unit 2"} }})} + }; + ConvertCheckLiquidTemplate( + ECRPath, + attributes, + @"""use"": """", ""line"": [ ""132 Main St"", ""Unit 2"", ], ""city"": """", ""state"": """", ""country"": """", ""postalCode"": """", ""district"": """", ""period"": { ""start"":"""", ""end"":"""", },"); + } + + [Fact] + public void GivenCityReturnsCity() + { + var attributes = new Dictionary{ + {"Address", Hash.FromAnonymousObject(new { city = new { _ = "Town" }})} + }; + ConvertCheckLiquidTemplate( + ECRPath, + attributes, + @"""use"": """", ""line"": [ ], ""city"": ""Town"", ""state"": """", ""country"": """", ""postalCode"": """", ""district"": """", ""period"": { ""start"":"""", ""end"":"""", },"); + } + + [Fact] + public void GivenStateReturnsState() + { + var attributes = new Dictionary{ + {"Address", Hash.FromAnonymousObject(new { state = new { _ = "State" }})} + }; + ConvertCheckLiquidTemplate( + ECRPath, + attributes, + @"""use"": """", ""line"": [ ], ""city"": """", ""state"": ""State"", ""country"": """", ""postalCode"": """", ""district"": """", ""period"": { ""start"":"""", ""end"":"""", },"); + } + + [Fact] + public void GivenPostalCodeReturnsPostalCode() + { + var attributes = new Dictionary{ + {"Address", Hash.FromAnonymousObject(new { postalCode = new { _ = "PostalCode" }})} + }; + ConvertCheckLiquidTemplate( + ECRPath, + attributes, + @"""use"": """", ""line"": [ ], ""city"": """", ""state"": """", ""country"": """", ""postalCode"": ""PostalCode"", ""district"": """", ""period"": { ""start"":"""", ""end"":"""", },"); + } + + [Fact] + public void GivenCountyReturnsDistrict() + { + var attributes = new Dictionary{ + {"Address", Hash.FromAnonymousObject(new { county = new { _ = "County" }})} + }; + ConvertCheckLiquidTemplate( + ECRPath, + attributes, + @"""use"": """", ""line"": [ ], ""city"": """", ""state"": """", ""country"": """", ""postalCode"": """", ""district"": ""County"", ""period"": { ""start"":"""", ""end"":"""", },"); + } + + [Fact] + public void GivenCountrReturnsCountry() + { + var attributes = new Dictionary{ + {"Address", Hash.FromAnonymousObject(new { country = new { _ = "Country" }})} + }; + ConvertCheckLiquidTemplate( + ECRPath, + attributes, + @"""use"": """", ""line"": [ ], ""city"": """", ""state"": """", ""country"": ""Country"", ""postalCode"": """", ""district"": """", ""period"": { ""start"":"""", ""end"":"""", },"); + } + + [Fact] + public void GivenPeriodReturnsNothing() + { + var attributes = new Dictionary{ + {"Address", Hash.FromAnonymousObject(new { useablePeriod = new { low = new { value = "20240313"}} })} + }; + ConvertCheckLiquidTemplate( + ECRPath, + attributes, + @""); + } + + [Fact] + public void GivenPeriodAndCountryReturnsBoth() + { + var attributes = new Dictionary{ + {"Address", Hash.FromAnonymousObject(new { country = new {_ = "Country" }, useablePeriod = new { low = new { value = "20240313"}} })} + }; + ConvertCheckLiquidTemplate( + ECRPath, + attributes, + @"""use"": """", ""line"": [ ], ""city"": """", ""state"": """", ""country"": ""Country"", ""postalCode"": """", ""district"": """", ""period"": { ""start"":""2024-03-13"", ""end"":"""", },"); + } + + } + +} diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/DataType/ContactPointTests.cs b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/DataType/ContactPointTests.cs index 5d1604b5..9ea32b46 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/DataType/ContactPointTests.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Templates/eCR/DataType/ContactPointTests.cs @@ -5,7 +5,7 @@ namespace Microsoft.Health.Fhir.Liquid.Converter.UnitTests { - public class ContactPointTests : BaseConvertLiquidTemplate + public class ContactPointTests : BaseECRLiquidTests { private static readonly string ECRPath = Path.Join( TestConstants.ECRTemplateDirectory, "DataType", "_ContactPoint.liquid"