`;
reportContentEl.innerHTML = reportHtml;
reportPlaceholderEl.classList.add('hidden');
reportContentEl.classList.remove('hidden');
}
// --- CONFIGURATION TAB ---
function populateConfig() {
const container = document.getElementById('config-inputs');
container.innerHTML = Object.entries(state.config.sectionTitles).map(([key, value]) => `
`).join('');
container.addEventListener('change', handleConfigChange);
}
function handleConfigChange(e) {
if (e.target.dataset.configKey) {
const key = e.target.dataset.configKey;
state.config.sectionTitles[key] = e.target.value;
}
}
// --- PDF GENERATION ---
window.downloadPDF = async () => {
const { jsPDF } = window.jspdf;
if (!state.reportData) return;
const { selections, recommendations } = state.reportData;
const reportContainer = document.createElement('div');
reportContainer.id = 'pdf-report';
reportContainer.className = 'w-[800px] bg-white p-10 text-gray-800';
reportContainer.style.position = 'absolute';
reportContainer.style.left = '-9999px';
reportContainer.style.fontFamily = 'Inter, sans-serif';
const selectionsHtml = state.markers.map(marker => {
const selectedOption = marker.o.find(opt => opt.v === selections[marker.id]);
return ``;
} else {
if (diet.length > 0) {
recommendationsHtml += ``;
}
if (lifestyle.length > 0) {
recommendationsHtml += ``;
}
if (screening.length > 0) {
recommendationsHtml += ``;
}
}
reportContainer.innerHTML = `
`;
document.body.appendChild(reportContainer);
try {
const canvas = await html2canvas(reportContainer, { scale: 2, useCORS: true, logging: false });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' });
const pageHeight = pdf.internal.pageSize.getHeight();
const pageWidth = pdf.internal.pageSize.getWidth();
const margin = 15;
const contentWidth = pageWidth - (margin * 2);
const imgProps = pdf.getImageProperties(imgData);
const contentHeight = (imgProps.height * contentWidth) / imgProps.width;
let heightLeft = contentHeight;
let position = 0;
pdf.addImage(imgData, 'PNG', margin, margin, contentWidth, contentHeight);
heightLeft -= (pageHeight - (margin * 2));
while (heightLeft > 0) {
position -= (pageHeight - (margin * 2));
pdf.addPage();
pdf.addImage(imgData, 'PNG', margin, position + margin, contentWidth, contentHeight);
heightLeft -= (pageHeight - (margin * 2));
}
pdf.save('Genetic-Risk-Factor-Report.pdf');
} catch (error) {
console.error("Error generating PDF:", error);
alert("Sorry, there was an error creating the PDF report.");
} finally {
document.body.removeChild(reportContainer);
}
};
// --- INITIALIZATION ---
switchTab(1);
populateQuestions();
populateConfig();
});
${marker.q}: ${selectedOption.t}
`;
}).join('');
let recommendationsHtml = '';
const { diet, lifestyle, screening } = recommendations;
if (diet.length === 0 && lifestyle.length === 0 && screening.length === 0) {
recommendationsHtml += `Based on your selections, you have no variants associated with the specific health risks in this tool. Continue to follow general health guidelines and consult your doctor for personalized advice.
${state.config.sectionTitles.diet}
- ${diet.map(item => `
- ${item.marker}: ${item.text} `).join('')}
${state.config.sectionTitles.lifestyle}
- ${lifestyle.map(item => `
- ${item.marker}: ${item.text} `).join('')}
${state.config.sectionTitles.screening}
- ${screening.map(item => `
- ${item.marker}: ${item.text} `).join('')}
Genetic Risk Factor Report
Generated: ${new Date().toLocaleString('en-US', { dateStyle: 'full', timeStyle: 'short' })}
Your Genetic Profile Summary
${selectionsHtml}
Your Personalized Recommendations
${recommendationsHtml}Important Disclaimer: This tool is for educational purposes only and uses simulated genetic data. It is NOT a substitute for professional medical advice or real genetic testing. Always consult with a healthcare provider or genetic counselor to understand your health risks.
