fix(api): record prescription fills outside facility ledger - #486
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
ankit-yc
left a comment
There was a problem hiding this comment.
Reviewed as a related follow-on to #329/#330 in this same narrowing/compartment area.
PrescriptionFill is chart-scoped (compartment on patientId, deliberately no facilityColumn), append-only via RLS REVOKE UPDATE/DELETE, one row per StockPosting via the unique index, and the backfill only picks up postings that already have a proving StockMovement line - matches the migration's own stated intent. childRows' invariant check (DISPENSE + patientId required) is unreachable from the HTTP schema (dispenseSchema already requires patientId and only dispenseSchema carries prescriptionId), so the plain Error there is correct, not an ApiError gap.
CI's full test matrix (test api, Prisma migrations, static) is green on this commit - only sonar / Sonar scan (api) is red, and that's an org-wide SonarCloud token failure hitting every open PR right now (filed as #489), not this diff.
|



Problem
Prescription fills existed only as facility-scoped stock postings, so two clinicians reading the same chart could derive different refill counts from their facility grants.
Change
Add an append-only, tenant- and chart-scoped
PrescriptionFillrecord created atomically with a prescription-linked dispense. Backfill valid historical dispenses whose prescription and patient agree and whose stock movement proves a completed fill.Fixes #326
Validation