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

Code

This Python code defines functions for a hospital management system that allows users to admit patients, update paid fees, and generate bills. It uses CSV files to store patient records with information like name, date of birth, fees, etc. The main menu loop prompts the user to choose an action and calls the corresponding function, which may write new data to the CSV or search for and display existing records.

Uploaded by

hely.satish9a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Code

This Python code defines functions for a hospital management system that allows users to admit patients, update paid fees, and generate bills. It uses CSV files to store patient records with information like name, date of birth, fees, etc. The main menu loop prompts the user to choose an action and calls the corresponding function, which may write new data to the CSV or search for and display existing records.

Uploaded by

hely.satish9a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#code

import csv
from datetime import datetime

def display_menu():
print("\nHospital Management System Menu:")
print("1. Admit a Patient")
print("2. Update Paid Fees")
print("3. Generate Bill")
print("4. Exit")

def get_patient_number():
with open("hospital_records.csv", "r") as file:
reader = csv.reader(file)
records = list(reader)
return str(1 + len(records))

def admit_patient():
patient_number = get_patient_number()
patient_name = input("Enter Patient's First Name: ")
last_name = input("Enter Patient's Last Name: ")
guardian_name = input("Enter Guardian's Name: ")
dob = int(input("Enter Date of Birth (YYYYMMDD): "))
admitting_date = int(input("Enter Admitting Date (YYYYMMDD): "))
phone_number = input("Enter Phone Number (10 digits): ")
while len(phone_number) != 10 or not phone_number.isdigit():
print("Invalid phone number. Please enter a 10-digit number.")
phone_number = input("Enter Phone Number (10 digits): ")
doctor_name = input("Enter Consultant Doctor's Name: ")
room_number = input("Enter Room Number: ")
total_fees = float(input("Enter Total Fees: "))
paid_fees = float(input("Enter Paid Fees: "))

# Save patient information to CSV file


with open("hospital_records.csv", "a", newline="") as file:
writer = csv.writer(file)
writer.writerow([patient_number, patient_name, last_name, guardian_name, dob, admitting_date,
phone_number, doctor_name, room_number, total_fees, paid_fees])

print(f"Patient {patient_number} admitted successfully.")

def update_paid_fees():
patient_number = input("Enter Patient Number: ")

with open("hospital_records.csv", "r") as file:


reader = csv.reader(file)
records = list(reader)

for record in records:


if record[0] == patient_number:
total_fees = float(record[9])
paid_fees = float(record[10])
remaining_fees_before = total_fees - paid_fees

amount_paid = float(input("Enter Amount to Pay: "))


new_paid_fees = paid_fees + amount_paid

with open("hospital_records.csv", "w", newline="") as file:


writer = csv.writer(file)
for r in records:
if r[0] == patient_number:
r[10] = new_paid_fees
writer.writerow(r)

remaining_fees_after = total_fees - new_paid_fees

print(f"Payment of {amount_paid} successfully processed.")


print(f"Remaining fees before update: {remaining_fees_before}")
print(f"Remaining fees after update: {remaining_fees_after}")
return

print("Patient not found.")

def generate_bill():
patient_number = input("Enter Patient Number: ")

with open("hospital_records.csv", "r") as file:


reader = csv.reader(file)
records = list(reader)

for record in records:


if record[0] == patient_number:
total_fees = float(record[9])
paid_fees = float(record[10])

remaining_fees = max(0, total_fees - paid_fees) # Initialize remaining_fees to zero if already


paid
print(f"Remaining fees to pay: {remaining_fees}")

if remaining_fees > 0:
update_paid_fees()
else:
discharge_date = datetime.now().strftime("%Y%m%d")
print("\nBill Details:")
print(f"Patient Number: {record[0]}")
print(f"Patient Name: {record[1]} {record[2]}")
print(f"Guardian Name: {record[3]}")
print(f"Date of Birth: {record[4]}")
print(f"Admitting Date: {record[5]}")
print(f"Consultant Doctor: {record[7]}")
print(f"Room Number: {record[8]}")
print(f"Total Fees: {total_fees}")
print(f"Paid Fees: {paid_fees}")
print(f"Remaining Fees: {remaining_fees}")
print(f"Discharge Date: {discharge_date}")
return

print("Patient not found.")

# Main program loop


while True:
display_menu()
choice = input("Enter your choice (1-4): ")

if choice == "1":
admit_patient()
elif choice == "2":
update_paid_fees()
elif choice == "3":
generate_bill()
elif choice == "4":
print("Exiting Hospital Management System.")
break
else:
print("Invalid choice. Please enter a number between 1 and 4.")

You might also like