Skip to content

Commit

Permalink
working Observation components with/without units.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Mar 3, 2024
1 parent 181d8a7 commit 36c2a2f
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 38 deletions.
7 changes: 6 additions & 1 deletion backend/pkg/utils/ips/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ func NewNarrative() (*Narrative, error) {
}
return template.HTML(*s)
},
"parseList": func(data datatypes.JSON) []map[string]interface{} {
"parseStringList": func(data datatypes.JSON) []string {
var parsed []string
_ = json.Unmarshal(data, &parsed)
return parsed
},
"parseMapList": func(data datatypes.JSON) []map[string]interface{} {
var parsed []map[string]interface{}
_ = json.Unmarshal(data, &parsed)
return parsed
Expand Down
10 changes: 5 additions & 5 deletions backend/pkg/utils/ips/templates/allergies_intolerances.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Comments: AllergyIntolerance.note[x].text (separated by <br />)
{{- /*gotype: github.com/fastenhealth/fasten-onprem/backend/pkg/utils/ips.NarrativeTemplateData*/ -}}
{{range $index, $entry := .AllergyIntolerance }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Code | parseList) | uniq | join "," }}</td> {{/* Allergen */}}
<td>{{pluckList "code" ($entry.ClinicalStatus | parseList) | uniq | join "," }}</td> {{/* Status */}}
<td>{{pluckList "code" ($entry.Category | parseList) | uniq | join "," }}</td> {{/* Category */}}
<td>{{pluckList "text" ($entry.Manifestation | parseList) | uniq | join "," }}</td> {{/* Reaction */}}
<td>{{pluckList "code" ($entry.Criticality | parseList) | uniq | join ","}}</td> {{/* Severity */}}
<td>{{pluckList "text" ($entry.Code | parseMapList) | uniq | join "," }}</td> {{/* Allergen */}}
<td>{{pluckList "code" ($entry.ClinicalStatus | parseMapList) | uniq | join "," }}</td> {{/* Status */}}
<td>{{pluckList "code" ($entry.Category | parseMapList) | uniq | join "," }}</td> {{/* Category */}}
<td>{{pluckList "text" ($entry.Manifestation | parseMapList) | uniq | join "," }}</td> {{/* Reaction */}}
<td>{{pluckList "code" ($entry.Criticality | parseMapList) | uniq | join ","}}</td> {{/* Severity */}}
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td> {{/* Comments - TODO: use FHIRPath */}}
<td>{{default "unknown" $entry.Onset }}</td> {{/* Onset */}}
</tr>
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/utils/ips/templates/history_of_illness.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Onset Date: Condition.onsetDateTime || Condition.onsetPeriod.start && “-“ &&
{{- /*gotype: github.com/fastenhealth/fasten-onprem/backend/pkg/utils/ips.NarrativeTemplateData*/ -}}
{{range $index, $entry := .Condition }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Code | parseList) | uniq | join "," }}</td> {{/* Medical Problem */}}
<td>{{pluckList "code" ($entry.ClinicalStatus | parseList) | uniq | join "," }}</td> {{/* Status */}}
<td>{{pluckList "text" ($entry.Code | parseMapList) | uniq | join "," }}</td> {{/* Medical Problem */}}
<td>{{pluckList "code" ($entry.ClinicalStatus | parseMapList) | uniq | join "," }}</td> {{/* Status */}}
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td> {{/* Comments - TODO: use FHIRPath */}}
<td>{{$entry.OnsetDate | date "2006-01-02"}}</td> {{/* Onset */}}
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Date: Procedure.performedDateTime || Procedure.performedPeriod.start && “-“
{{- /*gotype: github.com/fastenhealth/fasten-onprem/backend/pkg/utils/ips.NarrativeTemplateData*/ -}}
{{range $index, $entry := .Procedure }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Code | parseList) | uniq | join "," }}</td> {{/* Procedure */}}
<td>{{pluckList "text" ($entry.Code | parseMapList) | uniq | join "," }}</td> {{/* Procedure */}}
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td> {{/* Comments - TODO: use FHIRPath */}}
<td>{{$entry.Date | date "2006-01-02"}}</td> {{/* Performed Date */}}
</tr>
Expand Down
6 changes: 3 additions & 3 deletions backend/pkg/utils/ips/templates/immunizations.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Date: Immunization.occurrenceDateTime || Immunization.occurrenceString
{{- /*gotype: github.com/fastenhealth/fasten-onprem/backend/pkg/utils/ips.NarrativeTemplateData*/ -}}
{{range $index, $entry := .Immunization }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.VaccineCode | parseList) | uniq | join "," }}</td> {{/* Immunization */}}
<td>{{pluckList "code" ($entry.Status | parseList) | uniq | join "," }}</td> {{/* Status */}}
<td>{{pluckList "text" ($entry.VaccineCode | parseMapList) | uniq | join "," }}</td> {{/* Immunization */}}
<td>{{pluckList "code" ($entry.Status | parseMapList) | uniq | join "," }}</td> {{/* Status */}}
<td th:insert="~{IpsUtilityFragments :: concatDoseNumber (list=*{getProtocolApplied()})}">Dose Number</td> {{/* Comments - TODO: use FHIRPath */}}
<td>{{pluckList "display" ($entry.Manufacturer | parseList) | uniq | join "," }}</td> {{/* Manufacturer */}}
<td>{{pluckList "display" ($entry.Manufacturer | parseMapList) | uniq | join "," }}</td> {{/* Manufacturer */}}
<td>{{$entry.LotNumber}}</td> {{/* Lot Number */}}
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td>
<td>{{$entry.Date | date "2006-01-02"}}</td> {{/* Performed Date */}}
Expand Down
12 changes: 6 additions & 6 deletions backend/pkg/utils/ips/templates/includes/observation-unit.gohtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{if not (empty .ValueString) }}
{{if not (empty (.ValueString | parseMapList)) }}
{{.ValueString}}
{{else if not (empty (.ValueQuantity | parseList)) }}
{{.ValueQuantity | parseList | pluckList "unit" | join "," }}
{{else if not (empty (.ValueQuantity | parseMapList)) }}
{{.ValueQuantity | parseMapList | pluckList "unit" | join "," }}
{{else if not (empty .ValueDate) }}
{{.ValueDate | date "2006-01-02" }}
{{else if not (empty (.ValueConcept | parseList)) }}
{{else if not (empty (.ValueConcept | parseMapList)) }}
{{.ValueConcept}}
{{else if not (empty (.ComponentValueQuantity | parseList)) }}
{{.ComponentValueQuantity | parseList | pluckList "unit" | join "," }}
{{else if not (empty (.ComponentValueQuantity | parseMapList)) }}
{{.ComponentValueQuantity | parseMapList | pluckList "unit" | join "," }}
{{end}}
28 changes: 16 additions & 12 deletions backend/pkg/utils/ips/templates/includes/observation-value.gohtml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
{{if not (empty .entry.ValueString) }}
{{.ValueString}}
{{else if not (empty (.entry.ValueQuantity | parseList)) }}
{{.entry.ValueQuantity | parseList | pluckList "value" | roundList 2 | join "," }}
{{if not (empty (.entry.ValueString | parseMapList)) }}
{{.entry.ValueString | parseStringList | join ","}}
{{else if not (empty (.entry.ValueQuantity | parseMapList)) }}
{{.entry.ValueQuantity | parseMapList | pluckList "value" | roundList 2 | join "," }}
{{if (get . "include_unit")}}
{{.entry.ValueQuantity | parseList | pluckList "unit" | join "," }}
{{.entry.ValueQuantity | parseMapList | pluckList "unit" | join "," }}
{{end}}
{{else if not (empty .entry.ValueDate) }}
{{.entry.ValueDate | date "2006-01-02" }}
{{else if not (empty (.entry.ValueConcept | parseList)) }}
{{else if not (empty (.entry.ValueConcept | parseMapList)) }}
{{.entry.ValueConcept}}
{{else if not (empty (.entry.ComponentValueQuantity | parseList)) }}
{{$componentCodeText := $.entry.ComponentCode | parseList | pluckList "text" }}
{{$componentValueQuantity := $.entry.ComponentValueQuantity | parseList | pluckList "value" | roundList 2 }}
{{else if not (empty (.entry.ComponentValueQuantity | parseMapList)) }}
{{$componentCodeText := .entry.ComponentCode | parseMapList | pluckList "text" }}
{{$componentValueQuantity := .entry.ComponentValueQuantity | parseMapList | pluckList "value" | roundList 2 }}
{{$componentValueQuantityUnit := .entry.ComponentValueQuantity | parseMapList | pluckList "unit" }}


