import mysql.
connector
import datetime # for date and time
# -------- DATABASE CONNECTION --------
con = [Link](
host="localhost",
user="root",
password="root@8789635740", # add password if any
database="hospital"
)
cursor = [Link]()
# -------- FUNCTIONS --------
def add_patient():
pid = int(input("Enter Patient ID: "))
pname = input("Enter Name: ")
age = int(input("Enter Age: "))
disease = input("Enter Disease: ")
phone = input("Enter Phone: ")
[Link](
"INSERT INTO patient VALUES(%s,%s,%s,%s,%s)",
(pid, pname, age, disease, phone)
)
[Link]()
print("Patient added successfully")
def view_patients():
[Link]("SELECT * FROM patient")
for row in [Link]():
print(row)
def search_patient():
pid = int(input("Enter Patient ID to search: "))
[Link]("SELECT * FROM patient WHERE pid=%s", (pid,))
record = [Link]()
if record:
print(record)
else:
print("Patient not found")
def delete_patient():
pid = int(input("Enter Patient ID to delete: "))
[Link]("DELETE FROM patient WHERE pid=%s", (pid,))
[Link]()
print("Patient record deleted")
def add_doctor():
did = int(input("Enter Doctor ID: "))
dname = input("Enter Doctor Name: ")
spec = input("Enter Speciality: ")
[Link](
"INSERT INTO doctor VALUES(%s,%s,%s)",
(did, dname, spec)
)
[Link]()
print("Doctor added successfully")
def view_doctors():
[Link]("SELECT * FROM doctor")
for row in [Link]():
print(row)
def book_appointment():
aid = int(input("Enter Appointment ID: "))
pid = int(input("Enter Patient ID: "))
did = int(input("Enter Doctor ID: "))
today = [Link]()
now = [Link]().strftime("%H:%M:%S")
[Link](
"INSERT INTO appointment VALUES(%s,%s,%s,%s,%s)",
(aid, pid, did, str(today), now)
)
[Link]()
print("Appointment booked on", today, "at", now)
def view_appointments():
[Link]("SELECT * FROM appointment")
for row in [Link]():
print(row)
# -------- MAIN MENU --------
while True:
print("\n====== HOSPITAL MANAGEMENT SYSTEM ======")
print("1. Add Patient")
print("2. View Patients")
print("3. Search Patient")
print("4. Delete Patient")
print("5. Add Doctor")
print("6. View Doctors")
print("7. Book Appointment (with Date & Time)")
print("8. View Appointments")
print("9. Exit")
ch = int(input("Enter your choice: "))
if ch == 1:
add_patient()
elif ch == 2:
view_patients()
elif ch == 3:
search_patient()
elif ch == 4:
delete_patient()
elif ch == 5:
add_doctor()
elif ch == 6:
view_doctors()
elif ch == 7:
book_appointment()
elif ch == 8:
view_appointments()
elif ch == 9:
print("Program terminated")
break
else:
print("Invalid choice")