b291885b97
- The EEG preview dialog gets "Guardar como PDF": previewPdfContent is a
pure function (verdict, checks, metrics with scores per electrode and
zone, ADOS-2 classification/CSS and items by their Core titles,
warnings), downloadPreviewPdf a thin wrapper over export/pdf; the file
is tea-gobernanza-<day>.pdf. Unit-tested without mocks.
- e2e/pages.spec.ts now holds only the TEA page tests (the CaCu/CaMa
cases needed fixtures P7 removed): every indicator tab, the follow-up
xlsx export, the patient record and risk page with their PDFs, and
every Gobernanza section in sync mode including the preview PDF. Each
download is checked for a file and a name without a record number.
- Fixes the page tests found: the TEA xlsx name ('seguimiento-tea') failed
validateName, so the export always threw; it is now tea-<page>-<day>.
ng serve crashed on every Plotly page (has-hover reads 'global'): the
build defines global as globalThis. Record numbers repeated once per
source identifier; they are deduplicated. A refused bundle export showed
'{}': the blob error body is now read for the API's detail.
105 lines
3.2 KiB
TypeScript
105 lines
3.2 KiB
TypeScript
import { downloadPdf, type PdfContent } from '../../export/pdf';
|
|
import { safeName } from '../../export/safe-name';
|
|
import type { PreviewResult } from '../../api/models/preview-result';
|
|
import type { Score } from '../../api/models/score';
|
|
|
|
function shown(value: unknown): string {
|
|
return value == null || value === '' ? '—' : String(value);
|
|
}
|
|
|
|
function yesNo(value: unknown): string {
|
|
return value === true ? 'Sí' : value === false ? 'No' : '—';
|
|
}
|
|
|
|
function verdict(valid: boolean | null): string {
|
|
return valid === true ? 'Válido' : valid === false ? 'No válido' : '—';
|
|
}
|
|
|
|
function scoreCells(score: Score | null): string[] {
|
|
return [
|
|
shown(score?.z),
|
|
`${shown(score?.p5)} / ${shown(score?.median)} / ${shown(score?.p95)}`,
|
|
shown(score?.outside),
|
|
];
|
|
}
|
|
|
|
function table(headers: string[], rows: string[][]): PdfContent {
|
|
if (!rows.length) return '—';
|
|
return {
|
|
layout: 'lightHorizontalLines',
|
|
table: {
|
|
headerRows: 1,
|
|
widths: ['*', ...headers.slice(1).map(() => 'auto' as const)],
|
|
body: [headers, ...rows],
|
|
},
|
|
};
|
|
}
|
|
|
|
function heading(text: string): PdfContent {
|
|
return { text, bold: true, fontSize: 14, margin: [0, 12, 0, 5] };
|
|
}
|
|
|
|
export function previewPdfName(day = new Date()): string {
|
|
return safeName(['tea', 'gobernanza', day.toISOString().slice(0, 10)]);
|
|
}
|
|
|
|
export function previewPdfContent(result: PreviewResult): PdfContent[] {
|
|
const { eeg, ados2, warnings } = result;
|
|
const content: PdfContent[] = [
|
|
{ text: 'Vista previa del estudio EEG', fontSize: 18, bold: true },
|
|
`${eeg.level} · ${verdict(eeg.valid)}`,
|
|
];
|
|
if (eeg.error) content.push(eeg.error);
|
|
|
|
content.push(
|
|
heading('Comprobaciones'),
|
|
table(
|
|
['Comprobación', 'Electrodo', 'Resultado', 'Rango', 'Anormal'],
|
|
eeg.checks.map((check) => [
|
|
shown(check['code']),
|
|
shown(check['electrode']),
|
|
`${shown(check['value'] ?? check['text'])}${check['unit'] ? ' ' + check['unit'] : ''}`,
|
|
`${shown(check['low'])} / ${shown(check['high'])}`,
|
|
yesNo(check['abnormal']),
|
|
]),
|
|
),
|
|
);
|
|
|
|
content.push(
|
|
heading('Métricas'),
|
|
table(
|
|
['Métrica', 'Valor', 'z', 'p5 / mediana / p95', 'Fuera de rango'],
|
|
eeg.metrics.flatMap((metric) => [
|
|
[metric.code, shown(metric.value), ...scoreCells(metric.score)],
|
|
...[...Object.entries(metric.electrodes), ...Object.entries(metric.zones)].map(
|
|
([site, value]) => [
|
|
`${metric.code} · ${site}`,
|
|
shown(value.value),
|
|
...scoreCells(value.score),
|
|
],
|
|
),
|
|
]),
|
|
),
|
|
);
|
|
|
|
if (ados2) {
|
|
content.push(
|
|
heading('ADOS-2'),
|
|
`${shown(ados2.classification)} · CSS ${shown(ados2.css)}`,
|
|
table(
|
|
['Ítem', 'Puntuación'],
|
|
Object.entries(ados2.items)
|
|
.filter(([field, value]) => field in ados2.titles || value != null)
|
|
.map(([field, value]) => [ados2.titles[field] ?? field, shown(value)]),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (warnings.length) content.push(heading('Advertencias'), { ul: [...warnings] });
|
|
return content;
|
|
}
|
|
|
|
export function downloadPreviewPdf(result: PreviewResult): Promise<void> {
|
|
return downloadPdf(previewPdfName(), previewPdfContent(result));
|
|
}
|