-
Notifications
You must be signed in to change notification settings - Fork 0
/
mia.py
591 lines (510 loc) · 20.6 KB
/
mia.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
from flask import Flask, render_template, request, jsonify, session, redirect, url_for, flash
from flask_mysqldb import MySQL
import MySQLdb.cursors
import json
app = Flask(__name__)
app.static_folder = 'static'
app.secret_key = 'yo'
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = '123'
app.config['MYSQL_DB'] = 'mia'
mysql = MySQL(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/contact')
def contact():
return render_template('contact.html')
@app.route('/about')
def about():
return render_template('aboutus.html')
#doctor sign up
@app.route('/dsign.html',methods=['GET', 'POST'])
def dsign():
if request.method == "POST":
details = request.form
Doc_id = details['Doc_id']
Passwd = details['Passwd']
Name = details['Name']
Specialization = details['Specialization']
Experience = details['Experience']
Qualification = details['Qualification']
Clinic = details['Clinic']
Patient_id = details['Patient_id']
Contact = details['Contact']
cur = mysql.connection.cursor()
try:
cur.execute("INSERT INTO Doctors (Doc_id, Name, Specialization , Experience, Clinic, Qualification, Contact ,Patient_id, Passwd) VALUES (%s, %s , %s , %s , %s , %s, %s, %s, %s)", (Doc_id, Name, Specialization, Experience, Clinic, Qualification, Contact, Patient_id, Passwd))
mysql.connection.commit()
except Exception as e:
flash("Error!! Try Again!")
return render_template('dsign.html',msg=e)
cur.close()
return redirect(url_for('signup'))
return render_template('dsign.html')
#patient sign up
@app.route('/psign.html',methods=['GET', 'POST'])
def psign():
msg= ' '
if request.method == "POST":
details = request.form
Pat_id = details['Pat_id']
passwd = details['passwd']
Name = details['Name']
Contact = details['Contact']
Insurance_id = details['Insurance_id']
Medical_info = details['Medical_info']
Doc_Id = details['Doc_Id']
cur = mysql.connection.cursor()
try:
cur.execute("INSERT INTO Patient(Pat_id, Name, Contact, Insurance_id, Medical_info, Doc_Id, passwd) VALUES (%s, %s , %s , %s , %s , %s, %s)", (Pat_id, Name, Contact, Insurance_id, Medical_info, Doc_Id, passwd))
mysql.connection.commit()
except Exception as e:
flash("Error !! Try again")
return render_template('psign.html', msg=e)
cur.close()
return redirect(url_for('logpat'))
return render_template('psign.html')
#business sign up
@app.route('/esign.html',methods=['GET', 'POST'])
def esign():
if request.method == "POST":
details = request.form
licence= details['licence']
passwd = details['passwd']
Name = details['Name']
Address = details['Address']
owner = details['owner']
cur = mysql.connection.cursor()
try:
cur.execute("INSERT INTO Retailer(licence, Name, Address, owner, passwd) VALUES (%s, %s , %s , %s, %s)", (licence, Name, Address, owner, passwd))
mysql.connection.commit()
except Exception as e:
flash("Error!!!!Try again!")
return render_template('esign.html', msg=e)
cur.close()
return redirect(url_for('logenter'))
return render_template('esign.html')
#doctors sign in
@app.route('/signup.html', methods=['GET', 'POST'])
def signup():
msg = ''
if request.method == "POST":
details = request.form
Doc_id = details['doc_id']
Passwd = details['passwd']
cur = mysql.connection.cursor()
try:
cur.execute("SELECT * FROM Doctors where Doc_id = %s AND Passwd = %s", (Doc_id, Passwd))
username = cur.fetchone()
if username:
session['loggedin'] = True
session['Doc_id'] = username[0]
session['Name'] = username[1]
session['Specialization'] = username[2]
session['Experience'] = username[3]
session['Clinic'] = username[4]
session['Qualification'] = username[5]
session['Contact'] = username[6]
session['Patient_id'] = username[7]
# Redirect to home page
return redirect(url_for('home'))
else :
flash("Incorrect ID or password! Try Again")
except Exception as e:
flash("Incorrect ID or password! Try Again")
return render_template('signup.html',msg=e)
# Show the login form with message (if any)
return render_template('signup.html',msg= msg)
#patient log in
@app.route('/logpat.html', methods=['GET', 'POST'])
def logpat():
msg=' '
if request.method == "POST":
details = request.form
pat_id = details['pat_id']
passwd = details['passwd']
cur = mysql.connection.cursor()
try:
cur.execute("SELECT * FROM Patient where Pat_id = %s and passwd = %s",(pat_id, passwd))
username = cur.fetchone()
if username:
session['loggedin'] = True
session['Pat_id'] = username[0]
session['Name'] = username[1]
session['Contact'] = username[2]
session['Insurance_id'] = username[3]
session['Medical_info'] = username[4]
session['Doc_id'] = username[5]
session['passwd'] = username[6]
# Redirect to home page
return redirect(url_for('phome'))
else :
flash("Try Again ! Invalid username or password")
mysql.connection.commit()
except Exception as e:
flash("Error!!!")
# Account doesnt exist or username/password incorrect
return render_template('logpat.html', msg=e)
cur.close()
return render_template('logpat.html')
#shop log in
@app.route('/logenter.html', methods=['GET', 'POST'])
def logenter():
msg=''
if request.method == "POST":
details = request.form
licence = details['licence']
passwd = details['passwd']
cur = mysql.connection.cursor()
try:
cur.execute("SELECT * FROM Retailer where licence = %s and passwd = %s",(licence, passwd))
username = cur.fetchone()
if username:
session['loggedin'] = True
session['licence'] = username[0]
session['Name'] = username[1]
session['Address'] = username[2]
session['owner'] = username[3]
session['passwd'] = username[4]
# Redirect to home page
return redirect(url_for('ehome'))
else :
flash("Try Again ! Invalid username or password")
mysql.connection.commit()
except Exception as e:
flash("Error!!!")
# Account doesnt exist or username/password incorrect
cur.close()
return render_template('logenter.html')
#doctors home
@app.route('/signup/home')
def home():
data= ""
# Check if user is loggedin
if 'loggedin' in session:
# User is loggedin show them the home page
cur = mysql.connection.cursor()
nocount = 0
args =[session['Doc_id'],0]
try:
cursor = mysql.connection.cursor()
args = ['123',0]
statement = ("CALL noofpatients(%s,@nocount);" %(session['Doc_id']))
cursor.execute(statement)
# cursor.callproc("noofpatients",args)
result = cursor.fetchall()
mysql.connection.commit()
# cursor.close()
# cursor = mysql.connection.cursor()
cursor.execute('SELECT @nocount')
result = cursor.fetchall()
mysql.connection.commit()
except Exception as e:
flash(e)
return render_template('home.html', name=session['Name'], result = result)
# User is not loggedin redirect to login page
return redirect(url_for('signup'))
@app.route('/signup/profile')
def profile():
# Check if user is loggedin
if 'loggedin' in session:
# We need all the account info for the user so we can display it on the profile page
cursor = mysql.connection.cursor()
cursor.execute('SELECT * FROM Doctors WHERE Doc_id = %s', [session['Doc_id']])
username = cursor.fetchone()
# Show the profile page with account info
return render_template('profile.html', username=username)
# User is not loggedin redirect to login page
return redirect(url_for('signup'))
@app.route('/signup/logout')
def logout():
# Remove session data, this will log the user out
session.pop('loggedin', None)
session.pop('Doc_id', None)
session.pop('Name', None)
# Redirect to login page
return redirect(url_for('signup'))
@app.route('/profile/search', methods=['GET', 'POST'])
def search():
if request.method == "POST":
Pat_id = request.form['Pat_id']
# search by pat_id
cur = mysql.connection.cursor()
cur.execute(" SELECT * FROM Patient WHERE Pat_id = %s", [Pat_id])
data = cur.fetchall()
# #all in the search box will return all the tuples
if len(data) == 0 or Pat_id == 'all':
cur.execute("SELECT * from Patient")
data = cur.fetchall()
mysql.connection.commit()
return render_template('search.html', data = data)
return render_template('search.html')
@app.route('/profile/med',methods=['GET', 'POST'])
def med():
msg = ""
if request.method == "POST":
details = request.form
Drug_name = details['Drug_name']
Disease = details['Disease']
shop_id = details['shop_id']
company = details['company']
cur = mysql.connection.cursor()
try:
cur.execute("INSERT INTO Drugs(Drug_name, Disease , Shop_id, company) VALUES (%s, %s , %s , %s)", (Drug_name, Disease , shop_id , company))
mysql.connection.commit()
except Exception as e:
flash(" Error !!!Please check the details again")
cur.close()
return render_template('med.html', msg=e)
return render_template('med.html',msg=msg)
@app.route('/signup/dupdate.html', methods=['GET', 'POST'])
def dupdate():
msg = ""
if request.method == "POST":
details = request.form
# Doc_id = details['Doc_id']
# Passwd = details['Passwd']
Name = details['Name']
Specialization = details['Specialization']
Experience = details['Experience']
Qualification = details['Qualification']
Clinic = details['Clinic']
# Patient_id = details['Patient_id']
Contact = details['Contact']
cur = mysql.connection.cursor()
try:
cur.execute("UPDATE Doctors SET Name = %s , Specialization = %s, Experience = %s, Clinic = %s, Qualification= %s, Contact =%s WHERE Doc_id = %s",(Name,Specialization,Experience,Clinic,Qualification,Contact,[session['Doc_id']]))
mysql.connection.commit()
flash("Updated!!")
except Exception as e:
flash(e)
return render_template('dupdate.html',msg=e)
cur.close()
return render_template('dupdate.html')
#doctors appointment page
@app.route('/signup/appt.html', methods=['POST', 'GET'])
def appt():
msg=' '
if request.method == "POST":
#search by date
date = request.form['date']
cur = mysql.connection.cursor()
try:
cur.execute(" SELECT * FROM Appointment WHERE date = %s", [date])
data = cur.fetchall()
mysql.connection.commit()
# to handle exceptions
except Exception as e:
flash("Try again!!")
return render_template('appt.html',msg=e)
if len(data)==0:
flash("All appointments")
cur.execute(" SELECT * FROM Appointment WHERE doctorID = %s", [session['Doc_id']])
data = cur.fetchall()
return render_template('appt.html', data=data)
cur.close()
return render_template('appt.html')
#--------------------------------------------------------------------------------------------------
#patient route
@app.route('/logpat/phome')
def phome():
# Check if user is loggedin
if 'loggedin' in session:
# User is loggedin show them the home page
return render_template('phome.html', name=session['Name'])
# User is not loggedin redirect to login page
return redirect(url_for('logpat'))
@app.route('/logpat/uprofile')
def uprofile():
# Check if user is loggedin
if 'loggedin' in session:
# We need all the account info for the user so we can display it on the profile page
cursor = mysql.connection.cursor()
cursor.execute('SELECT * FROM Patient WHERE Pat_id = %s', [session['Pat_id']])
username = cursor.fetchone()
# Show the profile page with account info
return render_template('uprofile.html', username=username)
# User is not loggedin redirect to login page
return redirect(url_for('logpat'))
@app.route('/logpat/plogout')
def plogout():
# Remove session data, this will log the user out
session.pop('loggedin', None)
session.pop('Pat_id', None)
session.pop('Name', None)
# Redirect to login page
return redirect(url_for('logpat'))
@app.route('/logpat/pupdate.html', methods=['GET', 'POST'])
def pupdate():
msg = ""
if request.method == "POST":
details = request.form
# Doc_id = details['Doc_id']
# Passwd = details['Passwd']
Name = details['Name']
Medical_info = details['Medical_info']
Insurance_id = details['Insurance_id']
Doc_id = details['Doc_id']
# Clinic = details['Clinic']
# Patient_id = details['Patient_id']
Contact = details['Contact']
cur = mysql.connection.cursor()
try:
cur.execute("UPDATE Patient SET Name = %s , Medical_info = %s, Insurance_id = %s, Doc_id = %s, Contact =%s WHERE Pat_id = %s",(Name,Medical_info,Insurance_id,Doc_id,Contact,[session['Pat_id']]))
mysql.connection.commit()
flash("Updated!!")
except Exception as e:
flash(e)
return render_template('pupdate.html',msg=e)
cur.close()
return render_template('pupdate.html')
@app.route('/uprofile/search', methods=['GET', 'POST'])
def usearch():
if request.method == "POST":
Specialization = request.form['Specialization']
# search by Specialization
cur = mysql.connection.cursor()
cur.execute("SELECT * FROM Doctors WHERE Specialization = %s", [Specialization])
data = cur.fetchall()
# #all in the search box will return all the tuples
if len(data) == 0 or Specialization == 'all':
cur.execute("SELECT * from Doctors")
data = cur.fetchall()
mysql.connection.commit()
return render_template('usearch.html', data = data)
return render_template('usearch.html')
@app.route('/logpat/uappt.html', methods=['POST', 'GET'])
def uappt():
msg=' '
if request.method == "POST":
#search by date
Doc_id = request.form['Doc_id']
date = request.form['date']
starttime = request.form['starttime']
endtime = request.form['endtime']
cur = mysql.connection.cursor()
try:
cur.execute("INSERT INTO Appointment (doctorID,date,startTime,endTime,Pat_id) VALUES(%s , %s ,%s, %s, %s )" ,(Doc_id,date,starttime,endtime,session['Pat_id'],))
cur.execute(" SELECT * FROM Appointment WHERE date = %s", [date])
data = cur.fetchall()
mysql.connection.commit()
# to handle exceptions
except Exception as e:
flash(e)
return render_template('uappt.html',msg=e)
return render_template('uappt.html', data=data)
cur.close()
return render_template('uappt.html')
#-------------------------------------------------------------------------------------------------------
#Business Man
#home
@app.route('/logenter/ehome')
def ehome():
# Check if user is loggedin
if 'loggedin' in session:
# User is loggedin show them the home page
return render_template('ehome.html', name=session['Name'])
# User is not loggedin redirect to login page
return redirect(url_for('logenter'))
#profile
@app.route('/logenter/eprofile')
def eprofile():
# Check if user is loggedin
if 'loggedin' in session:
# We need all the account info for the user so we can display it on the profile page
cursor = mysql.connection.cursor()
cursor.execute('SELECT * FROM Retailer WHERE licence= %s', [session['licence']])
username = cursor.fetchone()
# Show the profile page with account info
return render_template('eprofile.html', username=username)
# User is not loggedin redirect to login page
return redirect(url_for('logenter'))
#logout
@app.route('/logenter/elogout')
def elogout():
# Remove session data, this will log the user out
session.pop('loggedin', None)
session.pop('licence', None)
session.pop('Name', None)
# Redirect to login page
return redirect(url_for('logenter'))
#update profile
@app.route('/logenter/eupdate.html', methods=['GET', 'POST'])
def eupdate():
msg = ""
if request.method == "POST":
details = request.form
# Doc_id = details['Doc_id']
# Passwd = details['Passwd']
Name = details['Name']
Address = details['Address']
owner = details['owner']
passwd= details['passwd']
# Clinic = details['Clinic']
# Patient_id = details['Patient_id']
cur = mysql.connection.cursor()
try:
cur.execute("UPDATE Retailer SET Name = %s , Address = %s, owner = %s, passwd = %s WHERE licence = %s",(Name,Address,owner,passwd,[session['licence']]))
mysql.connection.commit()
flash("Updated!! Please Log In Again")
except Exception as e:
flash(e)
return render_template('eupdate.html',msg=e)
cur.close()
return render_template('eupdate.html')
# to check alternative medicine
@app.route('/eprofile/esearch', methods=['GET', 'POST'])
def esearch():
if request.method == "POST":
Disease = request.form['Disease']
# search by Disease
cur = mysql.connection.cursor()
cur.execute("SELECT * FROM Drugs WHERE Disease = %s", [Disease])
data = cur.fetchall()
# the search box will return no tuples if nothing is entered else it shows error
if len(data) == 0:
flash("Something Went Wrong. Please try again")
mysql.connection.commit()
return render_template('esearch.html', data = data)
return render_template('esearch.html')
# to update the stocks
@app.route('/eprofile/stock',methods=['GET', 'POST'])
def stock():
msg = ""
if request.method == "POST":
details = request.form
Shop_id = details['Shop_id']
Drug = details['Drug']
price = details['price']
quantity = details['quantity']
cur = mysql.connection.cursor()
try:
cur.execute("INSERT INTO Stock (Shop_id, Drug ,price, quantity) VALUES (%s,%s,%s,%s)", (Shop_id,Drug,price,quantity))
mysql.connection.commit()
flash("Updated!!")
except Exception as e:
flash(" Error !!!Please check the details again")
cur.close()
return render_template('stock.html')
return render_template('stock.html')
# to display the inventory / stocks
@app.route('/eprofile/inventory', methods=['GET', 'POST'])
def inventory():
if request.method == "POST":
Drug = request.form['Drug']
# search by Drug name
cur = mysql.connection.cursor()
cur.execute("SELECT * FROM Stock WHERE Drug = %s", [Drug])
data = cur.fetchall()
# the search box will return no tuples if nothing is entered else it shows error
if Drug=='all' or len(data)==0:
cur.execute("SELECT * from Stock")
data = cur.fetchall()
flash("Displaying entire Inventory")
mysql.connection.commit()
return render_template('inventory.html', data = data)
return render_template('inventory.html')
if __name__ == "__main__":
app.run()