Hospital Management Project Class12
Hospital Management Project Class12
This is to certify that [Your Name], a student of Class XII, has successfully completed the project
titled
'Hospital Management System' as part of the Computer Science curriculum during the academic
year 2024-25.
Project demonstrates the understanding of functions, connectivity, and DBMS concepts using
Acknowledgement
I would like to express my sincere gratitude to my Computer Science teacher for her guidance
Introduction
The Hospital Management System is designed to manage patient, doctor, and appointment records
efficiently. This project uses Python for logic, MySQL for database management, and demonstrates
Objective
- To manage patient and doctor data.
Scope
The system can be implemented in clinics or small hospitals to maintain patient records and
schedule appointments.
- Database: MySQL
- Library: mysql.connector
System Requirements
Hardware:
- RAM: 2 GB minimum
Software:
- Python 3.x
- MySQL Server
- mysql-connector-python package
Database Design
Tables:
Functional Modules
- Add/View Patient
- Add/View Doctor
- Create/View Appointment
Advantages
- Easy to use and extend
- Quick database access
Limitations
- No graphical interface
- No login/authentication
Future Scope
- Add GUI using Tkinter or Flask
Conclusion
The project successfully demonstrates Class 12 concepts including functions, connectivity, and
Bibliography
- CBSE Computer Science Textbook
- https://www.geeksforgeeks.org
- https://dev.mysql.com/doc/
Source Code
"""
Hospital Management System - Class 12 Computer Science Project
Concepts: Functions, DBMS, Connectivity
Language: Python with MySQL
"""
import mysql.connector
def connect_db():
return mysql.connector.connect(
host="localhost",
user="root",
password="yourpassword",
database="hospital")
def create_tables():
con = connect_db()
cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS patient (pid INT PRIMARY KEY, name
VARCHAR(50), age INT, gender VARCHAR(10), disease VARCHAR(100))")
cur.execute("CREATE TABLE IF NOT EXISTS doctor (did INT PRIMARY KEY, name
VARCHAR(50), specialization VARCHAR(50))")
cur.execute("CREATE TABLE IF NOT EXISTS appointment (aid INT PRIMARY KEY, pid INT, did
INT, date DATE, time TIME, FOREIGN KEY(pid) REFERENCES patient(pid), FOREIGN KEY(did)
REFERENCES doctor(did))")
con.commit()
con.close()
def add_patient():
con = connect_db()
cur = con.cursor()
pid = int(input("Enter Patient ID: "))
name = input("Enter Name: ")
age = int(input("Enter Age: "))
gender = input("Enter Gender: ")
disease = input("Enter Disease: ")
cur.execute("INSERT INTO patient VALUES (%s, %s, %s, %s, %s)", (pid, name, age, gender,
disease))
con.commit()
con.close()
print("Patient record added.")
def view_patients():
con = connect_db()
cur = con.cursor()
cur.execute("SELECT * FROM patient")
for row in cur.fetchall():
print(row)
con.close()
def add_doctor():
con = connect_db()
cur = con.cursor()
did = int(input("Enter Doctor ID: "))
name = input("Enter Doctor Name: ")
specialization = input("Enter Specialization: ")
cur.execute("INSERT INTO doctor VALUES (%s, %s, %s)", (did, name, specialization))
con.commit()
con.close()
print("Doctor added successfully.")
def view_doctors():
con = connect_db()
cur = con.cursor()
cur.execute("SELECT * FROM doctor")
for row in cur.fetchall():
print(row)
con.close()
def create_appointment():
con = connect_db()
cur = con.cursor()
aid = int(input("Enter Appointment ID: "))
pid = int(input("Enter Patient ID: "))
did = int(input("Enter Doctor ID: "))
date = input("Enter Date (YYYY-MM-DD): ")
time = input("Enter Time (HH:MM:SS): ")
cur.execute("INSERT INTO appointment VALUES (%s, %s, %s, %s, %s)", (aid, pid, did, date,
time))
con.commit()
con.close()
print("Appointment created successfully.")
def view_appointments():
con = connect_db()
cur = con.cursor()
cur.execute("SELECT a.aid, p.name, d.name, a.date, a.time FROM appointment a JOIN patient p
ON a.pid = p.pid JOIN doctor d ON a.did = d.did")
for row in cur.fetchall():
print(row)
con.close()
def main():
create_tables()
while True:
print("\nHospital Management System")
print("1. Add Patient")
print("2. View Patients")
print("3. Add Doctor")
print("4. View Doctors")
print("5. Create Appointment")
print("6. View Appointments")
print("7. Exit")
choice = input("Enter your choice: ")
if choice == '1': add_patient()
elif choice == '2': view_patients()
elif choice == '3': add_doctor()
elif choice == '4': view_doctors()
elif choice == '5': create_appointment()
elif choice == '6': view_appointments()
elif choice == '7': break
else: print("Invalid choice.")