0% found this document useful (0 votes)
39 views18 pages

Cs Project (Shiv)

Uploaded by

Aman Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views18 pages

Cs Project (Shiv)

Uploaded by

Aman Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

NAVY CHILDREN SCHOOL

KARWAR

COMPUTER SCIENCE PROJECT


2024-25

PROJECT TOPIC:
HOSPITAL MANAGEMENT SYSTEM

Submitted By:
Name: Shivang Savant
Class: XII-A
CBSE Roll Number:

Under the Guidance of:


SMITHA RODRIGUES, PGT(CS)
0

CERTIFICATE

This is to certify that Shivang Savant, a


student of Class XII-A, Navy Children
School Karwar, has successfully
completed the project titled “Hospital
Management System“ under my
supervision.
The student has shown great interest,
dedication, and sincerity in the
completion of this project.
I hereby certify that the project meets the
expected standards and adheres to the
guidelines prescribed by the Central
Board of Secondary Education (CBSE),
New Delhi.

Internal Examiner External Examiner


1

ACKNOWLEDGMENT

I would like to express my heartfelt


gratitude to Mrs. Smitha Rodrigues, PGT
(CS), whose dedication and expertise in
teaching Computer Science have deeply
enriched my understanding of the subject.
Her guidance has been instrumental in the
completion of this project.
I am also immensely grateful to our
Principal, Dr. Anjali Singh, for her
unwavering encouragement and support.
Her inspiration has been a driving force
behind the success of this project, and I
am truly appreciative of her leadership.
Finally, I would like to extend my sincere
appreciation to my fellow students for their
friendship and the memorable moments
we have shared throughout this journey.
Their camaraderie has made this
experience even more rewarding.
1

HARDWARE/SOFTWARE/
MODULE REQUIRED

∙ HARDWAREs
∙ Desktop/Computer/Laptop
∙ Mobile Phone
∙ SOFTWAREs
∙ Python
∙ MySQL
∙ MODULEs
∙ mysql.connector (to connect
MySQL to Python) ∙ bcrypt (For
Authentication)
∙ pyfiglet (For ASCII Art)

1
CONTENTS
S.N Topic Page
o. No.
1 CERTIFICATE 1

2 ACKNOWLEDGMENT 2

3 HARDWARE/SOFTWARE/M 3
ODULE REQUIRED
4 INTRODUCTION 5

5 FUNCTIONS LIST 12

6 PYTHON SOURCE CODE 15

7 MYSQL DATABASE 26

8 OUTPUT 30

INTRODUCTION
Introduction to the Hospital Management System

● Overview:-

The Hospital Management System (HMS) is a software application designed to streamline and
automate the daily operations of a hospital or clinic. It provides an efficient platform to manage
patient records, doctor schedules, appointments, and billing processes. By leveraging Python for
its backend logic and MySQL as a database, this system aims to improve accuracy, reduce
redundancy, and enhance user experience.

● Background:-

Traditionally, hospitals relied on manual methods to manage their workflows, which were prone to
errors, inefficiencies, and delays. The integration of digital solutions like the Hospital Management
System has transformed the healthcare sector by enabling better record management and operational
efficiency. This project seeks to implement a simplified version of such a system.

● Objectives:-

The primary objectives of the project are:

1. Streamlined Patient Management: Simplify the process of adding, updating, and retrieving patient records.

2. Enhanced Doctor Coordination: Maintain detailed doctor profiles and assign doctors to patients effectively.

3. Efficient Appointment Scheduling: Facilitate easy scheduling of appointments between doctors and
patients.

4. Accurate Billing Management: Automate the generation and tracking of bills for services rendered.

5. User-Friendly Interface: Ensure the system is easy to use, making it accessible to hospital administrators
and staff.

● Key Features:-

1. Patient Management: Store, retrieve, and update patient records.

2. Doctor Management: Maintain doctor details and specializations.


3. Appointment System: Schedule and view patient-doctor appointments.

4. Billing Module: Generate and manage patient bills.

5. Database Integration: Use MySQL to securely store all hospital data.

● Significance of the Project:-

This project is significant because it addresses the challenges of manual hospital management by:

Reducing paperwork and clerical errors.

Ensuring accurate and up-to-date records.

Enhancing operational efficiency, allowing staff to focus on patient care.

Providing a scalable framework that can be extended with additional features, such as inventory
management or reporting.

● Technologies Used:-

Python: A versatile programming language to handle the backend logic and user interface.

