Designing an ER Diagram for a Hospital Management System (Patients, Doctors, Departments, Appointments)
Designing an ER Diagram for a Hospital Management System (Patients, Doctors, Departments, Appointments)
Designing an ER diagram for a Hospital Management System starts by identifying the core Entity types, then specifying each Attribute and the Relationship between them with correct Cardinality and (optionally) Participation.
Below is a complete ER design using four main entities—Patients, Doctors, Departments, and Appointments—then explicitly defining their attributes and cardinalities, including the critical Appointment relationships that tie together Patients and Doctors.
Key modeling decisions:
- Use APPOINTMENT as a relationship-associative entity that captures the scheduling event between a PATIENT and a DOCTOR.
- Model DEPARTMENT–DOCTOR as a typical “one department has many doctors” association.
- Optionally (but commonly), derive Department for an Appointment from the doctor’s department, or store it explicitly to preserve history and support reporting.
Pro Tip: If you need accurate historical reporting (e.g., which department handled the appointment at the time), model department_id on APPOINTMENT explicitly, even if it can be inferred from the doctor later.
ER Diagram Design Roadmap
Start with real-world objects
1. Identify EntitiesPatient, Doctor, Department, Appointment"
Choose identifiers and descriptive fields
2. Add AttributesPrimary keys, dates, contact details, times, status"
Connect entities with meaning
3. Define RelationshipsAppointment links Patient & Doctor; Department links to Doctor (and optionally Appointment)"
Ensure constraints match business rules
4. Set Cardinalities1-to-many and many-to-one with appointment scheduling"
Mark total vs partial participation
5. (Optional) Participation ConstraintsE.g., every Appointment must have a Patient and a Doctor"
Entities, Attributes, and Keys (Hospital Core)
1) PATIENT
Suggested attributes
- patient_id (PK)
- full_name
- date_of_birth
- gender
- phone
- address
Notes
- Keep patient_id as the stable unique identifier.
- Demographic attributes are typically immutable-ish, but you may allow updates later.
2) DEPARTMENT
Suggested attributes
- department_id (PK)
- department_name
- location
- phone
3) DOCTOR
Suggested attributes
- doctor_id (PK)
- full_name
- specialty (e.g., Cardiology, Dermatology)
- license_number
- phone
4) APPOINTMENT
Suggested attributes
- appointment_id (PK)
- start_time
- end_time (optional but useful)
- appointment_type (e.g., New Visit, Follow-up)
- status (e.g., Scheduled, Completed, Canceled)
- reason (optional)
- notes (optional)
- (recommended) patient_id, doctor_id, and optionally department_id as foreign-key-like link attributes in the relational mapping stage
Relationships and Cardinalities (the critical design part)
Relationship A: Patient ↔ Appointment
Meaning: A patient can have many appointments; each appointment belongs to exactly one patient.
- [PATIENT] (1) —— (many) [APPOINTMENT]
- Cardinality:
- PATIENT to APPOINTMENT: one-to-many
- APPOINTMENT to PATIENT: many-to-one
- Participation:
- Total on the Appointment side (every appointment must have a patient)
Formally:
- Each Appointment has exactly 1 patient.
- Each Patient can have 0..N appointments.
Relationship B: Doctor ↔ Appointment
Meaning: A doctor can attend many appointments; each appointment is attended by exactly one doctor.
- [DOCTOR] (1) —— (many) [APPOINTMENT]
Cardinality:
- DOCTOR to APPOINTMENT: one-to-many
- APPOINTMENT to DOCTOR: many-to-one Participation:
- Total on Appointment side (every appointment must have a doctor)
Relationship C: Department ↔ Doctor
Meaning: A department employs many doctors; each doctor belongs to exactly one department (common assumption).
- [DEPARTMENT] (1) —— (many) [DOCTOR]
Cardinality:
- DEPARTMENT to DOCTOR: one-to-many
- DOCTOR to DEPARTMENT: many-to-one
Warning: Some hospitals allow a doctor to work across multiple departments (e.g., joint appointments). If that’s required, this relationship becomes many-to-many and the model must change (e.g., a Doctor_Department associative entity). The design here assumes one primary department per doctor.
Relationship D (Option/Recommendation): Department ↔ Appointment
There are two approaches:
-
Infer Department from Doctor
- No direct DEPARTMENT–APPOINTMENT relationship.
- Reporting depends on joining through DOCTOR.
-
Store Department on Appointment (recommended for history)
- DEPARTMENT (1) —— (many) APPOINTMENT
- Appointment records remain accurate even if a doctor later changes departments.
In the ER diagram above, we modeled Department ↔ Appointment as one-to-many.
Step-by-Step: Produce the Hospital ER Diagram with Cardinalities
- 1Step 1
Create four entities: PATIENT, DOCTOR, DEPARTMENT, APPOINTMENT.
- 2Step 2
Set patient_id, doctor_id, department_id, appointment_id as PKs.
- 3Step 3
Assign descriptive fields (names, dates, contact info) to each entity.
- 4Step 4
Model APPOINTMENT as an entity/event connected to PATIENT and DOCTOR.
- 5Step 5
PATIENT (1) to APPOINTMENT (many); each appointment must reference exactly one patient.
- 6Step 6
DOCTOR (1) to APPOINTMENT (many); each appointment must reference exactly one doctor.
- 7Step 7
DEPARTMENT (1) to DOCTOR (many); each doctor belongs to exactly one department (assumption).
- 8Step 8
Either infer via DOCTOR or store department_id in APPOINTMENT for historical correctness.
- 9Step 9
Ensure constraints match reality (e.g., no appointment without a patient/doctor).
Cardinality Summary for Key ER Relationships
How many instances on each side of the relationship
Cardinality Table (Concrete Constraints)
| Relationship | Cardinality (ER) | Business Constraint |
|---|---|---|
| PATIENT — APPOINTMENT | 1 to many | A patient may have appointments; each appointment has patient |
| DOCTOR — APPOINTMENT | 1 to many | A doctor may have appointments; each appointment has doctor |
| DEPARTMENT — DOCTOR | 1 to many | A department has doctors; each doctor has department |
| DEPARTMENT — APPOINTMENT (optional) | 1 to many | A department covers appointments; each appointment has department |
Modeling Edge Cases & Assumptions
Pro Tip: Use Appointment as the scheduling “event” entity
Even if you think of Appointment as a relationship, modeling it as an entity with its own attributes (time, status, reason) makes the ER design clearer and supports constraints.
Warning: Many-to-many requires an associative entity
If doctors can belong to multiple departments (and vice versa), DEPARTMENT–DOCTOR becomes many-to-many and you should introduce something like DoctorDepartment (with its own attributes if needed).
ER Diagram Tutorial (Chen Notation & Practice)
Knowledge Check
In the ER design, which relationship should be modeled as an entity/event to capture time and status explicitly?