Templates/Health

Pharmacy database schema

Prescriptions from prescribers, fills against stock and patient pickups.

6 tables, 5 relationships

Opens as a new diagram you can change. Free.

Tables

patients

  • iduuid not null
  • full_nametext not null
  • date_of_birthdate not null
  • created_attimestamptz not null

prescribers

  • iduuid not null
  • full_nametext not null
  • registration_numbertext not null
  • created_attimestamptz not null

drugs

  • iduuid not null
  • nametext not null
  • strengthtext not null
  • barcodetext
  • created_attimestamptz not null

drug_stock

  • iduuid not null
  • drug_id> drugsuuid not null
  • on_handinteger not null
  • reorder_levelinteger not null
  • created_attimestamptz not null

prescriptions

  • iduuid not null
  • patient_id> patientsuuid not null
  • prescriber_id> prescribersuuid not null
  • drug_id> drugsuuid not null
  • quantityinteger not null
  • refillsinteger not null
  • created_attimestamptz not null

fills

  • iduuid not null
  • prescription_id> prescriptionsuuid not null
  • quantityinteger not null
  • filled_attimestamptz not null
  • collected_attimestamptz
  • created_attimestamptz not null

As PostgreSQL

The same diagram exports to MySQL, MariaDB, SQLite, SQL Server and Oracle, and to Prisma, Drizzle, SQLAlchemy and Convex models.

CREATE TABLE "drug_stock" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "drug_id" UUID NOT NULL UNIQUE,
  "on_hand" INTEGER DEFAULT 0 NOT NULL,
  "reorder_level" INTEGER DEFAULT 0 NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "drugs" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "strength" TEXT NOT NULL,
  "barcode" TEXT UNIQUE,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "fills" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "prescription_id" UUID NOT NULL,
  "quantity" INTEGER NOT NULL,
  "filled_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  "collected_at" TIMESTAMPTZ,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "patients" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "full_name" TEXT NOT NULL,
  "date_of_birth" DATE NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "prescribers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "full_name" TEXT NOT NULL,
  "registration_number" TEXT NOT NULL UNIQUE,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "prescriptions" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "patient_id" UUID NOT NULL,
  "prescriber_id" UUID NOT NULL,
  "drug_id" UUID NOT NULL,
  "quantity" INTEGER NOT NULL,
  "refills" INTEGER DEFAULT 0 NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "drug_stock" ADD CONSTRAINT "fk_drug_stock_drug_id" FOREIGN KEY ("drug_id") REFERENCES "drugs" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "prescriptions" ADD CONSTRAINT "fk_prescriptions_patient_id" FOREIGN KEY ("patient_id") REFERENCES "patients" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "prescriptions" ADD CONSTRAINT "fk_prescriptions_prescriber_id" FOREIGN KEY ("prescriber_id") REFERENCES "prescribers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "prescriptions" ADD CONSTRAINT "fk_prescriptions_drug_id" FOREIGN KEY ("drug_id") REFERENCES "drugs" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "fills" ADD CONSTRAINT "fk_fills_prescription_id" FOREIGN KEY ("prescription_id") REFERENCES "prescriptions" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

More Health templates

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.