From 2add96e38ad3811fa23a41d2232ef3749528732c Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 3 Dec 2026 13:51:40 -0600 Subject: [PATCH] F2b: TEA record after the 3 Dec review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a label above each completed timeline diamond and a baseline tick at each completed step date, retaining the dotted line and day annotations. Group each study and metric into one alterations block with its fields, head map and age norm. Name the centile bands, shorten the norm title, explain the head-map z scale and use Puntas paroxísticas consistently in the shared biomarker labels. Update the logic and page expectations. Choices left open by the spec: - Use label annotations shifted upward by 26 pixels and a 40-pixel top margin; retain the existing categorical axis and pending annotations. Use the completed dates as explicit date-axis ticks. - Add an optional charts array for the grouped row while retaining chart for standalone plots. Put the map first and norm second, omit absent figures, and keep a block even when neither figure is available. - Use two equal grid columns with the existing space-4 gap, stacking at 800 pixels. Separate adjacent blocks with the existing border color, space-6 margin and space-4 padding. - Keep grouped figures in the PDF export's existing sequential image order, consuming one image for each figure. - Make bandFill's final name parameter optional and show its legend only when a name is supplied, preserving unnamed governance bands. - Keep the existing lighter outer/darker inner band drawing order. - Keep tea-data.ts unchanged: its spike title already matches the required Puntas paroxísticas. Preserve the existing spike exclusion in loadNorms. Verification: git diff --check passed. Prettier skipped because this worktree has no WebApp/node_modules/.bin/prettier. Angular tests/build and browser page tests were not run on the saturated lab server, as specified. No API signatures, schemas or endpoints changed. --- e2e/pages.spec.ts | 2 +- src/app/eeg-labels.ts | 2 +- src/app/gobernanza/figures.ts | 4 +- src/app/paciente/paciente.ts | 2 +- src/app/paciente/tea-figures.ts | 17 ++++- src/app/paciente/tea-patient.spec.ts | 68 ++++++++++++++--- src/app/paciente/tea-section.ts | 109 +++++++++++++++++---------- src/app/paciente/tea-sections.ts | 31 ++++---- 8 files changed, 161 insertions(+), 74 deletions(-) diff --git a/e2e/pages.spec.ts b/e2e/pages.spec.ts index f9fa564..d65ee59 100644 --- a/e2e/pages.spec.ts +++ b/e2e/pages.spec.ts @@ -178,7 +178,7 @@ test('tea complete child: every screen has data', async ({ page }) => { await expect(section('Calidad del EEG').locator('tbody tr').first()).toBeVisible(); const alterations = section('Alteraciones'); await expect( - alterations.locator('h3:text-is("Norma por edad · p5–p95") + app-plot .point').first(), + alterations.locator('h3:text-is("Norma por edad") + app-plot .point').first(), ).toBeAttached(); await expect( alterations.locator('h3:text-is("Mapa de la cabeza") + app-plot .contourlayer path').first(), diff --git a/src/app/eeg-labels.ts b/src/app/eeg-labels.ts index 531763d..762d7a5 100644 --- a/src/app/eeg-labels.ts +++ b/src/app/eeg-labels.ts @@ -12,7 +12,7 @@ export const ZONE_NAMES: Record = { }; export const BIOMARKER_NAMES: Record = { - spikes: 'Picos paroxísticos', + spikes: 'Puntas paroxísticas', spindles: 'Husos de sueño N2', posterior_rhythm: 'Ritmo posterior', gradient: 'Gradiente anteroposterior', diff --git a/src/app/gobernanza/figures.ts b/src/app/gobernanza/figures.ts index 8c3fdec..ebc0524 100644 --- a/src/app/gobernanza/figures.ts +++ b/src/app/gobernanza/figures.ts @@ -16,6 +16,7 @@ export function bandFill( high: (number | null)[], colour: string, alpha: string, + name?: string, ): Partial { const rows = x.flatMap((age, i) => low[i] != null && high[i] != null @@ -31,7 +32,8 @@ export function bandFill( fillcolor: `${colour}${alpha}`, line: { width: 0 }, hoverinfo: 'skip', - showlegend: false, + name, + showlegend: name != null, }; } diff --git a/src/app/paciente/paciente.ts b/src/app/paciente/paciente.ts index d107ec9..323d6f2 100644 --- a/src/app/paciente/paciente.ts +++ b/src/app/paciente/paciente.ts @@ -417,7 +417,7 @@ export class Paciente { return [ `${eeg.id}|${metric.key}`, { - title: 'Norma por edad · p5–p95', + title: 'Norma por edad', figure: ageNorm(rows, metric, eeg.age), }, ] as const; diff --git a/src/app/paciente/tea-figures.ts b/src/app/paciente/tea-figures.ts index 08296c8..4a038ad 100644 --- a/src/app/paciente/tea-figures.ts +++ b/src/app/paciente/tea-figures.ts @@ -38,9 +38,13 @@ export function timeline(steps: TeaStep[]): Figure | null { ], layout: { showlegend: false, - margin: { l: 140, r: 90, t: 16, b: 40 }, + margin: { l: 140, r: 90, t: 40, b: 40 }, xaxis: { type: 'date', + showline: true, + ticks: 'outside', + tickmode: 'array', + tickvals: done.map((step) => step.date), tickformat: '%d/%m/%Y', ...(done.every((step) => step.date === last) ? { @@ -59,6 +63,13 @@ export function timeline(steps: TeaStep[]): Figure | null { fixedrange: true, }, annotations: [ + ...done.map((step) => ({ + x: step.date, + y: step.label, + yshift: 26, + showarrow: false, + text: step.label, + })), ...spans.map((span) => ({ x: new Date((Date.parse(span.from.date) + Date.parse(span.to.date)) / 2) .toISOString() @@ -180,7 +191,7 @@ export function headMap(sites: Site[]): Figure { contours: { coloring: 'heatmap', showlines: true }, line: { width: 0.5, color: 'rgba(8,24,57,.3)' }, hoverinfo: 'skip', - colorbar: { title: { text: 'z' } }, + colorbar: { title: { text: 'z (distancia a la referencia)' } }, }); } const markers = Object.entries(electrodes); @@ -217,6 +228,7 @@ export function ageNorm(rows: Centile[], metric: Metric, age: number): Figure { rows.map((row) => row.p95), PALETTE[4], '29', + 'P5–P95 (90 %)', ), bandFill( x, @@ -224,6 +236,7 @@ export function ageNorm(rows: Centile[], metric: Metric, age: number): Figure { rows.map((row) => row.p75 ?? null), PALETTE[4], '52', + 'P25–P75 (50 % de la referencia)', ), { type: 'scatter', diff --git a/src/app/paciente/tea-patient.spec.ts b/src/app/paciente/tea-patient.spec.ts index 2a933f3..b987b7b 100644 --- a/src/app/paciente/tea-patient.spec.ts +++ b/src/app/paciente/tea-patient.spec.ts @@ -149,7 +149,16 @@ describe('Figuras del paciente TEA', () => { it('dibuja los centiles del campeón y el valor observado a la edad del paciente', () => { const figure = ageNorm(centiles, metric, 20.5); - expect(figure.data[0]).toMatchObject({ fill: 'toself', y: [2, 2.2, 0.2, 0] }); + expect(figure.data[0]).toMatchObject({ + fill: 'toself', + y: [2, 2.2, 0.2, 0], + name: 'P5–P95 (90 %)', + showlegend: true, + }); + expect(figure.data[1]).toMatchObject({ + name: 'P25–P75 (50 % de la referencia)', + showlegend: true, + }); expect(figure.data[3]).toMatchObject({ mode: 'markers', x: [20.5], y: [1.7] }); }); @@ -211,8 +220,14 @@ describe('Figuras del paciente TEA', () => { it('anota los días entre etapas y deja pendientes las que faltan', () => { const figure = timeline(steps)!; const notes = figure.layout?.annotations ?? []; - expect(notes.map((note) => note.text)).toEqual(['21 días', 'Pendiente', 'Pendiente']); - expect(notes.slice(1).map((note) => note.y)).toEqual(['Neuropediatría', 'EEG']); + expect(notes.map((note) => note.text)).toEqual([ + 'M-CHAT', + 'Psicología', + '21 días', + 'Pendiente', + 'Pendiente', + ]); + expect(notes.slice(3).map((note) => note.y)).toEqual(['Neuropediatría', 'EEG']); expect(figure.layout?.yaxis?.categoryarray).toEqual([ 'EEG', 'Neuropediatría', @@ -311,17 +326,48 @@ describe('Expediente TEA', () => { ]); }); - it('pone la norma de cada métrica tras su mapa de la cabeza', () => { - const patient = { ...record, studies: [eeg] }; - const norm = { title: 'Norma por edad · p5–p95', figure: ageNorm(centiles, metric, eeg.age) }; + it('agrupa el mapa y la norma en un bloque por estudio y métrica', () => { + const spikes = { ...metric, key: 'paroxysmal_spikes', title: 'Puntas paroxísticas' }; + const patient = { + ...record, + studies: [ + { ...eeg, metrics: [metric, spikes] }, + { ...eeg, id: 'eeg-2', date: '2025-12-01' }, + ], + }; + const norm = { title: 'Norma por edad', figure: ageNorm(centiles, metric, eeg.age) }; 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.chart?.title)).toEqual([ - 'Mapa de la cabeza', - 'Norma por edad · p5–p95', + expect(altered?.blocks.map((block) => block.title)).toEqual([ + '2025-11-30 · Husos N2', + '2025-11-30 · Puntas paroxísticas', + '2025-12-01 · Husos N2', + ]); + expect(altered?.blocks[0].fields).toEqual([ + ['z', '0.3'], + ['Resultado', 'En rango'], + ]); + expect(altered?.blocks.map((block) => block.charts?.map((chart) => chart.title))).toEqual([ + ['Mapa de la cabeza', 'Norma por edad'], + ['Mapa de la cabeza'], + ['Mapa de la cabeza'], + ]); + expect(altered?.blocks[0].charts?.[1]).toBe(norm); + }); + + it('exporta el mapa y la norma del mismo bloque en el orden de sus imágenes', () => { + const norm = { title: 'Norma por edad', figure: ageNorm(centiles, metric, eeg.age) }; + const sections = recordSections( + { ...record, studies: [eeg] }, + new Map([[`eeg-1|${metric.key}`, norm]]), + ).filter((section) => section.title === 'Alteraciones'); + const content = teaPdfContent('Expediente TEA', sections, ['mapa', 'norma']); + expect(content.slice(-4)).toEqual([ + { text: 'Mapa de la cabeza', bold: true }, + { image: 'mapa', fit: [510, 620] }, + { text: 'Norma por edad', bold: true }, + { image: 'norma', fit: [510, 620] }, ]); - const without = recordSections(patient, new Map()).find((s) => s.title === 'Alteraciones'); - expect(without?.blocks).toHaveLength(1); }); it('exporta las secciones, tablas y figuras con un nombre sin identificador', () => { diff --git a/src/app/paciente/tea-section.ts b/src/app/paciente/tea-section.ts index b3fb7f2..9eb7d6b 100644 --- a/src/app/paciente/tea-section.ts +++ b/src/app/paciente/tea-section.ts @@ -12,50 +12,62 @@ import { Section } from './tea-sections'; @for (block of section().blocks; track $index) { - @if (block.title) { -

{{ block.title }}

- } - @if (block.text) { -

{{ block.text }}

- } - @if (block.fields; as fields) { -
- @for (field of fields; track $index) { -
-
{{ field[0] }}
-
{{ field[1] }}
-
- } -
- } - @if (block.table; as table) { - @if (table.rows.length) { - - - - @for (header of table.headers; track $index) { - - } - - - - @for (row of table.rows; track $index) { +
+ @if (block.title) { +

{{ block.title }}

+ } + @if (block.text) { +

{{ block.text }}

+ } + @if (block.fields; as fields) { +
+ @for (field of fields; track $index) { +
+
{{ field[0] }}
+
{{ field[1] }}
+
+ } +
+ } + @if (block.table; as table) { + @if (table.rows.length) { +
{{ header }}
+ - @for (cell of row; track $index) { - + @for (header of table.headers; track $index) { + } - } - -
{{ cell }}{{ header }}
- } @else { -

—

+ + + @for (row of table.rows; track $index) { + + @for (cell of row; track $index) { + {{ cell }} + } + + } + + + } @else { +

—

+ } } - } - @if (block.chart; as chart) { -

{{ chart.title }}

- - } + @if (block.chart; as chart) { +

{{ chart.title }}

+ + } + @if (block.charts; as charts) { +
+ @for (chart of charts; track $index) { +
+

{{ chart.title }}

+ +
+ } +
+ } + } @empty {

—

} @@ -69,6 +81,21 @@ import { Section } from './tea-sections'; mat-card-content { overflow-x: auto; } + section + section { + border-top: 1px solid var(--color-border); + margin-top: var(--space-6); + padding-top: var(--space-4); + } + .charts { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: var(--space-4); + } + @media (max-width: 800px) { + .charts { + grid-template-columns: minmax(0, 1fr); + } + } dl { display: flex; flex-wrap: wrap; @@ -87,4 +114,4 @@ import { Section } from './tea-sections'; }) export class TeaSection { readonly section = input.required
(); -} \ No newline at end of file +} diff --git a/src/app/paciente/tea-sections.ts b/src/app/paciente/tea-sections.ts index aeea330..57faf2e 100644 --- a/src/app/paciente/tea-sections.ts +++ b/src/app/paciente/tea-sections.ts @@ -11,6 +11,7 @@ type Block = { fields?: string[][]; table?: Table; chart?: Chart; + charts?: Chart[]; text?: string; }; export type Section = { title: string; blocks: Block[] }; @@ -64,21 +65,19 @@ export function recordSections(patient: TeaPatient, norms: ReadonlyMap - eeg.metrics.flatMap((m) => { + eeg.metrics.map((m) => { const norm = norms.get(`${eeg.id}|${m.key}`); - return [ - { - title: `${eeg.date} · ${m.title}`, - fields: [ - ['z', shown(m.z)], - ['Resultado', alteration(m.outside)], - ], - chart: m.sites.length - ? { title: 'Mapa de la cabeza', figure: headMap(m.sites) } - : undefined, - }, - ...(norm ? [{ chart: norm }] : []), - ]; + return { + title: `${eeg.date} · ${m.title}`, + fields: [ + ['z', shown(m.z)], + ['Resultado', alteration(m.outside)], + ], + charts: [ + ...(m.sites.length ? [{ title: 'Mapa de la cabeza', figure: headMap(m.sites) }] : []), + ...(norm ? [norm] : []), + ], + }; }), ), }, @@ -188,9 +187,9 @@ export function teaPdfContent( : '—', ); } - if (block.chart) { + for (const chart of [...(block.chart ? [block.chart] : []), ...(block.charts ?? [])]) { const image = charts.next().value; - content.push({ text: block.chart.title, bold: true }); + content.push({ text: chart.title, bold: true }); if (image) content.push({ image, fit: [510, 620] }); } }