SOURCE CODE
=====================================================
HOSPITAL MANAGEMENT SYSTEM
#
# CLASS XII CBSE COMPUTER SCIENCE PROJECT
# LANGUAGE : PYTHON
# DATABASE : MYSQL
# AUTHOR : STUDENT NAME
# BOOK : SUMITA ARORA
=====================================================
import [Link]
import sys
# ---------------- DATABASE CONNECTION ----------------
con = [Link](
host="localhost",
user="root",
password="root",
database="hospital"
)
cur = [Link]()
# ---------------- TABLE CREATION ----------------
[Link]("""
c
CREATE TABLE IF NOT EXISTS patient(
pid INT PRIMARY KEY,
name VARCHAR(30),
age INT,
gender VARCHAR(10),
disease VARCHAR(30),
doctor VARCHAR(30)
)
""")
[Link]("""
c
CREATE TABLE IF NOT EXISTS doctor(
did INT PRIMARY KEY,
name VARCHAR(30),
specialization VARCHAR(30),
phone VARCHAR(15)
)
""")
[Link]("""
c
CREATE TABLE IF NOT EXISTS staff(
sid INT PRIMARY KEY,
name VARCHAR(30),
designation VARCHAR(30),
salary INT
)
""")
[Link]("""
c
CREATE TABLE IF NOT EXISTS billing(
billno INT PRIMARY KEY,
pid INT,
days INT,
room_charge INT,
medicine_charge INT,
doctor_charge INT,
total INT
)
""")
---------------- PATIENT FUNCTIONS ----------------
#
def add_patient():
pid=int(input("Enter Patient ID: "))
name=input("Enter Name: ")
age=int(input("Enter Age: "))
gender=input("Enter Gender: ")
disease=input("Enter Disease: ")
doctor=input("Enter Doctor Name: ")
[Link]("INSERT INTO patient
VALUES(%s,%s,%s,%s,%s,%s)",(pid,name,age,gender,disease,do
ctor))
[Link]()
print("Patient Record Added Successfully")
def display_patient():
[Link]("SELECT * FROM patient")
data=[Link]()
for row in data:
print(row)
def search_patient():
pid=int(input("Enter Patient ID to Search: "))
[Link]("SELECT * FROM patient WHERE pid=%s",(pid,))
data=[Link]()
print(data)
def update_patient():
pid=int(input("Enter Patient ID to Update: "))
disease=input("Enter New Disease: ")
doctor=input("Enter New Doctor: ")
[Link]("UPDATE patient SET disease=%s,doctor=%s
WHERE pid=%s",(disease,doctor,pid))
[Link]()
print("Patient Record Updated")
def delete_patient():
pid=int(input("Enter Patient ID to Delete: "))
[Link]("DELETE FROM patient WHERE pid=%s",(pid,))
[Link]()
print("Patient Record Deleted")
# ---------------- DOCTOR FUNCTIONS ----------------
def add_doctor():
did=int(input("Enter Doctor ID: "))
name=input("Enter Doctor Name: ")
spec=input("Enter Specialization: ")
phone=input("Enter Phone No: ")
[Link]("INSERT INTO doctor
VALUES(%s,%s,%s,%s)",(did,name,spec,phone))
[Link]()
print("Doctor Added Successfully")
def display_doctor():
[Link]("SELECT * FROM doctor")
for row in [Link]():
print(row)
def update_doctor():
did=int(input("Enter Doctor ID: "))
phone=input("Enter New Phone: ")
[Link]("UPDATE doctor SET phone=%s WHERE
did=%s",(phone,did))
[Link]()
print("Doctor Updated")
def delete_doctor():
did=int(input("Enter Doctor ID: "))
[Link]("DELETE FROM doctor WHERE did=%s",(did,))
[Link]()
print("Doctor Deleted")
# ---------------- STAFF FUNCTIONS ----------------
def add_staff():
sid=int(input("Enter Staff ID: "))
name=input("Enter Staff Name: ")
des=input("Enter Designation: ")
sal=int(input("Enter Salary: "))
[Link]("INSERT INTO staff
VALUES(%s,%s,%s,%s)",(sid,name,des,sal))
[Link]()
print("Staff Added")
def display_staff():
[Link]("SELECT * FROM staff")
for row in [Link]():
print(row)
def update_staff():
sid=int(input("Enter Staff ID: "))
sal=int(input("Enter New Salary: "))
[Link]("UPDATE staff SET salary=%s WHERE
sid=%s",(sal,sid))
[Link]()
print("Staff Updated")
def delete_staff():
sid=int(input("Enter Staff ID: "))
[Link]("DELETE FROM staff WHERE sid=%s",(sid,))
[Link]()
print("Staff Deleted")
# ---------------- BILLING FUNCTIONS ----------------
def add_bill():
bill=int(input("Enter Bill No: "))
pid=int(input("Enter Patient ID: "))
days=int(input("Enter No of Days: "))
room=int(input("Room Charge: "))
med=int(input("Medicine Charge: "))
doc=int(input("Doctor Charge: "))
total=(days*room)+med+doc
[Link]("INSERT INTO billing
VALUES(%s,%s,%s,%s,%s,%s,%s)",(bill,pid,days,room,med,doc,t
otal))
[Link]()
print("Bill Generated. Total Amount =",total)
def display_bill():
[Link]("SELECT * FROM billing")
for row in [Link]():
print(row)
# ---------------- MAIN MENU ----------------
while True:
print("===== HOSPITAL MANAGEMENT SYSTEM =====")
print("1. Patient Management")
print("2. Doctor Management")
print("3. Staff Management")
print("4. Billing Management")
print("5. Exit")
ch=int(input("Enter Choice: "))
if ch==1:
print("[Link] [Link] [Link] [Link] [Link]")
c=int(input("Enter Option: "))
if c==1: add_patient()
elif c==2: display_patient()
elif c==3: search_patient()
lif c==4: update_patient()
e
elif c==5: delete_patient()
elif ch==2:
print("[Link] [Link] [Link] [Link]")
c=int(input("Enter Option: "))
if c==1: add_doctor()
elif c==2: display_doctor()
elif c==3: update_doctor()
elif c==4: delete_doctor()
elif ch==3:
print("[Link] [Link] [Link] [Link]")
c=int(input("Enter Option: "))
if c==1: add_staff()
elif c==2: display_staff()
elif c==3: update_staff()
elif c==4: delete_staff()
elif ch==4:
print("[Link] Bill [Link] Bill")
c=int(input("Enter Option: "))
if c==1: add_bill()
elif c==2: display_bill()
elif ch==5:
print("Thank You")
break
else:
print("Invalid Choice")
[Link]()