99script_dir = os .path .dirname (os .path .abspath (__file__ ))
1010
1111# Load Excel database
12- disease_df = pd .read_excel (os .path .join (script_dir , 'diseases.xlsx' ), sheet_name = 'Disease' )
1312users_df = pd .read_excel (os .path .join (script_dir , 'database.xlsx' ), sheet_name = 'users' )
1413
1514# Ensure proper column types
16- users_df ['Diagnosis ' ] = users_df ['Diagnosis ' ].astype (str )
15+ users_df ['Symptoms ' ] = users_df ['Symptoms ' ].astype (str )
1716if 'Appointment Slot' not in users_df .columns :
1817 users_df ['Appointment Slot' ] = ''
1918if 'Preferred Doctor' not in users_df .columns :
@@ -157,9 +156,6 @@ def show_patient_dashboard():
157156 global results_frame
158157 frame = ttk .Frame (root , padding = "20" )
159158 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 )
163159
164160 # Load and display image
165161 img = Image .open (os .path .join (script_dir , 'patient_dashboard_image.png' ))
@@ -180,65 +176,13 @@ def show_patient_dashboard():
180176 results_frame .pack (pady = 10 , fill = 'both' , expand = True )
181177
182178def 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' )
240184
241- def save_patient_data ():
185+ def save_data ():
242186 try :
243187 with pd .ExcelWriter (os .path .join (script_dir , 'database.xlsx' ), engine = 'openpyxl' , mode = 'a' , if_sheet_exists = 'replace' ) as writer :
244188 users_df .to_excel (writer , sheet_name = 'users' , index = False )
@@ -247,7 +191,7 @@ def save_patient_data():
247191 except Exception as e :
248192 messagebox .showerror ('Error' , f'An error occurred: { e } ' )
249193
250- def save_data ():
194+ def save_patient_data ():
251195 try :
252196 with pd .ExcelWriter (os .path .join (script_dir , 'database.xlsx' ), engine = 'openpyxl' , mode = 'a' , if_sheet_exists = 'replace' ) as writer :
253197 users_df .to_excel (writer , sheet_name = 'users' , index = False )
@@ -269,13 +213,13 @@ def show_select_doctor():
269213 tree = ttk .Treeview (frame , columns = columns , show = 'headings' )
270214 for col in columns :
271215 tree .heading (col , text = col , anchor = 'w' )
272- tree .column (col , width = 200 , anchor = 'w' )
216+ tree .column (col , width = 300 , anchor = 'w' )
273217
274218 # Filter doctors based on the patient's city
275219 for _ , row in users_df [(users_df ['City' ] == patient_city ) & (users_df ['User Type' ] == 'Doctor' )].iterrows ():
276220 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 )
279223 tree .insert ('' , 'end' , values = (name , specialization , address ))
280224
281225 tree .pack (side = 'left' , fill = 'both' , expand = True )
@@ -373,7 +317,7 @@ def load_patient_data(username, frame):
373317 ttk .Label (frame , text = 'No assigned patients found.' ).pack (pady = 10 )
374318 return
375319
376- columns = ('Name' , 'Diagnosis ' , 'Appointment Slot' , 'Preferred Doctor ID' )
320+ columns = ('Name' , 'Symptoms ' , 'Appointment Slot' , 'Preferred Doctor ID' )
377321 tree = ttk .Treeview (frame , columns = columns , show = 'headings' )
378322 for col in columns :
379323 tree .heading (col , text = col )
@@ -382,7 +326,7 @@ def load_patient_data(username, frame):
382326 for patient in assigned_patients :
383327 patient_data = users_df [users_df ['Username' ] == patient ]
384328 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 ]))
386330
387331 tree .pack (side = 'left' , fill = 'both' , expand = True )
388332
0 commit comments