TEA record: ADOS-2 items, CSS and classification from its one observation

This commit is contained in:
Roberto Treviño
2026-12-06 04:00:36 -06:00
parent 83a360aed1
commit ec3eeeef65
+19 -19
View File
@@ -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}<extra></extra>',
},
@@ -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) }] : []),
],
};
});