Knowledge Guide
HomeDatabasesNormalization

Designing a Hospital Management System

In this case study, we will design a database for a Hospital Management System. The objective is to model a system that can manage information about patients, doctors, treatments, room assignments, guardians, and medical tests. We’ll follow a structured approach, step-by-step, to create an ER diagram and map it to a relational schema.

Requirements Analysis

The first and most critical step in database modeling is understanding the requirements of the system. This involves interacting with stakeholders, analyzing existing processes, and defining the scope of the system.

For our case study, let's outline the key functionalities that the HMS should support:

  1. Patient Management: Register new patients, update patient information, and record patient visits.
  2. Doctor Management: Maintain doctor profiles, specialties, schedules, and availability.
  3. Appointment Scheduling: Schedule appointments between patients and doctors.
  4. Medical Records: Store and retrieve patient medical histories, treatments, and prescriptions.
  5. Billing: Generate bills for services rendered, manage payments and insurance details.
  6. Room Management: Assign rooms to patients, manage room availability and types.

Step-by-Step ER Diagram Creation

We will build the ER diagram for the Hospital Management System through the following four steps.

Step 1: Identify Entities

Based on the requirements, we can identify the following entities:

  1. Patient
  2. Doctor
  3. Appointment
  4. Medical_Record
  5. Prescription
  6. Bill
  7. Room
  8. Department
  9. Medicine
  10. Insurance
Hospital Management System Entities
Hospital Management System Entities

Step 2: Identify Attributes and Define Primary Keys

Next, let’s identify attributes for each entity and define primary keys:

1. Patient

2. Doctor

3. Appointment

4. Medical_Record

5. Prescription

6. Bill

7. Room

8. Department

9. Medicine

10. Insurance

Adding attributes in ER diagram of HMS
Adding attributes in ER diagram of HMS

Step 3: Establish Relationships Between Entities

Now, we will establish relationships between the entities based on the requirements:

Common Types of Relationships

Relationships in HMS

1. Patient and Appointment

2. Doctor and Appointment

3. Patient and Medical_Record

4. Doctor and Medical_Record

5. Medical_Record and Prescription

6. Prescription and Medicine

7. Patient and Bill

8. Patient and Room

9. Patient and Department

10. Department and Doctor

11. Patient and Insurance

Here is the final ER diagram.

Hospital Management System ER Diagram
Hospital Management System ER Diagram

Mapping the ER Diagram to a Relational Schema

To create a relational schema from an ER diagram, we follow a structured approach that includes identifying entities, converting relationships, and handling attributes (especially primary and foreign keys). This ensures a well-designed relational database that preserves the relationships and dependencies specified in the ER model.

Step 1: Convert Entities to Tables

Each entity in the ER diagram becomes a table in the relational model. Here’s how to approach this:

  1. Identify each entity: In this case, the entities are Doctor, Patient, etc.
  2. Convert each entity to a table: Each entity box in the ER diagram will directly translate to a table with the same name.
  3. Assign primary keys: Each table should have a primary key based on the unique attribute of each entity (e.g., Doctor_ID for Doctor, Patient_ID for Patient).

Step 2: Convert Attributes for Each Entity

For each table, we add columns based on the attributes shown in the ER diagram. Here’s how to handle attributes:

  1. Direct Attributes: Each attribute in the ER diagram becomes a column in the corresponding table.
  2. Primary Key Identification: Ensure that each table’s primary key is clearly marked to uniquely identify each record.
  3. Handle Composite Attribute: Remove the composite attribute name and add its subfields first_name and last_name in the table.
  4. Handle Multi-valued Attribute: For each multi-values attributes like Phone_Number create a separate table.

Step 3: Map Relationships to Tables

a. One-to-One (1:1)

Example:

b. One-to-Many (1:N)

Example:

c. Many-to-Many (M:N)

Example:

Here is the final relational model for the Hospital Management System.

Relational Model for Hospital Management System
Relational Model for Hospital Management System

Step 4: Create Relational Schema

Now, we'll translate the ER diagram into a relational database schema.

1. Patient

