Añadir exportaciones de CaMa y conservar los filtros aplicados

This commit is contained in:
Angel Capetillo Zavala
2026-12-03 10:23:42 -06:00
parent 4ec071332d
commit 3bff3d5e3f
14 changed files with 1137 additions and 35 deletions
+20 -16
View File
@@ -16,8 +16,8 @@ import { MatSelectModule } from '@angular/material/select';
import { RouterLink } from '@angular/router';
import type { Bundle } from 'fhir/r4';
import { Fhir } from '../fhir';
import { saveExcel, savePdf } from '../export';
import { Stages } from '../paciente/stages';
import { saveFollowUp } from './follow-up-export';
import { cytologyResult, followUpSheet } from './follow-up-sheet';
import { bornFor, Row, rows, windowStart } from './follow-up';
import { PatientSearch, patientSearch } from './patient-search';
@@ -140,24 +140,28 @@ export class TabRiesgos {
/** The whole list, not the page shown, as a file. */
protected async save(kind: 'xlsx' | 'pdf'): Promise<void> {
const page = this.page();
if (!page) return;
this.saving.set(true);
this.saveError.set('');
try {
const cutoff = this.applied();
const asked = { ...this.query(), 'follow-up-cutoff': cutoff, _count: 200 };
const pages = await this.fhir.all(this.domain(), 'Patient', asked);
const start = windowStart(cutoff, this.window());
const all = pages.flatMap((p) => rows(p, start, cutoff, this.horizon()));
const sheet = followUpSheet(all, [
['Ventana consultada', `${start} al ${cutoff}`],
['Estatus de seguimiento', this.status() ? name(this.status()) : 'Todos'],
['Edad mínima', `${this.ageFrom() ?? 'Sin límite'}`],
['Edad máxima', `${this.ageTo() ?? 'Sin límite'}`],
['Búsqueda', this.search() || 'Ninguna'],
['Horizonte de la probabilidad (años)', `${this.horizon()}`],
]);
if (kind === 'xlsx') await saveExcel(sheet, 'seguimiento-cacu');
else await savePdf([sheet], 'seguimiento-cacu', true);
await saveFollowUp(this.fhir, this.domain(), page, kind, (pages, query) => {
const cutoffYear = Number(query.cutoff.slice(0, 4));
// bornFor encodes the minimum with le and the maximum with gt at one year earlier.
const lower = query.birthdates.find((value) => value.startsWith('le'));
const upper = query.birthdates.find((value) => value.startsWith('gt'));
const minimum = lower ? `${cutoffYear - Number(lower.slice(2, 6))}` : 'Sin límite';
const maximum = upper ? `${cutoffYear - Number(upper.slice(2, 6)) - 1}` : 'Sin límite';
const all = pages.flatMap((p) => rows(p, query.start, query.cutoff, query.horizon));
return followUpSheet(all, [
['Ventana consultada', query.window],
['Estatus de seguimiento', query.status],
['Edad mínima', minimum],
['Edad máxima', maximum],
['Búsqueda', query.search],
['Horizonte de la probabilidad (años)', `${query.horizon}`],
]);
});
} catch {
this.saveError.set('No se generó el archivo.');
} finally {