MySQL: A relational database management system for securely storing hospital data.

bcrypt: For password hashing to ensure secure authentication.

This Hospital Management System serves as a foundation for more complex healthcare solutions
and is a practical implementation of database management and programming concepts.

FUNCTIONS LIST
1. Patient Management:-

These functions handle operations related to patients:

● Add Patient

Adds a new patient's details (name, age, contact, address) to the system.

def add_patient()
● View Patients

Displays all registered patient records.

def view_patients():

● Update Patient (Optional)

Modifies the details of an existing patient.

def update_patient():

● Delete Patient (Optional)

Removes a patient's record from the system.

def delete_patient():

2. Doctor Management:-

These functions manage information about doctors:

● Add Doctor

Adds a new doctor to the system with details like name, specialization, and contact.

def add_doctor():

● View Doctors

Displays a list of all doctors and their specializations.

def view_doctors():

3. Appointment Management:-

These functions allow scheduling and managing appointments:

● Schedule Appointment

Schedules a patient-doctor appointment with the date.

def schedule_appointment():
● View Appointments

Displays all scheduled appointments, including patient and doctor details.

def view_appointments():

4. Billing Management:-

These functions handle patient billing operations:

● Generate Bill

Creates a bill for a patient with the total amount due.

def generate_bill():

● View Bills

Displays all billing records with patient names and amounts.

def view_bills():

5. Utility Functions:-

These are additional functions to facilitate core operations:

● Execute Query

Executes SQL queries to perform insert, update, delete, or other operations.

def execute_query(query, params=None):

● Fetch Results

Fetches data from the database for read operations.

def fetch_results(query, params=None)

● Create Connection

Establishes a connection between the Python script and the MySQL database.

def create_connection():
6. Main Menu Navigation

The main menu ties all functions together and allows the user to navigate between different operations:

● Main Menu

Displays options for Patient Management, Doctor Management, Appointment Management, and
Billing.

def main_menu():

PYTHON SOURCE CODE


import mysql.connector
import bcrypt

# Database Connection
def create_connection():
return mysql.connector.connect(
host="localhost",
user="root",
password="your_password", # Replace with your MySQL root password
database="hospital_management",
auth_plugin='mysql_native_password)

# Execute Query
def execute_query(query, params=None):
try:
conn = create_connection()
cursor = conn.cursor()
cursor.execute(query, params or ())
conn.commit()
cursor.close()
conn.close()
return True
except mysql.connector.Error as err:
print(f"Error: {err}")
return False

# Fetch Results
def fetch_results(query, params=None):
try:
conn = create_connection()
cursor = conn.cursor()
cursor.execute(query, params or ())
results = cursor.fetchall()
cursor.close()
conn.close()
return results
except mysql.connector.Error as err:
print(f"Error: {err}")
return []

# Patient Management
def add_patient():
name = input("Enter patient name: ")
age = int(input("Enter patient age: "))
contact = input("Enter contact number: ")
address = input("Enter address: ")
query = "INSERT INTO patients (name, age, contact, address) VALUES (%s, %s, %s,
%s)"
if execute_query(query, (name, age, contact, address)):
print("Patient added successfully.")

