Files
WebApp/src/app/features/indicadores/paciente-detalle/cama/cama-patient-card.ts
T
2026-11-22 16:12:44 -06:00

52 lines
2.5 KiB
TypeScript

import { AfterViewInit, Component, ElementRef, input, output, signal, viewChild } from '@angular/core';
import { downloadBlob, exportFilename } from '../../export/download-file';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatIconModule } from '@angular/material/icon';
import { CamaAnalisisRecurrencia } from './cama-analisis-recurrencia.component';
import { CamaAnalisisSupervivencia } from './cama-analisis-supervivencia.component';
import {
CamaPatientSummary, NOT_AVAILABLE, RECOMMENDATIONS_UNAVAILABLE,
} from './cama-patient.models';
/**
* Individual record of a CaMa follow-up patient. It shows what the follow-up list carries, the recurrence analysis with its risk
* factors ("Pronóstico y recomendaciones") and the survival analysis with its risk factors ("Riesgo de muerte"), one clinical
* scenario at a time (the recurrence analysis only for patients after treatment); the recommendations are not available yet.
*/
@Component({
selector: 'app-cama-patient-card',
imports: [MatButtonModule, MatCardModule, MatIconModule, CamaAnalisisRecurrencia, CamaAnalisisSupervivencia],
templateUrl: './cama-patient-card.html',
styleUrl: './cama-patient-card.scss',
})
export class CamaPatientCard implements AfterViewInit {
readonly summary = input.required<CamaPatientSummary>();
readonly back = output<void>();
readonly notAvailable = NOT_AVAILABLE;
/** The recurrence analysis is for patients who have been treated: it is shown only in this clinical scenario. */
readonly postTreatment = 'Post-tratamiento';
readonly recommendationsUnavailable = RECOMMENDATIONS_UNAVAILABLE;
private readonly title = viewChild<ElementRef<HTMLElement>>('title');
readonly generating = signal(false);
readonly failed = signal(false);
ngAfterViewInit() { this.title()?.nativeElement.focus(); }
/** Downloads the record as a PDF. The file name carries the report and the cut-off, never the patient. */
async exportPdf() {
if (this.generating()) return;
this.generating.set(true); this.failed.set(false);
try {
const patient = this.summary();
// The PDF library downloads only when the button is used.
const blob = await (await import('./cama-patient-pdf')).buildCamaPatientPdf(patient);
downloadBlob(blob, exportFilename('ficha-cancer-de-mama', patient.cutoff, 'pdf'));
} catch {
this.failed.set(true);
} finally {
this.generating.set(false);
}
}
}