0% found this document useful (0 votes)
1 views

hospital.py

The document outlines a Hospital Management System with functionalities for doctors and patients. Doctors can view, add, or delete patient records, while patients can search for doctors or register themselves. The main program facilitates user role selection and manages database connections.

Uploaded by

mufeedamanahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

hospital.py

The document outlines a Hospital Management System with functionalities for doctors and patients. Doctors can view, add, or delete patient records, while patients can search for doctors or register themselves. The main program facilitates user role selection and manages database connections.

Uploaded by

mufeedamanahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

# Doctor functionalities

def doctor_menu(cursor, conn):


while True:
print("\nDOCTOR MENU")
print("1. View Your Patients")
print("2. Add Patient Record")
print("3. Delete Patient Record")
print("4. Exit")

try:
choice = int(input("Enter your choice: "))
if choice == 1:
show_patients(cursor)
elif choice == 2:
register_patient(cursor, conn)
elif choice == 3:
delete_patient(cursor, conn)
elif choice == 4:
return
else:
print("Invalid choice! Please choose a valid option.")
except ValueError:
print("Invalid input! Only numbers are allowed.")

# Patient functionalities
def patient_menu(cursor, conn):
while True:
print("\nPATIENT MENU")
print("1. Search for Doctors")
print("2. Register Yourself")
print("3. Exit")

try:
choice = int(input("Enter your choice: "))
if choice == 1:
search_doctor(cursor)
elif choice == 2:
register_patient(cursor, conn)
elif choice == 3:
return
else:
print("Invalid choice! Please choose a valid option.")
except ValueError:
print("Invalid input! Only numbers are allowed.")

# Display all patients


def show_patients(cursor):
cursor.execute("SELECT name, age, problem, phone FROM patient_details")
rows = cursor.fetchall()
if rows:
print_table(rows, ['Name', 'Age', 'Problem', 'Phone'])
else:
print("No patient records found.")

# Display all doctors


def show_doctors(cursor):
cursor.execute("SELECT name, specialization, phone, timing FROM doctor_details")
rows = cursor.fetchall()
if rows:
print_table(rows, ['Name', 'Specialization', 'Phone', 'Timing'])
else:
print("No doctor records found.")

# Register a patient
def register_patient(cursor, conn):
if rows:
print_table(rows, ['Name', 'Specialization', 'Phone', 'Timing'])
else:
print(f"No records found for doctor: {d_name}")

# Display data in table format


def print_table(data, headers):
header_row = '| '.join(f"{header:<20}" for header in headers)
print('-' * len(header_row))
print(header_row)
print('-' * len(header_row))

for row in data:


data_row = '| '.join(f"{str(item):<20}" for item in row)
print(data_row)

print('-' * len(header_row))

# Main program
def main():
conn = connect_to_database()
cursor = conn.cursor()
while True:
print("Welcome to the Hospital Management System")
print("1. Admin")
print("2. Doctor")
print("3. Patient")
print("4. Exit")
try:
role = int(input("Enter your role (1/2/3/4): "))
if role == 1:
username = input("Enter Admin Username: ").strip()
password = input("Enter Admin Password: ").strip()
if username == "admin" and password == "admin123":
admin_menu(cursor, conn)
else:
print("Invalid Admin credentials!")
elif role == 2:
doctor_menu(cursor, conn)
elif role == 3:
patient_menu(cursor, conn)
elif role == 4:
print("Thank you for using Hospital management system!!!!")
break
else:
print("Invalid choice! Please choose a valid role.")
except ValueError:
print("Invalid input! Only numbers are allowed.")

cursor.close()
conn.close()

if __name__ == "__main__":
main()

You might also like