mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 13:52:20 +00:00
fix(medications): keep an auto-taken rolling cadence moving
A rolling cadence yields only lastIntakeAt + N, so a slot the auto-take pass never records (before the switch-on floor, past the catch-up window, inside a pause, skipped or removed by the person) held it still for good. Step the cadence forward by N past every such slot, keeping its rhythm, and feed the stepped anchor to the card, dashboard and schedule-tool next due so they show the slot the pass will record.
This commit is contained in:
1 parent
0375c2adc6
commit
a4cccc11ba
9 files changed
+718
-123
No files matched your search
@@ -32,6 +32,7 @@ import {
|
||||
toRevisionPayloadEntry,
|
||||
} from "@/lib/medications/scheduling/schedule-eras";
|
||||
import type { Prisma } from "@/generated/prisma/client";
|
||||
import { loadAutoTakeRollingAnchors } from "@/lib/medications/auto-take";
|
||||
import {
|
||||
computeDisplayDue,
|
||||
OVERDUE_LOOKBACK_MS,
|
||||
@@ -179,6 +180,16 @@ export const GET = apiHandler(
|
||||
// v1.39.1 (#1033) — intake tracking off: nothing is due from the
|
||||
// stored rows, and no runway derives from them.
|
||||
const liveSchedules = dueSchedules(medication);
|
||||
const userTz = user.timezone || DEFAULT_TIMEZONE;
|
||||
// v1.42.2 — under auto-take a rolling cadence stands where the job will
|
||||
// record next (see `auto-take.ts`).
|
||||
const engineLastIntakeAt = await loadAutoTakeRollingAnchors(prisma, {
|
||||
userId: user.id,
|
||||
medicationIds: medication.autoMarkTaken ? [id] : [],
|
||||
now,
|
||||
userTz,
|
||||
lastIntakeAt: () => lastIntake?.takenAt ?? null,
|
||||
});
|
||||
const display = computeDisplayDue({
|
||||
medication: {
|
||||
id: medication.id,
|
||||
@@ -189,8 +200,8 @@ export const GET = apiHandler(
|
||||
},
|
||||
schedules: liveSchedules,
|
||||
now,
|
||||
userTz: user.timezone || DEFAULT_TIMEZONE,
|
||||
lastIntakeAt: lastIntake?.takenAt ?? null,
|
||||
userTz,
|
||||
lastIntakeAt: engineLastIntakeAt(id),
|
||||
resolvedSlots: resolvedRows.map(toResolvedSlotMark),
|
||||
eraStart: latestRevision?.validUntil ?? null,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user