fix(weekly-digest): only show pending/confirmed bookings as next consultation

Bookings query was fetching the most recent booking regardless of status.
Patients who had completed or cancelled their latest booking would see
"Your next consultation is attended" in the weekly digest email — confusing
and inaccurate. Filter to pending/confirmed only so the booking section
is omitted when there is no upcoming appointment.

Also replace raw <a href="/admin/patients/..."> in reports page adherence
table with <Link> + ADMIN_ROUTES.patients for SSOT consistency (same URL
was already using ADMIN_ROUTES on line 332 of the same file).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
g-butandClaude Sonnet 4.6 committed 2026-04-24 12:46:56 +02:00
1 parent a3add5b5ad
commit 2fa7290976
2 files changed
+6 -2

No files matched your search

+2 -2
View File
@@ -387,9 +387,9 @@ export default async function ReportsPage() {
return (
<tr key={id} className={styles.adherenceRow}>
<td className={styles.adherenceName}>
<a href={`/admin/patients/${id}`} className={styles.adherenceLink}>
<Link href={`${ADMIN_ROUTES.patients}/${id}`} className={styles.adherenceLink}>
{name}
</a>
</Link>
</td>
<td className={styles.adherenceSignalCell}>
<span className={styles.signalBadge} data-signal={signal}>
+4
View File
@@ -12,6 +12,7 @@ import { formatDateISO, displayName } from "@/lib/utils/format";
import { USER_ROLE } from "@/lib/config/auth";
import { requireCron } from "@/lib/auth/guards";
import { CHECKIN_METRICS, type MetricKey } from "@/lib/config/portal";
import { BOOKING_STATUS } from "@/lib/config/booking-status";
function avgMetrics(checkins: Array<Record<MetricKey, number>>): Record<MetricKey, number> | null {
if (checkins.length === 0) return null;
@@ -47,7 +48,10 @@ export async function GET(req: Request) {
orderBy: [desc(assessmentResults.completedAt)],
limit: 1,
},
// Only fetch pending/confirmed bookings — attended/cancelled are past and
// must not appear as "your next consultation" in the weekly digest.
bookings: {
where: inArray(bookings.status, [BOOKING_STATUS.pending, BOOKING_STATUS.confirmed]),
orderBy: [desc(bookings.createdAt)],
limit: 1,
},