From 605daea27a4c8c9c9dbba65f5100c8efb0350763 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Tue, 5 Nov 2024 12:45:15 -0500 Subject: [PATCH 1/5] fix: account for more problem list comment types --- data/Templates/eCR/Resource/_Condition.liquid | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/data/Templates/eCR/Resource/_Condition.liquid b/data/Templates/eCR/Resource/_Condition.liquid index 7d83b8b40..ee875605c 100644 --- a/data/Templates/eCR/Resource/_Condition.liquid +++ b/data/Templates/eCR/Resource/_Condition.liquid @@ -39,12 +39,9 @@ "code": { {% assign translations = conditionEntry.value.translation | to_array -%} - {% if translations.first.code -%} - {% include 'DataType/CodeableConcept' CodeableConcept: translations.first -%} - {% endif -%} - {% if translations.first == null -%} - {% include 'DataType/CodeableConcept' CodeableConcept: conditionEntry.value -%} - {% endif -%} + {% assign code = conditionEntry.value | to_array -%} + {% assign codes = code | concat: translations %} + {% include 'DataType/CodeableConcept' CodeableConcept: codes -%} }, {% if conditionEntry.effectiveTime.low.value -%} "onsetDateTime":"{{ conditionEntry.effectiveTime.low.value | format_as_date_time }}", @@ -66,14 +63,12 @@ { {% for relatedEntry in relatedEntries -%} {% assign templateIdString = relatedEntry.act.templateId.root | to_json_string -%} - {% if templateIdString contains '"2.16.840.1.113883.10.20.22.4.64"' and relatedEntry.act.text.reference.value -%} + {% if templateIdString contains '"2.16.840.1.113883.10.20.22.4.64"' or templateIdString contains "2.16.840.1.113883.10.20.22.4.202" and relatedEntry.act.text.reference.value -%} {% assign commentRefVal = relatedEntry.act.text.reference.value | replace: '#', '' -%} {% assign commentObj = text | find_object_by_id: commentRefVal -%} {% if commentObj != null and commentObj.content != null %} - {% assign commentParagraphString = commentObj.paragraph | concat_strings %} - {% assign commentContentString = commentObj.content | concat_strings | remove: '"' %} - "text": "{{ commentParagraphString | append: "
" | append: commentContentString }}", + "text": "{{commentObj | to_html_string | escape_special_chars}}", {% endif %} {% endif -%} {% endfor -%} From 27e082a51cc1a594e2f47e1b04d65cd8adec4f91 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Wed, 6 Nov 2024 08:45:03 -0500 Subject: [PATCH 2/5] feat: add mechanism to get inner xml out of text block by id --- .../Templates/eCR/Entry/Problem/_entry.liquid | 2 +- data/Templates/eCR/Resource/_Condition.liquid | 7 +-- .../Filters/CustomFilters.cs | 43 +++++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/data/Templates/eCR/Entry/Problem/_entry.liquid b/data/Templates/eCR/Entry/Problem/_entry.liquid index e76519415..81589ecca 100644 --- a/data/Templates/eCR/Entry/Problem/_entry.liquid +++ b/data/Templates/eCR/Entry/Problem/_entry.liquid @@ -2,4 +2,4 @@ {% for probRelationship in entryRelationships %} {% include 'Entry/Problem/entry_act_entryRelationship' with probRelationship, text: text, relatedEntries: entryRelationships %} -{% endfor %} \ No newline at end of file +{% endfor %} diff --git a/data/Templates/eCR/Resource/_Condition.liquid b/data/Templates/eCR/Resource/_Condition.liquid index ee875605c..51b5f3344 100644 --- a/data/Templates/eCR/Resource/_Condition.liquid +++ b/data/Templates/eCR/Resource/_Condition.liquid @@ -65,11 +65,8 @@ {% assign templateIdString = relatedEntry.act.templateId.root | to_json_string -%} {% if templateIdString contains '"2.16.840.1.113883.10.20.22.4.64"' or templateIdString contains "2.16.840.1.113883.10.20.22.4.202" and relatedEntry.act.text.reference.value -%} {% assign commentRefVal = relatedEntry.act.text.reference.value | replace: '#', '' -%} - {% assign commentObj = text | find_object_by_id: commentRefVal -%} - - {% if commentObj != null and commentObj.content != null %} - "text": "{{commentObj | to_html_string | escape_special_chars}}", - {% endif %} + {% assign commentText = text._innerText | find_inner_text_by_id: commentRefVal -%} + "text": "{{ commentText | escape_special_chars }}", {% endif -%} {% endfor -%} diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs b/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs index 10ff7cdcd..443b42075 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Xml; using DotLiquid.Util; using Microsoft.VisualBasic.FileIO; using Newtonsoft.Json.Linq; @@ -519,6 +520,48 @@ private static Dictionary CSVMapDictionary(string filename) return element; } + /// + /// Searches for the original text content of a node with a specified ID within a + /// given xml string (`text._innerText` in most cases). + /// + /// The string of XML to search within. + /// The ID (reference value) to search for within the data structure. + /// A string with the content of the node with the specified ID, or null if not found. + public static string? FindInnerTextById(string fullText, string id) + { + XmlDocument doc = new (); + + // Add wrapper as the fragment may not have one root node. + doc.LoadXml($"{fullText}"); + XmlElement root = doc.DocumentElement; + return FindInnerTextByIdRecursive(root, id); + } + + private static string? FindInnerTextByIdRecursive(XmlElement root, string id) + { + foreach (XmlNode node in root.ChildNodes) + { + if (node is XmlElement el) + { + foreach (XmlAttribute attr in el.Attributes) + { + if (attr.LocalName.ToLower() == "id" && attr.Value == id) + { + return el.InnerXml; + } + } + + var res = FindInnerTextByIdRecursive(el, id); + if (res != null) + { + return res; + } + } + } + + return null; + } + /// /// Searches for an object with a specified ID within a given data structure. /// From 07f6ea34d6baa1ed2c16ca1082477c456ecb3d6f Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Wed, 6 Nov 2024 10:01:10 -0500 Subject: [PATCH 3/5] test: add unit tests --- .../Filters/CustomFiltersTests.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Filters/CustomFiltersTests.cs b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Filters/CustomFiltersTests.cs index 9ee28a89e..df7fe395c 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Filters/CustomFiltersTests.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Filters/CustomFiltersTests.cs @@ -280,6 +280,32 @@ public void FindObjectById_NullData_ReturnsNull() Assert.Null(actual); } + [Fact] + public void FindInnerTextById_ValidId_ReturnsString() + { + var innerXml = "hello"; + var fragment = $"{innerXml}bye"; + var actual = Filters.FindInnerTextById(fragment, "hi"); + Assert.Equal(actual, innerXml); + } + + [Fact] + public void FindInnerTextById_InalidId_ReturnsNull() + { + + var innerXml = "hello"; + var fragment = $"{innerXml}bye"; + var actual = Filters.FindInnerTextById(fragment, "nope"); + Assert.Null(actual); + } + + [Fact] + public void FindInnerTextById_Null_ReturnsNull() + { + var actual = Filters.FindInnerTextById(null, "nope"); + Assert.Null(actual); + } + [Fact] public void ConcatStrings_ValidData_ReturnsCorrectString() { From ac6d2ceb8ac2e2ac34786fb9384e5628b6f9f49c Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Thu, 7 Nov 2024 08:13:31 -0500 Subject: [PATCH 4/5] Update src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs --- .../Filters/CustomFilters.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs b/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs index 443b42075..5c717064d 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs @@ -521,7 +521,7 @@ private static Dictionary CSVMapDictionary(string filename) } /// - /// Searches for the original text content of a node with a specified ID within a + /// Searches for the original text content of a node with a specified ID within a /// given xml string (`text._innerText` in most cases). /// /// The string of XML to search within. From 406f13690844067f30e533c65458aca5d13ae453 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Thu, 7 Nov 2024 08:41:01 -0500 Subject: [PATCH 5/5] style: indentation --- .../Filters/CustomFilters.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs b/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs index 5c717064d..c5999f5cd 100644 --- a/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs +++ b/src/Microsoft.Health.Fhir.Liquid.Converter/Filters/CustomFilters.cs @@ -557,9 +557,9 @@ private static Dictionary CSVMapDictionary(string filename) return res; } } - } + } - return null; + return null; } ///