-
Notifications
You must be signed in to change notification settings - Fork 0
/
hospital.py
423 lines (360 loc) · 11.2 KB
/
hospital.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
import pymysql
import pickle
import csv
db = pymysql.connect(host='localhost', user='root', password='zohaibninja')
Mycur = db.cursor()
Mycur.execute('Use Computer_Project')
# Adding a Patient's Record
def AddP():
with open('GenInfo.dat', 'rb+') as F:
R = pickle.load(F)
Pno = input("Pno :")
Name = input("Name :")
Ailment = input("Ailment :")
RoomNo = input("RoomNo.")
Block = input("Block.")
Ano = input('Ano.')
DOJ = input("Date [YY-MM-DD]")
SQL = "INSERT INTO Patient_Record VALUES (" + Pno + ",'" + Name + "','" + Ailment + "'," + RoomNo + ",'" + Block + "'," + Ano + ",'" + DOJ + "')"
Mycur.execute(SQL)
db.commit()
for i in R:
if i[0] == "No.ofPatients":
i[1] += 1
F.seek(0)
pickle.dump(R, F)
# Adding a Doctor's Record
def AddD():
with open('GenInfo.dat', 'rb+') as F:
R = pickle.load(F)
Dno = input("Dno :")
Name = input("Name :")
Specialisation = input("Specs :")
Degree = input("Degree")
FromInstitution = input("Inst")
DOJ = input("Date [YY-MM-DD]")
SQL = "INSERT INTO Doctor_Record VALUES (" + Dno + ",'" + Name + "','" + Specialisation + "','" + Degree + "','" + FromInstitution + "','" + DOJ + "')"
Mycur.execute(SQL)
db.commit()
for i in R:
if i[0] == "No.ofDoctors":
i[1] += 1
F.seek(0)
pickle.dump(R, F)
# If Patient ends in a casualty
def CasualtyP():
with open('GenInfo.dat', 'rb+') as F:
R = pickle.load(F)
A = input('Enter the Patient No.')
SQL = "Delete from Patient_Record where Pno=" + A + ""
Mycur.execute(SQL)
db.commit()
for i in R:
if i[0] == "No.ofPatients":
i[1] -= 1
if i[0] == "Casualty":
i[1] += 1
F.seek(0)
pickle.dump(R, F)
# If Patient recovers
def RecoveryP():
with open('GenInfo.dat', 'rb+') as F:
R = pickle.load(F)
A = input('Enter the Patient No.')
SQL = "Delete from Patient_Record where Pno=" + A + ""
Mycur.execute(SQL)
db.commit()
for i in R:
if i[0] == "No.ofPatients":
i[1] -= 1
if i[0] == "Recovery":
i[1] += 1
F.seek(0)
pickle.dump(R, F)
# Removing a doctor
def RemoveD():
with open('GenInfo.dat', 'rb+') as F:
R = pickle.load(F)
A = input('Enter the Doctor No.')
SQL = "Delete from Doctor_Record where Dno=" + A + ""
Mycur.execute(SQL)
db.commit()
for i in R:
if i[0] == "No.ofDoctors":
i[1] -= 1
F.seek(0)
pickle.dump(R, F)
def ViewPatient():
SQL = "SELECT * FROM Patient_Record"
Mycur.execute(SQL)
R = Mycur.fetchall()
for Pno, PName, Ailment, Roomno, Block_, Ano, DOJ in R:
print("%5d | %20s | %10s | %5d | %2s | %5d |%s" % \
(Pno, PName.ljust(20, "_"), Ailment.ljust(10, '_'), Roomno, Block_.ljust(2, '_'), Ano,
DOJ.strftime("%Y-%m-%d")))
# Viewing Doctor_Record
def ViewDoctor():
SQL = "SELECT * FROM Doctor_Record"
Mycur.execute(SQL)
R = Mycur.fetchall()
for Dno, DName, Specialisation, Degree, FromInstitution, DOJ in R:
print("%5d | %20s | %10s | %7s | %20s| %s" % \
(Dno, DName.ljust(20, "_"), Specialisation.ljust(10, '_'), Degree.ljust(7, '_'),
FromInstitution.ljust(2, '_'), DOJ.strftime("%Y-%m-%d")))
# Viewing Assignments
def ViewAssignment():
SQL = "Select A.Ano,B.DName, A.Ailment as Assigned_For, A.Pno as Assigned_to, A.Pname as Pname from Patient_Record A, Doctor_Record B where A.Ano=B.Dno Order by A.Ano"
Mycur.execute(SQL)
R = Mycur.fetchall()
for Ano, DName, Assigned_For, Assigned_to, Pname in R:
print(" %20s | %10s | %5d | %20s" % \
(DName.ljust(20, "_"), Assigned_For.ljust(10, '_'), Assigned_to, Pname.ljust(20, '_')))
# Viewing No. of Patient assigned per Doctor
def ViewPatientPerDoctor():
SQL = "SELECT B.Dno, count(*) as PatientAssigned FROM Patient_Record A JOIN Doctor_Record B ON A.Ano = B.Dno GROUP BY B.Dno"
Mycur.execute(SQL)
R = Mycur.fetchall()
for Dno, PatientAssigned in R:
print("%5d | %3d" % \
(Dno, PatientAssigned))
# To search a patient Record
def searchP():
Pno = input('Enter The Patient Number')
SQL = "Select * from Patient_Record where PNo=" + Pno + ""
N = Mycur.execute(SQL)
if N > 0:
R = Mycur.fetchone()
print('Patient Found')
print('PatientNo. :', R[0])
print('Name :', R[1])
print('Ailment :', R[2])
print('Room No. :', R[3])
print('Block :', R[4])
print('ANo. :', R[5])
print('DOJ:', R[6])
else:
print(' Patient Record Not Found ')
# To search Doctor Record
def searchD():
Dno = input('Enter The Doctor Number')
SQL = "Select * from Doctor_Record where DNo=" + Dno + ""
N = Mycur.execute(SQL)
if N > 0:
R = Mycur.fetchone()
print('Doctor Found')
print('DoctorNo. :', R[0])
print('Name :', R[1])
print('Specialisation :', R[2])
print('Degree :', R[3])
print('From Institution:', R[4])
print('DOJ:', R[5])
else:
print(' Doctor Record Not Found ')
# To Modify Patient Record
def updateP():
while True:
Pno = input('Pno:')
X = input('What to change')
while True:
if X not in ['Pno', 'PName', 'Ailment', 'Roomo', 'Block', 'Ano', 'DOJ']:
X = input('Field does not exist. Enter Again')
else:
break
Y = input('Change to')
SQL = 'Update Patient_Record Set ' + X + "='" + Y + "' Where Pno=" + Pno + ""
Mycur.execute(SQL)
db.commit()
cont = input("Update more?")
if cont in ["n", "N"]:
break
# To Modify Doctor Record
def updateD():
while True:
Dno = input('Dno:')
X = input('What to change')
while True:
if X not in ['Dno', 'Name', 'Specialisation', 'Degree', 'From_Institution']:
X = input('Field does not exist. Enter Again')
else:
break
Y = input('Change to (enclose in Apsotrophe if string)')
SQL = 'Update Doctor_Record Set ' + X + "=" + Y + " Where Pno=" + Dno + ""
MyCur.execute(SQL)
db.commit()
cont = input('Update more?')
if cont in ['n', 'N']:
break
# To create the GenInfo/ Reset GenInfo
def creategeninfo():
with open("GenInfo.dat", "wb") as F:
R = [['Name of Hospital', "PeeJay"], ['No.ofPatients', 5], ['No.ofDoctors', 5], ["Recovered", 0],
["Casualty", 0]]
pickle.dump(R, F)
# To show the GenInfo
def showgeninfo():
with open("GenInfo.dat", 'rb') as F:
R = pickle.load(F)
for i in R:
print(i)
'''
JUST AN ADD ON
#To manage the AdminAccess Records
def create():
with open ("Accounts.csv",'w') as F:
LEL=csv.writer(F)
R=[]
while True:
Username=input('Enter Username')
Password=input('Enter Password')
R.append([Username,Password])
cont=input('Continue?')
if cont in ['n','N']:
break
LEL.writerows(R)
def show():
with open ("Accounts.csv",'r') as F:
R=csv.reader(F)
for i in R:
print(i)
def add():
with open ("Accounts.csv",'a') as F:
LEL=csv.writer(F)
R=[]
while True:
Username=input('Enter Username')
Password=input('Enter Password')
R.append([Username,Password])
cont=input('Continue?')
if cont in ['n','N']:
break
LEL.writerows(R)
def change():
with open ("Accounts.csv",'r+') as F:
R=csv.reader(F)
a=[]
c=input('Enter Username')
for i in R:
if i[0]==c:
i[1]=input('Enter the new password')
a.append(i)
F.seek(0)
potata=csv.writer(F)
potata.writerows(a)
def getpassword(Username):
with open ("Accounts.csv",'r') as F:
R=csv.reader(F)
for i in R:
if i[0]==Username:
return i[1]
#___________________________________________________________________________________________________________
ffs=input('Join as general?(Y/N)')
if ffs in ['n','N']:
while True:
User=input("Enter Username")
Pass=input("Enter Password")
if Pass==getpassword(User):
AdminAccess="Y"
break
elif:
ffs=input('Join as general?(Y/N)')
if ffs in ['Y','y']:
AdminAccess="N"
break
else:
AdminAcces="N"'''
def MenuDriven():
print('[1] Create')
print('[2] Update')
print('[3] View')
print('[4] Add')
print('[5] Search')
def MenuUpdate():
print('[7] Update Doctors Table')
print('[8] Update Patients Table')
def ShowView():
print('[9] View Patient')
print('[10] View Doctor')
print('[11] View Assignment')
print('[12] View GenInfo')
print('[13] View Assignedperdoc')
def Delete():
print('[14] RecoveryP')
print('[15] Casualties')
print('[16] RemoveD')
def Search():
print('[17] Search Doctor')
print('[18] Search Patient')
def Add():
print('[19] Add Patient')
print('[20] Add Doctor')
option = 1
while option != 0:
MenuDriven()
option = int(input('Enter The Option'))
if option == 1:
creategeninfo()
elif option == 2:
print('Select what you want to update?')
elif option == 3:
print('select What you want to view?')
elif option == 4:
print('select what you want to Search?')
elif option == 5:
print('select what you want to update?')
elif option == 6:
print('Select what you want to Remove?')
else:
print('Invalid Input')
print()
if option == 2:
MenuUpdate()
print()
option = int(input('Enter The Option You Want To Be Updated'))
print()
if option == 3:
ShowView()
print()
option = int(input('Enter the Option You Want To View'))
if option == 4:
Add()
print()
option = int(input('Enter The Option You Want To Add To'))
if option == 5:
Search()
print()
option = int(input('Enter The Option To Search'))
if option == 6:
Delete()
print()
option = int(input('Enter the Option to Remove'))
if option == 7:
updateD()
elif option == 8:
updateP()
elif option == 9:
ViewPatient()
elif option == 10:
ViewDoctor()
elif option == 11:
ViewAssignment()
elif option == 12:
showgeninfo()
elif option == 13:
ViewPatientPerDoctor()
elif option == 14:
RecoveryP()
elif option == 15:
CasualtyP()
elif option == 16:
RemoveD()
elif option == 17:
searchD()
elif option == 18:
searchP()
elif option == 19:
AddP()
elif option == 20:
AddD()
print()
print()
print('Program end Go Home')