F7b: ADOS-2 association as library 0.4.0 with the accepted spike tests
The risk page and the Gobernanza forest show the new spike tests: event texts, n, "(exploratorio)", the "datos insuficientes" notice with a greyed OR and a faded marker, spikes as "sin pico" or "con pico", and what the model computes (Toddler CSS from Esler 2015, one model adjusted for module, spike tests on the total CSS until the hospital sends CSS by domain).
This commit is contained in:
@@ -9,6 +9,9 @@ export const ZONE_NAMES: Record<string, string> = {
|
||||
occipital: 'Occipital',
|
||||
posterior: 'Posterior',
|
||||
global: 'Global',
|
||||
any: 'Cualquier zona',
|
||||
left: 'Izquierda (frontal + temporal)',
|
||||
right: 'Derecha (frontal + temporal)',
|
||||
};
|
||||
|
||||
export const BIOMARKER_NAMES: Record<string, string> = {
|
||||
@@ -41,9 +44,38 @@ export const OUTCOME_NAMES: Record<string, string> = {
|
||||
ados2_item_20: 'Interés sensorial inusual',
|
||||
ados2_item_21: 'Manierismos de manos y dedos',
|
||||
ados2_item_22: 'Intereses repetitivos o conductas estereotipadas',
|
||||
ados2_items_01_18: 'Vocalización dirigida o entonación (ítems 1 y 18)',
|
||||
ados2_items_04_05_07:
|
||||
'Contacto visual, expresiones faciales o disfrute compartido (ítems 4, 5 y 7)',
|
||||
CSS: 'Puntuación de severidad (CSS)',
|
||||
};
|
||||
|
||||
export const SPIKE_PREDICTOR = 'algún pico en NREM (sí/no)';
|
||||
|
||||
export function predictorName(biomarker: string, name: string): string {
|
||||
return biomarker === 'spikes' ? `${name}: ${SPIKE_PREDICTOR}` : name;
|
||||
}
|
||||
|
||||
const EVENT_NAMES: Record<string, string> = {
|
||||
'>=2': 'reactivo ≥ 2',
|
||||
'>=8': 'CSS ≥ 8',
|
||||
'alguno >=2': 'alguno de los reactivos ≥ 2',
|
||||
};
|
||||
|
||||
export function eventLabel(event: string | null | undefined): string {
|
||||
return event ? (EVENT_NAMES[event] ?? event) : '—';
|
||||
}
|
||||
|
||||
export function insufficient(reason: string | null | undefined): boolean {
|
||||
return !!reason?.startsWith('datos insuficientes');
|
||||
}
|
||||
|
||||
export function kindTitle(title: string, kind: string | null | undefined): string {
|
||||
return kind === 'exploratory' ? `${title} (exploratorio)` : title;
|
||||
}
|
||||
|
||||
export const FADED = 0.35;
|
||||
|
||||
export const REASON_NAMES: Record<string, string> = {
|
||||
'no-spindles': 'sin husos',
|
||||
'few-wake-windows': 'pocas ventanas en vigilia',
|
||||
|
||||
@@ -149,6 +149,45 @@ describe('governance figures', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('marks exploratory pairs, fades the insufficient ones and tells event and n', () => {
|
||||
const row = { odds_ratio: 2, ci_low: 1, ci_high: 3, q: null, n: 40 };
|
||||
const reason = 'datos insuficientes: 40 con evento y 0 sin evento (minimo 5)';
|
||||
const [found] = interpretabilityFigures({
|
||||
kind: 'forest',
|
||||
rows: [
|
||||
{
|
||||
...row,
|
||||
biomarker: 'spikes',
|
||||
zone: 'central',
|
||||
outcome_code: 'ados2_item_21',
|
||||
kind: 'exploratory',
|
||||
event: '>=2',
|
||||
reason: null,
|
||||
},
|
||||
{
|
||||
...row,
|
||||
biomarker: 'gradient',
|
||||
zone: 'global',
|
||||
outcome_code: 'CSS',
|
||||
kind: 'domain',
|
||||
event: '>=8',
|
||||
reason,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(found.figure.data[0]).toMatchObject({
|
||||
y: [
|
||||
'Puntas paroxísticas: algún pico en NREM (sí/no) · Central · Manierismos de manos y dedos (exploratorio)',
|
||||
],
|
||||
marker: { opacity: 1 },
|
||||
hovertemplate: expect.stringContaining('Evento: reactivo ≥ 2<br>n: 40'),
|
||||
});
|
||||
expect(found.figure.data[1]).toMatchObject({
|
||||
marker: { opacity: 0.35 },
|
||||
hovertemplate: expect.stringContaining(reason),
|
||||
});
|
||||
});
|
||||
|
||||
it('draws nothing for a report it does not know', () => {
|
||||
expect(interpretabilityFigures({ kind: 'other' })).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import type { Analysis } from '../api/models/analysis';
|
||||
import type { Figure } from '../plot';
|
||||
import { PALETTE } from '../plot';
|
||||
import { BIOMARKER_NAMES, OUTCOME_NAMES, ZONE_NAMES } from '../eeg-labels';
|
||||
import {
|
||||
BIOMARKER_NAMES,
|
||||
eventLabel,
|
||||
FADED,
|
||||
insufficient,
|
||||
kindTitle,
|
||||
OUTCOME_NAMES,
|
||||
predictorName,
|
||||
ZONE_NAMES,
|
||||
} from '../eeg-labels';
|
||||
import { logAxis } from '../indicadores/figures';
|
||||
|
||||
interface Band {
|
||||
@@ -106,10 +115,36 @@ interface AssociationRow {
|
||||
biomarker: string;
|
||||
zone: string;
|
||||
outcome_code: string;
|
||||
kind?: string | null;
|
||||
event?: string | null;
|
||||
n?: number | null;
|
||||
odds_ratio: number | null;
|
||||
ci_low: number | null;
|
||||
ci_high: number | null;
|
||||
q: number | null;
|
||||
reason?: string | null;
|
||||
}
|
||||
|
||||
function forestLabel(row: AssociationRow): string {
|
||||
const title = [
|
||||
predictorName(row.biomarker, BIOMARKER_NAMES[row.biomarker] ?? row.biomarker),
|
||||
ZONE_NAMES[row.zone] ?? row.zone,
|
||||
OUTCOME_NAMES[row.outcome_code] ?? row.outcome_code,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' · ');
|
||||
return kindTitle(title, row.kind);
|
||||
}
|
||||
|
||||
function forestHover(row: AssociationRow): string {
|
||||
return [
|
||||
'%{y}',
|
||||
'OR: %{x}',
|
||||
`q: ${row.q ?? '—'}`,
|
||||
`Evento: ${eventLabel(row.event)}`,
|
||||
`n: ${row.n ?? '—'}`,
|
||||
...(row.reason ? [row.reason] : []),
|
||||
].join('<br>');
|
||||
}
|
||||
|
||||
export function interpretabilityFigures(
|
||||
@@ -223,7 +258,7 @@ export function interpretabilityFigures(
|
||||
title: 'Asociaciones ADOS-2',
|
||||
figure: {
|
||||
data: (report['rows'] as AssociationRow[]).map((row) => {
|
||||
const label = [row.biomarker, row.zone, row.outcome_code].filter(Boolean).join(' · ');
|
||||
const label = forestLabel(row);
|
||||
const odds = row.odds_ratio;
|
||||
return {
|
||||
x: [odds],
|
||||
@@ -232,7 +267,7 @@ export function interpretabilityFigures(
|
||||
showlegend: false,
|
||||
type: 'scatter',
|
||||
mode: 'markers',
|
||||
marker: { color: PALETTE[4] },
|
||||
marker: { color: PALETTE[4], opacity: insufficient(row.reason) ? FADED : 1 },
|
||||
error_x:
|
||||
odds == null || row.ci_low == null || row.ci_high == null
|
||||
? undefined
|
||||
@@ -242,7 +277,7 @@ export function interpretabilityFigures(
|
||||
array: [row.ci_high - odds],
|
||||
arrayminus: [odds - row.ci_low],
|
||||
},
|
||||
hovertemplate: '%{y}<br>OR: %{x}<br>q: ' + (row.q ?? '—') + '<extra></extra>',
|
||||
hovertemplate: `${forestHover(row)}<extra></extra>`,
|
||||
};
|
||||
}),
|
||||
layout: {
|
||||
|
||||
@@ -54,7 +54,8 @@ export function teaRows(page: Bundle) {
|
||||
: ados.at(-1);
|
||||
const pairs = (risk?.prediction ?? []).map((p) => {
|
||||
const pair = associationPair(p);
|
||||
return { ...pair, title: pairTitle(pair.pair ?? '', evaluation) };
|
||||
const kind = ext(p, 'association-kind')?.valueCode;
|
||||
return { ...pair, title: pairTitle(pair.pair ?? '', evaluation, kind) };
|
||||
});
|
||||
return {
|
||||
patient,
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
RiskAssessment,
|
||||
} from 'fhir/r4';
|
||||
import { ados2Component, ados2Groups } from '../ados2';
|
||||
import { reasonLabel, ZONE_NAMES } from '../eeg-labels';
|
||||
import { kindTitle, OUTCOME_NAMES, predictorName, reasonLabel, ZONE_NAMES } from '../eeg-labels';
|
||||
import { code, CURP, ext, extensions, Fhir, label, resources } from '../fhir';
|
||||
|
||||
export const TEA_STEPS = [
|
||||
@@ -72,14 +72,19 @@ export function zoneLabel(zone: string): string {
|
||||
return zone === 'frontal_midline' ? 'Frontal medial' : (ZONE_NAMES[zone] ?? zone);
|
||||
}
|
||||
|
||||
export function pairTitle(key: string, ados?: Observation): string {
|
||||
export function pairTitle(key: string, ados?: Observation, kind?: string): string {
|
||||
const [biomarker, zone = '', outcome = ''] = key.split('|');
|
||||
const item = /^ados2_item_(\d+)$/.exec(outcome);
|
||||
return [
|
||||
METRIC_TITLES[BIOMARKER_METRICS[biomarker]] ?? biomarker,
|
||||
const title = [
|
||||
predictorName(biomarker, METRIC_TITLES[BIOMARKER_METRICS[biomarker]] ?? biomarker),
|
||||
zoneLabel(zone),
|
||||
item ? label(ados2Component(ados, Number(item[1]))?.code) || outcome : outcome,
|
||||
item
|
||||
? label(ados2Component(ados, Number(item[1]))?.code) || outcome
|
||||
: outcome.startsWith('ados2_items_')
|
||||
? (OUTCOME_NAMES[outcome] ?? outcome)
|
||||
: outcome,
|
||||
].join(' · ');
|
||||
return kindTitle(title, kind);
|
||||
}
|
||||
|
||||
const NSS = 'https://isssteleon.org/fhir/sid/nss';
|
||||
@@ -269,6 +274,11 @@ export type Pair = {
|
||||
high?: number;
|
||||
probability?: number;
|
||||
reference?: number;
|
||||
kind?: string;
|
||||
event?: string;
|
||||
n?: number;
|
||||
reason?: string;
|
||||
predictor?: number;
|
||||
};
|
||||
|
||||
export type Study = ReturnType<typeof study>;
|
||||
@@ -292,12 +302,20 @@ function associations(
|
||||
zone === 'global' || biomarker === 'posterior_rhythm'
|
||||
? metric
|
||||
: metric?.sites.find((s) => s.kind === 'zone' && s.name === zone);
|
||||
const spikes = biomarker === 'spikes';
|
||||
const kind = ext(p, 'association-kind')?.valueCode;
|
||||
const predictor = ext(p, 'association-predictor')?.valueDecimal;
|
||||
return {
|
||||
key,
|
||||
title: pairTitle(key, ados[0]),
|
||||
title: pairTitle(key, ados[0], kind),
|
||||
headline: ext(p, 'association-headline')?.valueBoolean === true,
|
||||
altered: site?.outside != null && site.outside !== 0,
|
||||
z: site?.z,
|
||||
altered: spikes ? predictor === 1 : site?.outside != null && site.outside !== 0,
|
||||
z: spikes ? undefined : site?.z,
|
||||
kind,
|
||||
event: ext(p, 'association-event')?.valueString,
|
||||
n: ext(p, 'association-n')?.valueInteger,
|
||||
reason: ext(p, 'association-reason')?.valueString,
|
||||
predictor,
|
||||
odds: ext(p, 'association-odds-ratio')?.valueDecimal,
|
||||
low: ext(p, 'association-ci-low')?.valueDecimal,
|
||||
high: ext(p, 'association-ci-high')?.valueDecimal,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { FADED, insufficient, SPIKE_PREDICTOR } from '../eeg-labels';
|
||||
import { bandFill, type Centile } from '../gobernanza/figures';
|
||||
import { logAxis, valueAxis } from '../indicadores/figures';
|
||||
import { Figure, PALETTE } from '../plot';
|
||||
@@ -290,7 +291,11 @@ export function forest(pairs: Pair[], alteredOnly: boolean): SingleTrace {
|
||||
array: intervals('high'),
|
||||
arrayminus: intervals('low'),
|
||||
},
|
||||
marker: { color: PALETTE[4], size: 8 },
|
||||
marker: {
|
||||
color: PALETTE[4],
|
||||
size: 8,
|
||||
opacity: visible.map((p) => (insufficient(p.reason) ? FADED : 1)),
|
||||
},
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
@@ -365,25 +370,68 @@ const ALTERED_Z = 2;
|
||||
|
||||
const expit = (x: number) => 1 / (1 + Math.exp(-x));
|
||||
|
||||
function logistic(pair: Pair): ((x: number) => number) | undefined {
|
||||
const { reference, odds } = pair;
|
||||
if (reference == null || reference <= 0 || reference >= 1 || !odds || odds <= 0) {
|
||||
return undefined;
|
||||
}
|
||||
const intercept = Math.log(reference / (1 - reference));
|
||||
return (x) => expit(intercept + Math.log(odds) * x);
|
||||
}
|
||||
|
||||
const SPIKE_ANSWERS = ['sin pico', 'con pico'];
|
||||
|
||||
function spikeProbability(pair: Pair): Figure {
|
||||
const model = logistic(pair);
|
||||
const data: Figure['data'] = [];
|
||||
if (pair.reference != null) {
|
||||
data.push({
|
||||
type: 'scatter',
|
||||
mode: 'markers',
|
||||
name: model ? 'Modelo' : 'Referencia',
|
||||
x: model ? SPIKE_ANSWERS : SPIKE_ANSWERS.slice(0, 1),
|
||||
y: model ? [0, 1].map((x) => 100 * model(x)) : [100 * pair.reference],
|
||||
marker: { size: 12, color: PALETTE[4], symbol: 'diamond-open' },
|
||||
});
|
||||
}
|
||||
if (pair.predictor != null && pair.probability != null) {
|
||||
data.push({
|
||||
type: 'scatter',
|
||||
mode: 'markers',
|
||||
name: 'Paciente',
|
||||
x: [SPIKE_ANSWERS[pair.predictor === 1 ? 1 : 0]],
|
||||
y: [100 * pair.probability],
|
||||
marker: { size: 10, color: PALETTE[2] },
|
||||
});
|
||||
}
|
||||
return {
|
||||
data,
|
||||
layout: {
|
||||
xaxis: {
|
||||
title: { text: SPIKE_PREDICTOR },
|
||||
type: 'category',
|
||||
categoryorder: 'array',
|
||||
categoryarray: SPIKE_ANSWERS,
|
||||
range: [-0.5, 1.5],
|
||||
},
|
||||
yaxis: { title: { text: 'Probabilidad (%)' }, ...valueAxis([0, 100]), range: [0, 100] },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function probabilityCurve(pair: Pair): Figure {
|
||||
if (pair.key.startsWith('spikes|')) return spikeProbability(pair);
|
||||
const data: Figure['data'] = [];
|
||||
const extent = Math.max(4, Math.ceil(Math.abs(pair.z ?? 0)) + 1);
|
||||
const modelled =
|
||||
pair.reference != null &&
|
||||
pair.reference > 0 &&
|
||||
pair.reference < 1 &&
|
||||
pair.odds &&
|
||||
pair.odds > 0;
|
||||
if (modelled) {
|
||||
const intercept = Math.log(pair.reference! / (1 - pair.reference!));
|
||||
const slope = Math.log(pair.odds!);
|
||||
const model = logistic(pair);
|
||||
if (model) {
|
||||
const x = Array.from({ length: 81 }, (_, i) => (extent * (i - 40)) / 40);
|
||||
data.push({
|
||||
type: 'scatter',
|
||||
mode: 'lines',
|
||||
name: 'Modelo',
|
||||
x,
|
||||
y: x.map((z) => 100 * expit(intercept + slope * z)),
|
||||
y: x.map((z) => 100 * model(z)),
|
||||
line: { color: PALETTE[4], width: 2.5 },
|
||||
hovertemplate: 'z = %{x:.1~f}: %{y:.1~f} %<extra></extra>',
|
||||
});
|
||||
@@ -429,7 +477,7 @@ export function probabilityCurve(pair: Pair): Figure {
|
||||
range: [-extent, extent],
|
||||
},
|
||||
yaxis: { title: { text: 'Probabilidad (%)' }, ...valueAxis([0, 100]), range: [0, 100] },
|
||||
...(modelled ? { shapes: [zone(-extent, -ALTERED_Z), zone(ALTERED_Z, extent)] } : {}),
|
||||
...(model ? { shapes: [zone(-extent, -ALTERED_Z), zone(ALTERED_Z, extent)] } : {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -230,6 +230,24 @@ describe('Figuras del paciente TEA', () => {
|
||||
expect(figure.layout?.shapes).toBeUndefined();
|
||||
});
|
||||
|
||||
it('dibuja las puntas como sin pico y con pico, y marca el caso del niño', () => {
|
||||
const figure = probabilityCurve({
|
||||
...pair,
|
||||
key: 'spikes|any|CSS',
|
||||
z: undefined,
|
||||
predictor: 1,
|
||||
});
|
||||
expect(figure.data).toMatchObject([
|
||||
{ mode: 'markers', name: 'Modelo', x: ['sin pico', 'con pico'] },
|
||||
{ mode: 'markers', name: 'Paciente', x: ['con pico'], y: [70] },
|
||||
]);
|
||||
const [without, withSpike] = (figure.data[0] as { y: number[] }).y;
|
||||
expect(without).toBeCloseTo(20);
|
||||
expect(withSpike).toBeCloseTo(100 * (0.75 / 1.75));
|
||||
expect(figure.layout?.xaxis?.title).toEqual({ text: 'algún pico en NREM (sí/no)' });
|
||||
expect(figure.layout?.shapes).toBeUndefined();
|
||||
});
|
||||
|
||||
it('marca con un rombo cada etapa completada en su fecha', () => {
|
||||
const figure = timeline(steps)!;
|
||||
const markers = figure.data.find((trace) => trace.type === 'scatter')!;
|
||||
@@ -320,6 +338,8 @@ describe('Expediente TEA', () => {
|
||||
);
|
||||
expect(section?.blocks[0].table?.headers).toEqual([
|
||||
'Par',
|
||||
'Evento',
|
||||
'n',
|
||||
'OR',
|
||||
'IC 95 %',
|
||||
'Prob. ADOS-2 severo',
|
||||
@@ -327,6 +347,29 @@ describe('Expediente TEA', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('atenúa el OR y avisa cuando un par tiene datos insuficientes, sin ocultar n', () => {
|
||||
const short: Pair = {
|
||||
...pair,
|
||||
headline: false,
|
||||
event: 'alguno >=2',
|
||||
n: 7,
|
||||
reason: 'datos insuficientes: 7 con evento y 0 sin evento (minimo 5)',
|
||||
};
|
||||
const patient = { ...record, pairs: [{ ...pair, event: '>=8', n: 40 }, short] };
|
||||
const section = recordSections(patient, new Map()).find(
|
||||
(section) => section.title === 'Relación con el ADOS-2',
|
||||
)!;
|
||||
expect(section.blocks[0].table?.rows.map((row) => row.slice(1, 3))).toEqual([
|
||||
['CSS ≥ 8', '40'],
|
||||
['alguno de los reactivos ≥ 2', '7'],
|
||||
]);
|
||||
expect(section.blocks[0].table?.faded).toEqual({ column: 3, rows: [1] });
|
||||
expect(section.blocks.slice(1)).toEqual([{ text: `${short.title}: ${short.reason}` }]);
|
||||
expect(forest(patient.pairs, false).data[0]).toMatchObject({ marker: { opacity: [1, 0.35] } });
|
||||
const content = teaPdfContent('Expediente TEA', [section], []);
|
||||
expect(JSON.stringify(content)).toContain('{"text":"3","color":"#767676"}');
|
||||
});
|
||||
|
||||
it('dibuja la línea del tiempo como un Gantt con rombos, no como tabla', () => {
|
||||
const [section] = recordSections(record, new Map());
|
||||
expect(section.title).toBe('Línea del tiempo');
|
||||
@@ -553,8 +596,8 @@ describe('Análisis de riesgo TEA', () => {
|
||||
expect(probability?.blocks).toEqual([
|
||||
{
|
||||
table: {
|
||||
headers: ['Par', 'Prob. ADOS-2 severo', 'Referencia'],
|
||||
rows: [['Husos de sueño · Central · CSS (principal)', '70%', '20%']],
|
||||
headers: ['Par', 'Evento', 'n', 'Prob. ADOS-2 severo', 'Referencia'],
|
||||
rows: [['Husos de sueño · Central · CSS (principal)', '—', '—', '70%', '20%']],
|
||||
},
|
||||
},
|
||||
{ text: 'No es la probabilidad de TEA.' },
|
||||
@@ -563,6 +606,53 @@ describe('Análisis de riesgo TEA', () => {
|
||||
'No es la probabilidad de TEA.',
|
||||
);
|
||||
});
|
||||
|
||||
it('toma de FHIR el par de puntas, que está alterado cuando hubo algún pico', async () => {
|
||||
const prediction = (outcome: string, kind: string, predictor: number) => ({
|
||||
outcome: { coding: [{ code: outcome }] },
|
||||
extension: [
|
||||
{ url: EXT + 'association-kind', valueCode: kind },
|
||||
{ url: EXT + 'association-event', valueString: '>=2' },
|
||||
{ url: EXT + 'association-n', valueInteger: 30 },
|
||||
{ url: EXT + 'association-predictor', valueDecimal: predictor },
|
||||
],
|
||||
});
|
||||
const bundle = {
|
||||
resourceType: 'Bundle',
|
||||
type: 'searchset',
|
||||
entry: [
|
||||
{ search: { mode: 'match' }, resource: { resourceType: 'Patient', id: 'child' } },
|
||||
{
|
||||
search: { mode: 'include' },
|
||||
resource: {
|
||||
resourceType: 'RiskAssessment',
|
||||
id: 'risk',
|
||||
status: 'final',
|
||||
subject: { reference: 'Patient/child' },
|
||||
prediction: [
|
||||
prediction('spikes|left|ados2_items_01_18', 'composite', 1),
|
||||
prediction('spikes|central|ados2_item_21', 'exploratory', 0),
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const fhir = { search: async () => bundle } as unknown as Fhir;
|
||||
const { pairs } = await loadTeaPatient(fhir, 'child');
|
||||
expect(pairs).toMatchObject([
|
||||
{
|
||||
title:
|
||||
'Puntas paroxísticas: algún pico en NREM (sí/no) · Izquierda (frontal + temporal) · Vocalización dirigida o entonación (ítems 1 y 18)',
|
||||
altered: true,
|
||||
event: '>=2',
|
||||
n: 30,
|
||||
predictor: 1,
|
||||
},
|
||||
{ altered: false, kind: 'exploratory', predictor: 0 },
|
||||
]);
|
||||
expect(pairs[1].title).toMatch(/\(exploratorio\)$/);
|
||||
expect(pairs[0].z).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Títulos de las asociaciones TEA', () => {
|
||||
@@ -572,11 +662,17 @@ describe('Títulos de las asociaciones TEA', () => {
|
||||
});
|
||||
|
||||
it('resuelve el ítem del ADOS-2 con la evaluación del paciente', () => {
|
||||
expect(pairTitle('spikes|frontal_midline|ados2_item_02', ados)).toBe(
|
||||
'Puntas paroxísticas · Frontal medial · Señalar',
|
||||
expect(pairTitle('posterior_rhythm|posterior|ados2_item_02', ados)).toBe(
|
||||
'Ritmo posterior · Posterior · Señalar',
|
||||
);
|
||||
expect(pairTitle('spikes|frontal_midline|ados2_item_02')).toBe(
|
||||
'Puntas paroxísticas · Frontal medial · ados2_item_02',
|
||||
expect(pairTitle('posterior_rhythm|posterior|ados2_item_02')).toBe(
|
||||
'Ritmo posterior · Posterior · ados2_item_02',
|
||||
);
|
||||
expect(pairTitle('spikes|right|ados2_items_04_05_07')).toBe(
|
||||
'Puntas paroxísticas: algún pico en NREM (sí/no) · Derecha (frontal + temporal) · Contacto visual, expresiones faciales o disfrute compartido (ítems 4, 5 y 7)',
|
||||
);
|
||||
expect(pairTitle('spikes|any|CSS')).toBe(
|
||||
'Puntas paroxísticas: algún pico en NREM (sí/no) · Cualquier zona · CSS',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -40,10 +40,18 @@ import { Section } from './tea-sections';
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (row of table.rows; track $index) {
|
||||
@for (row of table.rows; track $index; let index = $index) {
|
||||
<tr>
|
||||
@for (cell of row; track $index) {
|
||||
<td>{{ cell }}</td>
|
||||
<td
|
||||
[class.muted]="
|
||||
table.faded &&
|
||||
table.faded.column === $index &&
|
||||
table.faded.rows.includes(index)
|
||||
"
|
||||
>
|
||||
{{ cell }}
|
||||
</td>
|
||||
}
|
||||
</tr>
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { eventLabel, insufficient } from '../eeg-labels';
|
||||
import { downloadPdf, safeName, type PdfContent } from '../export';
|
||||
import type { Figure } from '../plot';
|
||||
import plotly from '../plotly-bundle';
|
||||
@@ -14,7 +15,7 @@ import {
|
||||
} from './tea-data';
|
||||
import { forest, headMap, probabilityCurve, timeline, zBars } from './tea-figures';
|
||||
|
||||
type Table = { headers: string[]; rows: string[][] };
|
||||
type Table = { headers: string[]; rows: string[][]; faded?: { column: number; rows: number[] } };
|
||||
type Chart = { title: string; figure: Figure; height?: number };
|
||||
type Block = {
|
||||
title?: string;
|
||||
@@ -31,17 +32,33 @@ export const probabilityTitle = 'Probabilidad según z';
|
||||
|
||||
const calculation =
|
||||
'Para cada alteración del EEG y región cerebral, el modelo da la probabilidad de que un ítem, un área o el puntaje total (CSS) del ADOS-2 salga severo, comparado con un niño en la referencia (z = 0).';
|
||||
const modelNotes =
|
||||
'El CSS del módulo Toddler sale de las tablas de Esler 2015. Un solo modelo reúne todos los módulos, ajustado por módulo. Las pruebas de puntas paroxísticas sobre el CSS usan el CSS total hasta que el hospital envíe el CSS por dominio. En esas puntas el modelo compara tener algún pico en NREM con no tener ninguno.';
|
||||
const limitations =
|
||||
'Las estimaciones dependen de la cohorte de referencia, de la calidad del EEG y de la disponibilidad de mediciones y pares. Las asociaciones no establecen causalidad. Las probabilidades no sustituyen la evaluación clínica ni establecen un diagnóstico.';
|
||||
|
||||
function associationRows(pairs: Pair[]): string[][] {
|
||||
return pairs.map((p) => [
|
||||
p.headline ? `${p.title} (principal)` : p.title,
|
||||
shown(p.odds),
|
||||
p.low == null && p.high == null ? '—' : `${shown(p.low)} a ${shown(p.high)}`,
|
||||
percent(p.probability),
|
||||
percent(p.reference),
|
||||
]);
|
||||
function pairCells(p: Pair): string[] {
|
||||
return [p.headline ? `${p.title} (principal)` : p.title, eventLabel(p.event), shown(p.n)];
|
||||
}
|
||||
|
||||
function associationTable(pairs: Pair[]): Table {
|
||||
return {
|
||||
headers: ['Par', 'Evento', 'n', 'OR', 'IC 95 %', 'Prob. ADOS-2 severo', 'Referencia'],
|
||||
rows: pairs.map((p) => [
|
||||
...pairCells(p),
|
||||
shown(p.odds),
|
||||
p.low == null && p.high == null ? '—' : `${shown(p.low)} a ${shown(p.high)}`,
|
||||
percent(p.probability),
|
||||
percent(p.reference),
|
||||
]),
|
||||
faded: { column: 3, rows: pairs.flatMap((p, i) => (insufficient(p.reason) ? [i] : [])) },
|
||||
};
|
||||
}
|
||||
|
||||
function notices(pairs: Pair[]): Block[] {
|
||||
return pairs
|
||||
.filter((p) => insufficient(p.reason))
|
||||
.map((p) => ({ text: `${p.title}: ${p.reason}` }));
|
||||
}
|
||||
|
||||
function metricCharts(m: Metric, norm: Chart | undefined): Chart[] {
|
||||
@@ -95,14 +112,7 @@ export function recordSections(patient: TeaPatient, norms: ReadonlyMap<string, C
|
||||
},
|
||||
{
|
||||
title: 'Relación con el ADOS-2',
|
||||
blocks: [
|
||||
{
|
||||
table: {
|
||||
headers: ['Par', 'OR', 'IC 95 %', 'Prob. ADOS-2 severo', 'Referencia'],
|
||||
rows: associationRows(patient.pairs),
|
||||
},
|
||||
},
|
||||
],
|
||||
blocks: [{ table: associationTable(patient.pairs) }, ...notices(patient.pairs)],
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -114,7 +124,7 @@ export function riskSections(patient: TeaPatient, alteredOnly: boolean, pair?: P
|
||||
.find(({ figure }) => figure.data[0].x?.length);
|
||||
const effects = forest(patient.pairs, alteredOnly);
|
||||
return [
|
||||
{ title: 'Qué calcula', blocks: [{ text: calculation }] },
|
||||
{ title: 'Qué calcula', blocks: [{ text: calculation }, { text: modelNotes }] },
|
||||
{
|
||||
title: 'Puntuaciones z por métrica y zona',
|
||||
blocks: scores
|
||||
@@ -147,6 +157,7 @@ export function riskSections(patient: TeaPatient, alteredOnly: boolean, pair?: P
|
||||
title: 'Probabilidad de un puntaje ADOS-2 severo',
|
||||
blocks: [
|
||||
{ table: probabilityRows(patient.pairs) },
|
||||
...notices(patient.pairs),
|
||||
{ text: 'No es la probabilidad de TEA.' },
|
||||
],
|
||||
},
|
||||
@@ -160,12 +171,8 @@ export function riskSections(patient: TeaPatient, alteredOnly: boolean, pair?: P
|
||||
|
||||
function probabilityRows(pairs: Pair[]): Table {
|
||||
return {
|
||||
headers: ['Par', 'Prob. ADOS-2 severo', 'Referencia'],
|
||||
rows: pairs.map((p) => [
|
||||
p.headline ? `${p.title} (principal)` : p.title,
|
||||
percent(p.probability),
|
||||
percent(p.reference),
|
||||
]),
|
||||
headers: ['Par', 'Evento', 'n', 'Prob. ADOS-2 severo', 'Referencia'],
|
||||
rows: pairs.map((p) => [...pairCells(p), percent(p.probability), percent(p.reference)]),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -188,7 +195,14 @@ export function teaPdfContent(
|
||||
if (block.text) content.push(block.text);
|
||||
if (block.fields) content.push(...block.fields.map(([key, value]) => `${key} · ${value}`));
|
||||
if (block.table) {
|
||||
const { headers, rows } = block.table;
|
||||
const { headers, rows, faded } = block.table;
|
||||
const cells = rows.map((row, i) =>
|
||||
row.map((cell, column) =>
|
||||
faded?.column === column && faded.rows.includes(i)
|
||||
? { text: cell, color: '#767676' }
|
||||
: cell,
|
||||
),
|
||||
);
|
||||
content.push(
|
||||
rows.length
|
||||
? {
|
||||
@@ -196,7 +210,7 @@ export function teaPdfContent(
|
||||
table: {
|
||||
headerRows: 1,
|
||||
widths: ['*', ...headers.slice(1).map(() => 'auto' as const)],
|
||||
body: [headers, ...rows],
|
||||
body: [headers, ...cells],
|
||||
},
|
||||
}
|
||||
: '—',
|
||||
|
||||
Reference in New Issue
Block a user