def view_patients():
patients = fetch_results("SELECT * FROM patients")
for patient in patients:
print(f"ID: {patient[0]}, Name: {patient[1]}, Age: {patient[2]}, Contact: {patient[3]},
Address: {patient[4]}")

# Doctor Management
def add_doctor():
name = input("Enter doctor name: ")
specialization = input("Enter specialization: ")
contact = input("Enter contact number: ")
query = "INSERT INTO doctors (name, specialization, contact) VALUES (%s, %s, %s)"
if execute_query(query, (name, specialization, contact)):
print("Doctor added successfully.")

def view_doctors():
doctors = fetch_results("SELECT * FROM doctors")
for doctor in doctors:
print(f"ID: {doctor[0]}, Name: {doctor[1]}, Specialization: {doctor[2]}, Contact:
{doctor[3]}")

# Appointment Management
def schedule_appointment():
patient_id = int(input("Enter patient ID: "))
doctor_id = int(input("Enter doctor ID: "))
date = input("Enter appointment date (YYYY-MM-DD): ")
query = "INSERT INTO appointments (patient_id, doctor_id, date) VALUES (%s,%s,%s)"
if execute_query(query, (patient_id, doctor_id, date)):
print("Appointment scheduled successfully.")

def view_appointments():
appointments = fetch_results("""
SELECT a.id, p.name AS patient, d.name AS doctor, a.date
FROM appointments a
JOIN patients p ON a.patient_id = p.id
JOIN doctors d ON a.doctor_id = d.id
""")
for appt in appointments:
print(f"ID: {appt[0]}, Patient: {appt[1]}, Doctor: {appt[2]}, Date: {appt[3]}")

# Billing Management
def generate_bill():
patient_id = int(input("Enter patient ID: "))
amount = float(input("Enter bill amount: "))
query = "INSERT INTO bills (patient_id, amount) VALUES (%s, %s)"
if execute_query(query, (patient_id, amount)):
print("Bill generated successfully.")

def view_bills():
bills = fetch_results("""
SELECT b.id, p.name AS patient, b.amount
FROM bills b
JOIN patients p ON b.patient_id = p.id
""")
for bill in bills:
print(f"ID: {bill[0]}, Patient: {bill[1]}, Amount: {bill[2]}")

# Main Menu
def main_menu():
while True:
print("\n--- Hospital Management System ---")
print("1. Patient Management")
print("2. Doctor Management")
print("3. Appointment Management")
print("4. Billing Management")
print("0. Exit")
choice = input("Enter your choice: ")
if choice == '1':
print("1. Add Patient\n2. View Patients")
sub_choice = input("Enter your choice: ")
if sub_choice == '1': add_patient()
elif sub_choice == '2': view_patients()
elif choice == '2':
print("1. Add Doctor\n2. View Doctors")
sub_choice = input("Enter your choice: ")
if sub_choice == '1': add_doctor()
elif sub_choice == '2': view_doctors()
elif choice == '3':
print("1. Schedule Appointment\n2. View Appointments")
sub_choice = input("Enter your choice: ")
if sub_choice == '1': schedule_appointment()
elif sub_choice == '2': view_appointments()
elif choice == '4':
print("1. Generate Bill\n2. View Bills")
sub_choice = input("Enter your choice: ")
if sub_choice == '1': generate_bill()
elif sub_choice == '2': view_bills()
elif choice == '0':
print("Exiting the system. Goodbye!")
break
else:
print("Invalid choice, try again.")

# Run the program


if __name__ == "__main__":
main_menu()

MYSQL DATABASE

Hospital Management Database:


1. Create Database and Tables

-- Create a new database for the hospital system


CREATE DATABASE hospital_management_system;

-- Use the created database


USE hospital_management_system;

-- Table for storing patient information


CREATE TABLE patients (
patient_id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
gender ENUM('Male', 'Female', 'Other') NOT NULL,
date_of_birth DATE NOT NULL,
address VARCHAR(255),
phone_number VARCHAR(15),
email VARCHAR(100),
emergency_contact VARCHAR(15),
registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP);

-- Table for storing doctor information


CREATE TABLE doctors (
doctor_id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
specialty VARCHAR(100),
gender ENUM('Male', 'Female', 'Other') NOT NULL,
phone_number VARCHAR(15),
email VARCHAR(100),
department_id INT,
hire_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (department_id) REFERENCES departments(department_id));

-- Table for storing appointment information


CREATE TABLE appointments (
appointment_id INT AUTO_INCREMENT PRIMARY KEY,
patient_id INT,
doctor_id INT,
appointment_date DATE,
appointment_time TIME,
status ENUM('Scheduled', 'Completed', 'Cancelled') DEFAULT 'Scheduled',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (patient_id) REFERENCES patients(patient_id),
FOREIGN KEY (doctor_id) REFERENCES doctors(doctor_id));

-- Table for storing department information


CREATE TABLE departments (
department_id INT AUTO_INCREMENT PRIMARY KEY,
department_name VARCHAR(100) NOT NULL,
description TEXT);

-- Table for storing prescriptions


CREATE TABLE prescriptions (
prescription_id INT AUTO_INCREMENT PRIMARY KEY,
appointment_id INT,
medicine_name VARCHAR(255),
dosage VARCHAR(255),
frequency VARCHAR(100),
prescribed_by INT,
FOREIGN KEY (appointment_id) REFERENCES appointments(appointment_id),
FOREIGN KEY (prescribed_by) REFERENCES doctors(doctor_id));

-- Table for storing hospital staff information


CREATE TABLE staff (
staff_id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
position VARCHAR(100),
phone_number VARCHAR(15),
email VARCHAR(100),
hire_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP);

2. Example Data Insertion

Now that we have the tables set up, let's add some example data to test the system.

-- Insert sample departments


INSERT INTO departments (department_name, description) VALUES
('Cardiology', 'Heart related diseases and treatment'),
('Neurology', 'Brain and nervous system treatment'),
('Orthopedics', 'Bone, joint and muscle related treatment');

-- Insert sample patients


INSERT INTO patients (first_name, last_name, gender, date_of_birth, address,
phone_number, email, emergency_contact) VALUES
('John', 'Doe', 'Male', '1985-04-23', '123 Main St, Springfield', '555-1234',
'[email protected]', '555-4321'),
('Jane', 'Smith', 'Female', '1990-07-19', '456 Oak St, Springfield', '555-5678',
'[email protected]', '555-8765');

-- Insert sample doctors


INSERT INTO doctors (first_name, last_name, specialty, gender, phone_number, email,
department_id) VALUES
('Dr. Mary', 'Johnson', 'Cardiologist', 'Female', '555-1111', '[email protected]', 1),
('Dr. David', 'Lee', 'Neurologist', 'Male', '555-2222', '[email protected]', 2);

-- Insert sample appointments


INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time)
VALUES
(1, 1, '2024-12-05', '10:00:00'),
(2, 2, '2024-12-06', '11:00:00');

-- Insert sample prescriptions


INSERT INTO prescriptions (appointment_id, medicine_name, dosage, frequency,
prescribed_by) VALUES
(1, 'Aspirin', '100mg', 'Once a day', 1),
(2, 'Topiramate', '50mg', 'Twice a day', 2);

-- Insert sample staff members


INSERT INTO staff (first_name, last_name, position, phone_number, email) VALUES
('Alice', 'Brown', 'Nurse', '555-3333', '[email protected]'),
('Bob', 'Williams', 'Receptionist', '555-4444', '[email protected]');
3. Sample Queries to View Data

Here are a few SQL queries to view data from the tables:

1. List of all patients:


SELECT * FROM patients;

Sample Output:

patien first_n last_n gen date_of_ addre phone_nu emergency_c registration


email
t_id ame ame der birth ss mber ontact _date
123
Main
1985-04- johndoe@examp 2024-12-02
1 John Doe Male St, 555-1234 555-4321
23 le.com 12:30:00
Springf
ield
456
Oak
Fem 1990-07- janesmith@exam 2024-12-02
2 Jane Smith St, 555-5678 555-8765
ale 19 ple.com 12:30:00
Springf
ield

2. List of appointments:
SELECT a.appointment_id, p.first_name AS patient_name, d.first_name AS doctor_name,
a.appointment_date, a.appointment_time, a.status
FROM appointments a
JOIN patients p ON a.patient_id = p.patient_id
JOIN doctors d ON a.doctor_id = d.doctor_id;

Sample Output:

appointment_id patient_name doctor_name appointment_date appointment_time status


1 John Mary 2024-12-05 10:00:00 Scheduled
2 Jane David 2024-12-06 11:00:00 Scheduled

3. List of prescriptions:
SELECT p.medicine_name, p.dosage, p.frequency, p.prescribed_by, d.first_name AS
doctor_name
FROM prescriptions p
JOIN doctors d ON p.prescribed_by = d.doctor_id;

Sample Output:

medicine_name dosage frequency prescribed_by doctor_name


Aspirin 100mg Once a day 1 Mary
Topiramate 50mg Twice a day 2 David
4. List of doctors:
SELECT doctor_id, first_name, last_name, specialty, department_name
FROM doctors d
JOIN departments dept ON d.department_id = dept.department_id;

Sample Output:

doctor_id first_name last_name specialty department_name


1 Mary Johnson Cardiologist Cardiology
2 David Lee Neurologist Neurology

Summary

 We created a simple Hospital Management System (HMS) with tables for patients, doctors,
appointments, prescriptions, departments, and staff.
 We added example data for testing.
 We demonstrated a few basic queries to view hospital records.

REFERENCES
∙ Python
▪ https://www.python.org/
∙ MySQL
▪ https://www.mysql.com/
∙ ANSI Escape Codes in Python
▪ https://pypi.org/project/ansi/
▪ https://replit.com/talk/learn/ANSI-Escape-
Codes
inPython/22803

https://gist.github.com/rened/9e584a7
dd2935d0f461904b9f 2950007
∙ Class 11th & 12th Computer Science Sumita
Arora Books
3

You might also like