43 lines
2.5 KiB
TypeScript
43 lines
2.5 KiB
TypeScript
import { renderPdf, PdfDefinition } from '../../export/pdf-engine';
|
|
import { COLORS, institutionalDocument, loadLogo } from '../../export/pdf-template';
|
|
import {
|
|
CamaPatientSummary, NOT_AVAILABLE, PROGNOSIS_PLACEHOLDERS, PROGNOSIS_UNAVAILABLE, RECOMMENDATIONS_UNAVAILABLE,
|
|
} from './cama-patient.models';
|
|
|
|
export const PATIENT_TITLE = 'Ficha de paciente — Cáncer de mama';
|
|
|
|
const rule = { hLineWidth: () => 0.5, vLineWidth: () => 0, hLineColor: () => COLORS.rule, paddingTop: () => 4, paddingBottom: () => 4 };
|
|
const value = (v: string | number | null) => (v === null ? { text: NOT_AVAILABLE, italics: true, color: COLORS.muted } : { text: String(v) });
|
|
const section = (title: string, rows: [string, string | number | null][]) => [
|
|
{ text: title, style: 'h2' },
|
|
{ table: { widths: [170, '*'], body: rows.map(([label, v]) => [{ text: label, bold: true }, value(v)]) }, layout: rule },
|
|
];
|
|
|
|
/** The document definition of one patient's record. Exported so its content can be checked without rendering. */
|
|
export function camaPatientDocument(patient: CamaPatientSummary, now: Date, logo?: string): PdfDefinition {
|
|
return institutionalDocument({ title: PATIENT_TITLE, logo, now, orientation: 'portrait' }, [
|
|
{ text: `Paciente ${patient.patientId}`, style: 'h1' },
|
|
{ text: `Fecha de corte: ${patient.cutoff}`, style: 'muted' },
|
|
...section('Resumen', [
|
|
[patient.idLabel, patient.patientId],
|
|
['Grupo de edad', patient.ageGroup],
|
|
['Escenario clínico', patient.clinicalScenario],
|
|
['Estatus de seguimiento', patient.status],
|
|
['Prioridad', patient.priority],
|
|
['Días de mastografía a diagnóstico', patient.daysMammographyToDiagnosis],
|
|
]),
|
|
...section('Mastografía', [['Categoría BI-RADS', patient.birads], ['Fecha de la mastografía', patient.mammographyDate]]),
|
|
...section('Histopatología', [['Resultado histopatológico', patient.histopathology], [patient.biopsyDateLabel ?? 'Fecha de biopsia', patient.biopsyDate]]),
|
|
...section('Pronóstico y recomendaciones', [
|
|
...PROGNOSIS_PLACEHOLDERS.map(p => [p.label, PROGNOSIS_UNAVAILABLE] as [string, string]),
|
|
['Recomendaciones', RECOMMENDATIONS_UNAVAILABLE],
|
|
]),
|
|
{ text: '“No disponible” indica dato no registrado, no ausencia clínica.', style: 'small', margin: [0, 10, 0, 0] },
|
|
]);
|
|
}
|
|
|
|
/** A one-patient PDF with the same frame as the follow-up report. */
|
|
export async function buildCamaPatientPdf(patient: CamaPatientSummary, now = new Date(), logo?: string): Promise<Blob> {
|
|
return renderPdf(camaPatientDocument(patient, now, logo ?? await loadLogo()));
|
|
}
|