0% completed
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.
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:
We will build the ER diagram for the Hospital Management System through the following four steps.
Based on the requirements, we can identify the following entities:
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
Now, we will establish relationships between the entities based on the requirements:
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.
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.
Each entity in the ER diagram becomes a table in the relational model. Here’s how to approach this:
Doctor_ID
for Doctor, Patient_ID
for Patient).For each table, we add columns based on the attributes shown in the ER diagram. Here’s how to handle attributes:
name
and add its subfields first_name
and last_name
in the table.Phone_Number
create a separate table.Example:
Patient
↔ Room
Room Table
with Assigned_Patient_ID (FK)
Example:
Doctor
↔ Appointment
Doctor Table
Appointment Table
with Doctor_ID (FK)
Example:
Prescription
↔ Medicine
Prescription_Medicine
with columns:
Prescription_ID (FK)
Medicine_ID (FK)
Here is the final relational model for the Hospital Management System.
Now, we'll translate the ER diagram into a relational database schema.
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) );
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) );
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) );
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) );
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) );
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) );
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) );
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) );
CREATE TABLE Medicine ( Medicine_ID INT PRIMARY KEY, Medicine_Name VARCHAR(256), Manufacturer VARCHAR(256), Price DECIMAL(10, 2) );
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) );
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) );
CREATE TABLE Department ( Department_ID INT PRIMARY KEY, Department_Name VARCHAR(256), Location VARCHAR(256) );
CREATE TABLE Insurance ( Insurance_ID INT PRIMARY KEY, Provider_Name VARCHAR(256), Policy_Number INT, Coverage_Details TEXT );
.....
.....
.....