Templates/Health

Clinic appointments database schema

Patients book practitioners at locations; visits get notes.

6 tables, 6 relationships

Opens as a new diagram you can change. Free.

Tables

patients

  • iduuid not null
  • full_nametext not null
  • date_of_birthdate not null
  • phonetext
  • emailtext
  • created_attimestamptz not null

practitioners

  • iduuid not null
  • full_nametext not null
  • specialtytext not null
  • created_attimestamptz not null

locations

  • iduuid not null
  • nametext not null
  • addresstext not null
  • created_attimestamptz not null

appointment_slots

  • iduuid not null
  • practitioner_id> practitionersuuid not null
  • location_id> locationsuuid not null
  • starts_attimestamptz not null
  • ends_attimestamptz not null
  • created_attimestamptz not null

appointments

  • iduuid not null
  • slot_id> appointment_slotsuuid not null
  • patient_id> patientsuuid not null
  • reasontext
  • statustext not null
  • created_attimestamptz not null

visit_notes

  • iduuid not null
  • appointment_id> appointmentsuuid not null
  • author_id> practitionersuuid not null
  • bodytext not null
  • 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 "appointment_slots" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "practitioner_id" UUID NOT NULL,
  "location_id" UUID NOT NULL,
  "starts_at" TIMESTAMPTZ NOT NULL,
  "ends_at" TIMESTAMPTZ NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "appointments" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "slot_id" UUID NOT NULL UNIQUE,
  "patient_id" UUID NOT NULL,
  "reason" TEXT,
  "status" TEXT DEFAULT 'booked' NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "locations" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "address" TEXT NOT NULL,
  "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,
  "phone" TEXT,
  "email" TEXT,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

CREATE TABLE "visit_notes" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "appointment_id" UUID NOT NULL,
  "author_id" UUID NOT NULL,
  "body" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "appointment_slots" ADD CONSTRAINT "fk_appointment_slots_practitioner_id" FOREIGN KEY ("practitioner_id") REFERENCES "practitioners" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "appointment_slots" ADD CONSTRAINT "fk_appointment_slots_location_id" FOREIGN KEY ("location_id") REFERENCES "locations" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "appointments" ADD CONSTRAINT "fk_appointments_slot_id" FOREIGN KEY ("slot_id") REFERENCES "appointment_slots" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

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

ALTER TABLE "visit_notes" ADD CONSTRAINT "fk_visit_notes_appointment_id" FOREIGN KEY ("appointment_id") REFERENCES "appointments" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "visit_notes" ADD CONSTRAINT "fk_visit_notes_author_id" FOREIGN KEY ("author_id") REFERENCES "practitioners" ("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.