`).join('');
};
const analyzeSymptoms = () => {
const selectedSymptoms = Array.from(document.querySelectorAll('#symptoms-group input:checked')).map(el => el.value);
if (selectedSymptoms.length === 0) {
alert('Please select at least one symptom to analyze.');
return;
}
const deficiencyCounts = {};
selectedSymptoms.forEach(symptom => {
if (deficiencyMap[symptom]) {
deficiencyMap[symptom].forEach(deficiency => {
deficiencyCounts[deficiency] = (deficiencyCounts[deficiency] || 0) + 1;
});
}
});
const sortedDeficiencies = Object.entries(deficiencyCounts).sort((a, b) => b[1] - a[1]);
renderResults(selectedSymptoms, sortedDeficiencies);
switchTab('results');
};
const renderResults = (symptoms, deficiencies) => {
const deficienciesHtml = deficiencies.map(([name, count]) => {
const relatedSymptoms = symptoms.filter(s => deficiencyMap[s] && deficiencyMap[s].includes(name)).join(', ');
return `
`;
}).join('');
resultsOutput.innerHTML = `
`;
resultsButtons.classList.remove('hidden');
};
const downloadPDF = () => {
const pdfContent = document.getElementById('pdf-content');
window.html2canvas(pdfContent, { scale: 2, backgroundColor: '#ffffff' }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfMargin = 40;
const contentWidth = pdfWidth - (pdfMargin * 2);
const imgHeight = canvas.height * contentWidth / canvas.width;
pdf.addImage(imgData, 'PNG', pdfMargin, pdfMargin, contentWidth, imgHeight);
pdf.save('Nutritional_Symptom_Report.pdf');
});
};
initialize();
});
function switchTab(tabId) {
const tabs = ['symptoms', 'results', 'info'];
tabs.forEach(id => {
document.getElementById(`${id}-tab`).style.display = (id === tabId) ? 'block' : 'none';
document.getElementById(`tab-${id}-btn`).classList.toggle('active', id === tabId);
});
if (document.getElementById('results-output').innerHTML.trim() !== '') {
document.getElementById('tab-results-btn').disabled = false;
}
}
${name}
Suggested by ${count} of your selected symptoms.
(${relatedSymptoms})
Food Sources: ${deficiencyInfo[name].sources}
Your Symptom Analysis
Disclaimer: This tool is for informational purposes only and does not constitute medical advice. Please consult with a healthcare professional for any health concerns or before making changes to your diet or lifestyle.
Potential Deficiencies to Discuss with a Professional
${deficienciesHtml}
