TEA record: ADOS-2 by item, EEG quality and its alterations against the age norm; page tests follow the cards' and dialog's words

This commit is contained in:
Roberto Treviño
2026-11-28 13:29:23 -06:00
parent cb0403affb
commit 37444a25a1
6 changed files with 192 additions and 3 deletions
+68
View File
@@ -13,6 +13,8 @@ import type {
RiskAssessment,
} from 'fhir/r4';
import { Api } from '../api/api';
import { studies as eegStudies } from '../api/fn/eeg/studies';
import { study as eegStudy } from '../api/fn/eeg/study';
import { readReport$Json } from '../api/fn/models/read-report-json';
import type { Domain } from '../api/models/domain';
import { code, EXT, ext, Fhir, label, resources } from '../fhir';
@@ -164,6 +166,72 @@ export class Paciente {
};
},
});
/** TEA: her latest ADOS-2 (an encounter whose observations are the catalog's
* `ados2.*` fields), item by item, and its totals. */
protected readonly ados2 = computed(() => {
const d = this.data.value();
if (!d) return undefined;
const field = (o: Observation) => (code(o.code) ?? '').replace(/^ados2\./, '');
const scored = [...d.observations.values()].filter(
(o) => (code(o.code) ?? '').startsWith('ados2.') && o.valueQuantity?.value !== undefined,
);
const latest = scored
.map((o) => o.effectiveDateTime ?? '')
.sort()
.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 figure: Figure = {
data: [
{
type: 'bar',
orientation: 'h',
y: items.map((o) => label(o.code)),
x: items.map((o) => o.valueQuantity!.value!),
marker: { color: PALETTE[0] },
hovertemplate: '%{y}: %{x}<extra></extra>',
},
],
layout: {
showlegend: false,
margin: { t: 10, r: 16, b: 40, l: 16 },
xaxis: { title: { text: 'Puntaje (0 a 3)' }, range: [0, 3], dtick: 1 },
yaxis: { autorange: 'reversed', automargin: true, type: 'category' },
},
};
return {
date: latest.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! })),
};
});
/** TEA: her EEG as analysed (the latest), its quality and its metrics against the age
* curves: those outside the band are its alterations. */
protected readonly eeg = resource({
params: () => (this.domain() === 'tea' ? this.id() : undefined),
loader: async ({ params: person }) => {
const mine = (await this.api.invoke(eegStudies))
.filter((s) => s.person_id === person && s.analysed)
.sort((a, b) => b.study_date.localeCompare(a.study_date));
if (!mine.length) return { study: undefined, analysis: undefined };
return {
study: mine[0],
analysis: await this.api.invoke(eegStudy, { eeg_id: mine[0].id }),
};
},
});
protected readonly alterations = computed(() =>
(this.eeg.value()?.analysis?.metrics ?? []).filter((m) => m.outside),
);
protected readonly scored = computed(() =>
(this.eeg.value()?.analysis?.metrics ?? []).some((m) => m.z !== null && m.z !== undefined),
);
protected readonly shown = signal<string | undefined>(undefined);
protected readonly curve = computed<Figure>(() => {
const models = this.models().filter((m) => m.predictions.length > 1);