SOURCE CODE
import [Link]
import pandas as pd
import [Link] as plt
def get_connection():
return [Link](
host="localhost",
user="root",
password="your_password", # change to your MySQL password
database="hospital_db"
def add_record():
con = get_connection()
cur = [Link]()
appointment_id = int(input("Enter Appointment ID: "))
patient_name = input("Enter Patient Name: ")
patient_age = int(input("Enter Patient Age: "))
gender = input("Enter Gender (M/F): ")
doctor_name = input("Enter Doctor Name: ")
specialization = input("Enter Doctor Specialization: ")
appointment_date = input("Enter Appointment Date (YYYY-MM-DD): ")
[Link]("""
INSERT INTO hospital
VALUES (%s, %s, %s, %s, %s, %s, %s)
""", (appointment_id, patient_name, patient_age, gender, doctor_name, specialization,
appointment_date))
[Link]()
[Link]()
print("Record added successfully!")
def view_records():
con = get_connection()
df = pd.read_sql("SELECT * FROM hospital", con)
[Link]()
print(df)
def report_patients_by_gender():
con = get_connection()
df = pd.read_sql("SELECT gender, COUNT(*) as total FROM hospital GROUP BY gender", con)
[Link]()
print(df)
[Link](df["gender"], df["total"])
[Link]("Patients by Gender")
[Link]("Gender")
[Link]("Count")
[Link]()
def report_doctors_by_specialization():
con = get_connection()
df = pd.read_sql("SELECT specialization, COUNT(*) as total FROM hospital GROUP BY
specialization", con)
[Link]()
print(df)
[Link](df["total"], labels=df["specialization"], autopct="%1.1f%%")
[Link]("Appointments by Doctor Specialization")
[Link]()
def main():
while True:
print("\n--- Hospital Management (One Table) ---")
print("1. Add Record")
print("2. View Records")
print("3. Report: Patients by Gender")
print("4. Report: Doctors by Specialization")
print("5. Exit")
choice = input("Enter choice: ")
if choice == "1":
add_record()
elif choice == "2":
view_records()
elif choice == "3":
report_patients_by_gender()
elif choice == "4":
report_doctors_by_specialization()
elif choice == "5":
print("Exiting...")
break
else:
print("Invalid choice! Try again.")
if _name_ == "_main_":
main()