diff --git a/release.yml b/release.yml index 22e032fe5..d30eaff2f 100644 --- a/release.yml +++ b/release.yml @@ -18,7 +18,7 @@ variables: buildConfiguration: 'Release' major: 5 minor: 0 - patch: 4 + patch: 5 buildnum: $[counter(format('{0}.{1}.{2}',variables['major'],variables['minor'], variables['patch']), 1)] version: $(major).$(minor).$(patch).$(buildnum) diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Processors/ProcessorTests.cs b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Processors/ProcessorTests.cs index 68a8054eb..e871ae6c5 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Processors/ProcessorTests.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Processors/ProcessorTests.cs @@ -11,6 +11,7 @@ using Microsoft.Health.Fhir.Liquid.Converter.Exceptions; using Microsoft.Health.Fhir.Liquid.Converter.Models; using Microsoft.Health.Fhir.Liquid.Converter.Processors; +using Newtonsoft.Json.Linq; using Xunit; namespace Microsoft.Health.Fhir.Liquid.Converter.UnitTests.Processors @@ -20,6 +21,7 @@ public class ProcessorTests private static readonly string _hl7v2TestData; private static readonly string _ccdaTestData; private static readonly string _jsonTestData; + private static readonly string _jsonExpectData; private static readonly string _fhirStu3TestData; private static readonly ProcessorSettings _processorSettings; @@ -28,6 +30,7 @@ static ProcessorTests() _hl7v2TestData = File.ReadAllText(Path.Join(TestConstants.SampleDataDirectory, "Hl7v2", "LRI_2.0-NG_CBC_Typ_Message.hl7")); _ccdaTestData = File.ReadAllText(Path.Join(TestConstants.SampleDataDirectory, "Ccda", "CCD.ccda")); _jsonTestData = File.ReadAllText(Path.Join(TestConstants.SampleDataDirectory, "Json", "ExamplePatient.json")); + _jsonExpectData = File.ReadAllText(Path.Join(TestConstants.ExpectedDirectory, "ExamplePatient.json")); _fhirStu3TestData = File.ReadAllText(Path.Join(TestConstants.SampleDataDirectory, "Stu3", "Patient.json")); _processorSettings = new ProcessorSettings(); } @@ -242,5 +245,15 @@ public void GivenTemplateWithNestingTooDeep_WhenConvert_ExceptionShouldBeThrown( exception = Assert.Throws(() => processor.Convert(data, "NestingTooDeepDiffTemplate", templateProvider)); Assert.Contains("Nesting too deep", exception.Message); } + + [Fact] + public void GivenJObjectInput_WhenConvertWithJsonProcessor_CorrectResultShouldBeReturned() + { + var processor = new JsonProcessor(_processorSettings); + var templateProvider = new TemplateProvider(TestConstants.JsonTemplateDirectory, DataType.Json); + var testData = JObject.Parse(_jsonTestData); + var result = processor.Convert(testData, "ExamplePatient", templateProvider); + Assert.True(JToken.DeepEquals(JObject.Parse(_jsonExpectData), JToken.Parse(result))); + } } } diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/TestData/Expected/ExamplePatient.json b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/TestData/Expected/ExamplePatient.json new file mode 100644 index 000000000..1e65aca0c --- /dev/null +++ b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/TestData/Expected/ExamplePatient.json @@ -0,0 +1,44 @@ +{ + "resourceType": "Patient", + "id": "e8b835f7-0c46-4166-22ad-23e6783aaf54", + "identifier": [ + { + "use": "usual", + "type": { + "coding": [ + { + "system": "http://terminology.hl7.org/CodeSystem/v2-0203", + "code": "MR" + } + ] + }, + "system": "urn:oid:2.16.840.1.113883.19.5", + "value": "M0R1N2" + } + ], + "active": true, + "name": [ + { + "family": "Smith", + "given": [ + "Jerry" + ] + } + ], + "telecom": [ + { + "system": "phone", + "value": "1234-5678" + }, + { + "system": "phone", + "value": "1234-5679" + } + ], + "gender": "male", + "birthDate": "2001-01-10", + "managingOrganization": { + "reference": "Organization/2.16.840.1.113883.19.5", + "display": "Good Health Clinic" + } +} \ No newline at end of file diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter/Parsers/JsonDataParser.cs b/src/Microsoft.Health.Fhir.Liquid.Converter/Parsers/JsonDataParser.cs index e86839480..c1be2cf78 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter/Parsers/JsonDataParser.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter/Parsers/JsonDataParser.cs @@ -4,7 +4,6 @@ // ------------------------------------------------------------------------------------------------- using System; -using System.Collections.Generic; using Microsoft.Health.Fhir.Liquid.Converter.Exceptions; using Microsoft.Health.Fhir.Liquid.Converter.Extensions; using Microsoft.Health.Fhir.Liquid.Converter.Models; diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter/Processors/JsonProcessor.cs b/src/Microsoft.Health.Fhir.Liquid.Converter/Processors/JsonProcessor.cs index ac3e45401..3b8a9ec35 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter/Processors/JsonProcessor.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter/Processors/JsonProcessor.cs @@ -6,9 +6,11 @@ using System.Collections.Generic; using System.Globalization; using DotLiquid; +using Microsoft.Health.Fhir.Liquid.Converter.Extensions; using Microsoft.Health.Fhir.Liquid.Converter.Models; using Microsoft.Health.Fhir.Liquid.Converter.Models.Json; using Microsoft.Health.Fhir.Liquid.Converter.Parsers; +using Newtonsoft.Json.Linq; using NJsonSchema; namespace Microsoft.Health.Fhir.Liquid.Converter.Processors @@ -28,6 +30,12 @@ public override string Convert(string data, string rootTemplate, ITemplateProvid return Convert(jsonData, rootTemplate, templateProvider, traceInfo); } + public string Convert(JObject data, string rootTemplate, ITemplateProvider templateProvider, TraceInfo traceInfo = null) + { + var jsonData = data.ToObject(); + return Convert(jsonData, rootTemplate, templateProvider, traceInfo); + } + protected override Context CreateContext(ITemplateProvider templateProvider, IDictionary data) { // Load data and templates