diff --git a/src/lib/jobs/intake-auto-take.ts b/src/lib/jobs/intake-auto-take.ts index e8d93e765..6915edc2c 100644 --- a/src/lib/jobs/intake-auto-take.ts +++ b/src/lib/jobs/intake-auto-take.ts @@ -55,6 +55,7 @@ import type { PrismaClient } from "@/generated/prisma/client"; import { invalidateUserMedications } from "@/lib/cache/invalidate"; +import { TRACKED_INTAKE_WHERE } from "@/lib/medications/intake-tracking"; import { autoTakeEligibleWhere, autoTakeFloor, @@ -265,7 +266,7 @@ export async function runIntakeAutoTakePass( const medications = (await prisma.medication.findMany({ // Opted in, active, not paused, not as-needed, intake tracked (a // record-only medication expects no dose, so none is recorded). - where: autoTakeEligibleWhere(now), + where: { ...autoTakeEligibleWhere(now), ...TRACKED_INTAKE_WHERE }, select: { id: true, userId: true, diff --git a/src/lib/medications/auto-take.ts b/src/lib/medications/auto-take.ts index e02e87a3e..271f0b3b8 100644 --- a/src/lib/medications/auto-take.ts +++ b/src/lib/medications/auto-take.ts @@ -245,7 +245,11 @@ export function autoTakeRowWindow(floor: Date, now: Date) { }; } -/** The medications the auto-take job works on (see `intake-auto-take.ts`). */ +/** + * The medications the auto-take job works on (see `intake-auto-take.ts`), + * apart from the intake-tracking switch, which each caller spreads itself + * (`TRACKED_INTAKE_WHERE`) so the structural guard sees every reader ask. + */ export function autoTakeEligibleWhere(now: Date) { return { autoMarkTaken: true, @@ -253,7 +257,6 @@ export function autoTakeEligibleWhere(now: Date) { active: true, pausedAt: null, asNeeded: false, - ...TRACKED_INTAKE_WHERE, }; } @@ -353,6 +356,7 @@ export async function loadAutoTakeRollingAnchors( userId: input.userId, id: { in: [...input.medicationIds] }, ...autoTakeEligibleWhere(now), + ...TRACKED_INTAKE_WHERE, schedules: { some: { rollingIntervalDays: { not: null } } }, }, select: {