Merge parity/F2b-web

This commit is contained in:
2026-12-03 13:52:27 -06:00
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(); await expect(section('Calidad del EEG').locator('tbody tr').first()).toBeVisible();
const alterations = section('Alteraciones'); const alterations = section('Alteraciones');
await expect( 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(); ).toBeAttached();
await expect( await expect(
alterations.locator('h3:text-is("Mapa de la cabeza") + app-plot .contourlayer path').first(), 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> = { export const BIOMARKER_NAMES: Record<string, string> = {
spikes: 'Picos paroxísticos', spikes: 'Puntas paroxísticas',
spindles: 'Husos de sueño N2', spindles: 'Husos de sueño N2',
posterior_rhythm: 'Ritmo posterior', posterior_rhythm: 'Ritmo posterior',
gradient: 'Gradiente anteroposterior', gradient: 'Gradiente anteroposterior',
+3 -1
View File
@@ -17,6 +17,7 @@ export function bandFill(
high: (number | null)[], high: (number | null)[],
colour: string, colour: string,
alpha: string, alpha: string,
name?: string,
): Partial<Plotly.Data> { ): Partial<Plotly.Data> {
const rows = x.flatMap((age, i) => const rows = x.flatMap((age, i) =>
low[i] != null && high[i] != null low[i] != null && high[i] != null
@@ -32,7 +33,8 @@ export function bandFill(
fillcolor: `${colour}${alpha}`, fillcolor: `${colour}${alpha}`,
line: { width: 0 }, line: { width: 0 },
hoverinfo: 'skip', hoverinfo: 'skip',
showlegend: false, name,
showlegend: name != null,
}; };
} }
+1 -1
View File
@@ -417,7 +417,7 @@ export class Paciente {
return [ return [
`${eeg.id}|${metric.key}`, `${eeg.id}|${metric.key}`,
{ {
title: 'Norma por edad · p5–p95', title: 'Norma por edad',
figure: ageNorm(rows, metric, eeg.age), figure: ageNorm(rows, metric, eeg.age),
}, },
] as const; ] as const;
+15 -2
View File
@@ -38,9 +38,13 @@ export function timeline(steps: TeaStep[]): Figure | null {
], ],
layout: { layout: {
showlegend: false, showlegend: false,
margin: { l: 140, r: 90, t: 16, b: 40 }, margin: { l: 140, r: 90, t: 40, b: 40 },
xaxis: { xaxis: {
type: 'date', type: 'date',
showline: true,
ticks: 'outside',
tickmode: 'array',
tickvals: done.map((step) => step.date),
tickformat: '%d/%m/%Y', tickformat: '%d/%m/%Y',
...(done.every((step) => step.date === last) ...(done.every((step) => step.date === last)
? { ? {
@@ -59,6 +63,13 @@ export function timeline(steps: TeaStep[]): Figure | null {
fixedrange: true, fixedrange: true,
}, },
annotations: [ annotations: [
...done.map((step) => ({
x: step.date,
y: step.label,
yshift: 26,
showarrow: false,
text: step.label,
})),
...spans.map((span) => ({ ...spans.map((span) => ({
x: new Date((Date.parse(span.from.date) + Date.parse(span.to.date)) / 2) x: new Date((Date.parse(span.from.date) + Date.parse(span.to.date)) / 2)
.toISOString() .toISOString()
@@ -180,7 +191,7 @@ export function headMap(sites: Site[]): Figure {
contours: { coloring: 'heatmap', showlines: true }, contours: { coloring: 'heatmap', showlines: true },
line: { width: 0.5, color: 'rgba(8,24,57,.3)' }, line: { width: 0.5, color: 'rgba(8,24,57,.3)' },
hoverinfo: 'skip', hoverinfo: 'skip',
colorbar: { title: { text: 'z' } }, colorbar: { title: { text: 'z (distancia a la referencia)' } },
}); });
} }
const markers = Object.entries(electrodes); const markers = Object.entries(electrodes);
@@ -217,6 +228,7 @@ export function ageNorm(rows: Centile[], metric: Metric, age: number): Figure {
rows.map((row) => row.p95), rows.map((row) => row.p95),
PALETTE[4], PALETTE[4],
'29', '29',
'P5–P95 (90 %)',
), ),
bandFill( bandFill(
x, x,
@@ -224,6 +236,7 @@ export function ageNorm(rows: Centile[], metric: Metric, age: number): Figure {
rows.map((row) => row.p75 ?? null), rows.map((row) => row.p75 ?? null),
PALETTE[4], PALETTE[4],
'52', '52',
'P25–P75 (50 % de la referencia)',
), ),
{ {
type: 'scatter', 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', () => { it('dibuja los centiles del campeón y el valor observado a la edad del paciente', () => {
const figure = ageNorm(centiles, metric, 20.5); 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] }); expect(figure.data[3]).toMatchObject({ mode: 'markers', x: [20.5], y: [1.7] });
}); });
@@ -226,8 +235,14 @@ describe('Figuras del paciente TEA', () => {
it('anota los días entre etapas y deja pendientes las que faltan', () => { it('anota los días entre etapas y deja pendientes las que faltan', () => {
const figure = timeline(steps)!; const figure = timeline(steps)!;
const notes = figure.layout?.annotations ?? []; const notes = figure.layout?.annotations ?? [];
expect(notes.map((note) => note.text)).toEqual(['21 días', 'Pendiente', 'Pendiente']); expect(notes.map((note) => note.text)).toEqual([
expect(notes.slice(1).map((note) => note.y)).toEqual(['Neuropediatría', 'EEG']); '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([ expect(figure.layout?.yaxis?.categoryarray).toEqual([
'EEG', 'EEG',
'Neuropediatría', 'Neuropediatría',
@@ -339,17 +354,48 @@ describe('Expediente TEA', () => {
]); ]);
}); });
it('pone la norma de cada métrica tras su mapa de la cabeza', () => { it('agrupa el mapa y la norma en un bloque por estudio y métrica', () => {
const patient = { ...record, studies: [eeg] }; const spikes = { ...metric, key: 'paroxysmal_spikes', title: 'Puntas paroxísticas' };
const norm = { title: 'Norma por edad · p5–p95', figure: ageNorm(centiles, metric, eeg.age) }; 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 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.chart?.title)).toEqual([ expect(altered?.blocks.map((block) => block.title)).toEqual([
'Mapa de la cabeza', '2025-11-30 · Husos N2',
'Norma por edad · p5–p95', '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', () => { it('exporta las secciones, tablas y figuras con un nombre sin identificador', () => {
+67 -40
View File
@@ -12,50 +12,62 @@ import { Section } from './tea-sections';
<mat-card-content> <mat-card-content>
<ng-content /> <ng-content />
@for (block of section().blocks; track $index) { @for (block of section().blocks; track $index) {
@if (block.title) { <section>
<h3>{{ block.title }}</h3> @if (block.title) {
} <h3>{{ block.title }}</h3>
@if (block.text) { }
<p>{{ block.text }}</p> @if (block.text) {
} <p>{{ block.text }}</p>
@if (block.fields; as fields) { }
<dl> @if (block.fields; as fields) {
@for (field of fields; track $index) { <dl>
<div> @for (field of fields; track $index) {
<dt>{{ field[0] }}</dt> <div>
<dd>{{ field[1] }}</dd> <dt>{{ field[0] }}</dt>
</div> <dd>{{ field[1] }}</dd>
} </div>
</dl> }
} </dl>
@if (block.table; as table) { }
@if (table.rows.length) { @if (block.table; as table) {
<table class="plain"> @if (table.rows.length) {
<thead> <table class="plain">
<tr> <thead>
@for (header of table.headers; track $index) {
<th scope="col">{{ header }}</th>
}
</tr>
</thead>
<tbody>
@for (row of table.rows; track $index) {
<tr> <tr>
@for (cell of row; track $index) { @for (header of table.headers; track $index) {
<td>{{ cell }}</td> <th scope="col">{{ header }}</th>
} }
</tr> </tr>
} </thead>
</tbody> <tbody>
</table> @for (row of table.rows; track $index) {
} @else { <tr>
<p class="muted">—</p> @for (cell of row; track $index) {
<td>{{ cell }}</td>
}
</tr>
}
</tbody>
</table>
} @else {
<p class="muted">—</p>
}
} }
} @if (block.chart; as chart) {
@if (block.chart; as chart) { <h3>{{ chart.title }}</h3>
<h3>{{ chart.title }}</h3> <app-plot [figure]="chart.figure" [height]="chart.height ?? 340" />
<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 { } @empty {
<p class="muted">—</p> <p class="muted">—</p>
} }
@@ -69,6 +81,21 @@ import { Section } from './tea-sections';
mat-card-content { mat-card-content {
overflow-x: auto; 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 { dl {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
+15 -16
View File
@@ -11,6 +11,7 @@ type Block = {
fields?: string[][]; fields?: string[][];
table?: Table; table?: Table;
chart?: Chart; chart?: Chart;
charts?: Chart[];
text?: string; text?: string;
}; };
export type Section = { title: string; blocks: Block[] }; export type Section = { title: string; blocks: Block[] };
@@ -64,21 +65,19 @@ export function recordSections(patient: TeaPatient, norms: ReadonlyMap<string, C
{ {
title: 'Alteraciones', title: 'Alteraciones',
blocks: patient.studies.flatMap((eeg) => blocks: patient.studies.flatMap((eeg) =>
eeg.metrics.flatMap((m) => { eeg.metrics.map((m) => {
const norm = norms.get(`${eeg.id}|${m.key}`); const norm = norms.get(`${eeg.id}|${m.key}`);
return [ return {
{ title: `${eeg.date} · ${m.title}`,
title: `${eeg.date} · ${m.title}`, fields: [
fields: [ ['z', shown(m.z)],
['z', shown(m.z)], ['Resultado', alteration(m.outside)],
['Resultado', alteration(m.outside)], ],
], charts: [
chart: m.sites.length ...(m.sites.length ? [{ title: 'Mapa de la cabeza', figure: headMap(m.sites) }] : []),
? { title: 'Mapa de la cabeza', figure: headMap(m.sites) } ...(norm ? [norm] : []),
: undefined, ],
}, };
...(norm ? [{ chart: norm }] : []),
];
}), }),
), ),
}, },
@@ -191,9 +190,9 @@ export function teaPdfContent(
: '—', : '—',
); );
} }
if (block.chart) { for (const chart of [...(block.chart ? [block.chart] : []), ...(block.charts ?? [])]) {
const image = charts.next().value; 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] }); if (image) content.push({ image, fit: [510, 620] });
} }
} }