Cs Project (Shiv)
Cs Project (Shiv)
KARWAR
PROJECT TOPIC:
HOSPITAL MANAGEMENT SYSTEM
Submitted By:
Name: Shivang Savant
Class: XII-A
CBSE Roll Number:
CERTIFICATE
ACKNOWLEDGMENT
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
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:-
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:-
This project is significant because it addresses the challenges of manual hospital management by:
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.
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:-
● Add Patient
Adds a new patient's details (name, age, contact, address) to the system.
def add_patient()
● View Patients
def view_patients():
def update_patient():
def delete_patient():
2. Doctor Management:-
● Add Doctor
Adds a new doctor to the system with details like name, specialization, and contact.
def add_doctor():
● View Doctors
def view_doctors():
3. Appointment Management:-
● Schedule Appointment
def schedule_appointment():
● View Appointments
def view_appointments():
4. Billing Management:-
● Generate Bill
def generate_bill():
● View Bills
def view_bills():
5. Utility Functions:-
● Execute Query
● Fetch Results
● 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():
# 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.")
MYSQL DATABASE
Now that we have the tables set up, let's add some example data to test the system.
Here are a few SQL queries to view data from the tables:
Sample Output:
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:
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:
Sample Output:
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