backend: prescription start/end dates + dispense ledger

Add optional startDate/endDate columns to prescriptions (schema,
validation, types, service) — when set, endDate drives expiry.

Add a new append-only `dispenses` resource (schema, types, validation,
service, route at /api/dispenses) recording who received which medication,
gated on the existing inventory RBAC statement. Migration 0020.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Khalid Abdi
2026-06-16 20:44:47 +03:00
parent 15fc7fdf26
commit f0fe501d62
15 changed files with 3749 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@ export type ActivityEntityType =
| "prescription"
| "invoice"
| "inventory"
| "dispense"
| "task";
export type ActivityEntry = {
+19
View File
@@ -0,0 +1,19 @@
// The canonical Dispense shape returned by the API. Mirrors the frontend
// `lib/dispenses.ts` Dispense type. Scoped to the active clinic; patient and
// dispenser fields are denormalized for display.
export type Dispense = {
id: string;
fileNumber: string;
name: string;
initials: string;
medication: string;
dose: string;
quantity: number;
unit: string;
prescriptionId: string | null;
dispensedBy: string | null;
dispensedByName: string;
dispensedAt: string; // ISO timestamp
notes: string | null;
createdAt: string;
};
+2
View File
@@ -13,6 +13,8 @@ export type Prescription = {
frequency: string;
prescriber: string;
prescribedAt: string; // YYYY-MM-DD
startDate: string | null; // YYYY-MM-DD, optional course start
endDate: string | null; // YYYY-MM-DD, optional course end (drives expiry)
status: PrescriptionStatus;
duration: string | null;
notes: string | null;