F7c: one spindle metric over all NREM sleep

Spindles are measured once, over every window the state classifier labels
sleep, and each child's detection thresholds come from all NREM sleep
samples. The 75 uV slow-wave rule labelled 89 % of the epochs after N2
onset in Helsinki toddlers (16-36 months) as N3 and was never validated
against technician-scored stages (biomarcadores-tea E13, usar_n3 = false).

spindles_n2 and spindles_n3 become spindles; the four N2/N3 age scenarios
become eeg-spindles and eeg-spindle-topography. The director's flag for a
posterior rhythm near the sigma band is kept as the rhythm_near_sigma
feature. Reasons: no-sleep under one minute of sleep, else no-spindles.
This commit is contained in:
2026-12-03 20:47:28 -06:00
parent 7a22e433f4
commit e345d45c60
10 changed files with 40 additions and 51 deletions
+2 -3
View File
@@ -13,7 +13,7 @@ export const ZONE_NAMES: Record<string, string> = {
export const BIOMARKER_NAMES: Record<string, string> = { export const BIOMARKER_NAMES: Record<string, string> = {
spikes: 'Puntas paroxísticas', spikes: 'Puntas paroxísticas',
spindles: 'Husos de sueño N2', spindles: 'Husos de sueño (NREM)',
posterior_rhythm: 'Ritmo posterior', posterior_rhythm: 'Ritmo posterior',
gradient: 'Gradiente anteroposterior', gradient: 'Gradiente anteroposterior',
}; };
@@ -45,8 +45,7 @@ export const OUTCOME_NAMES: Record<string, string> = {
}; };
export const REASON_NAMES: Record<string, string> = { export const REASON_NAMES: Record<string, string> = {
'no-n2': 'sin N2', 'no-spindles': 'sin husos',
'no-n3': 'sin N3',
'few-wake-windows': 'pocas ventanas en vigilia', 'few-wake-windows': 'pocas ventanas en vigilia',
'no-dominant-peak': 'sin ritmo dominante', 'no-dominant-peak': 'sin ritmo dominante',
'no-sleep': 'sin sueño', 'no-sleep': 'sin sueño',
+2 -4
View File
@@ -80,10 +80,8 @@ interface AgeCurveOptions {
const EEG_METRICS: Record<string, string> = { const EEG_METRICS: Record<string, string> = {
'eeg-posterior-rhythm': 'posterior_rhythm', 'eeg-posterior-rhythm': 'posterior_rhythm',
'eeg-spindles-n2': 'spindles_n2', 'eeg-spindles': 'spindles',
'eeg-spindle-topography-n2': 'spindles_n2', 'eeg-spindle-topography': 'spindles',
'eeg-spindles-n3': 'spindles_n3',
'eeg-spindle-topography-n3': 'spindles_n3',
'eeg-spikes': 'paroxysmal_spikes', 'eeg-spikes': 'paroxysmal_spikes',
'eeg-gradient': 'anteroposterior_gradient', 'eeg-gradient': 'anteroposterior_gradient',
}; };
+2 -2
View File
@@ -41,7 +41,7 @@ const result: PreviewResult = {
classification: 'autism', classification: 'autism',
read: ['module', 'pointing'], read: ['module', 'pointing'],
}, },
warnings: ['sin curva en producción para spindles_n2'], warnings: ['sin curva en producción para spindles'],
}; };
describe('previewPdfContent', () => { describe('previewPdfContent', () => {
@@ -92,7 +92,7 @@ describe('previewPdfContent', () => {
}, },
}, },
{ text: 'Advertencias', bold: true, fontSize: 14, margin: [0, 12, 0, 5] }, { text: 'Advertencias', bold: true, fontSize: 14, margin: [0, 12, 0, 5] },
{ ul: ['sin curva en producción para spindles_n2'] }, { ul: ['sin curva en producción para spindles'] },
]); ]);
}); });
+1 -2
View File
@@ -104,8 +104,7 @@ export class EegStudies {
}; };
protected readonly metricNames: Record<string, string> = { protected readonly metricNames: Record<string, string> = {
posterior_rhythm: 'Ritmo posterior (Hz)', posterior_rhythm: 'Ritmo posterior (Hz)',
spindles_n2: 'Husos de sueño N2 (por min)', spindles: 'Husos de sueño NREM (por min)',
spindles_n3: 'Husos de sueño N3 (por min)',
paroxysmal_spikes: 'Picos paroxísticos (por min)', paroxysmal_spikes: 'Picos paroxísticos (por min)',
anteroposterior_gradient: 'Gradiente anteroposterior', anteroposterior_gradient: 'Gradiente anteroposterior',
}; };
+1 -2
View File
@@ -124,8 +124,7 @@ export const LABELS: Record<string, string> = {
not_scored: 'Sin puntuar', not_scored: 'Sin puntuar',
no_valid_eeg: 'Sin EEG válido', no_valid_eeg: 'Sin EEG válido',
posterior_rhythm: 'Ritmo posterior', posterior_rhythm: 'Ritmo posterior',
spindles_n2: 'Husos N2', spindles: 'Husos de sueño',
spindles_n3: 'Husos N3',
paroxysmal_spikes: 'Puntas paroxísticas', paroxysmal_spikes: 'Puntas paroxísticas',
anteroposterior_gradient: 'Gradiente anteroposterior', anteroposterior_gradient: 'Gradiente anteroposterior',
good: 'Bueno', good: 'Bueno',
+5 -9
View File
@@ -27,12 +27,8 @@ export const TEA_DEFINITIONS: DefinitionGroup[] = [
text: `Actividad rítmica dominante de la región posterior del cerebro durante la vigilia. ${RANGE}`, text: `Actividad rítmica dominante de la región posterior del cerebro durante la vigilia. ${RANGE}`,
}, },
{ {
term: 'Husos de sueño N2', term: 'Husos de sueño (NREM)',
text: `Ráfagas breves de actividad rápida que aparecen en el sueño ligero (etapa N2). ${RANGE}`, text: `Ráfagas breves de actividad rápida que aparecen durante el sueño NREM. ${RANGE}`,
},
{
term: 'Husos de sueño N3',
text: `Los mismos husos, medidos en el sueño profundo (etapa N3). ${RANGE}`,
}, },
{ {
term: 'Puntas paroxísticas', term: 'Puntas paroxísticas',
@@ -67,8 +63,8 @@ export const TEA_DEFINITIONS: DefinitionGroup[] = [
title: 'Motivos de "No evaluable"', title: 'Motivos de "No evaluable"',
entries: [ entries: [
{ {
term: `${reasonLabel('no-n2')} / ${reasonLabel('no-n3')}`, term: reasonLabel('no-spindles'),
text: 'El registro no tiene sueño de esa etapa, o no se detectaron husos en ella.', text: 'No se detectaron husos en el sueño del registro.',
}, },
{ {
term: reasonLabel('few-wake-windows'), term: reasonLabel('few-wake-windows'),
@@ -80,7 +76,7 @@ export const TEA_DEFINITIONS: DefinitionGroup[] = [
}, },
{ {
term: reasonLabel('no-sleep'), term: reasonLabel('no-sleep'),
text: 'El registro no tiene sueño para calcular el gradiente.', text: 'El registro no tiene sueño suficiente para medir los husos o el gradiente.',
}, },
{ {
term: reasonLabel('few-electrodes'), term: reasonLabel('few-electrodes'),
+6 -6
View File
@@ -201,7 +201,7 @@ describe('TEA indicators', () => {
model: 'no', model: 'no',
age: '16-23', age: '16-23',
sex: 'female', sex: 'female',
alteration: 'spindles_n2', alteration: 'spindles',
mchatMin: 0, mchatMin: 0,
mchatMax: 20, mchatMax: 20,
cssMin: 1, cssMin: 1,
@@ -218,7 +218,7 @@ describe('TEA indicators', () => {
'tea-model': 'no', 'tea-model': 'no',
'tea-age-group': '16-23', 'tea-age-group': '16-23',
'tea-sex': 'female', 'tea-sex': 'female',
'tea-alteration': 'spindles_n2', 'tea-alteration': 'spindles',
'tea-mchat': ['ge0', 'le20'], 'tea-mchat': ['ge0', 'le20'],
'tea-css': ['ge1', 'le7'], 'tea-css': ['ge1', 'le7'],
'follow-up-window': 3, 'follow-up-window': 3,
@@ -247,7 +247,7 @@ describe('TEA indicators', () => {
alterations: 2, alterations: 2,
headline: { headline: {
pair: cssPair, pair: cssPair,
title: 'Husos N2 · Central · CSS', title: 'Husos de sueño · Central · CSS',
or: 2, or: 2,
low: 1.2, low: 1.2,
high: 4.5, high: 4.5,
@@ -329,7 +329,7 @@ describe('TEA indicators', () => {
rows: expect.arrayContaining([ rows: expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: 'child', id: 'child',
pair: 'Husos N2 · Central · CSS', pair: 'Husos de sueño · Central · CSS',
or: 2, or: 2,
low: 1.2, low: 1.2,
high: 4.5, high: 4.5,
@@ -631,12 +631,12 @@ describe('TEA clinical figures', () => {
strata: { strata: {
alteration: { alteration: {
posterior_rhythm: { numerator: 2, denominator: 4 }, posterior_rhythm: { numerator: 2, denominator: 4 },
spindles_n2: { numerator: 2, denominator: 4 }, spindles: { numerator: 2, denominator: 4 },
}, },
}, },
}); });
expect(figure.data[0]).toMatchObject({ expect(figure.data[0]).toMatchObject({
x: ['Alguna alteración', 'Ritmo posterior', 'Husos N2'], x: ['Alguna alteración', 'Ritmo posterior', 'Husos de sueño'],
y: [75, 50, 50], y: [75, 50, 50],
}); });
}); });
+1 -2
View File
@@ -173,8 +173,7 @@ export const TOKEN_FILTERS = [
label: 'Alteración', label: 'Alteración',
options: choices( options: choices(
'posterior_rhythm', 'posterior_rhythm',
'spindles_n2', 'spindles',
'spindles_n3',
'paroxysmal_spikes', 'paroxysmal_spikes',
'anteroposterior_gradient', 'anteroposterior_gradient',
), ),
+2 -3
View File
@@ -56,15 +56,14 @@ export function teaSteps(
const METRIC_TITLES: Record<string, string> = { const METRIC_TITLES: Record<string, string> = {
posterior_rhythm: 'Ritmo posterior', posterior_rhythm: 'Ritmo posterior',
spindles_n2: 'Husos N2', spindles: 'Husos de sueño',
spindles_n3: 'Husos N3',
paroxysmal_spikes: 'Puntas paroxísticas', paroxysmal_spikes: 'Puntas paroxísticas',
anteroposterior_gradient: 'Gradiente anteroposterior', anteroposterior_gradient: 'Gradiente anteroposterior',
}; };
const BIOMARKER_METRICS: Record<string, string> = { const BIOMARKER_METRICS: Record<string, string> = {
spikes: 'paroxysmal_spikes', spikes: 'paroxysmal_spikes',
spindles: 'spindles_n2', spindles: 'spindles',
posterior_rhythm: 'posterior_rhythm', posterior_rhythm: 'posterior_rhythm',
gradient: 'anteroposterior_gradient', gradient: 'anteroposterior_gradient',
}; };
+18 -18
View File
@@ -31,11 +31,11 @@ import {
} from './tea-sections'; } from './tea-sections';
const metric: Metric = { const metric: Metric = {
key: 'spindles_n2', key: 'spindles',
title: 'Husos N2', title: 'Husos de sueño',
value: 1.7, value: 1.7,
unit: undefined, unit: undefined,
model: 'tea.eeg-spindles-n2/1', model: 'tea.eeg-spindles/1',
z: 0.3, z: 0.3,
outside: 0, outside: 0,
reason: undefined, reason: undefined,
@@ -47,7 +47,7 @@ const metric: Metric = {
const pair: Pair = { const pair: Pair = {
key: 'spindles|central|CSS', key: 'spindles|central|CSS',
title: 'Husos N2 · Central · CSS', title: 'Husos de sueño · Central · CSS',
headline: true, headline: true,
altered: true, altered: true,
z: 2.4, z: 2.4,
@@ -203,7 +203,7 @@ describe('Figuras del paciente TEA', () => {
const figure = zBars(eeg); const figure = zBars(eeg);
expect(figure.data[0]).toMatchObject({ expect(figure.data[0]).toMatchObject({
x: [0.3, 2.4], x: [0.3, 2.4],
y: ['Husos N2 · Global', 'Husos N2 · Central'], y: ['Husos de sueño · Global', 'Husos de sueño · Central'],
}); });
expect(figure.layout?.shapes?.[0]).toMatchObject({ type: 'rect', x0: -2, x1: 2 }); expect(figure.layout?.shapes?.[0]).toMatchObject({ type: 'rect', x0: -2, x1: 2 });
}); });
@@ -378,9 +378,9 @@ describe('Expediente TEA', () => {
const norms = new Map([[`eeg-1|${metric.key}`, norm]]); const norms = new Map([[`eeg-1|${metric.key}`, norm]]);
const altered = recordSections(patient, norms).find((s) => s.title === 'Alteraciones'); const altered = recordSections(patient, norms).find((s) => s.title === 'Alteraciones');
expect(altered?.blocks.map((block) => block.title)).toEqual([ expect(altered?.blocks.map((block) => block.title)).toEqual([
'2025-11-30 · Husos N2', '2025-11-30 · Husos de sueño',
'2025-11-30 · Puntas paroxísticas', '2025-11-30 · Puntas paroxísticas',
'2025-12-01 · Husos N2', '2025-12-01 · Husos de sueño',
]); ]);
expect(altered?.blocks[0].fields).toEqual([ expect(altered?.blocks[0].fields).toEqual([
['z', '0.3'], ['z', '0.3'],
@@ -410,11 +410,11 @@ describe('Expediente TEA', () => {
}); });
it('muestra "No evaluable" con el motivo donde antes había un guion', () => { it('muestra "No evaluable" con el motivo donde antes había un guion', () => {
expect(alteration(undefined, 'no-n3')).toBe('No evaluable · sin N3'); expect(alteration(undefined, 'no-spindles')).toBe('No evaluable · sin husos');
expect(alteration(undefined, 'age-out-of-range')).toBe('No evaluable · edad fuera de la curva'); expect(alteration(undefined, 'age-out-of-range')).toBe('No evaluable · edad fuera de la curva');
expect(alteration(undefined, 'unknown-code')).toBe('No evaluable · unknown-code'); expect(alteration(undefined, 'unknown-code')).toBe('No evaluable · unknown-code');
expect(alteration(undefined)).toBe('—'); expect(alteration(undefined)).toBe('—');
expect(alteration(1, 'no-n3')).toBe('Alto'); expect(alteration(1, 'no-spindles')).toBe('Alto');
const unmeasured = { ...metric, z: undefined, outside: undefined, reason: 'invalid-eeg' }; const unmeasured = { ...metric, z: undefined, outside: undefined, reason: 'invalid-eeg' };
const section = recordSections( const section = recordSections(
{ ...record, studies: [{ ...eeg, metrics: [unmeasured] }] }, { ...record, studies: [{ ...eeg, metrics: [unmeasured] }] },
@@ -427,7 +427,7 @@ describe('Expediente TEA', () => {
}); });
it('no dibuja mapa ni norma de una métrica no evaluable', () => { it('no dibuja mapa ni norma de una métrica no evaluable', () => {
const unmeasured = { ...metric, z: undefined, outside: undefined, reason: 'no-n3' }; const unmeasured = { ...metric, z: undefined, outside: undefined, reason: 'no-spindles' };
const norm = { title: 'Norma por edad', figure: ageNorm(centiles, metric, eeg.age) }; const norm = { title: 'Norma por edad', figure: ageNorm(centiles, metric, eeg.age) };
expect(evaluable(metric)).toBe(true); expect(evaluable(metric)).toBe(true);
expect(evaluable(unmeasured)).toBe(false); expect(evaluable(unmeasured)).toBe(false);
@@ -439,7 +439,7 @@ describe('Expediente TEA', () => {
expect(blocks?.[0].charts).toHaveLength(2); expect(blocks?.[0].charts).toHaveLength(2);
expect(blocks?.[1].charts).toEqual([]); expect(blocks?.[1].charts).toEqual([]);
const content = teaPdfContent('Expediente TEA', sections, ['mapa', 'norma']); const content = teaPdfContent('Expediente TEA', sections, ['mapa', 'norma']);
expect(content.slice(-2)).toEqual(['z · —', 'Resultado · No evaluable · sin N3']); expect(content.slice(-2)).toEqual(['z · —', 'Resultado · No evaluable · sin husos']);
}); });
it('lee los motivos de la métrica y del estudio desde FHIR', async () => { it('lee los motivos de la métrica y del estudio desde FHIR', async () => {
@@ -462,31 +462,31 @@ describe('Expediente TEA', () => {
effectiveDateTime: '2025-11-30', effectiveDateTime: '2025-11-30',
conclusionCode: [{ coding: [{ code: 'bad' }] }, { coding: [{ code: 'not_valid' }] }], conclusionCode: [{ coding: [{ code: 'bad' }] }, { coding: [{ code: 'not_valid' }] }],
extension: [reason('few-clean-minutes'), reason('triage-not-analyzable')], extension: [reason('few-clean-minutes'), reason('triage-not-analyzable')],
result: [{ reference: 'Observation/n3' }], result: [{ reference: 'Observation/spindles' }],
}, },
}, },
{ {
search: { mode: 'include' }, search: { mode: 'include' },
resource: { resource: {
resourceType: 'Observation', resourceType: 'Observation',
id: 'n3', id: 'spindles',
status: 'final', status: 'final',
code: { code: {
coding: [ coding: [
{ {
system: 'https://isssteleon.org/fhir/CodeSystem/tea-eeg-metric', system: 'https://isssteleon.org/fhir/CodeSystem/tea-eeg-metric',
code: 'spindles_n3', code: 'spindles',
}, },
], ],
}, },
extension: [reason('no-n3')], extension: [reason('no-spindles')],
}, },
}, },
], ],
}; };
const fhir = { search: async () => bundle } as unknown as Fhir; const fhir = { search: async () => bundle } as unknown as Fhir;
const { studies } = await loadTeaPatient(fhir, 'child'); const { studies } = await loadTeaPatient(fhir, 'child');
expect(studies[0].metrics[0]).toMatchObject({ key: 'spindles_n3', reason: 'no-n3' }); expect(studies[0].metrics[0]).toMatchObject({ key: 'spindles', reason: 'no-spindles' });
expect(studies[0].summary).toContainEqual([ expect(studies[0].summary).toContainEqual([
'Motivos', 'Motivos',
'pocos minutos limpios · triaje no analizable', 'pocos minutos limpios · triaje no analizable',
@@ -553,7 +553,7 @@ describe('Análisis de riesgo TEA', () => {
{ {
table: { table: {
headers: ['Par', 'Prob. ADOS-2 severo', 'Referencia'], headers: ['Par', 'Prob. ADOS-2 severo', 'Referencia'],
rows: [['Husos N2 · Central · CSS (principal)', '70%', '20%']], rows: [['Husos de sueño · Central · CSS (principal)', '70%', '20%']],
}, },
}, },
{ text: 'No es la probabilidad de TEA.' }, { text: 'No es la probabilidad de TEA.' },
@@ -566,7 +566,7 @@ describe('Análisis de riesgo TEA', () => {
describe('Títulos de las asociaciones TEA', () => { describe('Títulos de las asociaciones TEA', () => {
it('nombra la métrica, la zona y el resultado del par', () => { it('nombra la métrica, la zona y el resultado del par', () => {
expect(pairTitle('spindles|central|CSS')).toBe('Husos N2 · Central · CSS'); expect(pairTitle('spindles|central|CSS')).toBe('Husos de sueño · Central · CSS');
expect(pairTitle('posterior_rhythm|posterior|CSS')).toBe('Ritmo posterior · Posterior · CSS'); expect(pairTitle('posterior_rhythm|posterior|CSS')).toBe('Ritmo posterior · Posterior · CSS');
}); });