F2b: TEA record after the 3 Dec review

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.
This commit is contained in:
2026-12-03 13:51:40 -06:00
parent 98eda5bc28
commit 2add96e38a
8 changed files with 161 additions and 74 deletions
+1 -1
View File
@@ -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(),
+1 -1
View File
@@ -12,7 +12,7 @@ export const ZONE_NAMES: Record<string, string> = {
};
export const BIOMARKER_NAMES: Record<string, string> = {
spikes: 'Picos paroxísticos',
spikes: 'Puntas paroxísticas',
spindles: 'Husos de sueño N2',
posterior_rhythm: 'Ritmo posterior',
gradient: 'Gradiente anteroposterior',
+3 -1
View File
@@ -16,6 +16,7 @@ export function bandFill(
high: (number | null)[],
colour: string,
alpha: string,
name?: string,
): Partial<Plotly.Data> {
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,
};
}
+1 -1
View File
@@ -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;
+15 -2
View File
@@ -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',
+57 -11
View File
@@ -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', () => {
+68 -41
View File
@@ -12,50 +12,62 @@ import { Section } from './tea-sections';
<mat-card-content>
<ng-content />
@for (block of section().blocks; track $index) {
@if (block.title) {
<h3>{{ block.title }}</h3>
}
@if (block.text) {
<p>{{ block.text }}</p>
}
@if (block.fields; as fields) {
<dl>
@for (field of fields; track $index) {
<div>
<dt>{{ field[0] }}</dt>
<dd>{{ field[1] }}</dd>
</div>
}
</dl>
}
@if (block.table; as table) {
@if (table.rows.length) {
<table class="plain">
<thead>
<tr>
@for (header of table.headers; track $index) {
<th scope="col">{{ header }}</th>
}
</tr>
</thead>
<tbody>
@for (row of table.rows; track $index) {
<section>
@if (block.title) {
<h3>{{ block.title }}</h3>
}
@if (block.text) {
<p>{{ block.text }}</p>
}
@if (block.fields; as fields) {
<dl>
@for (field of fields; track $index) {
<div>
<dt>{{ field[0] }}</dt>
<dd>{{ field[1] }}</dd>
</div>
}
</dl>
}
@if (block.table; as table) {
@if (table.rows.length) {
<table class="plain">
<thead>
<tr>
@for (cell of row; track $index) {
<td>{{ cell }}</td>
@for (header of table.headers; track $index) {
<th scope="col">{{ header }}</th>
}
</tr>
}
</tbody>
</table>
} @else {
<p class="muted">—</p>
</thead>
<tbody>
@for (row of table.rows; track $index) {
<tr>
@for (cell of row; track $index) {
<td>{{ cell }}</td>
}
</tr>
}
</tbody>
</table>
} @else {
<p class="muted">—</p>
}
}
}
@if (block.chart; as chart) {
<h3>{{ chart.title }}</h3>
<app-plot [figure]="chart.figure" [height]="chart.height ?? 340" />
}
@if (block.chart; as chart) {
<h3>{{ chart.title }}</h3>
<app-plot [figure]="chart.figure" [height]="chart.height ?? 340" />
}
@if (block.charts; as charts) {
<div class="charts">
@for (chart of charts; track $index) {
<div>
<h3>{{ chart.title }}</h3>
<app-plot [figure]="chart.figure" [height]="chart.height ?? 340" />
</div>
}
</div>
}
</section>
} @empty {
<p class="muted">—</p>
}
@@ -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<Section>();
}
}
+15 -16
View File
@@ -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<string, C
{
title: 'Alteraciones',
blocks: patient.studies.flatMap((eeg) =>
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] });
}
}