mirror of
https://github.com/gauvainboiche/ketapk.git
synced 2026-09-02 11:13:11 +02:00
refacto: Adding i18n support with FR and EN as base
This commit is contained in:
+22
-35
@@ -1,52 +1,39 @@
|
||||
/**
|
||||
* Génère et télécharge un rapport PDF de la simulation.
|
||||
* @param {Object} pkChart - L'instance Chart.js actuelle
|
||||
* @param {Object} patient - Les infos du patient { weight, age, height }
|
||||
* @param {String} mode - ESKETAMINE ou RACEMIQUE
|
||||
*/
|
||||
import { t } from './i18n.js';
|
||||
|
||||
export function generatePDFReport(pkChart, patient, mode) {
|
||||
// jsPDF est chargé globalement via le CDN dans index.html
|
||||
const { jsPDF } = window.jspdf;
|
||||
|
||||
// Format A4, orientation Paysage (landscape) idéal pour les graphiques
|
||||
const doc = new jsPDF('landscape', 'mm', 'a4');
|
||||
const doc = new jsPDF('landscape', 'mm', 'a4');
|
||||
|
||||
// --- 1. En-tête du document ---
|
||||
doc.setFillColor(30, 41, 59); // Couleur bleue nuit (slate-800)
|
||||
// En-tête
|
||||
doc.setFillColor(30, 41, 59);
|
||||
doc.rect(0, 0, 297, 25, 'F');
|
||||
|
||||
|
||||
doc.setTextColor(255, 255, 255);
|
||||
doc.setFontSize(18);
|
||||
doc.setFontSize(16);
|
||||
doc.setFont("helvetica", "bold");
|
||||
doc.text("KétaPK - Rapport de Simulation Pharmacocinétique", 14, 16);
|
||||
doc.text(t('pdf.title'), 14, 16);
|
||||
|
||||
// --- 2. Informations de la simulation ---
|
||||
// Informations Patient
|
||||
doc.setTextColor(50, 50, 50);
|
||||
doc.setFontSize(11);
|
||||
doc.setFontSize(10);
|
||||
doc.setFont("helvetica", "normal");
|
||||
|
||||
const dateStr = new Date().toLocaleString('fr-FR');
|
||||
|
||||
// Colonne de gauche (Patient)
|
||||
doc.text(`Date de simulation : ${dateStr}`, 14, 35);
|
||||
|
||||
const dateStr = new Date().toLocaleString();
|
||||
|
||||
doc.text(`${t('pdf.date')}${dateStr}`, 14, 35);
|
||||
doc.setFont("helvetica", "bold");
|
||||
doc.text(`Mode sélectionné : ${mode}`, 14, 42);
|
||||
doc.text(`Patient : Poids ${patient.weight} kg | Âge ${patient.age} ans | Taille ${patient.height} cm`, 14, 49);
|
||||
doc.text(`${t('pdf.mode')}${mode}`, 14, 42);
|
||||
doc.text(t('pdf.patient_info', patient), 14, 49);
|
||||
|
||||
// --- 3. Capture et insertion du Graphique ---
|
||||
// On récupère l'image du graphique sur fond blanc
|
||||
// Image du Graphique
|
||||
const chartImage = pkChart.toBase64Image('image/jpeg', 1.0);
|
||||
|
||||
// Placement : x=14mm, y=60mm, largeur=260mm, hauteur=110mm
|
||||
doc.addImage(chartImage, 'JPEG', 14, 60, 260, 110);
|
||||
doc.addImage(chartImage, 'JPEG', 14, 55, 268, 120);
|
||||
|
||||
// --- 4. Pied de page ---
|
||||
// Pied de page
|
||||
doc.setFont("helvetica", "italic");
|
||||
doc.setFontSize(9);
|
||||
doc.setFontSize(8);
|
||||
doc.setTextColor(150, 150, 150);
|
||||
doc.text("Ce document est généré par KétaPK Web. Il est destiné uniquement à l'enseignement et ne doit pas être utilisé pour la conduite thérapeutique.", 14, 190);
|
||||
doc.text(t('pdf.disclaimer'), 14, 192);
|
||||
|
||||
// --- 5. Téléchargement ---
|
||||
const fileName = `KetaPK_Rapport_${patient.weight}kg_${mode}.pdf`;
|
||||
doc.save(fileName);
|
||||
doc.save(`KetaPK_Simulation_${patient.weight}kg_${mode}.pdf`);
|
||||
}
|
||||
Reference in New Issue
Block a user