Skip to content

fix(api): record prescription fills outside facility ledger - #486

Merged
aupyay merged 1 commit into
devfrom
fix/326-chart-dispense-record
Sep 18, 2026
Merged

aupyay merged 1 commit into
devfrom
fix/326-chart-dispense-record

Conversation

@aupyay

@aupyay aupyay commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

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 PrescriptionFill record 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

  • Repository pre-push lint passed.
  • Repository pre-push type-check passed.
  • API and database suites, format checks, Prisma validation, secret checks, PHI guard, migration safety, and API build were run before commit.

@aupyay
aupyay requested a review from ankit-yc as a code owner September 12, 2026 14:32
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@ankit-yc ankit-yc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sonarqubecloud

Copy link
Copy Markdown

@aupyay
aupyay merged commit ff916fd into dev Sep 18, 2026
338 of 348 checks passed
@aupyay
aupyay deleted the fix/326-chart-dispense-record branch September 18, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants