better Observation value export & unit export - centralized in single include.

Added support for value rounding.
This commit is contained in:
Jason Kulatunga 2024-03-02 21:13:30 -08:00
parent 9608e07b85
commit 7900ccfeb6
No known key found for this signature in database
7 changed files with 40 additions and 35 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/fastenhealth/gofhir-models/fhir401"
"gorm.io/datatypes"
"html/template"
"math"
)
//go:embed templates
@ -66,6 +67,19 @@ func NewNarrative() (*Narrative, error) {
}
return values
},
"roundList": func(precision uint, listVals []interface{}) []interface{} {
results := []interface{}{}
for ndx, _ := range listVals {
switch listVal := listVals[ndx].(type) {
case float64:
ratio := math.Pow(10, float64(precision))
results = append(results, math.Round(listVal*ratio)/ratio)
default:
results = append(results, listVal)
}
}
return results
},
}).Funcs(sprig.FuncMap()).ParseFS(ipsTemplates, "templates/*.gohtml", "templates/includes/*.gohtml")
if err != nil {

View File

@ -32,7 +32,7 @@ Comments: AllergyIntolerance.note[x].text (separated by <br />)
<td>{{pluckList "text" ($entry.Manifestation | parseList) | uniq | join "," }}</td> {{/* Reaction */}}
<td>{{pluckList "code" ($entry.Criticality | parseList) | uniq | join ","}}</td> {{/* Severity */}}
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td> {{/* Comments - TODO: use FHIRPath */}}
<td>{{$entry.Onset | date "2006-01-02"}}</td> {{/* Onset */}}
<td>{{default "unknown" $entry.Onset }}</td> {{/* Onset */}}
</tr>
{{end}}
</tbody>

View File

@ -0,0 +1,9 @@
{{if not (empty .ValueString) }}
{{.ValueString}}
{{else if not (empty (.ValueQuantity | parseList)) }}
{{.ValueQuantity | parseList | pluckList "unit" | join "," }}
{{else if not (empty .ValueDate) }}
{{.ValueDate | date "2006-01-02" }}
{{else if not (empty (.ValueConcept | parseList)) }}
{{.ValueConcept}}
{{end}}

View File

@ -0,0 +1,12 @@
{{if not (empty .entry.ValueString) }}
{{.ValueString}}
{{else if not (empty (.entry.ValueQuantity | parseList)) }}
{{.entry.ValueQuantity | parseList | pluckList "value" | roundList 2 | join "," }}
{{if (get . "include_unit")}}
{{.entry.ValueQuantity | parseList | pluckList "unit" | join "," }}
{{end}}
{{else if not (empty .entry.ValueDate) }}
{{.entry.ValueDate | date "2006-01-02" }}
{{else if not (empty (.entry.ValueConcept | parseList)) }}
{{.entry.ValueConcept}}
{{end}}

View File

@ -21,17 +21,7 @@ Date: Observation.effectiveDateTime || Observation.effectivePeriod.start
{{range $index, $entry := .Observation }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Code | parseList) | uniq | join "," }}</td> {{/* Code */}}
<td>
{{if not (empty $entry.ValueString) }}
{{$entry.ValueString}}
{{else if not (empty ($entry.ValueQuantity | parseList)) }}
{{$entry.ValueQuantity}}
{{else if not (empty $entry.ValueDate) }}
{{$entry.ValueDate | date "2006-01-02" }}
{{else if not (empty ($entry.ValueConcept | parseList)) }}
{{$entry.ValueConcept}}
{{end}}
</td> {{/* Result */}}
<td>{{template "observation-value.gohtml" (dict "entry" $entry "include_unit" true)}}</td> {{/* Result */}}
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td>
<td>{{$entry.Date | date "2006-01-02"}}</td> {{/* Date */}}
</tr>

View File

@ -23,17 +23,7 @@ Date: Observation.effectiveDateTime || Observation.effectivePeriod.start
{{range $index, $entry := .Observation }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Code | parseList) | uniq | join "," }}</td> {{/* Code */}}
<td>
{{if not (empty $entry.ValueString) }}
{{$entry.ValueString}}
{{else if not (empty ($entry.ValueQuantity | parseList)) }}
{{$entry.ValueQuantity}}
{{else if not (empty $entry.ValueDate) }}
{{$entry.ValueDate | date "2006-01-02" }}
{{else if not (empty ($entry.ValueConcept | parseList)) }}
{{$entry.ValueConcept}}
{{end}}
</td> {{/* Result */}}
<td>{{template "observation-value.gohtml" (dict "entry" $entry "include_unit" false)}}</td> {{/* Result */}}
<td th:insert="~{IpsUtilityFragments :: renderValueUnit (value=*{getValue()})}">Unit</td>
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td>
<td>{{$entry.Date | date "2006-01-02"}}</td> {{/* Date */}}

View File

@ -26,18 +26,8 @@ Date: Observation.effectiveDateTime || Observation.effectivePeriod.start
{{range $index, $entry := .Observation }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Code | parseList) | uniq | join "," }}</td> {{/* Code */}}
<td>
{{if not (empty $entry.ValueString) }}
{{$entry.ValueString}}
{{else if not (empty ($entry.ValueQuantity | parseList)) }}
{{$entry.ValueQuantity}}
{{else if not (empty $entry.ValueDate) }}
{{$entry.ValueDate | date "2006-01-02" }}
{{else if not (empty ($entry.ValueConcept | parseList)) }}
{{$entry.ValueConcept}}
{{end}}
</td> {{/* Result */}}
<td th:insert="~{IpsUtilityFragments :: renderValueUnit (value=*{getValue()})}">Unit</td>
<td>{{template "observation-value.gohtml" (dict "entry" $entry "include_unit" false)}}</td> {{/* Result */}}
<td>{{template "observation-unit.gohtml" $entry}}</td>
<td th:replace="~{IpsUtilityFragments :: firstFromCodeableConceptList (list=*{getInterpretation()})}">Interpretation</td>
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td>
<td>{{$entry.Date | date "2006-01-02"}}</td> {{/* Date */}}