From e345d45c60a23421d0fcdf98c7bf9e026200f138 Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 3 Dec 2026 20:47:28 -0600 Subject: [PATCH] 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. --- src/app/eeg-labels.ts | 5 ++- src/app/gobernanza/figures.ts | 6 ++-- src/app/gobernanza/tea/preview-pdf.spec.ts | 4 +-- src/app/gobernanza/tea/studies.ts | 3 +- src/app/indicadores/measures.ts | 3 +- src/app/indicadores/tea-definitions.ts | 14 +++------ src/app/indicadores/tea-indicators.spec.ts | 12 ++++---- src/app/indicadores/tea-rows.ts | 3 +- src/app/paciente/tea-data.ts | 5 ++- src/app/paciente/tea-patient.spec.ts | 36 +++++++++++----------- 10 files changed, 40 insertions(+), 51 deletions(-) diff --git a/src/app/eeg-labels.ts b/src/app/eeg-labels.ts index 8a73d22..329c737 100644 --- a/src/app/eeg-labels.ts +++ b/src/app/eeg-labels.ts @@ -13,7 +13,7 @@ export const ZONE_NAMES: Record = { export const BIOMARKER_NAMES: Record = { spikes: 'Puntas paroxísticas', - spindles: 'Husos de sueño N2', + spindles: 'Husos de sueño (NREM)', posterior_rhythm: 'Ritmo posterior', gradient: 'Gradiente anteroposterior', }; @@ -45,8 +45,7 @@ export const OUTCOME_NAMES: Record = { }; export const REASON_NAMES: Record = { - 'no-n2': 'sin N2', - 'no-n3': 'sin N3', + 'no-spindles': 'sin husos', 'few-wake-windows': 'pocas ventanas en vigilia', 'no-dominant-peak': 'sin ritmo dominante', 'no-sleep': 'sin sueño', diff --git a/src/app/gobernanza/figures.ts b/src/app/gobernanza/figures.ts index caaffce..830d052 100644 --- a/src/app/gobernanza/figures.ts +++ b/src/app/gobernanza/figures.ts @@ -80,10 +80,8 @@ interface AgeCurveOptions { const EEG_METRICS: Record = { 'eeg-posterior-rhythm': 'posterior_rhythm', - 'eeg-spindles-n2': 'spindles_n2', - 'eeg-spindle-topography-n2': 'spindles_n2', - 'eeg-spindles-n3': 'spindles_n3', - 'eeg-spindle-topography-n3': 'spindles_n3', + 'eeg-spindles': 'spindles', + 'eeg-spindle-topography': 'spindles', 'eeg-spikes': 'paroxysmal_spikes', 'eeg-gradient': 'anteroposterior_gradient', }; diff --git a/src/app/gobernanza/tea/preview-pdf.spec.ts b/src/app/gobernanza/tea/preview-pdf.spec.ts index 4842c94..56573a9 100644 --- a/src/app/gobernanza/tea/preview-pdf.spec.ts +++ b/src/app/gobernanza/tea/preview-pdf.spec.ts @@ -41,7 +41,7 @@ const result: PreviewResult = { classification: 'autism', read: ['module', 'pointing'], }, - warnings: ['sin curva en producción para spindles_n2'], + warnings: ['sin curva en producción para spindles'], }; describe('previewPdfContent', () => { @@ -92,7 +92,7 @@ describe('previewPdfContent', () => { }, }, { 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'] }, ]); }); diff --git a/src/app/gobernanza/tea/studies.ts b/src/app/gobernanza/tea/studies.ts index f44b77a..f4d14b2 100644 --- a/src/app/gobernanza/tea/studies.ts +++ b/src/app/gobernanza/tea/studies.ts @@ -104,8 +104,7 @@ export class EegStudies { }; protected readonly metricNames: Record = { posterior_rhythm: 'Ritmo posterior (Hz)', - spindles_n2: 'Husos de sueño N2 (por min)', - spindles_n3: 'Husos de sueño N3 (por min)', + spindles: 'Husos de sueño NREM (por min)', paroxysmal_spikes: 'Picos paroxísticos (por min)', anteroposterior_gradient: 'Gradiente anteroposterior', }; diff --git a/src/app/indicadores/measures.ts b/src/app/indicadores/measures.ts index 37ef0d1..6621f5e 100644 --- a/src/app/indicadores/measures.ts +++ b/src/app/indicadores/measures.ts @@ -124,8 +124,7 @@ export const LABELS: Record = { not_scored: 'Sin puntuar', no_valid_eeg: 'Sin EEG válido', posterior_rhythm: 'Ritmo posterior', - spindles_n2: 'Husos N2', - spindles_n3: 'Husos N3', + spindles: 'Husos de sueño', paroxysmal_spikes: 'Puntas paroxísticas', anteroposterior_gradient: 'Gradiente anteroposterior', good: 'Bueno', diff --git a/src/app/indicadores/tea-definitions.ts b/src/app/indicadores/tea-definitions.ts index 855543e..6d0d9d8 100644 --- a/src/app/indicadores/tea-definitions.ts +++ b/src/app/indicadores/tea-definitions.ts @@ -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}`, }, { - term: 'Husos de sueño N2', - text: `Ráfagas breves de actividad rápida que aparecen en el sueño ligero (etapa N2). ${RANGE}`, - }, - { - term: 'Husos de sueño N3', - text: `Los mismos husos, medidos en el sueño profundo (etapa N3). ${RANGE}`, + term: 'Husos de sueño (NREM)', + text: `Ráfagas breves de actividad rápida que aparecen durante el sueño NREM. ${RANGE}`, }, { term: 'Puntas paroxísticas', @@ -67,8 +63,8 @@ export const TEA_DEFINITIONS: DefinitionGroup[] = [ title: 'Motivos de "No evaluable"', entries: [ { - term: `${reasonLabel('no-n2')} / ${reasonLabel('no-n3')}`, - text: 'El registro no tiene sueño de esa etapa, o no se detectaron husos en ella.', + term: reasonLabel('no-spindles'), + text: 'No se detectaron husos en el sueño del registro.', }, { term: reasonLabel('few-wake-windows'), @@ -80,7 +76,7 @@ export const TEA_DEFINITIONS: DefinitionGroup[] = [ }, { 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'), diff --git a/src/app/indicadores/tea-indicators.spec.ts b/src/app/indicadores/tea-indicators.spec.ts index a3623a0..c35be51 100644 --- a/src/app/indicadores/tea-indicators.spec.ts +++ b/src/app/indicadores/tea-indicators.spec.ts @@ -201,7 +201,7 @@ describe('TEA indicators', () => { model: 'no', age: '16-23', sex: 'female', - alteration: 'spindles_n2', + alteration: 'spindles', mchatMin: 0, mchatMax: 20, cssMin: 1, @@ -218,7 +218,7 @@ describe('TEA indicators', () => { 'tea-model': 'no', 'tea-age-group': '16-23', 'tea-sex': 'female', - 'tea-alteration': 'spindles_n2', + 'tea-alteration': 'spindles', 'tea-mchat': ['ge0', 'le20'], 'tea-css': ['ge1', 'le7'], 'follow-up-window': 3, @@ -247,7 +247,7 @@ describe('TEA indicators', () => { alterations: 2, headline: { pair: cssPair, - title: 'Husos N2 · Central · CSS', + title: 'Husos de sueño · Central · CSS', or: 2, low: 1.2, high: 4.5, @@ -329,7 +329,7 @@ describe('TEA indicators', () => { rows: expect.arrayContaining([ expect.objectContaining({ id: 'child', - pair: 'Husos N2 · Central · CSS', + pair: 'Husos de sueño · Central · CSS', or: 2, low: 1.2, high: 4.5, @@ -631,12 +631,12 @@ describe('TEA clinical figures', () => { strata: { alteration: { posterior_rhythm: { numerator: 2, denominator: 4 }, - spindles_n2: { numerator: 2, denominator: 4 }, + spindles: { numerator: 2, denominator: 4 }, }, }, }); 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], }); }); diff --git a/src/app/indicadores/tea-rows.ts b/src/app/indicadores/tea-rows.ts index dd13610..d6815df 100644 --- a/src/app/indicadores/tea-rows.ts +++ b/src/app/indicadores/tea-rows.ts @@ -173,8 +173,7 @@ export const TOKEN_FILTERS = [ label: 'Alteración', options: choices( 'posterior_rhythm', - 'spindles_n2', - 'spindles_n3', + 'spindles', 'paroxysmal_spikes', 'anteroposterior_gradient', ), diff --git a/src/app/paciente/tea-data.ts b/src/app/paciente/tea-data.ts index 2847e21..63a1976 100644 --- a/src/app/paciente/tea-data.ts +++ b/src/app/paciente/tea-data.ts @@ -56,15 +56,14 @@ export function teaSteps( const METRIC_TITLES: Record = { posterior_rhythm: 'Ritmo posterior', - spindles_n2: 'Husos N2', - spindles_n3: 'Husos N3', + spindles: 'Husos de sueño', paroxysmal_spikes: 'Puntas paroxísticas', anteroposterior_gradient: 'Gradiente anteroposterior', }; const BIOMARKER_METRICS: Record = { spikes: 'paroxysmal_spikes', - spindles: 'spindles_n2', + spindles: 'spindles', posterior_rhythm: 'posterior_rhythm', gradient: 'anteroposterior_gradient', }; diff --git a/src/app/paciente/tea-patient.spec.ts b/src/app/paciente/tea-patient.spec.ts index d9f9e70..8b80cf6 100644 --- a/src/app/paciente/tea-patient.spec.ts +++ b/src/app/paciente/tea-patient.spec.ts @@ -31,11 +31,11 @@ import { } from './tea-sections'; const metric: Metric = { - key: 'spindles_n2', - title: 'Husos N2', + key: 'spindles', + title: 'Husos de sueño', value: 1.7, unit: undefined, - model: 'tea.eeg-spindles-n2/1', + model: 'tea.eeg-spindles/1', z: 0.3, outside: 0, reason: undefined, @@ -47,7 +47,7 @@ const metric: Metric = { const pair: Pair = { key: 'spindles|central|CSS', - title: 'Husos N2 · Central · CSS', + title: 'Husos de sueño · Central · CSS', headline: true, altered: true, z: 2.4, @@ -203,7 +203,7 @@ describe('Figuras del paciente TEA', () => { const figure = zBars(eeg); expect(figure.data[0]).toMatchObject({ 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 }); }); @@ -378,9 +378,9 @@ describe('Expediente TEA', () => { const norms = new Map([[`eeg-1|${metric.key}`, norm]]); const altered = recordSections(patient, norms).find((s) => s.title === 'Alteraciones'); 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-12-01 · Husos N2', + '2025-12-01 · Husos de sueño', ]); expect(altered?.blocks[0].fields).toEqual([ ['z', '0.3'], @@ -410,11 +410,11 @@ describe('Expediente TEA', () => { }); 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, 'unknown-code')).toBe('No evaluable · unknown-code'); 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 section = recordSections( { ...record, studies: [{ ...eeg, metrics: [unmeasured] }] }, @@ -427,7 +427,7 @@ describe('Expediente TEA', () => { }); 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) }; expect(evaluable(metric)).toBe(true); expect(evaluable(unmeasured)).toBe(false); @@ -439,7 +439,7 @@ describe('Expediente TEA', () => { expect(blocks?.[0].charts).toHaveLength(2); expect(blocks?.[1].charts).toEqual([]); 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 () => { @@ -462,31 +462,31 @@ describe('Expediente TEA', () => { effectiveDateTime: '2025-11-30', conclusionCode: [{ coding: [{ code: 'bad' }] }, { coding: [{ code: 'not_valid' }] }], extension: [reason('few-clean-minutes'), reason('triage-not-analyzable')], - result: [{ reference: 'Observation/n3' }], + result: [{ reference: 'Observation/spindles' }], }, }, { search: { mode: 'include' }, resource: { resourceType: 'Observation', - id: 'n3', + id: 'spindles', status: 'final', code: { coding: [ { 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 { 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([ 'Motivos', 'pocos minutos limpios · triaje no analizable', @@ -553,7 +553,7 @@ describe('Análisis de riesgo TEA', () => { { table: { 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.' }, @@ -566,7 +566,7 @@ describe('Análisis de riesgo TEA', () => { describe('Títulos de las asociaciones TEA', () => { 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'); });