`;
}
function downloadResultPDF() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ unit: 'pt', format: 'a4' });
const docWidth = doc.internal.pageSize.getWidth();
const margin = 40;
let currentY = margin;
// Header
doc.setFont('helvetica', 'bold');
doc.setFontSize(22);
doc.setTextColor(79, 70, 229);
doc.text('Injury Symptom Assessment Report', margin, currentY);
currentY += 25;
doc.setFont('helvetica', 'normal');
doc.setFontSize(10);
doc.setTextColor(108, 117, 125);
doc.text(`Report Date: ${new Date().toLocaleDateString('en-US')}`, margin, currentY);
currentY += 40;
const addSectionHeader = (title) => {
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.setTextColor(33, 37, 41);
doc.text(title, margin, currentY);
currentY += 15;
doc.setDrawColor(222, 226, 230);
doc.line(margin, currentY, docWidth - margin, currentY);
currentY += 25;
};
// Symptoms Reported
addSectionHeader('Symptoms Reported');
doc.autoTable({
startY: currentY,
body: Object.entries(lastResult.inputs),
theme: 'plain',
styles: { font: 'helvetica', fontSize: 11 },
columnStyles: { 0: { fontStyle: 'bold' } }
});
currentY = doc.autoTable.previous.finalY + 30;
// Assessment Result
addSectionHeader('Assessment Result');
doc.setFontSize(12);
doc.text('Likely Injury:', margin, currentY);
doc.setFont('helvetica', 'bold');
doc.setFontSize(16);
doc.setTextColor(79, 70, 229);
doc.text(lastResult.injury, margin + 100, currentY);
currentY += 25;
const definitions = {
Sprain: "A sprain is the stretching or tearing of ligaments, which are the tough bands of tissue that connect two bones together in your joints.",
Strain: "A strain is the stretching or tearing of a muscle or a tendon. Tendons are the fibrous cords of tissue that connect muscles to bones."
};
doc.setFont('helvetica', 'normal');
doc.setFontSize(11);
doc.setTextColor(55, 65, 81);
const defLines = doc.splitTextToSize(definitions[lastResult.injury], docWidth - margin * 2);
doc.text(defLines, margin, currentY);
currentY += defLines.length * 12 + 30;
// Recommendations
addSectionHeader('General Recommendations (R.I.C.E.)');
const recommendations = [
['Rest:', 'Avoid activities that cause pain, swelling, or discomfort.'],
['Ice:', 'Apply an ice pack for 15-20 minutes at a time, every 2-3 hours.'],
['Compression:', 'Compress the area with an elastic bandage to help reduce swelling.'],
['Elevation:', 'Elevate the injured limb above the level of your heart.']
];
doc.autoTable({
startY: currentY,
body: recommendations,
theme: 'plain',
styles: { font: 'helvetica', fontSize: 11 },
columnStyles: { 0: { fontStyle: 'bold', cellWidth: 80 } }
});
currentY = doc.autoTable.previous.finalY + 30;
// Disclaimer
const pageHeight = doc.internal.pageSize.getHeight();
doc.setFont('helvetica', 'bold');
doc.setFontSize(10);
doc.setTextColor(220, 38, 38);
const disclaimerY = pageHeight - 60;
doc.text('Disclaimer: This is not a medical diagnosis.', margin, disclaimerY);
doc.setFont('helvetica', 'normal');
doc.setFontSize(9);
doc.setTextColor(108, 117, 125);
doc.text('This tool provides a preliminary assessment based on common symptoms. Please consult a healthcare professional for a proper diagnosis and treatment plan.', margin, disclaimerY + 15);
doc.save('Injury-Symptom-Report.pdf');
}
