fix: unify stock semantics across planner and scheduler (#245)

* fix: unify stock semantics across planner and scheduler

* fix: stabilize dashboard hmr and align stock helper tests
This commit is contained in:
Daniel Volz
2026-02-21 15:24:53 +01:00
committed by GitHub
parent 02af93ec55
commit 612aa007aa
14 changed files with 846 additions and 285 deletions
+3 -6
View File
@@ -3,6 +3,8 @@
// =============================================================================
import type { BlisterStock, Medication } from "../types";
import { getMedTotal } from "../types";
import { splitCurrentBlisterStock } from "./stock";
/**
* Map timezone to region code (ISO 3166-1 alpha-2).
@@ -302,12 +304,7 @@ export function getExpiryClass(expiryDate: string | null | undefined, thresholdD
* Calculate blister stock breakdown for a medication
*/
export function getBlisterStock(med: Medication): BlisterStock {
const total =
med.packCount * med.blistersPerPack * med.pillsPerBlister + med.looseTablets + (med.stockAdjustment ?? 0);
const bSize = med.pillsPerBlister;
const fullBlisters = Math.floor(total / bSize);
const openBlisterPills = total % bSize;
return { fullBlisters, openBlisterPills, loosePills: openBlisterPills };
return splitCurrentBlisterStock(getMedTotal(med), med.pillsPerBlister, med.looseTablets);
}
/**