${phase1}` };
}
return profile;
}
function generatePdf() {
const { jsPDF } = jspdf;
const doc = new jsPDF();
const pageW = doc.internal.pageSize.getWidth();
const score = Object.values(document.querySelectorAll('select')).reduce((acc, sel) => acc + parseInt(sel.value), 0);
const { level, timeline, color, plan } = getRecoveryProfile(score);
// Header
doc.setFillColor(37, 99, 235);
doc.rect(0, 0, pageW, 25, 'F');
doc.setFont('helvetica', 'bold');
doc.setFontSize(16);
doc.setTextColor(255, 255, 255);
doc.text('Shin Splints Recovery Plan', pageW / 2, 15, { align: 'center' });
// Result Summary
doc.autoTable({
startY: 30,
theme: 'plain',
body: [
[{ content: 'Severity Level:', styles: { fontStyle: 'bold' } }, { content: level, styles: { textColor: color, fontStyle: 'bold' } }],
[{ content: 'Estimated Timeline:', styles: { fontStyle: 'bold' } }, { content: timeline, styles: { fontStyle: 'bold' } }]
]
});
// Recovery Plan (simplified for PDF)
let planText = '';
if (score <= 16) {
planText = 'Phase 1: Rest & Pain Management (RICE)\n- Rest from painful activities.\n- Ice shins for 15-20 minutes, multiple times a day.\n- Use compression sleeves.\n- Elevate legs when possible.\n\nPhase 2: Gentle Strengthening & Flexibility (when pain-free)\n- Perform calf stretches and toe raises.\n\nPhase 3: Gradual Return to Activity\n- Start with low-impact cross-training.\n- Reintroduce primary sport at 50% intensity, increasing by 10% weekly.';
} else {
planText = 'Immediate Action Required:\nYour symptoms indicate a high severity. It is crucial to stop all aggravating activities immediately and consult a doctor or physical therapist to rule out a stress fracture.\n\nInitial Care: Follow the RICE protocol (Rest, Ice, Compression, Elevation) while you await your appointment.';
}
doc.autoTable({
startY: doc.lastAutoTable.finalY + 5,
theme: 'grid',
headStyles: { fillColor: [37, 99, 235] },
head: [['Action Plan']],
body: [[planText]]
});
// Disclaimer
doc.autoTable({
startY: doc.lastAutoTable.finalY + 10,
theme: 'plain',
body: [[ "Disclaimer: This estimator provides a general guideline and is not a substitute for a medical diagnosis. If pain is severe, localized to one spot, or does not improve with rest, consult a healthcare professional." ]]
});
// Footer
const pageH = doc.internal.pageSize.getHeight();
doc.setLineWidth(0.5);
doc.setDrawColor(37, 99, 235);
doc.line(15, pageH - 15, pageW - 15, pageH - 15);
doc.setFontSize(8);
doc.setTextColor(128, 128, 128);
doc.text('Personalized Recovery Estimator', pageW / 2, pageH - 10, { align: 'center' });
doc.save('Shin_Splints_Recovery_Plan.pdf');
}
updateUI();
});
