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();
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
@@ -17,6 +17,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
@@ -32,7 +33,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] });
});
@@ -226,8 +235,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',
@@ -339,17 +354,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', () => {
+27
View File
@@ -12,6 +12,7 @@ import { Section } from './tea-sections';
<mat-card-content>
<ng-content />
@for (block of section().blocks; track $index) {
<section>
@if (block.title) {
<h3>{{ block.title }}</h3>
}
@@ -56,6 +57,17 @@ import { Section } from './tea-sections';
<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;
+10 -11
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 [
{
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 }] : []),
];
charts: [
...(m.sites.length ? [{ title: 'Mapa de la cabeza', figure: headMap(m.sites) }] : []),
...(norm ? [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;
content.push({ text: block.chart.title, bold: true });
content.push({ text: chart.title, bold: true });
if (image) content.push({ image, fit: [510, 620] });
}
}