10
10
11
11
# Load Excel database
12
12
disease_df = pd .read_excel (os .path .join (script_dir , 'diseases.xlsx' ), sheet_name = 'Disease' )
13
- patient_df = pd .read_excel (os .path .join (script_dir , 'database.xlsx' ), sheet_name = 'patients' )
14
- doctor_df = pd .read_excel (os .path .join (script_dir , 'database.xlsx' ), sheet_name = 'doctors' )
13
+ users_df = pd .read_excel (os .path .join (script_dir , 'database.xlsx' ), sheet_name = 'users' )
15
14
16
15
# Ensure proper column types
17
- patient_df ['Diagnosis' ] = patient_df ['Diagnosis' ].astype (str )
18
- if 'Appointment Slot' not in patient_df .columns :
19
- patient_df ['Appointment Slot' ] = ''
20
- if 'Preferred Doctor' not in patient_df .columns :
21
- patient_df ['Preferred Doctor' ] = ''
22
-
23
- # Ensure 'Name' column exists in doctor_df
24
- if 'Name' not in doctor_df .columns :
25
- doctor_df ['Name' ] = doctor_df ['Username' ] # or another appropriate default value
26
-
27
- # Ensure 'Specialization' column exists in doctor_df
28
- if 'Specialization' not in doctor_df .columns :
29
- doctor_df ['Specialization' ] = '' # or another appropriate default value
16
+ users_df ['Diagnosis' ] = users_df ['Diagnosis' ].astype (str )
17
+ if 'Appointment Slot' not in users_df .columns :
18
+ users_df ['Appointment Slot' ] = ''
19
+ if 'Preferred Doctor' not in users_df .columns :
20
+ users_df ['Preferred Doctor' ] = ''
30
21
31
22
# Main root window
32
23
root = tk .Tk ()
@@ -77,12 +68,7 @@ def show_login():
77
68
password_entry = ttk .Entry (frame , show = '*' )
78
69
password_entry .pack (pady = 5 )
79
70
80
- ttk .Label (frame , text = 'User Type' ).pack (pady = 5 )
81
- user_type_var = tk .StringVar (value = 'Patient' )
82
- ttk .Radiobutton (frame , text = 'Patient' , variable = user_type_var , value = 'Patient' ).pack (pady = 5 )
83
- ttk .Radiobutton (frame , text = 'Doctor' , variable = user_type_var , value = 'Doctor' ).pack (pady = 5 )
84
-
85
- login_btn = ttk .Button (frame , text = 'Login' , command = lambda : authenticate_user (username_entry , password_entry , user_type_var ))
71
+ login_btn = ttk .Button (frame , text = 'Login' , command = lambda : authenticate_user (username_entry , password_entry ))
86
72
login_btn .pack (pady = 10 )
87
73
88
74
signup_btn = ttk .Button (frame , text = 'Sign Up' , command = lambda : show_view ('signup' ))
@@ -104,99 +90,76 @@ def show_signup():
104
90
password_entry = ttk .Entry (frame , show = '*' )
105
91
password_entry .pack (pady = 5 )
106
92
107
- ttk .Label (frame , text = 'User Type' ).pack (pady = 5 )
108
- user_type_var = tk .StringVar (value = 'Patient' )
109
- ttk .Radiobutton (frame , text = 'Patient' , variable = user_type_var , value = 'Patient' ).pack (pady = 5 )
110
- ttk .Radiobutton (frame , text = 'Doctor' , variable = user_type_var , value = 'Doctor' ).pack (pady = 5 )
111
-
112
- specialization_label = ttk .Label (frame , text = 'Specialization' )
113
- specialization_entry = ttk .Entry (frame )
114
-
115
- city_label = ttk .Label (frame , text = 'City' )
116
- city_label .pack (pady = 5 )
93
+ ttk .Label (frame , text = 'City' ).pack (pady = 5 )
117
94
city_entry = ttk .Entry (frame )
118
95
city_entry .pack (pady = 5 )
119
96
120
97
ttk .Label (frame , text = 'Address' ).pack (pady = 5 )
121
98
address_entry = ttk .Entry (frame )
122
99
address_entry .pack (pady = 5 )
123
100
124
- def update_specialization_field (* args ):
125
- if user_type_var .get () == 'Doctor' :
126
- specialization_label .pack (pady = 5 , before = city_label )
127
- specialization_entry .pack (pady = 5 , before = city_label )
128
- else :
129
- specialization_label .pack_forget ()
130
- specialization_entry .pack_forget ()
131
-
132
- user_type_var .trace ('w' , update_specialization_field )
101
+ ttk .Label (frame , text = 'Specialization (if Doctor)' ).pack (pady = 5 )
102
+ specialization_entry = ttk .Entry (frame )
103
+ specialization_entry .pack (pady = 5 )
133
104
134
- signup_btn = ttk .Button (frame , text = 'Sign Up' , command = lambda : register_user (name_entry , username_entry , password_entry , user_type_var , city_entry , address_entry , specialization_entry ))
105
+ signup_btn = ttk .Button (frame , text = 'Sign Up' , command = lambda : register_user (name_entry , username_entry , password_entry , city_entry , address_entry , specialization_entry ))
135
106
signup_btn .pack (pady = 10 )
136
107
137
108
login_btn = ttk .Button (frame , text = 'Back to Login' , command = lambda : show_view ('login' ))
138
109
login_btn .pack (pady = 10 )
139
110
140
- def register_user (name_entry , username_entry , password_entry , user_type_var , city_entry , address_entry , specialization_entry ):
141
- global patient_df
142
- global doctor_df
111
+ def register_user (name_entry , username_entry , password_entry , city_entry , address_entry , specialization_entry ):
112
+ global users_df
143
113
144
114
name = name_entry .get ()
145
115
username = username_entry .get ()
146
116
password = password_entry .get ()
147
- user_type = user_type_var .get ()
148
117
city = city_entry .get ()
149
118
address = address_entry .get ()
119
+ user_type = 'Doctor' if specialization_entry .get () else 'Patient'
150
120
specialization = specialization_entry .get () if user_type == 'Doctor' else ''
151
121
152
122
if not name or not username or not password or not city or not address or (user_type == 'Doctor' and not specialization ):
153
123
messagebox .showerror ('Error' , 'All fields are required.' )
154
124
return
155
125
156
- if user_type == 'Patient' :
157
- if username in patient_df ['Username' ].values :
158
- messagebox .showerror ('Error' , 'Username already exists.' )
159
- return
160
- new_user = pd .DataFrame ([[name , username , password , '' , '' , city , address ]], columns = ['Name' , 'Username' , 'Password' , 'Diagnosis' , 'Appointment Slot' , 'City' , 'Address' ])
161
- patient_df = pd .concat ([patient_df , new_user ], ignore_index = True )
162
- elif user_type == 'Doctor' :
163
- if username in doctor_df ['Username' ].values :
164
- messagebox .showerror ('Error' , 'Username already exists.' )
165
- return
166
- new_user = pd .DataFrame ([[name , username , password , '' , city , address , specialization ]], columns = ['Name' , 'Username' , 'Password' , 'Assigned Patients' , 'City' , 'Address' , 'Specialization' ])
167
- doctor_df = pd .concat ([doctor_df , new_user ], ignore_index = True )
126
+ if username in users_df ['Username' ].values :
127
+ messagebox .showerror ('Error' , 'Username already exists.' )
128
+ return
129
+
130
+ new_user = pd .DataFrame ([[name , username , password , address , city , '' , '' , '' , user_type , specialization , '' , '' ]],
131
+ columns = ['Name' , 'Username' , 'Password' , 'Address' , 'City' , 'Diagnosis' , 'Appointment Slot' , 'Preferred Doctor' , 'User Type' , 'Specialization' , 'Assigned Patients' , 'Doctor ID' ])
132
+ users_df = pd .concat ([users_df , new_user ], ignore_index = True )
168
133
169
134
save_data ()
170
135
messagebox .showinfo ('Success' , 'User registered successfully.' )
171
136
show_view ('login' )
172
137
173
- def authenticate_user (username_entry , password_entry , user_type_var ):
138
+ def authenticate_user (username_entry , password_entry ):
174
139
global current_user
175
140
current_user = None # Reset current_user on each login attempt
176
141
177
142
username = username_entry .get ()
178
143
password = password_entry .get ()
179
- user_type = user_type_var .get ()
180
144
181
- if user_type == 'Patient' :
182
- user = patient_df [(patient_df ['Username' ] == username ) & (patient_df ['Password' ] == password )]
183
- if not user .empty :
184
- current_user = username
145
+ user = users_df [(users_df ['Username' ] == username ) & (users_df ['Password' ] == password )]
146
+ if not user .empty :
147
+ current_user = username
148
+ user_type = user ['User Type' ].values [0 ]
149
+ if user_type == 'Patient' :
185
150
show_view ('patient' )
186
- else :
187
- messagebox .showerror ('Error' , 'Invalid username or password.' )
188
- elif user_type == 'Doctor' :
189
- doctor = doctor_df [(doctor_df ['Username' ] == username ) & (doctor_df ['Password' ] == password )]
190
- if not doctor .empty :
191
- current_user = username
151
+ elif user_type == 'Doctor' :
192
152
show_view ('doctor' )
193
- else :
194
- messagebox .showerror ('Error' , 'Invalid username or password.' )
153
+ else :
154
+ messagebox .showerror ('Error' , 'Invalid username or password.' )
195
155
196
156
def show_patient_dashboard ():
197
157
global results_frame
198
158
frame = ttk .Frame (root , padding = "20" )
199
159
frame .pack (fill = 'both' , expand = True )
160
+ ttk .Label (frame , text = f'Welcome, { current_user } ' ).pack (pady = 10 )
161
+ patient_info = users_df [users_df ['Username' ] == current_user ].iloc [0 ]
162
+ ttk .Label (frame , text = f'Name: { patient_info ["Name" ]} ' ).pack (pady = 5 )
200
163
201
164
# Load and display image
202
165
img = Image .open (os .path .join (script_dir , 'patient_dashboard_image.png' ))
@@ -215,6 +178,7 @@ def show_patient_dashboard():
215
178
216
179
results_frame = ttk .Frame (frame )
217
180
results_frame .pack (pady = 10 , fill = 'both' , expand = True )
181
+
218
182
def submit_diagnosis (diagnosis_entry ):
219
183
symptoms = [s .strip ().lower () for s in diagnosis_entry .get ().split (',' )]
220
184
disease_df ['Symptoms' ] = disease_df ['Symptoms' ].str .strip ().str .lower ()
@@ -228,9 +192,6 @@ def submit_diagnosis(diagnosis_entry):
228
192
update_table (results )
229
193
save_patient_data ()
230
194
231
- import tkinter as tk
232
- from tkinter import ttk
233
-
234
195
def update_table (results ):
235
196
global results_frame
236
197
global confirm_btn
@@ -267,25 +228,33 @@ def show_confirm_button(event, tree):
267
228
confirm_btn .destroy ()
268
229
confirm_btn = ttk .Button (results_frame , text = 'Confirm Selection' , command = lambda : confirm_selection (tree ))
269
230
confirm_btn .pack (pady = 10 , side = 'right' , anchor = 'n' ) # Ensure the button is anchored to the top right
231
+
270
232
def confirm_selection (tree ):
271
- global patient_df
272
233
selected_item = tree .selection ()
273
234
if selected_item :
274
235
selected_disease = tree .item (selected_item [0 ], 'values' )[0 ]
275
- patient_df .loc [patient_df ['Username' ] == current_user , 'Diagnosis' ] = selected_disease
276
- save_patient_data ()
236
+ users_df .loc [users_df ['Username' ] == current_user , 'Diagnosis' ] = selected_disease
237
+ save_data ()
277
238
messagebox .showinfo ('Success' , f'Diagnosis "{ selected_disease } " has been added to your record.' )
278
239
show_view ('select_doctor' )
279
240
280
241
def save_patient_data ():
281
242
try :
282
243
with pd .ExcelWriter (os .path .join (script_dir , 'database.xlsx' ), engine = 'openpyxl' , mode = 'a' , if_sheet_exists = 'replace' ) as writer :
283
- patient_df .to_excel (writer , sheet_name = 'patients ' , index = False )
244
+ users_df .to_excel (writer , sheet_name = 'users ' , index = False )
284
245
except FileNotFoundError :
285
246
messagebox .showerror ('Error' , 'Database file not found. Please check the file path.' )
286
247
except Exception as e :
287
248
messagebox .showerror ('Error' , f'An error occurred: { e } ' )
288
249
250
+ def save_data ():
251
+ try :
252
+ with pd .ExcelWriter (os .path .join (script_dir , 'database.xlsx' ), engine = 'openpyxl' , mode = 'a' , if_sheet_exists = 'replace' ) as writer :
253
+ users_df .to_excel (writer , sheet_name = 'users' , index = False )
254
+ except FileNotFoundError :
255
+ messagebox .showerror ('Error' , 'Database file not found. Please check the file path.' )
256
+ except Exception as e :
257
+ messagebox .showerror ('Error' , f'An error occurred: { e } ' )
289
258
290
259
def show_select_doctor ():
291
260
frame = ttk .Frame (root , padding = "20" )
@@ -294,7 +263,7 @@ def show_select_doctor():
294
263
ttk .Label (frame , text = 'Select Preferred Doctor:' ).pack (pady = 10 )
295
264
296
265
# Get the city of the current patient
297
- patient_city = patient_df .loc [patient_df ['Username' ] == current_user , 'City' ].values [0 ]
266
+ patient_city = users_df .loc [users_df ['Username' ] == current_user , 'City' ].values [0 ]
298
267
299
268
columns = ('Name' , 'Specialization' , 'Address' )
300
269
tree = ttk .Treeview (frame , columns = columns , show = 'headings' )
@@ -303,7 +272,7 @@ def show_select_doctor():
303
272
tree .column (col , width = 200 , anchor = 'w' )
304
273
305
274
# Filter doctors based on the patient's city
306
- for _ , row in doctor_df [ doctor_df ['City' ] == patient_city ].iterrows ():
275
+ for _ , row in users_df [( users_df ['City' ] == patient_city ) & ( users_df [ 'User Type' ] == 'Doctor' ) ].iterrows ():
307
276
name = row ['Name' ]
308
277
specialization = textwrap .fill (str (row ['Specialization' ]), width = 30 )
309
278
address = textwrap .fill (str (row ['Address' ]), width = 30 )
@@ -335,9 +304,6 @@ def show_select_doctor():
335
304
schedule_btn .pack (pady = 10 )
336
305
337
306
def schedule_appointment (tree , slot_var ):
338
- global patient_df
339
- global doctor_df
340
-
341
307
selected_item = tree .selection ()
342
308
if not selected_item :
343
309
messagebox .showerror ('Error' , 'Please select a doctor.' )
@@ -347,14 +313,14 @@ def schedule_appointment(tree, slot_var):
347
313
selected_slot = slot_var .get ()
348
314
349
315
# Check if the selected doctor exists in the DataFrame
350
- doctor_row = doctor_df . loc [ doctor_df ['Name' ] == selected_doctor ]
316
+ doctor_row = users_df [( users_df ['Name' ] == selected_doctor ) & ( users_df [ 'User Type' ] == 'Doctor' ) ]
351
317
if doctor_row .empty :
352
318
messagebox .showerror ('Error' , 'Selected doctor not found.' )
353
319
return
354
320
355
321
doctor_id = doctor_row ['Username' ].values [0 ]
356
- patient_df .loc [patient_df ['Username' ] == current_user , 'Appointment Slot' ] = str (selected_slot )
357
- patient_df .loc [patient_df ['Username' ] == current_user , 'Preferred Doctor' ] = doctor_id
322
+ users_df .loc [users_df ['Username' ] == current_user , 'Appointment Slot' ] = str (selected_slot )
323
+ users_df .loc [users_df ['Username' ] == current_user , 'Preferred Doctor' ] = doctor_id
358
324
359
325
assigned_patients = doctor_row ['Assigned Patients' ].values [0 ]
360
326
if pd .isnull (assigned_patients ):
@@ -363,7 +329,7 @@ def schedule_appointment(tree, slot_var):
363
329
assigned_patients = assigned_patients .split (', ' )
364
330
365
331
assigned_patients .append (current_user )
366
- doctor_df .loc [doctor_df ['Username' ] == doctor_id , 'Assigned Patients' ] = ', ' .join (assigned_patients )
332
+ users_df .loc [users_df ['Username' ] == doctor_id , 'Assigned Patients' ] = ', ' .join (assigned_patients )
367
333
368
334
save_data ()
369
335
messagebox .showinfo ('Appointment' , f'Appointment scheduled with Dr. { selected_doctor } at { selected_slot } ' )
@@ -374,6 +340,7 @@ def schedule_appointment(tree, slot_var):
374
340
375
341
# Redirect to login view
376
342
show_view ('login' )
343
+
377
344
def show_doctor_dashboard ():
378
345
global action_frame
379
346
frame = ttk .Frame (root , padding = "20" )
@@ -390,7 +357,7 @@ def show_doctor_dashboard():
390
357
back_btn .pack (pady = 10 )
391
358
392
359
def load_patient_data (username , frame ):
393
- doc_info = doctor_df [ doctor_df ['Username' ] == username ]
360
+ doc_info = users_df [( users_df ['Username' ] == username ) & ( users_df [ 'User Type' ] == 'Doctor' ) ]
394
361
if doc_info .empty :
395
362
messagebox .showerror ('Error' , 'No doctor data found for the username.' )
396
363
return
@@ -413,7 +380,7 @@ def load_patient_data(username, frame):
413
380
tree .column (col , width = 150 )
414
381
415
382
for patient in assigned_patients :
416
- patient_data = patient_df [ patient_df ['Username' ] == patient ]
383
+ patient_data = users_df [ users_df ['Username' ] == patient ]
417
384
if not patient_data .empty :
418
385
tree .insert ('' , 'end' , values = (patient_data ['Name' ].values [0 ], patient_data ['Diagnosis' ].values [0 ], patient_data ['Appointment Slot' ].values [0 ], patient_data ['Preferred Doctor' ].values [0 ]))
419
386
@@ -430,7 +397,7 @@ def show_action_buttons(event, tree, username, assigned_patients):
430
397
selected_item = tree .selection ()
431
398
if selected_item :
432
399
patient_name = tree .item (selected_item [0 ], 'values' )[0 ]
433
- patient_username = patient_df [ patient_df ['Name' ] == patient_name ]['Username' ].values [0 ]
400
+ patient_username = users_df [ users_df ['Name' ] == patient_name ]['Username' ].values [0 ]
434
401
435
402
# Remove existing buttons if any
436
403
for widget in action_frame .winfo_children ():
@@ -443,13 +410,10 @@ def show_action_buttons(event, tree, username, assigned_patients):
443
410
btn_progress .pack (pady = 5 )
444
411
445
412
def mark_done (patient_username , username , assigned_patients ):
446
- global patient_df
447
- global doctor_df
448
-
449
413
if patient_username in assigned_patients :
450
414
assigned_patients .remove (patient_username )
451
- doctor_df .loc [doctor_df ['Username' ] == username , 'Assigned Patients' ] = ', ' .join (assigned_patients )
452
- patient_df .loc [patient_df ['Username' ] == patient_username , 'Preferred Doctor' ] = ''
415
+ users_df .loc [users_df ['Username' ] == username , 'Assigned Patients' ] = ', ' .join (assigned_patients )
416
+ users_df .loc [users_df ['Username' ] == patient_username , 'Preferred Doctor' ] = ''
453
417
save_data ()
454
418
show_view ('doctor' )
455
419
else :
@@ -458,21 +422,11 @@ def mark_done(patient_username, username, assigned_patients):
458
422
def mark_in_progress (patient_username , assigned_patients ):
459
423
next_patient = assigned_patients [0 ] if assigned_patients else None
460
424
if next_patient :
461
- next_patient_name = patient_df [ patient_df ['Username' ] == next_patient ]['Name' ].values [0 ]
425
+ next_patient_name = users_df [ users_df ['Username' ] == next_patient ]['Name' ].values [0 ]
462
426
messagebox .showinfo ('Next Patient' , f'Next patient: { next_patient_name } ' )
463
427
else :
464
428
messagebox .showinfo ('Next Patient' , 'No more patients in the schedule.' )
465
429
466
- def save_data ():
467
- try :
468
- with pd .ExcelWriter (os .path .join (script_dir , 'database.xlsx' ), engine = 'openpyxl' , mode = 'a' , if_sheet_exists = 'replace' ) as writer :
469
- patient_df .to_excel (writer , sheet_name = 'patients' , index = False )
470
- doctor_df .to_excel (writer , sheet_name = 'doctors' , index = False )
471
- except FileNotFoundError :
472
- messagebox .showerror ('Error' , 'Database file not found. Please check the file path.' )
473
- except Exception as e :
474
- messagebox .showerror ('Error' , f'An error occurred: { e } ' )
475
-
476
430
# Show login view initially
477
431
show_view ('login' )
478
432
0 commit comments