import type { Sheet } from '../export'; import { STATES } from '../paciente/stages'; import type { CamaRow, Row } from './follow-up'; import { name } from './measures'; const NONE = 'No disponible'; const HEAD = [ 'Paciente', 'CURP', 'Edad', 'Estatus', 'Etapas', 'Última citología', 'VPH', 'Biopsia', 'LIEAG+', 'Cáncer', 'Días a diagnóstico', ]; /** A cytology's result, or why it has none. */ export function cytologyResult(c: NonNullable): string { if (c.result) return name(c.result); return c.adequacy === 'unsatisfactory' ? 'Insatisfactoria' : 'Pendiente'; } const percent = (p?: number) => (p === undefined ? NONE : `${(100 * p).toFixed(1)} %`); /** The follow-up list as a table to save, with the query it answers. */ export function followUpSheet(rows: Row[], query: [string, string][]): Sheet { return { title: 'Resultados de seguimiento', query: [...query, ['Registros', `${rows.length}`]], head: HEAD, rows: rows.map((r) => [ r.name ?? r.patient.id!.slice(0, 10), r.curp ?? NONE, `${r.age ?? NONE}`, name(r.status), r.stages .filter((s) => s.state !== 'unknown') .map((s) => `${s.label}: ${s.day ?? STATES[s.state]}`) .join('\n'), r.cytology ? `${cytologyResult(r.cytology)} (${r.cytology.date})` : NONE, r.hpv ? `${r.hpv.positive ? 'Positivo' : 'Negativo'} (${r.hpv.date})` : NONE, r.biopsy ? `${name(r.biopsy.histology ?? '') || 'Sin grado'} (${r.biopsy.date})` : NONE, percent(r.risk.cin2), percent(r.risk.cancer), `${r.daysToDiagnosis ?? NONE}`, ]), }; } const CAMA_HEAD = [ 'Paciente', 'CURP', 'Grupo de edad', 'Última mastografía (BI-RADS)', 'Fecha de la mastografía', 'Última biopsia', 'Fecha de reporte de la biopsia', 'Estatus de seguimiento', 'Prioridad', ]; /** CaMa's follow-up list as a table to save: what the page shows, a missing value said as such and * never filled in. */ export function camaFollowUpSheet( rows: CamaRow[], query: [string, string][], priority: (code: string) => string, ): Sheet { return { title: 'Resultados de seguimiento de cáncer de mama', query: [...query, ['Registros', `${rows.length}`]], head: CAMA_HEAD, rows: rows.map((r) => [ r.name ?? r.patient.id!.slice(0, 10), r.curp ?? NONE, r.ageGroup || NONE, (r.mammogram.birads && name(r.mammogram.birads)) || 'Sin dato', r.mammogram.date || NONE, r.biopsy ? name(r.biopsy.histology ?? '') || 'Sin resultado' : NONE, r.biopsy?.date ?? NONE, name(r.status), priority(r.priority) || NONE, ]), }; }