{{range $index, $text := $componentCodeText }}
{{$text}} - {{index $componentValueQuantity $index}}
{{if (get $ "include_unit")}}
{{index $componentValueQuantityUnit $index}}
{{end}}
<br/>
{{end}}

{{if (get . "include_unit")}}
{{.ComponentValueQuantity | parseList | pluckList "unit" | join "," }}
{{end}}

{{end}}
4 changes: 2 additions & 2 deletions backend/pkg/utils/ips/templates/medical_devices.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Date Recorded: DeviceUseStatement.recordedDateTime
{{- /*gotype: github.com/fastenhealth/fasten-onprem/backend/pkg/utils/ips.NarrativeTemplateData*/ -}}
{{range $index, $entry := .Device }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Type | parseList) | uniq | join "," }}</td> {{/* Device */}}
<td>{{pluckList "code" ($entry.Status | parseList) | uniq | join "," }}</td> {{/* Status */}}
<td>{{pluckList "text" ($entry.Type | parseMapList) | uniq | join "," }}</td> {{/* Device */}}
<td>{{pluckList "code" ($entry.Status | parseMapList) | uniq | join "," }}</td> {{/* Status */}}
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td>
<td></td> {{/* Date Recorded */}}
</tr>
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/utils/ips/templates/plan_of_care.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Planned End: CarePlan.period.end
{{range $index, $entry := .CarePlan }}
<tr id="{{$entry.SourceResourceID}}">
<td th:text="*{getDescription()}">Activity</td>
<td>{{pluckList "code" ($entry.Intent | parseList) | uniq | join "," }}</td> {{/* Intent */}}
<td>{{pluckList "code" ($entry.Intent | parseMapList) | uniq | join "," }}</td> {{/* Intent */}}
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td>
<td>{{$entry.Date}}</td>{{/* Planned Start */}}
<td th:text="*{getPeriod().getEndElement().getValue()}">Planned End</td>
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/utils/ips/templates/pregnancy.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Date: Observation.effectiveDateTime || Observation.effectivePeriod.start
{{- /*gotype: github.com/fastenhealth/fasten-onprem/backend/pkg/utils/ips.NarrativeTemplateData*/ -}}
{{range $index, $entry := .Observation }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Code | parseList) | uniq | join "," }}</td> {{/* Code */}}
<td>{{pluckList "text" ($entry.Code | parseMapList) | uniq | join "," }}</td> {{/* Code */}}
<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 */}}
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/utils/ips/templates/problem_list.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Onset Date: Condition.onsetDateTime || Condition.onsetPeriod.start && “-“ &&
{{- /*gotype: github.com/fastenhealth/fasten-onprem/backend/pkg/utils/ips.NarrativeTemplateData*/ -}}
{{range $index, $entry := .Condition }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Code | parseList) | uniq | join "," }}</td> {{/* Medical Problems */}}
<td>{{pluckList "code" ($entry.ClinicalStatus | parseList) | uniq | join "," }}</td> {{/* Status */}}
<td>{{pluckList "text" ($entry.Code | parseMapList) | uniq | join "," }}</td> {{/* Medical Problems */}}
<td>{{pluckList "code" ($entry.ClinicalStatus | parseMapList) | uniq | join "," }}</td> {{/* Status */}}
<td th:insert="~{IpsUtilityFragments :: concat (list=*{getNote()},attr='text')}">Comments</td>
<td>{{$entry.OnsetDate | date "2006-01-02"}}</td> {{/* Onset */}}
</tr>
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/utils/ips/templates/social_history.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Date: Observation.effectiveDateTime || Observation.effectivePeriod.start
{{- /*gotype: github.com/fastenhealth/fasten-onprem/backend/pkg/utils/ips.NarrativeTemplateData*/ -}}
{{range $index, $entry := .Observation }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Code | parseList) | uniq | join "," }}</td> {{/* Code */}}
<td>{{pluckList "text" ($entry.Code | parseMapList) | uniq | join "," }}</td> {{/* Code */}}
<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>
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/utils/ips/templates/vital_signs.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Date: Observation.effectiveDateTime || Observation.effectivePeriod.start
{{- /*gotype: github.com/fastenhealth/fasten-onprem/backend/pkg/utils/ips.NarrativeTemplateData*/ -}}
{{range $index, $entry := .Observation }}
<tr id="{{$entry.SourceResourceID}}">
<td>{{pluckList "text" ($entry.Code | parseList) | uniq | join "," }}</td> {{/* Code */}}
<td>{{pluckList "text" ($entry.Code | parseMapList) | uniq | join "," }}</td> {{/* Code */}}
<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>
Expand Down

0 comments on commit 36c2a2f

Please sign in to comment.