diff --git a/src/app/paciente/tea-record.ts b/src/app/paciente/tea-record.ts index dbdf2a3..08ef10d 100644 --- a/src/app/paciente/tea-record.ts +++ b/src/app/paciente/tea-record.ts @@ -15,7 +15,7 @@ import { OUTCOME_NAMES, ZONE_NAMES, } from '../eeg-labels'; -import { code, label } from '../fhir'; +import { code, ext, label } from '../fhir'; import { name } from '../indicadores/labels'; import { Loading } from '../loading'; import { Figure, PALETTE, Plot } from '../plot'; @@ -34,28 +34,24 @@ export class TeaRecord { protected readonly name = name; protected readonly levelNames = LEVEL_NAMES; - /** TEA: her latest ADOS-2 (an encounter whose observations are the catalog's - * `ados2.*` fields), item by item, and its totals. */ + /** TEA: her latest ADOS-2 (one observation: its items as components, its CSS the value + * and its classification the interpretation), item by item. */ protected readonly ados2 = computed(() => { - const field = (o: Observation) => (code(o.code) ?? '').replace(/^ados2\./, ''); - const scored = this.observations().filter( - (o) => (code(o.code) ?? '').startsWith('ados2.') && o.valueQuantity?.value !== undefined, - ); - const latest = scored - .map((o) => o.effectiveDateTime ?? '') - .sort() + const latest = this.observations() + .filter((o) => code(o.code) === 'ados2') + .sort((a, b) => (a.effectiveDateTime ?? '').localeCompare(b.effectiveDateTime ?? '')) .at(-1); if (latest === undefined) return undefined; - const results = scored.filter((o) => (o.effectiveDateTime ?? '') === latest); - const totals = ['social_affect_total', 'restricted_repetitive_total', 'overall_total']; - const items = results.filter((o) => !totals.includes(field(o))); + const items = (latest.component ?? []).filter( + (c) => ext(c, 'ados2-domain') && c.valueQuantity?.value !== undefined, + ); const figure: Figure = { data: [ { type: 'bar', orientation: 'h', - y: items.map((o) => label(o.code)), - x: items.map((o) => o.valueQuantity!.value!), + y: items.map((c) => c.code.text ?? label(c.code)), + x: items.map((c) => c.valueQuantity!.value!), marker: { color: PALETTE[0] }, hovertemplate: '%{y}: %{x}', }, @@ -67,13 +63,17 @@ export class TeaRecord { yaxis: { autorange: 'reversed', automargin: true, type: 'category' }, }, }; + const classification = latest.interpretation?.[0]; return { - date: latest.slice(0, 10), + date: (latest.effectiveDateTime ?? '').slice(0, 10), figure, height: 60 + items.length * 22, - totals: results - .filter((o) => totals.includes(field(o))) - .map((o) => ({ label: label(o.code), value: o.valueQuantity!.value! })), + totals: [ + ...(latest.valueInteger !== undefined + ? [{ label: 'CSS', value: latest.valueInteger }] + : []), + ...(classification ? [{ label: 'Clasificación', value: label(classification) }] : []), + ], }; });