`;
div.querySelector('.delete-btn').onclick = () => { deleteItem('goals', item.id); renderGoals(); };
return div;
});
}
// --- Plan Compilation & PDF ---
function compilePlan() {
const container = document.getElementById('plan-summary');
container.innerHTML = `
`;
// This is a simplified render for the screen; PDF will have tables
renderList('medications', 'plan-meds', item => { const p = document.createElement('p'); p.textContent = `${item.name} (${item.dosage}) - ${item.frequency}`; return p; });
renderList('symptoms', 'plan-symptoms', item => { const p = document.createElement('p'); p.textContent = `${new Date(item.date).toLocaleDateString()}: ${item.description} (${item.severity}/10)`; return p; });
renderList('appointments', 'plan-appts', item => { const p = document.createElement('p'); p.textContent = `${new Date(item.date).toLocaleDateString()}: Dr. ${item.doctor}`; return p; });
renderList('goals', 'plan-goals', item => { const p = document.createElement('p'); p.textContent = item.description; return p; });
}
async function generatePDF() {
const { jsPDF } = window.jspdf;
const downloadBtn = document.getElementById('download-pdf-btn');
const originalButtonText = downloadBtn.textContent;
downloadBtn.textContent = 'Generating...';
downloadBtn.disabled = true;
const pdfWrapper = document.createElement('div');
pdfWrapper.style.position = 'absolute';
pdfWrapper.style.left = '-9999px';
pdfWrapper.style.top = '0';
pdfWrapper.style.width = '800px';
pdfWrapper.style.backgroundColor = 'white';
pdfWrapper.className = 'p-8';
const tableHeader = '';
const tableFooter = '';
const medsTable = `${tableHeader}${tableHeader}${tableHeader}${tableHeader}
Medication Schedule
Recent Symptoms
Upcoming Appointments
Health Goals
Medications
| Name | Dosage | Frequency | ${state.medications.map(i => `
|---|---|---|
| ${i.name} | ${i.dosage} | ${i.frequency} |
| Date | Symptom | Severity | ${state.symptoms.map(i => `
|---|---|---|
| ${new Date(i.date).toLocaleDateString()} | ${i.description} | ${i.severity}/10 |
| Date | Doctor | Notes | ${state.appointments.map(i => `
|---|---|---|
| ${new Date(i.date).toLocaleDateString()} at ${i.time} | ${i.doctor} | ${i.notes} |
| Goal | Target Date | ${state.goals.map(i => `
|---|---|
| ${i.description} | ${new Date(i.targetDate).toLocaleDateString()} |
