fix(daily-loop): thread the overdue medication id into the digest's Log-dose link

The Today digest's dose-window rail item linked to the bare /medications
list even though the overdue medication's id was already resolved
server-side alongside its name — a tap landed the user on a generic list
they then had to scan themselves.

buildMedsTodayBlock now carries nextDueMedicationId; the digest's
"Log dose" action links to /medications?highlight=<id> when the id is
known, falling back to the bare list for an older cached block. The
medications page reads the highlight param, scrolls the matching card
into view, and rings it briefly (mirrors the vault's duplicate-upload
highlight) in both the card grid and the table view. Regenerates
docs/api/openapi.yaml for the new medsToday field.
This commit is contained in:
Marc-André Bombeck committed 2026-07-18 00:37:24 +02:00
1 parent 844b24c7ba
commit 2b3ff0e58f
15 files changed
+213 -8

No files matched your search

+20
View File
@@ -35,6 +35,7 @@ function meds(over: Partial<MedsTodayBlock> = {}): MedsTodayBlock {
nextDueAt: null,
nextDueOverdue: false,
nextDueMedicationName: null,
nextDueMedicationId: null,
...over,
};
}
@@ -201,6 +202,7 @@ describe("buildDailyDigest — worth-a-look rail item builders", () => {
medsToday: meds({
nextDueOverdue: true,
nextDueMedicationName: "Ramipril",
nextDueMedicationId: "med-ramipril",
}),
}),
t,
@@ -213,6 +215,24 @@ describe("buildDailyDigest — worth-a-look rail item builders", () => {
expect(dose?.body).toBe("Ramipril is due today.");
expect(dose?.actions).toHaveLength(1);
expect(dose?.actions[0].intent).toBe("dose.log");
// Deep-links straight to the overdue medication's card, not the bare
// list — the tap should land on the right med.
expect(dose?.actions[0].href).toBe("/medications?highlight=med-ramipril");
});
it("falls back to the bare medications list when no id is known (older cached block)", () => {
const d = buildDailyDigest(
input({
medsToday: meds({
nextDueOverdue: true,
nextDueMedicationName: "Ramipril",
nextDueMedicationId: null,
}),
}),
t,
);
const dose = d.worthALook.find((i) => i.kind === "dose_window");
expect(dose?.actions[0].href).toBe("/medications");
});
it("does NOT emit a dose-window item when the medications module is off", () => {
+7 -1
View File
@@ -258,6 +258,7 @@ function buildDoseWindowItem(
if (!moduleEnabled(modules, "medications")) return null;
if (!meds.nextDueOverdue) return null;
const name = meds.nextDueMedicationName;
const id = meds.nextDueMedicationId;
return {
kind: "dose_window",
title: t("daily.item.doseWindow.title"),
@@ -269,7 +270,12 @@ function buildDoseWindowItem(
{
labelKey: "daily.action.logDose",
intent: "dose.log",
href: "/medications",
// Deep-link straight to the overdue medication's card so the tap
// lands on the right one instead of a generic list the user then
// has to scan (the id is known server-side whenever the name is).
// The bare list stays the honest fallback for an older cached
// block that predates the id field.
href: id ? `/medications?highlight=${id}` : "/medications",
},
],
moduleKey: "medications",
@@ -207,6 +207,7 @@ describe("buildMedsTodayBlock — tally", () => {
nextDueAt: null,
nextDueOverdue: false,
nextDueMedicationName: null,
nextDueMedicationId: null,
});
});
@@ -259,6 +260,7 @@ describe("buildMedsTodayBlock — next due (real engine)", () => {
expect(block.nextDueAt).toBe("2026-06-10T16:00:00.000Z");
expect(block.nextDueOverdue).toBe(false);
expect(block.nextDueMedicationName).toBe("Abendmittel");
expect(block.nextDueMedicationId).toBe("med-evening");
});
it("surfaces an open overdue slot (anchor passed, band still open)", async () => {
@@ -282,6 +284,7 @@ describe("buildMedsTodayBlock — next due (real engine)", () => {
expect(block.nextDueAt).toBe("2026-06-10T09:00:00.000Z");
expect(block.nextDueOverdue).toBe(true);
expect(block.nextDueMedicationName).toBe("Mittagsmittel");
expect(block.nextDueMedicationId).toBe("med-1");
});
it("advances past a RESOLVED slot to the next future anchor", async () => {
@@ -329,5 +332,6 @@ describe("buildMedsTodayBlock — next due (real engine)", () => {
expect(block.nextDueAt).toBeNull();
expect(block.nextDueOverdue).toBe(false);
expect(block.nextDueMedicationName).toBeNull();
expect(block.nextDueMedicationId).toBeNull();
});
});
@@ -53,6 +53,7 @@ function medsToday(partial: Partial<MedsTodayBlock> = {}): MedsTodayBlock {
nextDueAt: null,
nextDueOverdue: false,
nextDueMedicationName: null,
nextDueMedicationId: null,
...partial,
};
}
+10
View File
@@ -68,6 +68,13 @@ export interface MedsTodayBlock {
nextDueOverdue: boolean;
/** Name of the medication carrying `nextDueAt`; null when none due. */
nextDueMedicationName: string | null;
/**
* Id of the medication carrying `nextDueAt`; null when none due. Threaded
* through so a consumer (the Today digest's dose-window rail item) can
* deep-link straight to the overdue medication's card instead of the bare
* list.
*/
nextDueMedicationId: string | null;
}
export async function buildMedsTodayBlock(
@@ -182,6 +189,7 @@ export async function buildMedsTodayBlock(
let nextDueAt: Date | null = null;
let nextDueOverdue = false;
let nextDueMedicationName: string | null = null;
let nextDueMedicationId: string | null = null;
for (const m of medications) {
const display = computeDisplayDue({
medication: {
@@ -203,6 +211,7 @@ export async function buildMedsTodayBlock(
nextDueAt = display.at;
nextDueOverdue = display.overdue;
nextDueMedicationName = m.name;
nextDueMedicationId = m.id;
}
}
@@ -214,5 +223,6 @@ export async function buildMedsTodayBlock(
nextDueAt: nextDueAt ? nextDueAt.toISOString() : null,
nextDueOverdue,
nextDueMedicationName,
nextDueMedicationId,
};
}
+2 -1
View File
@@ -896,9 +896,10 @@ export const dashboardSnapshotResponse = z
nextDueAt: z.string().nullable(),
nextDueOverdue: z.boolean(),
nextDueMedicationName: z.string().nullable(),
nextDueMedicationId: z.string().nullable(),
})
.describe(
"Today's medication block: active-medication count, today-window tally (scheduled / taken / skipped), and the earliest next-due slot across active medications. `nextDueOverdue: true` marks an OPEN overdue slot (anchor passed, still inside its catch-up band). Staleness contract: the snapshot is cache-served, so a `nextDueAt` in the past with `nextDueOverdue: false` means the anchor passed after the snapshot was built — render the plain day summary, never an overdue state.",
"Today's medication block: active-medication count, today-window tally (scheduled / taken / skipped), and the earliest next-due slot across active medications. `nextDueOverdue: true` marks an OPEN overdue slot (anchor passed, still inside its catch-up band). `nextDueMedicationId` deep-links a consumer straight to the overdue medication's card. Staleness contract: the snapshot is cache-served, so a `nextDueAt` in the past with `nextDueOverdue: false` means the anchor passed after the snapshot was built — render the plain day summary, never an overdue state.",
),
// Dashboard hero — health score (warm phase, nullable on a
// rollup-coverage miss). Score + band + delta only; the per-pillar