Templates/Health

Patient records database schema

Encounters with diagnoses, prescriptions, medications and allergies.

7 tables, 6 relationships

Opens as a new diagram you can change. Free.

Tables

patients

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

clinicians

  • iduuid not null
  • full_nametext not null
  • roletext not null
  • created_attimestamptz not null

encounters

  • iduuid not null
  • patient_id> patientsuuid not null
  • clinician_id> cliniciansuuid not null
  • kindtext not null
  • occurred_attimestamptz not null
  • created_attimestamptz not null

diagnoses

  • iduuid not null
  • encounter_id> encountersuuid not null
  • codetext not null
  • descriptiontext not null
  • created_attimestamptz not null

medications

  • iduuid not null
  • nametext not null
  • formtext
  • strengthtext
  • created_attimestamptz not null

prescriptions

  • iduuid not null
  • encounter_id> encountersuuid not null
  • medication_id> medicationsuuid not null
  • dosetext not null
  • frequencytext not null
  • ends_ondate
  • created_attimestamptz not null

allergies

  • iduuid not null
  • patient_id> patientsuuid not null
  • substancetext not null
  • reactiontext
  • severitytext 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 "allergies" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "patient_id" UUID NOT NULL,
  "substance" TEXT NOT NULL,
  "reaction" TEXT,
  "severity" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

CREATE TABLE "diagnoses" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "encounter_id" UUID NOT NULL,
  "code" TEXT NOT NULL,
  "description" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "encounters" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "patient_id" UUID NOT NULL,
  "clinician_id" UUID NOT NULL,
  "kind" TEXT NOT NULL,
  "occurred_at" TIMESTAMPTZ NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

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

CREATE TABLE "prescriptions" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "encounter_id" UUID NOT NULL,
  "medication_id" UUID NOT NULL,
  "dose" TEXT NOT NULL,
  "frequency" TEXT NOT NULL,
  "ends_on" DATE,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

ALTER TABLE "encounters" ADD CONSTRAINT "fk_encounters_clinician_id" FOREIGN KEY ("clinician_id") REFERENCES "clinicians" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "diagnoses" ADD CONSTRAINT "fk_diagnoses_encounter_id" FOREIGN KEY ("encounter_id") REFERENCES "encounters" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "prescriptions" ADD CONSTRAINT "fk_prescriptions_encounter_id" FOREIGN KEY ("encounter_id") REFERENCES "encounters" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "prescriptions" ADD CONSTRAINT "fk_prescriptions_medication_id" FOREIGN KEY ("medication_id") REFERENCES "medications" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "allergies" ADD CONSTRAINT "fk_allergies_patient_id" FOREIGN KEY ("patient_id") REFERENCES "patients" ("id") ON DELETE CASCADE 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.