import type { Sheet } from '../export'; import type { RiskScale } from './risk-scales'; import { ANTECEDENTS } from './record-groups'; import { SOURCES, Stage, STATES } from './stages'; const NONE = 'No disponible'; const percent = (p: number) => `${(100 * p).toFixed(2)} %`; interface Event { date: string; kind: string; text: string; } interface Test { date: string; kind: string; reported?: string; results: string[]; /** the extra findings (collapsed on the page) */ findings: string[]; } interface Form { date: string; values: Record; } /** A patient's record as the tables of her PDF, in the page's order. */ export function recordSheets( facts: [string, string | undefined][], stages: Stage[], history: Event[], tests: Test[], forms: Form[], scales: RiskScale[], ): Sheet[] { return [ { title: 'Datos de la paciente', head: ['Dato', 'Valor'], rows: facts.map(([k, v]) => [k, v || NONE]), }, { title: 'Etapas del tamizaje', head: ['Etapa', 'Estado', 'Fecha', 'Procedencia'], rows: stages.map((s) => [ s.label, STATES[s.state], s.day ?? (s.requested ? `Solicitada el ${s.requested}` : ''), (s.sources ?? []).map((c) => SOURCES[c]).join(' · '), ]), }, { title: 'Historial médico', head: ['Fecha', 'Tipo', 'Detalle'], rows: history.map((h) => [h.date, h.kind, h.text]), }, { title: 'Antecedentes y evaluación ginecológica (declarados en el formulario de la citología; no son diagnósticos confirmados)', head: ['Toma', ...ANTECEDENTS.map((a) => a.title)], rows: forms.map((f) => [ f.date, ...ANTECEDENTS.map((a) => f.values[a.field] ?? 'No documentado'), ]), }, { title: 'Pruebas y resultados', head: ['Toma', 'Estudio', 'Reporte', 'Resultados', 'Hallazgos'], rows: tests.map((t) => [ t.date, t.kind, t.reported ?? 'Pendiente', t.results.join(' · '), t.findings.join(' · '), ]), }, { title: 'Riesgos', head: ['Riesgo', 'Probabilidad', 'IC 95 %'], rows: scales.map(({ label, risk }) => [ label, risk ? percent(risk.p) : NONE, risk?.low === undefined ? NONE : `${percent(risk.low)} a ${percent(risk.high!)}`, ]), }, ]; }