Skip to content

Commit

Permalink
ensure decimal is persisted by adding leading 0 if applicable (#24)
Browse files Browse the repository at this point in the history
* add to_json_string so it will bring periods with value

* remove uneeded change

* Add value helper unit tests

* remove print

* change to_json_string to_json_number

* ensure decimal is persisted by adding leading 0 if applicable

* final_final_copy_4
  • Loading branch information
lina-roth authored Dec 17, 2024
1 parent c8656ba commit 9ad09a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion data/Templates/eCR/Utils/_ValueHelper.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -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 }},
{% else %}
{{ value.value }},
{% endif %}
{% if value.unit and value.unit != "null" -%}
"unit":"{{ value.unit }}",
{% endif -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void GivenDecimalProperlyReturnsWithDecimal()
var attributes = new Dictionary<string, object>{
{"value", Hash.FromAnonymousObject(new { value = ".29"})}
};
ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":.29, },");
ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\": 0.29, },");
}

[Fact]
Expand All @@ -32,7 +32,7 @@ public void GivenIntProperlyReturnsInt()
var attributes = new Dictionary<string, object>{
{"value", Hash.FromAnonymousObject(new { value = "300"})}
};
ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":300, },");
ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\": 300, },");
}

[Fact]
Expand All @@ -41,7 +41,7 @@ public void GivenDecimalProperlyReturnsDecimal()
var attributes = new Dictionary<string, object>{
{"value", Hash.FromAnonymousObject(new { value = "300.00"})}
};
ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":300.00, },");
ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\": 300.00, },");
}

[Fact]
Expand All @@ -50,7 +50,7 @@ public void GivenNegativeValueProperlyReturnsNegativeValue()
var attributes = new Dictionary<string, object>{
{"value", Hash.FromAnonymousObject(new { value = "-300.00"})}
};
ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\":-300.00, },");
ConvertCheckLiquidTemplate(ECRPath, attributes, "\"valueQuantity\": { \"value\": -300.00, },");
}

[Fact]
Expand All @@ -59,7 +59,7 @@ public void GivenValueUnitProperlyReturnsWithValueUnit()
var attributes = new Dictionary<string, object>{
{"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\", },");
}
}
}

0 comments on commit 9ad09a2

Please sign in to comment.