From ff3ef9147c51086a62fa2939c77c4112f10d15bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 25 Sep 2026 10:03:09 +0200 Subject: [PATCH] fix(coach): give no supply span for a GLP-1 medication kept as a record --- .../ai/coach/__tests__/glp1-snapshot.test.ts | 17 +++++++++++++++++ src/lib/ai/coach/glp1-snapshot.ts | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/src/lib/ai/coach/__tests__/glp1-snapshot.test.ts b/src/lib/ai/coach/__tests__/glp1-snapshot.test.ts index 1d93cc3c8..51a1485b5 100644 --- a/src/lib/ai/coach/__tests__/glp1-snapshot.test.ts +++ b/src/lib/ai/coach/__tests__/glp1-snapshot.test.ts @@ -158,6 +158,23 @@ describe("buildGlp1SnapshotBlock", () => { }); }); + it("keeps the pen count but no supply span when intake is not tracked (#1033)", async () => { + prismaMock.medication.findMany.mockResolvedValue([ + fakeMedication({ + trackIntake: false, + unitsPerDose: 1, + inventoryItems: [{ state: "ACTIVE", unitsTotal: 4, unitsRemaining: 4 }], + }), + ]); + const out = await buildGlp1SnapshotBlock("user-1"); + expect(out?.medications[0].penInventory).toEqual({ + pensRemaining: 1, + dosesRemaining: 4, + weeksOfSupplyApprox: null, + }); + expect(out?.medications[0].nextInjection).toBeNull(); + }); + // W1 — ledger-only accounts (the pre-item delta writer) keep their // pen count in the Coach prompt instead of a silent omission. it("falls back to the legacy ledger when the medication has zero items", async () => { diff --git a/src/lib/ai/coach/glp1-snapshot.ts b/src/lib/ai/coach/glp1-snapshot.ts index a36c48d36..c452eaa8e 100644 --- a/src/lib/ai/coach/glp1-snapshot.ts +++ b/src/lib/ai/coach/glp1-snapshot.ts @@ -385,6 +385,10 @@ export async function buildGlp1SnapshotBlock( weeksOfSupplyApprox = Math.round(dosesRemaining / dosesPerWeek); } + // v1.39.1 (#1033) — with intake tracking off no dose consumes the + // stock, so a supply span derived from the cadence would be invented. + if (isRecordOnly(med)) weeksOfSupplyApprox = null; + const penInventory: PenInventory | null = pensRemaining !== null ? { pensRemaining, dosesRemaining, weeksOfSupplyApprox }