better Observation value export & unit export - centralized in single include.
Added support for value rounding.
This commit is contained in:
parent
9608e07b85
commit
7900ccfeb6
|
@ -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 {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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}}
|
|
@ -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}}
|
|
@ -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>
|
||||
|
|
|
@ -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 */}}
|
||||
|
|
|
@ -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 */}}
|
||||
|
|
Loading…
Reference in New Issue