// dashboard.jsx — Today's dashboard wired to the live store. const { useState: useStateD, useMemo: useMemoD } = React; function StatCard({ label, value, sub, accent }) { return (
{label}
{value}
{sub &&
{sub}
}
); } function statusFor(a) { switch (a.status) { case "in-room": return { label: "In room", cls: "warn" }; case "checked-in": return { label: "Checked in", cls: "info" }; case "confirmed": return { label: "Confirmed", cls: "success" }; case "done": return { label: "Done", cls: "" }; case "cancelled": return { label: "Cancelled", cls: "" }; case "no-show": return { label: "No-show", cls: "" }; default: return { label: "Scheduled", cls: "" }; } } function ScheduleStrip({ appointments, onOpenEncounter, providerById }) { const t = window.MSStore.useT(); if (!appointments.length) { return (
{t("dash.yourDay")}
{t("dash.noToday")}
); } const counts = appointments.reduce((acc, a) => { if (a.status === "done") acc.done++; else if (a.status === "in-room") acc.inRoom++; return acc; }, { done: 0, inRoom: 0 }); return (
{t("dash.yourDay")}
{t("sched.sub", { n: appointments.length })}
{appointments.map((a, i) => { const isCurrent = a.status === "in-room"; const status = statusFor(a); const provider = a.providerId ? providerById[a.providerId] : null; return (
{a.time || "—"}
{a.duration}m
{i < appointments.length - 1 &&
}
); })}
); } function TasksCard() { const t = window.MSStore.useT(); const [items, setItems] = useStateD([]); const [done, setDone] = useStateD({}); const [draft, setDraft] = useStateD(""); function addTask(e) { if (e && e.preventDefault) e.preventDefault(); const text = draft.trim(); if (!text) return; const item = { id: "task-" + Date.now(), text, kind: "doc" }; setItems(list => [item, ...list]); setDraft(""); } return (
{t("dash.tasks")}
{items.filter(task => !done[task.id]).length} open
setDraft(e.target.value)} placeholder="Add a task…" />
{items.length === 0 && (
No tasks yet.
)} {items.map(t => { const isDone = !!done[t.id]; const iconMap = { labs: Icon.Lab, rx: Icon.Pill, msg: Icon.Mail, doc: Icon.Document }; const TI = iconMap[t.kind] || Icon.Document; return ( ); })}
); } function InboxCard({ onNav }) { const store = window.MSStore.useStore(); const notifications = store.notifications || []; return (
Notifications
{notifications.length === 0 &&
No notifications
} {notifications.slice(0, 5).map(m => ( ))}
); } function Dashboard({ onNav, onOpenEncounter }) { const store = window.MSStore.useStore(); const t = window.MSStore.useT(); const profile = store.profile; const todayAppts = useMemoD(() => { const today = new Date(); today.setHours(0, 0, 0, 0); const tomorrow = new Date(today.getTime() + 86400000); return (store.appointments || []).filter(a => { const t = new Date(a.scheduledAt); return !isNaN(t) && t >= today && t < tomorrow; }); }, [store.appointments]); const providerById = useMemoD(() => { const map = {}; for (const p of (store.providers || [])) map[p.id] = p; return map; }, [store.providers]); const counts = useMemoD(() => { const c = { done: 0, inRoom: 0, remaining: 0 }; const now = new Date(); for (const a of todayAppts) { if (a.status === "done") c.done++; else if (a.status === "in-room") c.inRoom++; const t = new Date(a.scheduledAt); if (!isNaN(t) && t > now && a.status !== "done") c.remaining++; } return c; }, [todayAppts]); const lastName = profile && profile.name ? profile.name.replace(/^Dr\.?\s+/i, "").split(" ").pop() : null; const greetingPart = getGreetingPart(); const greetingKey = greetingPart === "morning" ? "dash.greeting.morning" : greetingPart === "afternoon" ? "dash.greeting.afternoon" : "dash.greeting.evening"; const lang = (window.MSi18n && window.MSi18n.getLang()) || "en"; const greeting = lastName ? `${t(greetingKey)}, Dr. ${lastName}` : t(greetingKey); const today = new Date(); const dayLabel = today.toLocaleDateString(lang === "es" ? "es-ES" : "en-US", { weekday: "long", month: "long", day: "numeric" }); return (
{dayLabel}

{greeting}

{todayAppts.length === 0 ? t("dash.subNoVisits") : t("dash.subVisits", { n: counts.remaining })}
); } function getGreetingPart() { const h = new Date().getHours(); if (h < 12) return "morning"; if (h < 17) return "afternoon"; return "evening"; } window.Dashboard = Dashboard;