This project is focused on designing the Hospital Management System (HMS) database using MySQL. The database schema is structured to efficiently store and manage data for patients, doctors, appointments, rooms, and invoices. It provides an optimized relational model for handling hospital operations, including patient information, doctor details, room assignments, appointment schedules, and billing.
The Hospital Management System Database consists of several interrelated tables that store different aspects of hospital operations:
Stores the personal and medical details of patients.
patient_id
: INT, Primary Key, Auto Incrementfirst_name
: VARCHAR(50)last_name
: VARCHAR(50)phone_no
: VARCHAR(15)age
: INTvisit_date
: DATEhealth_issue
: TEXT
Stores information about doctors, including their specializations and contact details.
doctor_id
: INT, Primary Key, Auto Incrementfull_name
: VARCHAR(100)email
: VARCHAR(100)phone_no
: VARCHAR(15)speciality
: VARCHAR(50)availability
: ENUM('available', 'not available')
Keeps track of appointments between doctors and patients.
appointment_id
: INT, Primary Key, Auto Incrementpatient_id
: INT, Foreign Key referencingpatient_id
doctor_id
: INT, Foreign Key referencingdoctor_id
appointment_date
: DATETIMEstatus
: ENUM('Scheduled', 'Completed', 'Cancelled')
Manages room availability and occupancy for patients.
room_id
: INT, Primary Key, Auto Incrementroom_number
: VARCHAR(20)capacity
: INTcurrent_occupancy
: INTis_available
: BOOLEAN (1 for available, 0 for not available)
Tracks which patient is assigned to which room.
assign_id
: INT, Primary Key, Auto Incrementroom_id
: INT, Foreign Key referencingroom_id
patient_id
: INT, Foreign Key referencingpatient_id
assign_date
: DATEdischarge_date
: DATE
Handles patient billing, including room charges, doctor fees, and medical charges.
txn_id
: INT, Primary Key, Auto Incrementassign_id
: INT, Foreign Key referencingassign_id
room_charge
: DECIMAL(10,2)doctor_charge
: DECIMAL(10,2)medical_charge
: DECIMAL(10,2)discount
: DECIMAL(10,2)tax
: DECIMAL(10,2)total_amount
: DECIMAL(10,2)payable_amount
: DECIMAL(10,2)
- Patient ↔ Appointment: One-to-many relationship (one patient can have multiple appointments).
- Doctor ↔ Appointment: One-to-many relationship (one doctor can have multiple appointments).
- Patient ↔ Room Assignment: One-to-many relationship (a patient can be assigned to multiple rooms during their stay).
- Room ↔ Room Assignment: One-to-many relationship (a room can be assigned to multiple patients over time).
- Room Assignment ↔ Invoices: One-to-one relationship (one room assignment corresponds to one invoice).
Stored procedures help streamline the process of fetching data based on specific parameters and ensure better performance for frequently used queries.
For example, the GetPatientDetail procedure retrieves detailed patient information based on the patient ID, doctor ID, and appointment status.
DELIMITER $$
CREATE PROCEDURE GetPatientDetail(
IN p_patient_id INT,
IN p_doctor_id INT,
IN p_status VARCHAR(20)
)
BEGIN
SELECT
patient.patient_id,
CONCAT(patient.first_name, ' ', patient.last_name) AS Full_name,
patient.health_issue,
appointment.appointment_id,
appointment.doctor_id,
doctor.full_name AS doctor_name,
appointment.appointment_date,
appointment.status
FROM
patient
JOIN
appointment ON patient.patient_id = appointment.patient_id
JOIN
doctor ON doctor.doctor_id = appointment.doctor_id
WHERE
(p_patient_id IS NULL OR patient.patient_id = p_patient_id) AND
(p_doctor_id IS NULL OR doctor.doctor_id = p_doctor_id) AND
(p_status IS NULL OR appointment.status = p_status)
ORDER BY
appointment.appointment_date;
END $$
DELIMITER ;
Triggers automate specific actions when certain conditions are met.
- After Insert Trigger: Automatically assigns a new room to a patient when a new room assignment record is inserted. It ensures that rooms are available and have sufficient capacity.
- Invoice Calculation Trigger: Calculates the total and payable amounts after the insertion of a new invoice record.
-
Clone the Repository: If the database script is hosted on GitHub:
git clone https://github.com/your-username/hospital-management-system-db.git cd hospital-management-system-db
-
Run the SQL Script: Import the database schema into your MySQL database. Use MySQL Workbench or a CLI:
source hospital_management_system.sql;
-
Test the Database:
- Insert some test data into the tables (
patients
,doctors
,appointments
, etc.). - Call the stored procedures to check if everything works as expected.
- Insert a few room assignments and invoices to test the triggers.
- Insert some test data into the tables (
This project is licensed under the MIT License - see the LICENSE file for details.