${level}
${description}
Key Takeaways:
${getTakeaways(userInputs)}
Disclaimer: This calculator provides an estimation based on common risk factors and is not a medical diagnosis. Consult a dermatologist for an accurate assessment.
`;
downloadPdfBtn.style.display = 'inline-block';
}
function getRiskProfile(score) {
if (score <= 8) return { level: 'Low Risk', description: 'Your profile suggests a low likelihood of significant hair loss based on these factors.', color: '#22c55e' };
if (score <= 16) return { level: 'Moderate Risk', description: 'Your profile indicates some risk factors are present. It may be beneficial to monitor your hair and scalp health.', color: '#f59e0b' };
if (score <= 25) return { level: 'High Risk', description: 'Your profile shows a combination of significant risk factors. Proactive consultation with a specialist could be beneficial.', color: '#ef4444' };
return { level: 'Very High Risk', description: 'Your profile indicates a strong predisposition based on multiple key factors. Seeking professional advice is highly recommended.', color: '#b91c1c' };
}
function getTakeaways(inputs) {
let takeaways = '';
if (inputs['Does your father have hair loss?'] === 'Yes' || inputs["Does your mother's father have hair loss?"] === 'Yes') {
takeaways += '
Genetic factors appear to be a primary contributor to your risk profile.';
}
if (inputs['Your Typical Stress Level'] === 'High') {
takeaways += '
High stress levels can contribute to hair shedding. Managing stress may be beneficial.';
}
if (inputs['Have you noticed visible thinning?'] === 'Yes, noticeably thinner') {
takeaways += '
Your observation of thinning is a key factor. A dermatologist can help determine the cause.';
}
if (takeaways === '') {
takeaways = '
Your risk profile appears balanced. Maintaining a healthy lifestyle is key.';
}
return takeaways;
}
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, description, color } = getRiskProfile(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('Hair Loss Risk Assessment Report', pageW / 2, 15, { align: 'center' });
// Result
doc.setFontSize(12);
doc.setFont('helvetica', 'normal');
doc.text('Your Estimated Risk Level:', pageW / 2, 40, { align: 'center' });
doc.setFontSize(22);
doc.setFont('helvetica', 'bold');
doc.setTextColor(color);
doc.text(level, pageW / 2, 50, { align: 'center' });
doc.setFontSize(11);
doc.setFont('helvetica', 'normal');
doc.setTextColor(100, 116, 139);
const splitDescription = doc.splitTextToSize(description, pageW - 40);
doc.text(splitDescription, pageW / 2, 60, { align: 'center' });
// Summary of Inputs
const tableData = Object.entries(userInputs).map(([key, value]) => [key, value]);
doc.autoTable({
startY: 80,
theme: 'striped',
headStyles: { fillColor: [37, 99, 235] },
head: [['Factor', 'Your Answer']],
body: tableData,
});
// Disclaimer
doc.autoTable({
startY: doc.lastAutoTable.finalY + 10,
theme: 'plain',
body: [[ "Disclaimer: This is an educational tool, not a medical diagnosis. The risk score is an estimate based on common factors associated with hair loss. For an accurate diagnosis and treatment options, please consult a qualified dermatologist or healthcare provider." ]]
});
// 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('Confidential Health Assessment', pageW / 2, pageH - 10, { align: 'center' });
doc.save('Hair_Loss_Risk_Report.pdf');
}
updateUI();
});