Advertisement
Guest User

Untitled

a guest
Dec 24th, 2022
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.50 KB | None | 0 0
  1. from Doctor import Doctor
  2.  
  3. class Admin:
  4. def __init__(self, username, password, address = ''):
  5.  
  6. self.__username = username
  7. self.__password = password
  8. self.__address = address
  9.  
  10. def view(self,a_list):
  11. for index, item in enumerate(a_list):
  12. print(f'{index+1:3}|{item}')
  13.  
  14. def login(self):
  15.  
  16. print("-----Login-----")
  17.  
  18. username = input('Enter the username: ')
  19. password = input('Enter the password: ')
  20.  
  21. return self.__username in username and self.__password == password
  22.  
  23. def find_index(self,index,doctors):
  24.  
  25. if index in range(0,len(doctors)):
  26.  
  27. return True
  28. else:
  29. return False
  30.  
  31. def get_doctor_details(self):
  32.  
  33. first_name = input('Enter the first name: ')
  34. surname = input('Enter the surname: ')
  35. speciality = input('Enter the speciality: ')
  36. return first_name, surname, speciality
  37.  
  38. def doctor_management(self, doctors):
  39.  
  40. print("\n-----Doctor Management-----")
  41. print('Choose the operation:')
  42. print(' 1 - Register')
  43. print(' 2 - View')
  44. print(' 3 - Update')
  45. print(' 4 - Delete')
  46.  
  47. op = input('Input: ')
  48.  
  49. if op == '1':
  50. print("-----Register-----")
  51.  
  52. print('Enter the doctor\'s details:')
  53. first_name, surname, speciality = self.get_doctor_details()
  54.  
  55. name_exists = False
  56. for doctor in doctors:
  57. if first_name.lower() == doctor.get_first_name().lower() and surname.lower() == doctor.get_surname().lower():
  58. print('Name already exists.')
  59. name_exists=True
  60. if(name_exists==False):
  61. doctors.append(Doctor(first_name, surname, speciality))
  62. print('Doctor registered.')
  63.  
  64.  
  65. elif op == '2':
  66. if doctors:
  67. print("\n-----List of Doctors-----")
  68. print('ID | Full name | Speciality')
  69. self.view(doctors)
  70. else:
  71. print('There are no doctors in the system to view.')
  72.  
  73. elif op == '3':
  74. if doctors:
  75. while True:
  76. print("\n-----Update Doctor`s Details-----")
  77. print('ID | Full name | Speciality')
  78. self.view(doctors)
  79. try:
  80. index = int(input('Enter the ID of the doctor: ')) - 1
  81. doctor_index=self.find_index(index,doctors)
  82. if doctor_index!=False:
  83.  
  84. break
  85.  
  86. else:
  87. print("Doctor not found")
  88.  
  89. except ValueError:
  90. print('The ID entered is incorrect')
  91.  
  92. print('Choose the field to be updated:')
  93. print(' 1 First name')
  94. print(' 2 Surname')
  95. print(' 3 Speciality')
  96. op = int(input('Input: '))
  97.  
  98. doctor = doctors[index]
  99. if op==1:
  100. fn=input('Enter the new first name: ')
  101. doctor.set_first_name(fn)
  102.  
  103. if op==2:
  104. sn=input('Enter the new surname: ')
  105. doctor.set_surname(sn)
  106.  
  107. if op==3:
  108. sp=input('Enter the new speciality: ')
  109. doctor.set_speciality(sp)
  110. else:
  111. print('There are no doctors in the system to update.')
  112.  
  113. elif op == '4':
  114. if doctors:
  115. print("\n-----Delete Doctor-----")
  116. print('ID | Full Name | Speciality')
  117. self.view(doctors)
  118.  
  119. doctor_index = input('Enter the ID of the doctor to be deleted: ')
  120.  
  121. try:
  122. doctors.pop(int(doctor_index) -1)
  123. print('Doctor deleted')
  124. except:
  125. print("The id entered was not found")
  126. return doctors
  127.  
  128. print('The id entered is incorrect')
  129.  
  130. else:
  131. print('There are no doctors to delete.')
  132.  
  133. def view_patient(self, patients):
  134.  
  135. print("\n-----View Patients-----")
  136. print('ID | Full Name | Doctor`s Full Name | Age | Mobile | Postcode | Symptom ')
  137. self.view(patients)
  138.  
  139. def discharge(self, patients, discharge_patients):
  140.  
  141. print("\n-----Discharge Patient-----")
  142. print('ID | Full Name | Doctor`s Full Name | Age | Mobile | Postcode | Symptom ')
  143. self.view(patients)
  144. while True:
  145.  
  146. try:
  147. patient_index=int(input('Please enter the patient ID: ')) - 1
  148. patient_valid=self.find_index(patient_index,patients)
  149. if patient_valid!=False:
  150. return patient_index
  151. break
  152.  
  153. else:
  154. print("ID not found")
  155.  
  156. except ValueError:
  157. print("entered id is invalid.")
  158.  
  159. def dischargeview(self, discharged_patients):
  160.  
  161. print("\n-----Discharged Patients-----")
  162. print('ID | Full Name | Doctor`s Full Name | Age | Mobile | Postcode | Symptom ')
  163. self.view(discharged_patients)
  164.  
  165. def assign_doctor_to_patient(self, patients, doctors):
  166.  
  167. print("\n-----Assign Patients-----")
  168. print('ID | Full Name | Doctor`s Full Name | Age | Mobile | Postcode | Symptom ')
  169. self.view(patients)
  170.  
  171. patient_index = input('Please enter the patient ID: ')
  172.  
  173. try:
  174. patient_index = int(patient_index) -1
  175.  
  176. if patient_index not in range(len(patients)):
  177. print('The id entered was not found.')
  178. return
  179. except ValueError:
  180. print('The id entered is incorrect')
  181. return
  182.  
  183. print("-----Doctors Select-----")
  184. print('Select the doctor that fits these symptoms:')
  185.  
  186.  
  187. print('--------------------------------------------------')
  188. print('ID | Full Name | Speciality ')
  189. self.view(doctors)
  190. doctor_index = input('Please enter the doctor ID: ')
  191.  
  192.  
  193. try:
  194. doctor_index = int(doctor_index) -1
  195.  
  196. if self.find_index(doctor_index,doctors)!=False:
  197. patients[patient_index].link(doctors[doctor_index].full_name())
  198. doctors[doctor_index].add_patient(doctors[doctor_index])
  199. print('The patient is now assign to the doctor.')
  200. else:
  201. print('The id entered was not found.')
  202. except ValueError:
  203. print('The id entered is incorrect')
  204.  
  205. def group_family(self,patients):
  206. print("\n-----Patients Family-----")
  207. print(' Full Name | Doctor`s Full Name | Age | Mobile | Postcode | Symptom ')
  208. family = ("Smith")
  209. print(*[p for p in patients if p.get_surname() == family], sep='\n')
  210.  
  211.  
  212.  
  213.  
  214. def management_report(self,doctors,patients):
  215. print("\n-----Management Reports-----")
  216. print('Choose the operation:')
  217. print(' 1 - Amount of doctors')
  218. print(' 2 - Patients per Doctors')
  219.  
  220. op = input('Input: ')
  221. if op =='1':
  222. print("Amount of doctors: {0}".format(len(doctors)))
  223.  
  224. elif op =='2':
  225. print("{0} has {1} patients".format(doctors,len(patients)))
  226.  
  227.  
  228. def update_details(self):
  229.  
  230. print('Choose the field to be updated:')
  231. print(' 1 Username')
  232. print(' 2 Password')
  233. print(' 3 Address')
  234. print(' 4 Admin Details')
  235. op = int(input('Input: '))
  236. while True:
  237.  
  238. if op == 1:
  239.  
  240. username = input('Enter the new username: ')
  241. if username == input('Enter the new Username again: '):
  242. self.__username = username
  243. print("User has been updated to {0}".format(username))
  244. break
  245. else:
  246. print("Username does not match, try again")
  247.  
  248. elif op == 2:
  249. password = input('Enter the new password: ')
  250. if password == input('Enter the new password again: '):
  251. self.__password = password
  252. print("Password has been changed.")
  253. break
  254. else:
  255. print("Password does not match")
  256.  
  257. elif op == 3:
  258. address = input('Enter the new address: ')
  259. if address == input('Enter the new address again: '):
  260. self.__address = address
  261. print("Address has been changed to {0}.".format(address))
  262. break
  263.  
  264. elif op == 4:
  265. print('Admin Details\nUsername: {0}\nPassword: {1} \nAddress: {2}'.format(self.__username, self.__password, self.__address))
  266. break
  267.  
  268. else:
  269. return
  270.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement