import os
class patiensInfo:
def __init__(self, name=None, surname=None, patientId=None):
self.name = name,
self.surname = surname,
self.patientId = patientId,
self.filename='patient.txt'
def __str__(self):
return '[Name: {0} | Surname: {1} | PatientId: {2}]'.\
format(self.name, self.surname, self.patientId)
def __repr__(self):
return '[Name: {0} | Surname: {1} | PatientId: {2}]'.\
format(self.name, self.surname, self.patientId)
def patient_add(self):
self.name=input("Patient name: ")
self.surname = input("Patient surname: ")
self.patientId = input("Patient patientId: ")
try:
if os.path.exists(self.filename) and os.path.getsize(self.filename)>0:
myPatientDb= open(self.filename, 'a')
myPatientDb.write(self.name+" "+self.surname+" "+self.patientId+"\n")
else:
myPatientDb = open(self.filename, 'w')
myPatientDb.write(self.name+" "+self.surname+" "+self.patientId+"\n")
except IOError:
print("Bir hata oluştu!")
finally:
myPatientDb.close()
def displayPatients(self):
if os.path.exists(self.filename) and os.path.getsize(self.filename) > 0:
myPatientDb = open(self.filename, 'r')
for records in myPatientDb:
print(records, end="")
myPatientDb.close()
def searchPatients(self):
if os.path.exists(self.filename) and os.path.getsize(self.filename) > 0:
myPatientDb = open(self.filename, 'r')
try:
patientsSearch = input("Enter the patientId: ")
counter = 0
for patient in myPatientDb.readlines():
if patientsSearch == patient.split()[2]:
print(patient)
counter +=1
if counter == 0:
print("No record found whose name is:", patientsSearch)
except:
print("Error occured!")
else:
print("No record in patient.txt")
def deletePatient(self):
if os.path.exists(self.filename) and os.path.getsize(self.filename)>0:
myPatientDb = open(self.filename, 'r')
try:
patientsSearch = input("Enter the patientId: ")
counter = 0
liste = myPatientDb.readlines()
for patient in liste:
if patientsSearch == patient.split()[2]:
k = liste.index(patient)
del liste[k]
myPatientDb.close()
myPatientDb = open(self.filename, 'w')
myPatientDb.writelines(liste)
myPatientDb.close()
counter +=1
if counter == 0:
print("No record found whose name is:", patientsSearch)
except:
print("Error occured!")
else:
print("No record in patient.txt")
if __name__ == '__main__':
ourPatiens = patiensInfo()
print("Enter 1.To add 2.For search 3.Display 4.Delete 5.Exit")
while True:
choice = input("Enter your choice: ").lower()
if choice == "1":
ourPatiens.patient_add()
elif choice == "2":
ourPatiens.searchPatients()
elif choice == "3":
ourPatiens.displayPatients()
elif choice == "4":
ourPatiens.deletePatient()
elif choice == 'q':
exit()
else:
print("Invalid option. Try again!")
Bu Blogda Ara
Dosyaya Hasta Bilgisi Ekleme etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Dosyaya Hasta Bilgisi Ekleme etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
12 Aralık 2020 Cumartesi
Dosya İşlemleri (Ekleme-Arama-Silme)
Kaydol:
Kayıtlar (Atom)