const STAGES = ["No DR", "Mild", "Moderate", "Severe", "Proliferative"]; Promise.all([ fetch('/stats').then(r => r.json()), fetch('/history').then(r => r.json()) ]).then(([s, h]) => { document.getElementById('mTotal').textContent = s.total; document.getElementById('mRefer').textContent = s.referable; document.getElementById('mNormal').textContent = s.normal; document.getElementById('mRate').textContent = (s.total ? Math.round(s.referable / s.total * 100) : 0) + '%'; const max = Math.max(1, ...STAGES.map(c => s.dist[c] || 0)); document.getElementById('dist').innerHTML = STAGES.map((c, i) => { const v = s.dist[c] || 0; return `
${c}${v}
`; }).join(''); const hist = document.getElementById('hist'); if (!h.length) { hist.innerHTML = '
ยังไม่มีประวัติการตรวจ
'; return; } hist.innerHTML = h.slice(0, 30).map(x => `
${x.grade_name} ${(x.time || '').replace('T', ' ')} ${x.risk_percent}%
`).join(''); }).catch(() => { document.getElementById('hist').innerHTML = '
โหลดข้อมูลไม่สำเร็จ
'; });