mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 13:01:00 +00:00
fix(insights): leave record-only medications out of the adherence storyline
This commit is contained in:
1 parent
0095fda216
commit
2311f9b47d
2 files changed
+10
-2
No files matched your search
@@ -34,6 +34,7 @@ import {
|
||||
MED_TARGET_MAP,
|
||||
type MedTargetClass,
|
||||
} from "@/lib/medications/med-target-map";
|
||||
import { TRACKED_INTAKE_WHERE } from "@/lib/medications/intake-tracking";
|
||||
|
||||
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
||||
const MAD_TO_SIGMA = 1.4826;
|
||||
@@ -164,6 +165,9 @@ export async function buildAdherenceStoryline(
|
||||
where: {
|
||||
userId,
|
||||
active: true,
|
||||
// v1.39.1 (#1033) — the adherence figure below counts tracked
|
||||
// medications only, so a record-only one cannot be its subject.
|
||||
...TRACKED_INTAKE_WHERE,
|
||||
OR: [{ endsOn: null }, { endsOn: { gte: now } }],
|
||||
},
|
||||
select: { name: true, treatmentClass: true },
|
||||
|
||||
@@ -196,7 +196,9 @@ describe("intake tracking off — nothing is due", () => {
|
||||
|
||||
const block = await buildMedsTodayBlock(prisma, userId, TZ, new Date());
|
||||
expect(block.activeCount).toBe(1);
|
||||
expect(block.dueCandidates.map((c) => c.medicationId)).toEqual([tracked]);
|
||||
expect((block.dueCandidates ?? []).map((c) => c.medicationId)).toEqual([
|
||||
tracked,
|
||||
]);
|
||||
|
||||
const intakeRoute = await import("@/app/api/medications/intake/route");
|
||||
const today = await call<Array<{ medicationId: string }>>(
|
||||
@@ -350,7 +352,9 @@ describe("switching intake tracking back on", () => {
|
||||
// Today's 08:00 lies before the switch: not projected, not reminded.
|
||||
const block = await buildMedsTodayBlock(prisma, userId, TZ, new Date());
|
||||
expect(block.scheduledToday).toBe(0);
|
||||
expect(block.dueCandidates.every((c) => c.overdue === false)).toBe(true);
|
||||
expect((block.dueCandidates ?? []).every((c) => c.overdue === false)).toBe(
|
||||
true,
|
||||
);
|
||||
await handleReminderCheck([]);
|
||||
expect(dispatchedFor(medicationId)).toBe(0);
|
||||
|
||||
|
||||
Reference in new issue
Block a user