Fall Risk Assessment Tool

Fall Risk Assessment Tool

Answer the questions below to understand your risk of falling.

Please answer "Yes" or "No" to the following questions:

${q.text}

`; questionnaireContainer.appendChild(questionRow); }); } // --- ASSESSMENT LOGIC --- function assessRisk() { let score = 0; let riskLevel = ''; let recommendation = ''; let summaryHtml = ''; questions.forEach(q => { const selected = document.querySelector(`input[name="${q.id}"]:checked`); const answer = selected.value; if (answer === 'yes') { score += q.points; } summaryHtml += `

${q.text}

${answer}
`; }); if (score >= 4) { riskLevel = 'High Risk'; resultLevelEl.className = 'text-4xl font-bold text-red-600'; recommendation = 'Your score indicates a high risk of falling. It is strongly recommended to discuss these results with your healthcare provider. They can help identify specific causes and create a personalized prevention plan.'; } else if (score >= 1 && score < 4) { riskLevel = 'Moderate Risk'; resultLevelEl.className = 'text-4xl font-bold text-yellow-600'; recommendation = 'Your score indicates a moderate risk of falling. You may benefit from simple interventions like a home safety check, a review of your medications with your doctor, and exercises to improve strength and balance.'; } else { riskLevel = 'Low Risk'; resultLevelEl.className = 'text-4xl font-bold text-green-600'; recommendation = 'Your score indicates a low risk of falling. Continue to stay active and be mindful of home safety to maintain this low risk.'; } // Display results resultScoreEl.textContent = score; resultLevelEl.textContent = riskLevel; resultRecommendationEl.innerHTML = recommendation; summaryAnswersEl.innerHTML = summaryHtml; pdfOutputArea.classList.remove('hidden'); pdfOutputArea.scrollIntoView({ behavior: 'smooth' }); } // --- PDF DOWNLOAD FUNCTIONALITY --- async function downloadPDF() { if (pdfOutputArea.classList.contains('hidden')) { errorMessageEl.textContent = 'Please complete the assessment before downloading.'; return; } const buttonToHide = document.getElementById('download-pdf-btn'); buttonToHide.style.display = 'none'; try { const { jsPDF } = window.jspdf; const canvas = await html2canvas(pdfOutputArea, { scale: 2, useCORS: true }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasAspectRatio = canvas.height / canvas.width; let imgWidth = pdfWidth * 0.9; let imgHeight = imgWidth * canvasAspectRatio; if (imgHeight > pdfHeight * 0.95) { imgHeight = pdfHeight * 0.95; imgWidth = imgHeight / canvasAspectRatio; } const xPos = (pdfWidth - imgWidth) / 2; const yPos = (pdfHeight - imgHeight) / 2; pdf.addImage(imgData, 'PNG', xPos, yPos, imgWidth, imgHeight); pdf.save('Fall-Risk-Assessment-Report.pdf'); } catch (error) { console.error("Failed to generate PDF:", error); errorMessageEl.textContent = 'An error occurred while creating the PDF.'; } finally { buttonToHide.style.display = 'flex'; } } // --- EVENT LISTENERS --- assessRiskBtn.addEventListener('click', assessRisk); downloadPdfBtn.addEventListener('click', downloadPDF); // --- INITIALIZATION --- renderQuestions(); });
Scroll to Top