Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: account for more problem list comment types #5

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/Templates/eCR/Entry/Problem/_entry.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

{% for probRelationship in entryRelationships %}
{% include 'Entry/Problem/entry_act_entryRelationship' with probRelationship, text: text, relatedEntries: entryRelationships %}
{% endfor %}
{% endfor %}
20 changes: 6 additions & 14 deletions data/Templates/eCR/Resource/_Condition.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}",
Expand All @@ -66,15 +63,10 @@
{
{% 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: "<br/>" | append: commentContentString }}",
{% endif %}
{% assign commentText = text._innerText | find_inner_text_by_id: commentRefVal -%}
"text": "{{ commentText | escape_special_chars }}",
{% endif -%}
{% endfor -%}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,32 @@ public void FindObjectById_NullData_ReturnsNull()
Assert.Null(actual);
}

[Fact]
public void FindInnerTextById_ValidId_ReturnsString()
{
var innerXml = "<paragraph style=\"bold\">hello</paragraph>";
var fragment = $"<content ID=\"hi\">{innerXml}</content><content ID=\"bye\">bye</content>";
var actual = Filters.FindInnerTextById(fragment, "hi");
Assert.Equal(actual, innerXml);
}

[Fact]
public void FindInnerTextById_InalidId_ReturnsNull()
{

var innerXml = "<paragraph style=\"bold\">hello</paragraph>";
var fragment = $"<content ID=\"hi\">{innerXml}</content><content ID=\"bye\">bye</content>";
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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -519,6 +520,48 @@ private static Dictionary<string, string> CSVMapDictionary(string filename)
return element;
}

/// <summary>
/// Searches for the original text content of a node with a specified ID within a
/// given xml string (`text._innerText` in most cases).
/// </summary>
/// <param name="fullText">The string of XML to search within.</param>
/// <param name="id">The ID (reference value) to search for within the data structure.</param>
/// <returns>A string with the content of the node with the specified ID, or null if not found.</returns>
public static string? FindInnerTextById(string fullText, string id)
{
XmlDocument doc = new ();

// Add wrapper <doc> as the fragment may not have one root node.
doc.LoadXml($"<doc>{fullText}</doc>");
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;
}

/// <summary>
/// Searches for an object with a specified ID within a given data structure.
/// </summary>
Expand Down
Loading