9
9
script_dir = os .path .dirname (os .path .abspath (__file__ ))
10
10
11
11
# Load Excel database
12
- disease_df = pd .read_excel (os .path .join (script_dir , 'diseases.xlsx' ), sheet_name = 'Disease' )
13
12
users_df = pd .read_excel (os .path .join (script_dir , 'database.xlsx' ), sheet_name = 'users' )
14
13
15
14
# Ensure proper column types
16
- users_df ['Diagnosis ' ] = users_df ['Diagnosis ' ].astype (str )
15
+ users_df ['Symptoms ' ] = users_df ['Symptoms ' ].astype (str )
17
16
if 'Appointment Slot' not in users_df .columns :
18
17
users_df ['Appointment Slot' ] = ''
19
18
if 'Preferred Doctor' not in users_df .columns :
@@ -157,9 +156,6 @@ def show_patient_dashboard():
157
156
global results_frame
158
157
frame = ttk .Frame (root , padding = "20" )
159
158
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 )
163
159
164
160
# Load and display image
165
161
img = Image .open (os .path .join (script_dir , 'patient_dashboard_image.png' ))
@@ -180,65 +176,13 @@ def show_patient_dashboard():
180
176
results_frame .pack (pady = 10 , fill = 'both' , expand = True )
181
177
182
178
def submit_diagnosis (diagnosis_entry ):
183
- symptoms = [s .strip ().lower () for s in diagnosis_entry .get ().split (',' )]
184
- disease_df ['Symptoms' ] = disease_df ['Symptoms' ].str .strip ().str .lower ()
185
-
186
- results = []
187
- for symptom in symptoms :
188
- result = disease_df [disease_df ['Symptoms' ].str .contains (symptom , case = False , na = False )]
189
- if not result .empty :
190
- results .append (result )
191
-
192
- update_table (results )
193
- save_patient_data ()
194
-
195
- def update_table (results ):
196
- global results_frame
197
- global confirm_btn
198
- for widget in results_frame .winfo_children ():
199
- widget .destroy ()
200
-
201
- columns = ('Disease' , 'Symptoms' , 'Severity' , 'Initial Treatment' )
202
- tree = ttk .Treeview (results_frame , columns = columns , show = 'headings' )
203
- for col in columns :
204
- tree .heading (col , text = col )
205
- tree .column (col , width = 150 )
206
- for result in results :
207
- for _ , row in result .iterrows ():
208
- tree .insert ('' , 'end' , values = (row ['Disease' ], row ['Symptoms' ], row ['Severity' ], row ['Initial Treatment' ]))
209
- tree .pack (side = 'left' , fill = 'both' , expand = True )
210
-
211
- scrollbar = ttk .Scrollbar (results_frame , orient = 'vertical' , command = tree .yview )
212
- scrollbar .pack (side = 'right' , fill = 'y' )
213
- tree .configure (yscrollcommand = scrollbar .set )
214
-
215
- # Create and display the Confirm Selection button
216
- if confirm_btn :
217
- confirm_btn .destroy ()
218
- confirm_btn = ttk .Button (results_frame , text = 'Confirm Selection' , command = lambda : confirm_selection (tree ))
219
- confirm_btn .pack (pady = 10 , side = 'right' , anchor = 'n' ) # Ensure the button is anchored to the top right
220
-
221
- tree .bind ('<<TreeviewSelect>>' , lambda event : show_confirm_button (event , tree ))
222
-
223
- def show_confirm_button (event , tree ):
224
- global confirm_btn
225
- selected_item = tree .selection ()
226
- if selected_item :
227
- if confirm_btn :
228
- confirm_btn .destroy ()
229
- confirm_btn = ttk .Button (results_frame , text = 'Confirm Selection' , command = lambda : confirm_selection (tree ))
230
- confirm_btn .pack (pady = 10 , side = 'right' , anchor = 'n' ) # Ensure the button is anchored to the top right
231
-
232
- def confirm_selection (tree ):
233
- selected_item = tree .selection ()
234
- if selected_item :
235
- selected_disease = tree .item (selected_item [0 ], 'values' )[0 ]
236
- users_df .loc [users_df ['Username' ] == current_user , 'Diagnosis' ] = selected_disease
237
- save_data ()
238
- messagebox .showinfo ('Success' , f'Diagnosis "{ selected_disease } " has been added to your record.' )
239
- show_view ('select_doctor' )
179
+ symptoms = diagnosis_entry .get ().strip ().lower ()
180
+ users_df .loc [users_df ['Username' ] == current_user , 'Symptoms' ] = symptoms
181
+ save_data ()
182
+ messagebox .showinfo ('Success' , 'Symptoms have been added to your record.' )
183
+ show_view ('select_doctor' )
240
184
241
- def save_patient_data ():
185
+ def save_data ():
242
186
try :
243
187
with pd .ExcelWriter (os .path .join (script_dir , 'database.xlsx' ), engine = 'openpyxl' , mode = 'a' , if_sheet_exists = 'replace' ) as writer :
244
188
users_df .to_excel (writer , sheet_name = 'users' , index = False )
@@ -247,7 +191,7 @@ def save_patient_data():
247
191
except Exception as e :
248
192
messagebox .showerror ('Error' , f'An error occurred: { e } ' )
249
193
250
- def save_data ():
194
+ def save_patient_data ():
251
195
try :
252
196
with pd .ExcelWriter (os .path .join (script_dir , 'database.xlsx' ), engine = 'openpyxl' , mode = 'a' , if_sheet_exists = 'replace' ) as writer :
253
197
users_df .to_excel (writer , sheet_name = 'users' , index = False )
@@ -269,13 +213,13 @@ def show_select_doctor():
269
213
tree = ttk .Treeview (frame , columns = columns , show = 'headings' )
270
214
for col in columns :
271
215
tree .heading (col , text = col , anchor = 'w' )
272
- tree .column (col , width = 200 , anchor = 'w' )
216
+ tree .column (col , width = 300 , anchor = 'w' )
273
217
274
218
# Filter doctors based on the patient's city
275
219
for _ , row in users_df [(users_df ['City' ] == patient_city ) & (users_df ['User Type' ] == 'Doctor' )].iterrows ():
276
220
name = row ['Name' ]
277
- specialization = textwrap .fill (str (row ['Specialization' ]), width = 30 )
278
- address = textwrap .fill (str (row ['Address' ]), width = 30 )
221
+ specialization = textwrap .fill (str (row ['Specialization' ]), width = 90 )
222
+ address = textwrap .fill (str (row ['Address' ]), width = 50 )
279
223
tree .insert ('' , 'end' , values = (name , specialization , address ))
280
224
281
225
tree .pack (side = 'left' , fill = 'both' , expand = True )
@@ -373,7 +317,7 @@ def load_patient_data(username, frame):
373
317
ttk .Label (frame , text = 'No assigned patients found.' ).pack (pady = 10 )
374
318
return
375
319
376
- columns = ('Name' , 'Diagnosis ' , 'Appointment Slot' , 'Preferred Doctor ID' )
320
+ columns = ('Name' , 'Symptoms ' , 'Appointment Slot' , 'Preferred Doctor ID' )
377
321
tree = ttk .Treeview (frame , columns = columns , show = 'headings' )
378
322
for col in columns :
379
323
tree .heading (col , text = col )
@@ -382,7 +326,7 @@ def load_patient_data(username, frame):
382
326
for patient in assigned_patients :
383
327
patient_data = users_df [users_df ['Username' ] == patient ]
384
328
if not patient_data .empty :
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 ]))
329
+ tree .insert ('' , 'end' , values = (patient_data ['Name' ].values [0 ], patient_data ['Symptoms ' ].values [0 ], patient_data ['Appointment Slot' ].values [0 ], patient_data ['Preferred Doctor' ].values [0 ]))
386
330
387
331
tree .pack (side = 'left' , fill = 'both' , expand = True )
388
332
0 commit comments