Left Shoulder Over
${leftRating.text}
Measurement: ${leftScore} inches
`;
downloadPdfBtn.style.display = 'inline-block';
}
function generatePdf() {
if (typeof jspdf === 'undefined' || typeof jspdf.jsPDF.API.autoTable !== 'function') {
console.error('jsPDF or jsPDF-AutoTable library is not loaded.');
return;
}
const { jsPDF } = jspdf;
const doc = new jsPDF();
const pageW = doc.internal.pageSize.getWidth();
// Report Header
doc.setFillColor(31, 41, 55); // Dark Gray
doc.rect(0, 0, pageW, 25, 'F');
doc.setFont('helvetica', 'bold');
doc.setFontSize(16);
doc.setTextColor(255, 255, 255);
doc.text('Shoulder Flexibility Test Report', pageW / 2, 15, { align: 'center' });
// Report Details
doc.autoTable({
startY: 30,
theme: 'plain',
styles: { fontSize: 11, cellPadding: 2 },
body: [
['Test Type:', 'Back Scratch Test'],
['Report Date:', new Date().toLocaleDateString('en-US')],
],
});
// Results Table
doc.autoTable({
startY: doc.lastAutoTable.finalY + 10,
theme: 'grid',
headStyles: { fillColor: [31, 41, 55] },
head: [['Shoulder Tested', 'Measurement (inches)', 'Flexibility Rating']],
body: [
['Right Shoulder Over', resultsData.right.score, resultsData.right.rating],
['Left Shoulder Over', resultsData.left.score, resultsData.left.rating],
],
didParseCell: function (data) {
if (data.column.dataKey === 2) { // Rating column
if (data.cell.raw === 'Excellent') data.cell.styles.textColor = [22, 163, 74];
if (data.cell.raw === 'Good') data.cell.styles.textColor = [37, 99, 235];
if (data.cell.raw === 'Average') data.cell.styles.textColor = [202, 138, 4];
if (data.cell.raw === 'Needs Improvement') data.cell.styles.textColor = [220, 38, 38];
}
}
});
// Interpretation Section
doc.autoTable({
startY: doc.lastAutoTable.finalY + 10,
theme: 'grid',
headStyles: { fillColor: [31, 41, 55] },
head: [['Rating Interpretation']],
body: [[
'This test assesses the range of motion of your shoulder girdle. Good shoulder flexibility is important for posture and performing overhead activities without risk of injury.\n\n- Excellent/Good: Indicates healthy range of motion.\n- Average: Functional, but could benefit from stretching.\n- Needs Improvement: Indicates tightness that may increase injury risk. Consider a consistent stretching program.\n\nDisclaimer: This is a fitness estimation tool. Consult a physical therapist or doctor for persistent pain or mobility issues.'
]],
});
// Footer
const pageH = doc.internal.pageSize.getHeight();
doc.setLineWidth(0.5);
doc.setDrawColor(31, 41, 55);
doc.line(15, pageH - 15, pageW - 15, pageH - 15);
doc.setFontSize(8);
doc.setTextColor(128, 128, 128);
doc.text('Confidential Fitness Report', pageW / 2, pageH - 10, { align: 'center' });
// Save Document
doc.save('Shoulder_Flexibility_Report.pdf');
}
// Initialize first tab
updateTabs();
});