Iron Deficiency Risk Calculator

Iron Deficiency Risk Calculator

User Details
Risk Factors

Unusual tiredness, shortness of breath, pale skin, headaches, and cold hands/feet.

`; // Update Chart const chartCtx = document.getElementById('risk-chart').getContext('2d'); if (riskChartInstance) { riskChartInstance.destroy(); } riskChartInstance = new Chart(chartCtx, { type: 'doughnut', data: { labels: ['Your Risk Score', ''], datasets: [{ data: [results.percentage, 100 - results.percentage], backgroundColor: [results.colorClass.replace('text-', 'bg-').replace('-600', '-500'), '#e5e7eb'], borderColor: ['#ffffff'], borderWidth: 4, circumference: 180, rotation: 270, }] }, options: { responsive: true, aspectRatio: 2, cutout: '70%', plugins: { legend: { display: false }, tooltip: { enabled: false } } } }); resultsSection.style.display = 'block'; resultsSection.scrollIntoView({ behavior: 'smooth' }); } /** * Generates and downloads a PDF report. */ async function generatePdf() { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const results = calculateRisk(); if (!results) return; const userName = document.getElementById('user-name').value || 'N/A'; const assessmentDate = assessmentDateInput.value ? new Date(assessmentDateInput.value).toLocaleDateString() : 'N/A'; const pageHeight = doc.internal.pageSize.height; const pageWidth = doc.internal.pageSize.width; const margin = 15; let y = margin; // Header doc.setFont('helvetica', 'bold'); doc.setFontSize(20); doc.text('Iron Deficiency Risk Report', margin, y); y += 15; // User Info doc.setFont('helvetica', 'bold'); doc.setFontSize(11); doc.text('Name:', margin, y); doc.setFont('helvetica', 'normal'); doc.text(userName, margin + 20, y); doc.setFont('helvetica', 'bold'); doc.text('Date:', pageWidth / 2 + 20, y); doc.setFont('helvetica', 'normal'); doc.text(assessmentDate, pageWidth / 2 + 35, y); y += 10; doc.setDrawColor(226, 232, 240); doc.line(margin, y, pageWidth - margin, y); y += 15; // Result Summary doc.setFont('helvetica', 'bold'); doc.setFontSize(14); doc.text('Assessment Result', margin, y); y += 10; doc.setFontSize(12); doc.text('Calculated Risk Level:', margin, y); doc.setFont('helvetica', 'bold'); if (results.level.includes('Low')) doc.setTextColor(34, 197, 94); else if (results.level.includes('Moderate')) doc.setTextColor(234, 179, 8); else doc.setTextColor(220, 38, 38); doc.text(results.level, margin + 55, y); doc.setTextColor(0, 0, 0); y += 15; // Recommendation doc.setFillColor(243, 244, 246); doc.rect(margin, y, pageWidth - 2 * margin, 40, 'F'); doc.setFont('helvetica', 'bold'); doc.setFontSize(12); doc.text('Recommendation:', margin + 5, y + 8); doc.setFont('helvetica', 'normal'); doc.setFontSize(10); const recLines = doc.splitTextToSize(results.advice, pageWidth - (margin * 2) - 10); doc.text(recLines, margin + 5, y + 16); y += 50; // Footer doc.setFontSize(8); doc.setTextColor(148, 163, 184); doc.text(`This tool provides a general risk assessment and is not a substitute for a medical diagnosis.`, margin, pageHeight - 15); doc.text(`If you have concerns about iron deficiency, consult a healthcare professional for testing and advice.`, margin, pageHeight - 10); doc.save(`Iron_Deficiency_Risk_Report_${userName.replace(/ /g, '_')}.pdf`); } // --- EVENT LISTENERS --- if(calculateBtn) calculateBtn.addEventListener('click', displayResults); if(downloadPdfBtn) downloadPdfBtn.addEventListener('click', generatePdf); // --- INITIALIZATION --- assessmentDateInput.valueAsDate = new Date(); });
Scroll to Top