fix(coach): give no supply span for a GLP-1 medication kept as a record

This commit is contained in:
Marc-André Bombeck committed 2026-09-25 10:03:09 +02:00
1 parent 0e242cfea1
commit ff3ef9147c
2 files changed
+21

No files matched your search

@@ -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 () => {
+4
View File
@@ -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 }