๐ŸŽ™ Free live masterclass ยท Sun, 29 Nov, 7:00 pm IST ยท Java Full Stack roadmap Register free โ†’
Skills101

Hospital management database

Patients, doctors, appointments, prescriptions and billing, with rules enforced inside the database.

Intermediateโฑ 8โ€“12 hours๐Ÿชœ 7 stepsPostgreSQLTriggersStored procedures

What you'll learn

  • โ—†Complex relationships
  • โ—†Triggers and stored procedures
  • โ—†Transactions and constraints that prevent bad data

What you'll build

  • โœ“No double-booking of a doctor's slot
  • โœ“Prescriptions linked to appointments
  • โœ“Automatic bill totals
  • โœ“Reports for daily visits and revenue

Step-by-step guide

  1. 1

    Model

    Patient, Doctor, Department, Appointment(doctor, patient, starts_at, status), Prescription, Medicine, Bill, BillItem.

  2. 2

    Prevent clashes

    UNIQUE (doctor_id, starts_at) for fixed slots, or an exclusion constraint on a time range for flexible ones.

  3. 3

    Procedure to book

    CREATE PROCEDURE book_appointment(...) that checks the doctor works that day and inserts the row.

  4. 4

    Trigger for bills

    After insert/update on bill_items, recompute bills.total.

  5. 5

    Reports

    Daily appointments per department, top prescribed medicines, monthly revenue with DATE_TRUNC.

  6. 6

    Roles

    Create database roles: receptionist (appointments), doctor (prescriptions), accountant (bills) with GRANT.

  7. 7

    Document

    A README with the ER diagram, rules and sample queries with their output.

๐Ÿš€ Make it stand out

  • +Audit log table filled by triggers
  • +Partition appointments by year
  • +A Flask or Spring front end