diff --git a/src/lib/insights/blood-pressure-status.ts b/src/lib/insights/blood-pressure-status.ts index 1eceae9ab..ad0c8bde0 100644 --- a/src/lib/insights/blood-pressure-status.ts +++ b/src/lib/insights/blood-pressure-status.ts @@ -276,6 +276,12 @@ export async function generateBloodPressureStatusForUser( userId, // v1.7.0 sync — exclude tombstoned rows. deletedAt: null, + // v1.12.7 — bound to the ~365-day window the continuity series + // and the 7/30-day compliance gate consume; this read was + // otherwise unbounded over all intake history. + scheduledFor: { + gte: new Date(now.getTime() - 365 * 24 * 60 * 60 * 1000), + }, medicationId: { in: bpMedications.map((medication) => medication.id), }, diff --git a/src/lib/insights/general-status.ts b/src/lib/insights/general-status.ts index 6f3a9b07f..703b776a2 100644 --- a/src/lib/insights/general-status.ts +++ b/src/lib/insights/general-status.ts @@ -178,9 +178,19 @@ export async function generateGeneralStatusForUser( }), ); + // v1.12.7 — bound the intake read to the ~365-day window the adherence + // series renders. Without a `scheduledFor` floor this scanned all intake + // history; the adherence fold below only consumes the trailing year. + const intakeWindowStart = new Date( + now.getTime() - 365 * 24 * 60 * 60 * 1000, + ); const intakeEvents = await prisma.medicationIntakeEvent.findMany({ // v1.7.0 sync — exclude tombstoned rows. - where: { userId, deletedAt: null }, + where: { + userId, + deletedAt: null, + scheduledFor: { gte: intakeWindowStart }, + }, orderBy: { scheduledFor: "asc" }, select: { scheduledFor: true,