Hospital management database
Patients, doctors, appointments, prescriptions and billing, with rules enforced inside the database.
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
Model
Patient, Doctor, Department, Appointment(doctor, patient, starts_at, status), Prescription, Medicine, Bill, BillItem.
- 2
Prevent clashes
UNIQUE (doctor_id, starts_at) for fixed slots, or an exclusion constraint on a time range for flexible ones.
- 3
Procedure to book
CREATE PROCEDURE book_appointment(...) that checks the doctor works that day and inserts the row.
- 4
Trigger for bills
After insert/update on bill_items, recompute bills.total.
- 5
Reports
Daily appointments per department, top prescribed medicines, monthly revenue with DATE_TRUNC.
- 6
Roles
Create database roles: receptionist (appointments), doctor (prescriptions), accountant (bills) with GRANT.
- 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