CREATE TABLE Patient ( Patient_ID INT PRIMARY KEY, First_Name VARCHAR(256), Last_Name VARCHAR(256), Gender CHAR(10), Address VARCHAR(512), Email VARCHAR(128), Date_of_Birth DATE, Department_ID INT FOREIGN KEY (Department_ID) REFERENCES Department(Department_ID) );

2. Patient_Phone_Number

CREATE TABLE Patient_Phone_Number ( Patient_ID INT, Phone_Number VARCHAR(13), PRIMARY KEY (Patient_ID, Phone_Number), FOREIGN KEY (Patient_ID) REFERENCES Patient(Patient_ID) );

3. Doctor

CREATE TABLE Doctor ( Doctor_ID INT PRIMARY KEY, First_Name VARCHAR(256), Last_Name VARCHAR(256), Specialty VARCHAR(16), Email VARCHAR(128), Department_ID INT FOREIGN KEY (Department_ID) REFERENCES Department(Department_ID) );

4. Doctor_Phone_Number

CREATE TABLE Doctor_Phone_Number ( Doctor_ID INT, Phone_Number VARCHAR(13), PRIMARY KEY (Doctor_ID, Phone_Number), FOREIGN KEY (Doctor_ID) REFERENCES Doctor(Doctor_ID) );

5. Appointment

CREATE TABLE Appointment ( Appointment_ID INT PRIMARY KEY, Appointment_Date DATE, Appointment_Time TIME, Patient_ID INT, Doctor_ID INT, Reason_For_Visit VARCHAR(1028), FOREIGN KEY (Patient_ID) REFERENCES Patient(Patient_ID), FOREIGN KEY (Doctor_ID) REFERENCES Doctor(Doctor_ID) );

6. Medical_Record

CREATE TABLE Medical_Record ( Record_ID INT PRIMARY KEY, Patient_ID INT, Diagnosis VARCHAR(512), Treatment_Details TEXT, Record_Date DATE, Doctor_ID INT, FOREIGN KEY (Patient_ID) REFERENCES Patient(Patient_ID), FOREIGN KEY (Doctor_ID) REFERENCES Doctor(Doctor_ID) );

7. Prescription

CREATE TABLE Prescription ( Prescription_ID INT PRIMARY KEY, Dosage INT, Frequency INT, Duration INT, Record_ID INT, FOREIGN KEY (Record_ID) REFERENCES Medical_Record(Record_ID) );

8. Prescription_Medicine

CREATE TABLE Prescription_Detail ( Prescription_ID INT, Medicine_ID INT, PRIMARY KEY (Prescription_ID, Medicine_ID), FOREIGN KEY (Prescription_ID) REFERENCES Prescription(Prescription_ID), FOREIGN KEY (Medicine_ID) REFERENCES Medicine(Medicine_ID) );

9. Medicine

CREATE TABLE Medicine ( Medicine_ID INT PRIMARY KEY, Medicine_Name VARCHAR(256), Manufacturer VARCHAR(256), Price DECIMAL(10, 2) );

10. Bill

CREATE TABLE Bill ( Bill_ID INT PRIMARY KEY, Patient_ID INT, Bill_Date DATE, Amount DECIMAL(10, 2), Payment_Method VARCHAR(18), Insurance_Coverage Boolean, FOREIGN KEY (Patient_ID) REFERENCES Patient(Patient_ID) );

11. Room

CREATE TABLE Room ( Room_Number INT PRIMARY KEY, Room_Type VARCHAR(50), Availability_Status Boolean, Assigned_Patient_ID INT, FOREIGN KEY (Assigned_Patient_ID) REFERENCES Patient(Patient_ID) );

12. Department

CREATE TABLE Department ( Department_ID INT PRIMARY KEY, Department_Name VARCHAR(256), Location VARCHAR(256) );

13. Insurance

CREATE TABLE Insurance ( Insurance_ID INT PRIMARY KEY, Provider_Name VARCHAR(256), Policy_Number INT, Coverage_Details TEXT );
🤖 Don't fully get this? Learn it with Claude

Stuck on Designing a Hospital Management System? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Designing a Hospital Management System** (Databases) and want to truly understand it. Explain Designing a Hospital Management System from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Designing a Hospital Management System** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Designing a Hospital Management System** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Designing a Hospital Management System** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes