-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
1088 lines (949 loc) · 38.4 KB
/
main.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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from flask import Flask,render_template,session,request,redirect,url_for,flash
import mysql.connector,hashlib
mydb = mysql.connector.connect(
host='localhost',
user='root',
password='$Prince08099',
database = 'DBMS_PROJECT'
)
mycursor = mydb.cursor(buffered=True)
app = Flask(__name__)
@app.route("/",methods = ['POST', 'GET'])
@app.route("/home",methods = ['POST','GET'])
def home():
if not session.get('login'):
return render_template('login.html'),401
else:
if session.get('isAdmin') :
return render_template('home.html')
else :
return home_student()
@app.route("/adminhome",methods = ['POST','GET'])
def adminhome():
if not session.get('adminlogin'):
return render_template('adminlogin.html'),401
else:
if session.get('isAdmin') :
return render_template('adminhome.html')
else :
return home_student()
@app.route("/adminlogin",methods = ['GET','POST'])
def adminlogin():
if request.method=='POST' :
query = """SELECT * FROM login WHERE username = '%s'""" %(request.form['username'])
mycursor.execute(query)
res = mycursor.fetchall()
if mycursor.rowcount == 0:
return adminhome()
if request.form['password'] != res[0][1]:
return render_template('adminlogin.html')
else:
session['adminlogin'] = True
session['username'] = request.form['username']
session['password'] = request.form['password']
session['isAdmin'] = (request.form['username']=='admin')
return adminhome()
return render_template('adminlogin.html')
@app.route("/login",methods = ['GET','POST'])
def login():
if request.method=='POST' :
query = """SELECT * FROM login WHERE username = '%s'""" %(request.form['username'])
mycursor.execute(query)
res = mycursor.fetchall()
if mycursor.rowcount == 0:
return home()
if request.form['password'] != res[0][1]:
return render_template('login.html')
else:
session['login'] = True
session['username'] = request.form['username']
session['password'] = request.form['password']
session['isAdmin'] = (request.form['username']=='admin')
return home()
return render_template('login.html')
@app.route("/donate",methods = ['POST','GET'])
def donate():
if not session.get('login'):
return redirect( url_for('home') )
return render_template('donorpage.html')
@app.route("/procure",methods = ['POST','GET'])
def procure():
if not session.get('login'):
return redirect( url_for('home') )
return render_template('procurepage.html')
@app.route("/show_update_detail",methods=['POST','GET'])
def show_update_detail():
if not session.get('login'):
return redirect( url_for('home') )
if request.method=='POST':
if request.form['User_ID'] =='':
return render_template("search_detail.html")
qry = "Select * from User where User.User_ID = %s" %(request.form['User_ID'])
qry1 = "Select * from User_phone_no where User_ID = %s" %(request.form['User_ID'])
mycursor.execute(qry)
not_found=False
res=()
if(mycursor.rowcount > 0):
res = mycursor.fetchone()
else:
not_found=True
fields = mycursor.column_names
qry_upd = "Select * from User where User_ID = %s" %(request.form['User_ID'])
mycursor.execute(qry_upd)
upd_res = ()
if(mycursor.rowcount > 0):
upd_res = mycursor.fetchone()
fields_upd = mycursor.column_names
mycursor.execute(qry1)
phone_no = mycursor.fetchall()
qry_pat = "select Patient_ID, organ_req, reason_of_procurement, Doctor_name from Patient inner join Doctor on Doctor.Doctor_ID = Patient.Doctor_ID and User_ID = %s" %(request.form['User_ID'])
qry_don = "select Donor_ID, organ_donated, reason_of_donation, Organization_name from Donor inner join Organization on Organization.Organization_ID = Donor.Organization_ID and User_ID = %s" %(request.form['User_ID'])
qry_trans = "select distinct Transaction.Patient_ID, Transaction.Donor_ID, Organ_ID, Date_of_transaction, Status from Transaction, Patient, Donor where (Patient.User_ID = %s and Patient.Patient_ID = Transaction.Patient_ID) or (Donor.User_Id= %s and Donor.Donor_ID = Transaction.Donor_ID)" %((request.form['User_ID']),(request.form['User_ID']))
#
res_pat = ()
res_dnr = ()
res_trans = ()
mycursor.execute(qry_pat)
if(mycursor.rowcount > 0):
res_pat = mycursor.fetchall()
fields_pat = mycursor.column_names
#
mycursor.execute(qry_don)
if(mycursor.rowcount > 0):
res_dnr = mycursor.fetchall()
fields_dnr = mycursor.column_names
#
mycursor.execute(qry_trans)
if(mycursor.rowcount > 0):
res_trans = mycursor.fetchall()
fields_trans = mycursor.column_names
print(res_trans)
if("show" in request.form):
return render_template('show_detail_2.html',res = res,fields = fields, not_found=not_found, phone_no = phone_no, res_dnr = res_dnr, res_pat = res_pat,res_trans = res_trans,fields_trans = fields_trans, fields_dnr = fields_dnr, fields_pat = fields_pat)
if("update" in request.form):
return render_template('update_detail.html',res = upd_res,fields = fields_upd, not_found=not_found)
if "delete" in request.form:
if not_found:
return render_template('show_detail_2.html',res = res,fields = fields, not_found=not_found, phone_no = phone_no, res_dnr = res_dnr, res_pat = res_pat,res_trans = res_trans,fields_trans = fields_trans, fields_dnr = fields_dnr, fields_pat = fields_pat)
else:
qry2 = "DELETE FROM User where User_ID = %s" %(request.form['User_ID'])
mycursor.execute(qry2)
mydb.commit()
return render_template("home.html")
@app.route("/search_detail",methods = ['POST','GET'])
def search_detail():
if not session.get('login'):
return redirect( url_for('home') )
return render_template('search_detail.html')
#--------------Adding Information--------------------------------------------------------------------------------------------
@app.route("/add_<id>_page",methods = ['POST','GET'])
def add_page(id):
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from " + id.capitalize()
mycursor.execute(qry)
fields = mycursor.column_names
return render_template('add_page.html',success=request.args.get('success'), error=request.args.get('error'), fields = fields, id= id)
@app.route("/add_User", methods=['POST','GET'])
def add_User():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from User"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['User_ID','Medical_insurance'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
qry = "INSERT INTO User Values (%s,%s,%s,%s,%s,%s,%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
mydb.commit()
return redirect(url_for('add_page', id='User', error=error,success=success))
@app.route("/add_User_phone_no", methods=['POST','GET'])
def add_User_phone_no():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from User_phone_no"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['User_ID','Phone_no'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
qry = "INSERT INTO User_phone_no Values (%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
mydb.commit()
return redirect(url_for('add_page', id='User_phone_no', error=error,success=success))
@app.route("/add_Patient", methods=['POST','GET'])
def add_Patient():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Patient"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['Patient_ID','User_ID','Doctor_ID'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
qry = "INSERT INTO Patient Values (%s,%s,%s,%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
mydb.commit()
return redirect(url_for('add_page', id='Patient', error=error,success=success))
@app.route("/add_Donor", methods=['POST','GET'])
def add_Donor():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Donor"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['Donor_ID','User_ID','Organization_ID'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
mycursor.execute( "START TRANSACTION;" )
qry = "INSERT INTO Donor Values (%s,%s,%s,%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
qry_insert = "insert into Organ_available (Organ_name, Donor_ID) Values (%s,%s) "%(val[1],val[0])
mycursor.execute(qry_insert)
mycursor.execute("COMMIT;")
mydb.commit()
return redirect(url_for('add_page', id='Donor', error=error,success=success))
@app.route("/add_Doctor", methods=['POST','GET'])
def add_Doctor():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Doctor"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['Doctor_ID','Organization_ID'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
qry = "INSERT INTO Doctor Values (%s,%s,%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
mydb.commit()
return redirect(url_for('add_page', id='Doctor', error=error,success=success))
@app.route("/add_Doctor_phone_no", methods=['POST','GET'])
def add_Doctor_phone_no():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Doctor_phone_no"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['Doctor_ID','Phone_no'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
qry = "INSERT INTO Doctor_phone_no Values (%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
mydb.commit()
return redirect(url_for('add_page', id='Doctor_phone_no', error=error,success=success))
@app.route("/add_Organ_available", methods=['POST','GET'])
def add_Organ_available():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Organ_available"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['Organ_ID','Donor_ID'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
qry = "INSERT INTO Organ_available Values (%s,%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
mydb.commit()
return redirect(url_for('add_page', id='Organ_available', error=error,success=success))
@app.route("/add_Organization", methods=['POST','GET'])
def add_Organization():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Organization"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['Government_approved','Organization_ID'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
qry = "INSERT INTO Organization Values (%s,%s,%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
mydb.commit()
return redirect(url_for('add_page', id='Organization', error=error,success=success))
@app.route("/add_Organization_phone_no", methods=['POST','GET'])
def add_Organization_phone_no():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Organization_phone_no"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['Organization_ID','Phone_no'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
qry = "INSERT INTO Organization_phone_no Values (%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
mydb.commit()
return redirect(url_for('add_page', id='Organization_phone_no', error=error,success=success))
@app.route("/add_Organization_head", methods=['POST','GET'])
def add_Organization_head():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Organization_head"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['Employee_ID','Term_length','Organization_ID'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
qry = "INSERT INTO Organization_head Values (%s,%s,%s,%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
mydb.commit()
return redirect(url_for('add_page', id='Organization_head', error=error,success=success))
@app.route("/add_Transaction", methods=['POST','GET'])
def add_Transaction_head():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Transaction"
mycursor.execute(qry)
fields = mycursor.column_names
val = ()
for field in fields:
temp = request.form.get(field)
if field not in ['Patient_ID','Donor_ID','Status','Organ_ID'] and temp != '':
temp = "\'"+temp+"\'"
if temp == '':
temp = 'NULL'
val = val + (temp,)
mycursor.execute( "START TRANSACTION;" )
qry = "INSERT INTO Transaction Values (%s,%s,%s,%s,%s)"%val
print(qry)
success = True
error = False
try:
mycursor.execute(qry)
except:
print("Error : User not Inserted")
error = True
success = False
qry_insert = "delete from Organ_available where Organ_ID = %s "%val[1]
mycursor.execute(qry_insert)
mycursor.execute("COMMIT;")
mydb.commit()
return redirect(url_for('add_page', id='Transaction', error=error,success=success))
#------------------------Update details------------------------------------- #-------------------------------------------------------------
@app.route("/update_user_page",methods = ['POST','GET'])
def update_user_page():
if not session.get('login'):
return redirect( url_for('home') )
qry_upd = "Select * from User"
mycursor.execute(qry_upd)
fields_upd = mycursor.column_names
upd_res=[None]*len(fields_upd)
return render_template('update_user_page.html',fields = fields_upd,res = upd_res)
@app.route("/update_user_details",methods = ['GET','POST'])
def update_details():
if not session.get('login'):
return redirect( url_for('home') )
mycursor.execute("SELECT * from User")
fields = mycursor.column_names
qry = "UPDATE User SET "
for field in fields:
if request.form[field] not in ['None','']:
if field in ['User_ID','Medical_insurance']:
qry = qry + "%s = %s , " %(field,request.form[field])
else:
qry = qry + " %s = \'%s\' , " %(field,request.form[field])
else:
qry = qry + "%s = NULL , " %(field)
qry = qry[:-2]
qry = qry + "WHERE User_ID = %s;" %(request.form['User_ID'])
print(qry)
try:
mycursor.execute(qry)
except:
print("update error")
mydb.commit()
qry2 = "select * from User where User_ID = %s" %(request.form['User_ID'])
mycursor.execute(qry2)
res = mycursor.fetchone()
qry = "Select * from User where User.User_ID = %s" %(request.form['User_ID'])
qry1 = "Select * from User_phone_no where User_ID = %s" %(request.form['User_ID'])
mycursor.execute(qry)
not_found=False
res=()
if(mycursor.rowcount > 0):
res = mycursor.fetchone()
else:
not_found=True
fields = mycursor.column_names
qry_upd = "Select * from User where User_ID = %s" %(request.form['User_ID'])
mycursor.execute(qry_upd)
upd_res = ()
if(mycursor.rowcount > 0):
upd_res = mycursor.fetchone()
fields_upd = mycursor.column_names
mycursor.execute(qry1)
phone_no = mycursor.fetchall()
qry_pat = "select Patient_ID, organ_req, reason_of_procurement, Doctor_name from Patient inner join Doctor on Doctor.Doctor_ID = Patient.Doctor_ID and User_ID = %s" %(request.form['User_ID'])
qry_don = "select Donor_ID, organ_donated, reason_of_donation, Organization_name from Donor inner join Organization on Organization.Organization_ID = Donor.Organization_ID and User_ID = %s" %(request.form['User_ID'])
qry_trans = "select distinct Transaction.Patient_ID, Transaction.Donor_ID, Organ_ID, Date_of_transaction, Status from Transaction, Patient, Donor where (Patient.User_ID = %s and Patient.Patient_ID = Transaction.Patient_ID) or (Donor.User_Id= %s and Donor.Donor_ID = Transaction.Donor_ID)" %((request.form['User_ID']),(request.form['User_ID']))
#
res_pat = ()
res_dnr = ()
res_trans = ()
mycursor.execute(qry_pat)
if(mycursor.rowcount > 0):
res_pat = mycursor.fetchall()
fields_pat = mycursor.column_names
#
mycursor.execute(qry_don)
if(mycursor.rowcount > 0):
res_dnr = mycursor.fetchall()
fields_dnr = mycursor.column_names
#
mycursor.execute(qry_trans)
if(mycursor.rowcount > 0):
res_trans = mycursor.fetchall()
fields_trans = mycursor.column_names
# if("show" in request.form):
return render_template('show_detail_2.html',res = res,fields = fields, not_found=not_found, phone_no = phone_no, res_dnr = res_dnr, res_pat = res_pat,res_trans = res_trans,fields_trans = fields_trans, fields_dnr = fields_dnr, fields_pat = fields_pat)
# return render_template("show_detail.html",res = res,fields=fields,not_found = False)
@app.route("/update_patient_page",methods = ['POST','GET'])
def update_patient_page():
if not session.get('login'):
return redirect( url_for('home') )
qry_upd = "Select * from Patient"
mycursor.execute(qry_upd)
fields_upd = mycursor.column_names
upd_res=[None]*len(fields_upd)
return render_template('update_patient_page.html',fields = fields_upd,res = upd_res)
@app.route("/update_patient_details",methods = ['GET','POST'])
def update_patient_details():
if not session.get('login'):
return redirect( url_for('home') )
mycursor.execute("SELECT * from Patient")
fields = mycursor.column_names
qry = "UPDATE Patient SET "
for field in fields:
if request.form[field] not in ['None','']:
if field in ['User_ID','Doctor_ID','Patient_ID']:
qry = qry + "%s = %s , " %(field,request.form[field])
else:
qry = qry + " %s = \'%s\' , " %(field,request.form[field])
else:
qry = qry + "%s = NULL , " %(field)
qry = qry[:-2]
qry = qry + "WHERE Patient_ID = %s and organ_req = \'%s\';" %(request.form['Patient_ID'],request.form['organ_req'])
print(qry)
try:
mycursor.execute(qry)
except:
print("update error")
mydb.commit()
qry2 = "select * from Patient WHERE Patient_ID = %s and organ_req = \'%s\';" %(request.form['Patient_ID'],request.form['organ_req'])
mycursor.execute(qry2)
res = mycursor.fetchone()
print(res)
print(qry2)
return render_template("show_detail.html",res = res,fields=fields,not_found = False)
@app.route("/update_donor_page",methods = ['POST','GET'])
def update_donor_page():
if not session.get('login'):
return redirect( url_for('home') )
qry_upd = "Select * from Donor"
mycursor.execute(qry_upd)
fields_upd = mycursor.column_names
upd_res=[None]*len(fields_upd)
return render_template('update_donor_page.html',fields = fields_upd,res = upd_res)
@app.route("/update_donor_details",methods = ['GET','POST'])
def update_donor_details():
if not session.get('login'):
return redirect( url_for('home') )
mycursor.execute("SELECT * from Donor")
fields = mycursor.column_names
qry = "UPDATE Donor SET "
for field in fields:
if request.form[field] not in ['None','']:
if field in ['User_ID','Organization_ID','Donor_ID']:
qry = qry + "%s = %s , " %(field,request.form[field])
else:
qry = qry + " %s = \'%s\' , " %(field,request.form[field])
else:
qry = qry + "%s = NULL , " %(field)
qry = qry[:-2]
qry = qry + "WHERE Donor_ID = %s and organ_donated = \"%s\";" %(request.form['Donor_ID'],request.form['organ_donated'])
print(qry)
try:
mycursor.execute(qry)
except:
print("update error")
mydb.commit()
qry2 = "select * from Patient WHERE Donor_ID = %s and organ_donated = \"%s\";" %(request.form['Donor_ID'],request.form['organ_donated'])
mycursor.execute(qry2)
res = mycursor.fetchone()
print(res)
print(qry2)
return render_template("show_detail.html",res = res,fields=fields,not_found = False)
@app.route("/update_doctor_page",methods = ['POST','GET'])
def update_doctor_page():
if not session.get('login'):
return redirect( url_for('home') )
qry_upd = "Select * from Doctor"
mycursor.execute(qry_upd)
fields_upd = mycursor.column_names
upd_res=[None]*len(fields_upd)
return render_template('update_doctor_page.html',fields = fields_upd,res = upd_res)
@app.route("/update_doctor_details",methods = ['GET','POST'])
def update_doctor_details():
if not session.get('login'):
return redirect( url_for('home') )
mycursor.execute("SELECT * from Doctor")
fields = mycursor.column_names
qry = "UPDATE Doctor SET "
for field in fields:
if request.form[field] not in ['None','']:
if field in ['Doctor_ID','Organization_ID']:
qry = qry + "%s = %s , " %(field,request.form[field])
else:
qry = qry + " %s = \'%s\' , " %(field,request.form[field])
else:
qry = qry + "%s = NULL , " %(field)
qry = qry[:-2]
qry = qry + "WHERE Doctor_ID = %s;" %(request.form['Doctor_ID'])
print(qry)
try:
mycursor.execute(qry)
except:
print("update error")
return render_template('error_page.html')
mydb.commit()
qry2 = "select * from Doctor WHERE Doctor_ID = %s;" %(request.form['Doctor_ID'])
mycursor.execute(qry2)
res = mycursor.fetchone()
return render_template("show_detail.html",res = res,fields=fields,not_found = False)
@app.route("/update_organization_page",methods = ['POST','GET'])
def update_organization_page():
if not session.get('login'):
return redirect( url_for('home') )
qry_upd = "Select * from Organization"
mycursor.execute(qry_upd)
fields_upd = mycursor.column_names
upd_res=[None]*len(fields_upd)
return render_template('update_organization_page.html',fields = fields_upd,res = upd_res)
@app.route("/update_organization_details",methods = ['GET','POST'])
def update_organization_details():
if not session.get('login'):
return redirect( url_for('home') )
mycursor.execute("SELECT * from Organization")
fields = mycursor.column_names
qry = "UPDATE Organization SET "
for field in fields:
if request.form[field] not in ['None','']:
if field in ['Organization_ID','Government_approved']:
qry = qry + "%s = %s , " %(field,request.form[field])
else:
qry = qry + " %s = \'%s\' , " %(field,request.form[field])
else:
qry = qry + "%s = NULL , " %(field)
qry = qry[:-2]
qry = qry + "WHERE Organization_ID = %s;" %(request.form['Organization_ID'])
print(qry)
try:
mycursor.execute(qry)
except:
print("update error")
return render_template('error_page.html')
mydb.commit()
qry2 = "select * from Organization WHERE Organization_ID = %s;" %(request.form['Organization_ID'])
mycursor.execute(qry2)
res = mycursor.fetchone()
return render_template("show_detail.html",res = res,fields=fields,not_found = False)
# @app.route("/update_organization_head_page",methods = ['POST','GET'])
# def update_organization_head_page():
# if not session.get('login'):
# return redirect( url_for('home') )
# qry_upd = "Select * from Organization_head"
# mycursor.execute(qry_upd)
# fields_upd = mycursor.column_names
# upd_res=[None]*len(fields_upd)
# return render_template('update_organization_head_page.html',fields = fields_upd,res = upd_res)
# @app.route("/update_organization_head_details",methods = ['GET','POST'])
# def update_organization_head_details():
# if not session.get('login'):
# return redirect( url_for('home') )
# mycursor.execute("SELECT * from Organization_head")
# fields = mycursor.column_names
# qry = "UPDATE Organization_head SET "
# for field in fields:
# if request.form[field] not in ['None','']:
# if field in ['Organization_ID','Employee_ID','Term_length']:
# qry = qry + "%s = %s , " %(field,request.form[field])
# else:
# qry = qry + " %s = \'%s\' , " %(field,request.form[field])
# else:
# qry = qry + "%s = NULL , " %(field)
# qry = qry[:-2]
# qry = qry + "WHERE Organization_ID = %s and Employee_ID = %s;" %(request.form['Organization_ID'],request.form['Employee_ID'])
# print(qry)
# try:
# mycursor.execute(qry)
# except:
# return render_template('error_page.html',qry=qry)
# mydb.commit()
# qry2 = "select * from Organization WHERE Organization_ID = %s and Employee_ID = %s;" %(request.form['Organization_ID'],request.form['Employee_ID'])
# mycursor.execute(qry2)
# res = mycursor.fetchone()
# return render_template("show_detail.html",res = res,fields=fields,not_found = False)
#----------------------------Logout-----------------------------------------
@app.route("/logout", methods=['POST','GET'])
def logout():
session['login'] = False
session['isAdmin'] = False
return redirect("/login")
#-----------------------Searching Information------------------------------
@app.route("/search_User_details",methods=['GET','POST'])
def search_User_details():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from User"
mycursor.execute(qry)
fields = mycursor.column_names
res = mycursor.fetchall()
return render_template('/search_and_show_list.html',res=res,fields=fields)
@app.route("/search_Patient_details",methods=['GET','POST'])
def search_Patient_details():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Patient"
mycursor.execute(qry)
fields = mycursor.column_names
res = mycursor.fetchall()
return render_template('/search_and_show_list.html',res=res,fields=fields)
@app.route("/search_Donor_details",methods=['GET','POST'])
def search_Donor_details():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Donor"
mycursor.execute(qry)
fields = mycursor.column_names
res = mycursor.fetchall()
return render_template('/search_and_show_list.html',res=res,fields=fields)
@app.route("/search_Organ_details",methods=['GET','POST'])
def search_Organ_details():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Organ_available"
mycursor.execute(qry)
fields = mycursor.column_names
res = mycursor.fetchall()
return render_template('/search_and_show_list.html',res=res,fields=fields)
@app.route("/search_Organization_details",methods=['GET','POST'])
def search_Organization_details():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Organization"
mycursor.execute(qry)
fields = mycursor.column_names
res = mycursor.fetchall()
return render_template('/search_and_show_list.html',res=res,fields=fields)
@app.route("/search_Organization_head_details",methods=['GET','POST'])
def search_Organization_head_details():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Organization_head"
mycursor.execute(qry)
fields = mycursor.column_names
res = mycursor.fetchall()
return render_template('/search_and_show_list.html',res=res,fields=fields)
@app.route("/search_Doctor_details",methods=['GET','POST'])
def search_Doctor_details():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Doctor"
mycursor.execute(qry)
fields = mycursor.column_names
res = mycursor.fetchall()
return render_template('/search_and_show_list.html',res=res,fields=fields)
@app.route("/search_Transaction",methods=['GET','POST'])
def search_Transaction_details():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from Transaction"
mycursor.execute(qry)
fields = mycursor.column_names
res = mycursor.fetchall()
return render_template('/search_and_show_list.html',res=res,fields=fields)
@app.route("/search_log",methods=['GET','POST'])
def search_log_details():
if not session.get('login'):
return redirect( url_for('home') )
qry = "SELECT * from log"
mycursor.execute(qry)
fields = mycursor.column_names
res = mycursor.fetchall()
return render_template('/search_and_show_list.html',res=res,fields=fields)
#---------------------Remove Pages--------------------------------------
@app.route('/remove_user',methods=['GET','POST'])
def remove_user():
if not session.get('login'):
return redirect( url_for('home') )
return render_template('/remove_user.html')
@app.route('/remove_patient',methods=['GET','POST'])
def remove_hostel():
if not session.get('login'):
return redirect( url_for('home') )
return render_template('/remove_patient.html')
@app.route('/remove_donor',methods=['GET','POST'])
def remove_room():
if not session.get('login'):
return redirect( url_for('home') )
return render_template('/remove_donor.html')
@app.route('/remove_doctor',methods=['GET','POST'])
def remove_doctor():
if not session.get('login'):
return redirect( url_for('home') )
return render_template('/remove_doctor.html')
@app.route('/remove_organization',methods=['GET','POST'])
def remove_organization():
if not session.get('login'):
return redirect( url_for('home') )
return render_template('/remove_organization.html')
@app.route('/remove_organization_head',methods=['GET','POST'])
def remove_organization_head():
if not session.get('login'):
return redirect( url_for('home') )
return render_template('/remove_organization_head.html')
#----------------Actual Deletion from database------------------------
@app.route('/del_user',methods=['GET','POST'])
def del_hostel():
if not session.get('login'):
return redirect( url_for('home') )
qry = "delete from User where User_ID="+str(request.form['User_ID'])
print(qry)
try:
mycursor.execute(qry)
except:
print("Error in deletion")
mydb.commit()
return redirect( url_for('home') )
@app.route('/del_patient',methods=['GET','POST'])
def del_patient():
if not session.get('login'):
return redirect( url_for('home') )
qry = "delete from Patient where Patient_ID="+str(request.form['Patient_ID'])+" and organ_req=\'%s\'"%(request.form['organ_req'])
print(qry)
try:
mycursor.execute(qry)
except:
print("Error in deletion")
mydb.commit()
return redirect( url_for('home') )
@app.route('/del_donor',methods=['GET','POST'])
def del_donor():
if not session.get('login'):
return redirect( url_for('home') )
qry = "delete from Donor where Donor_ID="+str(request.form['Donor_ID'])+" and organ_donated=\'%s\'" %request.form['organ_donated']
try:
mycursor.execute(qry)
except:
print("Error in deletion")
mydb.commit()
return redirect( url_for('home') )
@app.route('/del_doctor',methods=['GET','POST'])
def del_doctor():
if not session.get('login'):
return redirect( url_for('home') )
qry = "delete from Doctor where Doctor_ID="+str(request.form['Doctor_ID'])
try:
mycursor.execute(qry)
except:
print("Error in deletion")
mydb.commit()
return redirect( url_for('home') )