SOURCE CODE
import csv
import os
PATIENT_FILE = "[Link]"
DOCTOR_FILE = "[Link]"
# ----------------- FILE INITIALIZATION -----------------
def initialize_files():
if not [Link](PATIENT_FILE):
with open(PATIENT_FILE, "w", newline="") as f:
writer = [Link](f)
[Link](["Patient ID", "Name", "Age", "Gender", "Disease", "Doctor Assigned"])
if not [Link](DOCTOR_FILE):
with open(DOCTOR_FILE, "w", newline="") as f:
writer = [Link](f)
[Link](["Doctor ID", "Name", "Specialization", "Phone"])
# ----------------- ADD PATIENT -----------------
def add_patient():
with open(PATIENT_FILE, "a", newline="") as f:
writer = [Link](f)
pid = input("Enter Patient ID: ")
name = input("Enter Name: ")
age = input("Enter Age: ")
gender = input("Enter Gender: ")
disease = input("Enter Disease: ")
doctor = input("Enter Doctor Assigned: ")
[Link]([pid, name, age, gender, disease, doctor])
print("✅ Patient record added successfully!")
# ----------------- VIEW PATIENTS -----------------
def view_patients():
with open(PATIENT_FILE, "r") as f:
reader = [Link](f)
print("\n--- Patient Records ---")
for row in reader:
print(row)
# ----------------- SEARCH PATIENT -----------------
def search_patient():
pid = input("Enter Patient ID to search: ")
found = False
with open(PATIENT_FILE, "r") as f:
reader = [Link](f)
for row in reader:
if row and row[0] == pid:
print("Patient Found:", row)
found = True
if not found:
print("❌ Patient not found.")
# ----------------- ADD DOCTOR -----------------
def add_doctor():
with open(DOCTOR_FILE, "a", newline="") as f:
writer = [Link](f)
did = input("Enter Doctor ID: ")
name = input("Enter Name: ")
spec = input("Enter Specialization: ")
phone = input("Enter Phone: ")
[Link]([did, name, spec, phone])
print("✅ Doctor record added successfully!")
# ----------------- VIEW DOCTORS -----------------
def view_doctors():
with open(DOCTOR_FILE, "r") as f:
reader = [Link](f)
print("\n--- Doctor Records ---")
for row in reader:
print(row)
# ----------------- MAIN MENU -----------------
def main_menu():
initialize_files()
while True:
print("""
======== HOSPITAL MANAGEMENT SYSTEM ========
1. Add Patient
2. View Patients
3. Search Patient
4. Add Doctor
5. View Doctors
6. Exit
===========================================
""")
choice = input("Enter your choice (1-6): ")
if choice == "1":
add_patient()
elif choice == "2":
view_patients()
elif choice == "3":
search_patient()
elif choice == "4":
add_doctor()
elif choice == "5":
view_doctors()
elif choice == "6":
print("Thank you! Exiting system.")
break
else:
print("❌ Invalid choice. Try again.")
# ----------------- PROGRAM START -----------------
main_menu()