import os import csv def newpatient(): print("Add a New Patient Record") print("========================") f=open('hospital.csv','a',newline='\r\n') s=csv.writer(f) PatientId=int(input('Enter Patient Id=')) PatientName=input('Enter Patient Name=') Disease=input('Enter Disease=') Fee=float(input('Enter Fee=')) rec=[PatientId,PatientName,Disease,Fee] s.writerow(rec) f.close() print("Record Saved...") input("Press any key to continue..") def updatepatient(): print("Modify a Patient Record") print("=======================") f=open('hospital.csv','r',newline='\r\n') f1=open('temp.csv','w',newline='\r\n') f1=open('temp.csv','a',newline='\r\n') r=input('Enter Patient Id of patient you want to modify=') s=csv.reader(f) s1=csv.writer(f1) for rec in s: if rec[0]==r: print("PatientId=",rec[0]) print("PatientName=",rec[1]) print("Disease=",rec[2]) print("Fee=",rec[3]) choice=input("Do you want to modify..?(y/n)=") if choice=='y' or choice=='Y': PatientId=int(input('Enter New PatientId=')) PatientName=input('Enter new Patient Name=') Disease=input('Enter Disease=') Fee=float(input('Enter Fee=')) rec=[PatientId,PatientName,Disease,Fee] s1.writerow(rec) print("Record Modified...") else: s1.writerow(rec) else: s1.writerow(rec) f.close() f1.close() os.remove("hospital.csv") os.rename("temp.csv","hospital.csv") input("Press any key to continue...") def deletepatient(): f=open('hospital.csv','r',newline='\r\n') f1=open('temp.csv','w',newline='\r\n') f1=open('temp.csv','a',newline='\r\n') r=input('Enter PatientId of patient you want to delete=') s=csv.reader(f) s1=csv.writer(f1) for rec in s: if rec[0]==r: print("PatientId=",rec[0]) print("Patient Name=",rec[1]) print("Disease=",rec[2]) print("Fee=",rec[3]) choice=input("Do you want to delete this record(y/n)=") if choice=='y' or choice=='Y': pass print("Record Deleted...") else: s1.writerow(rec) else: s1.writerow(rec) f.close() f1.close() os.remove("hospital.csv") os.rename("temp.csv","hospital.csv") input("Press any key to continue...") def searchpatient(): print("Search a Record") print("===================") f=open('hospital.csv','r',newline='\r\n') #Remove new line character from output r=input('Enter PatientId you want to search=') s=csv.reader(f) for rec in s: if rec[0]==r: print("PatientId=",rec[0]) print("Patient Name=",rec[1]) print("Disease=",rec[2]) print("Fee=",rec[3]) f.close() input("Press any key to continue..") def listpatients(): print("List of All Patients") print("===================") f=open('hospital.csv','r',newline='\r\n') #Remove new line character from output s=csv.reader(f) for rec in s: print(rec[0],end="\t\t") print(rec[1],end="\t\t") print(rec[2],end="\t\t") print(rec[3]) f.close() input("Press any key to continue...") def menu(): choice=0 while choice!=6: print("\n") print("====================================") print("Softare for Hospital Data Management") print("====================================") print("\n==========") print("Main Menu") print("==========") print("1. Add a new Patient Record") print("2. Modify Existing Patient Record") print("3. Delete Existing Patient Record") print("4. Search a Patient Record") print("5. List of all Patients") print("6. Quit") choice=int(input('Enter your choice')) if choice==1: newpatient() elif choice==2: updatepatient() elif choice==3: deletepatient() elif choice==4: searchpatient() elif choice==5: listpatients() elif choice==6: print("Good Bye") break menu()