Skip to content

Commit

Permalink
better Observation value export & unit export - centralized in single…
Browse files Browse the repository at this point in the history
… include.

Added support for value rounding.
  • Loading branch information
AnalogJ committed Mar 3, 2024
1 parent 42c9c2e commit c47104b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 35 deletions.
14 changes: 14 additions & 0 deletions backend/pkg/utils/ips/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/fastenhealth/gofhir-models/fhir401"
"gorm.io/datatypes"
"html/template"
"math"
)

//go:embed templates
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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}}
12 changes: 12 additions & 0 deletions backend/pkg/utils/ips/templates/includes/observation-value.gohtml
Original file line number Diff line number Diff line change
@@ -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}}
12 changes: 1 addition & 11 deletions backend/pkg/utils/ips/templates/pregnancy.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
12 changes: 1 addition & 11 deletions backend/pkg/utils/ips/templates/social_history.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -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 */}}
Expand Down
14 changes: 2 additions & 12 deletions backend/pkg/utils/ips/templates/vital_signs.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -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 */}}
Expand Down

0 comments on commit c47104b

Please sign in to comment.