mirror of
https://github.com/temetro/temetro.git
synced 2026-08-27 10:56:58 +00:00
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:
@@ -0,0 +1,23 @@
|
||||
CREATE TABLE "dispenses" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"patient_file_number" text DEFAULT '' NOT NULL,
|
||||
"patient_name" text NOT NULL,
|
||||
"patient_initials" text DEFAULT '' NOT NULL,
|
||||
"medication" text NOT NULL,
|
||||
"dose" text DEFAULT '' NOT NULL,
|
||||
"quantity" integer DEFAULT 0 NOT NULL,
|
||||
"unit" text DEFAULT '' NOT NULL,
|
||||
"prescription_id" uuid,
|
||||
"dispensed_by" text,
|
||||
"dispensed_by_name" text DEFAULT '' NOT NULL,
|
||||
"dispensed_at" timestamp DEFAULT now() NOT NULL,
|
||||
"notes" text,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "prescriptions" ADD COLUMN "start_date" date;--> statement-breakpoint
|
||||
ALTER TABLE "prescriptions" ADD COLUMN "end_date" date;--> statement-breakpoint
|
||||
ALTER TABLE "dispenses" ADD CONSTRAINT "dispenses_organization_id_organization_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "dispenses" ADD CONSTRAINT "dispenses_dispensed_by_user_id_fk" FOREIGN KEY ("dispensed_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "dispenses_org_idx" ON "dispenses" USING btree ("organization_id");
|
||||
File diff suppressed because it is too large
Load Diff
@@ -141,6 +141,13 @@
|
||||
"when": 1781538797034,
|
||||
"tag": "0019_black_mole_man",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 20,
|
||||
"version": "7",
|
||||
"when": 1781629630102,
|
||||
"tag": "0020_freezing_tomas",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user