-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.py
More file actions
1168 lines (806 loc) · 54.6 KB
/
Copy pathWindow.py
File metadata and controls
1168 lines (806 loc) · 54.6 KB
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
import tkinter as tk
import tkinter.messagebox as tk_mb
import tkcalendar
from tkinter import ttk
class Window():
def __init__(self,db):
#Create tkinter instance
self.root = tk.Tk()
self.root.title("StudySchedule") #Update the text taht shows up on the top border of the window itself, AKA 'title'
#Assign database connection instance used for this class
self.db = db
#Establish a current frame variable
self.current_frame = None
self.main_menu() #Open the main menu
self.root.mainloop() #Get tkinter running for this window
def option_menu_action(self,function):
function()
def open_frame(self,function):
"""Serves to open a new frame within the tkinter window\n
function: the function that should be run to open a new frame"""
#If self.current_frame has been assigned
if self.current_frame:
#Close the current frame to make room for the new one
self.current_frame.destroy()
#run the target function to open a new frame
function()
def delete_widgets(self,widget_list):
for widget in widget_list:
widget.destroy()
def main_menu(self):
"""Opens the StudySchedule main menu """
self.main_menu_frame = tk.Frame(self.root) #Create main menu frame
self.root.geometry("") #Establish flexible size for the window
self.main_menu_frame.pack()
#Set/Reset the current frame
self.current_frame = self.main_menu_frame
#Establish labels and buttons in the main menu
self.main_menu_top_label = tk.Label(self.main_menu_frame,text="Welcome to StudySchedule")
self.main_menu_top_label.grid(row=0,column=0,columnspan=2,pady=5)
self.add_study_button = tk.Button(self.main_menu_frame,text="Add New Study",command=lambda:self.open_frame(self.add_new_study_window))
self.add_study_button.grid(row=1,column=0,padx=5)
self.view_study_button = tk.Button(self.main_menu_frame,text="View Study Info",command=lambda:self.open_frame(self.view_study_info_window))
self.view_study_button.grid(row=2,column=0)
self.edit_study_button = tk.Button(self.main_menu_frame,text="Edit Study",command=lambda:self.open_frame(self.open_edit_study_picker_window))
self.edit_study_button.grid(row=3,column=0)
self.add_participants_button = tk.Button(self.main_menu_frame,text="Add Participant",command=lambda:self.open_frame(self.open_add_participant_study_picker_window))
self.add_participants_button.grid(row=1,column=1)
self.edit_participant_button = tk.Button(self.main_menu_frame,text="Edit Participant",command=lambda:self.open_frame(self.open_edit_participant_study_picker_window))
self.edit_participant_button.grid(row=2,column=1)
self.edit_participant_initials_widgets = []
self.view_participant_button = tk.Button(self.main_menu_frame,text="View Participant",command=lambda:self.open_frame(self.open_view_participant_study_picker_window))
self.view_participant_button.grid(row=3,column=1)
self.view_participant_initials_widgets = []
self.view_entire_schedule_button = tk.Button(self.main_menu_frame,text="View Entire\n Study Schedule",command=lambda:self.open_frame(self.open_schedule_study_pickers_window))
self.view_entire_schedule_button.grid(row=1,rowspan=2,column=2)
self.exit_program_button = tk.Button(self.main_menu_frame,text="Exit",command=self.close_program)
self.exit_program_button.grid(row=3,column=2)
def add_new_study_window(self):
"""Opens a new frame to let users enter info for a new study to be added to the database"""
self.new_study_frame = tk.Frame(self.root) #Creates a new "new study" frame
self.new_study_frame.pack()
#Reset the current frame
self.current_frame = self.new_study_frame
#Establish labels, buttons, and text entries in frame
self.new_study_top_label = tk.Label(self.new_study_frame,text="Add New Study Information Below")
self.new_study_top_label.grid(row=0,column=0,columnspan=2)
self.new_study_name_label = tk.Label(self.new_study_frame,text="Study Name:")
self.new_study_name_label.grid(row=1,column=0)
self.new_study_name_entry = tk.Entry(self.new_study_frame)
self.new_study_name_entry.grid(row=2,column=0)
self.new_study_info_label = tk.Label(self.new_study_frame,text="Other Information:")
self.new_study_info_label.grid(row=3,column=0)
self.new_study_info_entry = tk.Text(self.new_study_frame,width=40,height=5)
self.new_study_info_entry.grid(row=4,column=0,padx=5)
self.new_date_entry_label = tk.Label(self.new_study_frame)
self.new_date_entry_label.grid(row=5,column=0)
self.new_info_date_entry = tkcalendar.DateEntry(self.new_study_frame,selectmode="day")
self.new_info_date_entry.grid(row=6,column=0)
#Varaible for storing/getting whether or not a date will be an in-house visit/stay, or a follow up visit
self.in_house = tk.IntVar()
self.in_house_check = tk.Checkbutton(self.new_study_frame,text="In-House Visit",variable=self.in_house,onvalue=1,offvalue=0)
self.in_house_check.grid(row=7,column=0)
self.date_entry_button = tk.Button(self.new_study_frame,text="Add Study Date",command=self.new_info_add_date_to_list)
self.date_entry_button.grid(row=8,column=0)
#Small frame to hold all the dates that have been chosen so far for the new study
self.new_study_date_list_frame = tk.Frame(self.new_study_frame)
self.new_study_date_list_frame.grid(row=9,column=0)
self.top_date_list_label= tk.Label(self.new_study_date_list_frame,text="Dates:")
self.top_date_list_label.grid(row=0,column=0)
self.new_study_date_dict = {} #Dictionary for holding all new dates to be part of the new study
self.back_button = tk.Button(self.new_study_frame,text="Back to Main Menu",command=lambda:self.open_frame(self.main_menu))
self.back_button.grid(row=11,column=0)
def new_info_add_date_to_list(self):
if len(self.new_study_date_dict) == 0:
self.finalize_new_study_button = tk.Button(self.new_study_frame,text="Add New Study",command=self.finalize_new_study)
self.finalize_new_study_button.grid(row=10,column=0)
if self.in_house.get() == 1:
type = "In House"
else:
type = "Follow Up"
new_date = self.new_info_date_entry.get_date().strftime("%m-%d-%y")
if new_date in self.new_study_date_dict.keys():
tk_mb.showinfo(message="Uh oh! Make sure none of your study dates are the same as one another")
else:
self.new_study_date_dict[new_date] = self.in_house.get()
new_label = tk.Label(self.new_study_date_list_frame,text=new_date + " - " + type)
new_label.grid(row=len(self.new_study_date_dict),column=0)
def finalize_new_study(self):
study_name = self.new_study_name_entry.get()
study_info = self.new_study_info_entry.get("1.0",tk.END).rstrip() #Get rid of newline at the end of string
if study_name == "":
tk_mb.showinfo(message="Sorry, make sure you add a name for this new study")
else:
if self.db.study_already_exists(study_name):
tk_mb.showinfo(message=f"Sorry, try picking another study name, {study_name} already exists in our system.")
else:
self.db.finalize_new_study(study_name,study_info,self.new_study_date_dict)
#cursor.execute(f"""INSERT INTO study (study_name, study_info) VALUES ('{study_name}',"{study_info}")""")
#connect.commit()
#cursor.execute(f"SELECT study_id FROM study WHERE study_name = '{study_name}'")
#study_id = tuple(cursor.fetchone())[0]
#self.add_dates_to_study(study_id,self.new_study_date_dict)
tk_mb.showinfo(message=f"Successfully added study {study_name}")
def view_study_info_window(self):
#Initialize new menu
self.view_study_master_frame = tk.Frame(self.root)
self.view_study_master_frame.pack()
self.current_frame = self.view_study_master_frame
self.view_study_picker_label = tk.Label(self.view_study_master_frame,text="Select Study:")
self.view_study_picker_label.grid(row=0,column=0)
self.view_study_picker_var = tk.StringVar()
study_names = self.db.get_study_names()
if study_names:
self.study_view_open = False
self.view_study_picker = ttk.OptionMenu(self.view_study_master_frame,self.view_study_picker_var,"",*study_names,command=lambda _:self.option_menu_action(self.display_study_info))
self.view_study_picker.grid(row=1,column=0)
self.exit_study_info_view_button = tk.Button(self.view_study_master_frame,text="Back to \nMain Menu",command=lambda:self.open_frame(self.main_menu))
self.exit_study_info_view_button.grid(row=3,column=1,padx=10)
else:
self.empty_label = tk.Label(self.view_study_master_frame,text="Sorry, there are no \nexisting studies")
self.empty_label.grid(row=0,column=0)
self.exit_study_info_view_button = tk.Button(self.view_study_master_frame,text="Back to \nMain Menu",command=lambda:self.open_frame(self.main_menu))
self.exit_study_info_view_button.grid(row=1,column=0)
def display_study_info(self,*args):
#NOW USES get_study_info from the database module
if self.study_view_open:
self.view_study_info_frame.destroy()
self.study_view_open = True
study_name = self.view_study_picker_var.get()
study_info = self.db.get_study_other_info(study_name)
#cursor.execute(f"SELECT study_info FROM study WHERE study_name = '{study_name}'")
#study_info = cursor.fetchone()[0]
study_dates = self.db.get_date_info_by_study(study_name)
#cursor.execute(f""" SELECT date, is_in_house FROM Study_Date_Times
# INNER JOIN
# study
# ON Study_Date_Times.study_id = study.study_id
# WHERE
# study.study_name = '{study_name}' """)
#study_dates = cursor.fetchall()
self.view_study_info_frame = tk.Frame(self.view_study_master_frame)
self.view_study_info_frame.grid(row=2,column=0)
self.study_name_label = tk.Label(self.view_study_info_frame,text=study_name)
self.study_name_label.grid(row=0,column=0,columnspan=2)
self.study_info_view_other_info_label = tk.Label(self.view_study_info_frame,text="Other Info:")
self.study_info_view_other_info_label.grid(row=1,column=1,padx=10)
self.study_other_info_text_label = tk.Label(self.view_study_info_frame,text=study_info)
self.study_other_info_text_label.grid(row=2,column=1)
self.schedule_label = tk.Label(self.view_study_info_frame,text="Dates:")
self.schedule_label.grid(row=1,column=0,padx=10)
for date in range(len(study_dates)):
if study_dates[date][1] == 1:
in_house = " - In House"
else:
in_house = " - Follow-Up Visit"
label_text = study_dates[date][0] + in_house
new_label = tk.Label(self.view_study_info_frame,text=label_text)
new_label.grid(row=2+date,column=0,padx=10)
delete_study_button = tk.Button(self.view_study_master_frame, text="Delete Study",command=lambda:self.delete_study(study_name))
delete_study_button.grid(row=2,column=1,padx=10)
def delete_study(self,study_name):
delete_confirmation = tk_mb.askyesno(title="Are you sure?",message=f"Are you sure you want to delete {study_name}")
if delete_confirmation:
self.db.delete_study(study_name)
tk_mb.showinfo(message=f"{study_name} study successfully deleted")
self.open_frame(self.main_menu)
def open_edit_study_picker_window(self):
self.edit_study_master_frame = tk.Frame(self.root)
self.edit_study_master_frame.pack()
self.current_frame = self.edit_study_master_frame
self.edit_study_picker_label = tk.Label(self.edit_study_master_frame,text="Select Study:")
self.edit_study_picker_label.grid(row=0,column=0)
self.edit_study_picker_var = tk.StringVar()
study_names = self.db.get_study_names()
if study_names:
self.study_edit_open = False
self.edit_study_picker = ttk.OptionMenu(self.edit_study_master_frame,self.edit_study_picker_var,"",*study_names,command=lambda _:self.option_menu_action(self.open_edit_study_window))
self.edit_study_picker.grid(row=1,column=0)
else:
self.empty_label = tk.Label(self.edit_study_master_frame,text="Sorry, there are no \nexisting studies")
self.empty_label.grid(row=1,column=0)
self.exit_study_edit_button = tk.Button(self.edit_study_master_frame,text="Back to Main Menu",command=lambda:self.open_frame(self.main_menu))
self.exit_study_edit_button.grid(row=3,column=0)
self.open_edit_study = False
def open_edit_study_window(self,*args):
self.root.geometry("")
if self.open_edit_study:
self.edit_study_frame.destroy()
self.open_edit_study = True
self.edit_study_master_frame.destroy()
self.edit_study_frame = tk.Frame(self.root)
self.edit_study_frame.grid(row=2,column=0)
self.current_frame = self.edit_study_frame
study_name = self.edit_study_picker_var.get()
study_info = self.db.get_study_info(study_name)
#cursor.execute(f""" SELECT study.study_info, Study_Date_Times.date, Study_Date_Times.is_in_house
# FROM study INNER JOIN Study_Date_Times
# ON Study_Date_Times.study_id = study.study_id
# WHERE study_name = '{study_name}' """)
#study_info = cursor.fetchall()
self.edit_other_info_entry_label = tk.Label(self.edit_study_frame,text="Study Info:")
self.edit_other_info_entry_label.grid(row=0,column=0)
self.edit_other_info_entry = tk.Text(self.edit_study_frame,height=5,width=40)
self.edit_other_info_entry.grid(row=1,column=0)
self.edit_other_info_entry.insert(tk.END,study_info[0][0])
self.edit_dates_frame = tk.Frame(self.edit_study_frame)
self.edit_dates_frame.grid(row=2,column=0)
self.edit_dates_label = tk.Label(self.edit_dates_frame,text="Study Dates:")
self.edit_dates_label.grid(row=0,column=0,columnspan=2)
self.edit_date_entries = []
self.edit_in_house_variables = []
current_row = 1
self.original_dates = []
for entry in study_info:
date = entry[1]
in_house = entry[2]
self.original_dates.append(date)
new_date_entry = tk.Entry(self.edit_dates_frame)
new_date_entry.grid(row=current_row,column=0)
new_date_entry.insert(0,date)
self.edit_date_entries.append(new_date_entry)
new_in_house_var = tk.IntVar()
new_check_button = tk.Checkbutton(self.edit_dates_frame,text="In-House Visit",variable=new_in_house_var,onvalue=1,offvalue=0)
new_check_button.grid(row=current_row,column=1)
self.edit_in_house_variables.append(new_in_house_var)
if in_house == 1:
new_check_button.select()
self.delete_buttons = {}
new_delete_button = tk.Button(self.edit_dates_frame,text="Delete",command=lambda study_name=study_name, date=date,date_entry=new_date_entry,check_button=new_check_button,current_row=current_row:self.delete_study_date(study_name,date,date_entry,check_button,current_row))
new_delete_button.grid(row=current_row,column=2)
self.delete_buttons[current_row] = new_delete_button
current_row += 1
#This button simply uses the add_more_dates function instead of open_frame, because it
# needs to exit the edit_dates_frame only after accessing the current changes to the dates of the study being edited
self.new_date_button = tk.Button(self.edit_dates_frame,text="Add Dates",command=lambda name = study_name:self.add_more_study_dates(name))
self.new_date_button.grid(row=current_row,column=0,columnspan=2)
self.edit_study_save_button = tk.Button(self.edit_dates_frame,text="Save",command=self.finalize_edit_study)
self.edit_study_save_button.grid(row=current_row+1,column=0,columnspan=2)
self.back_to_main_menu_button = tk.Button(self.edit_dates_frame,text="Back to Main Menu",command=lambda:self.open_frame(self.main_menu))
self.back_to_main_menu_button.grid(row=current_row+2,column=0,columnspan=2)
def delete_study_date(self,study_name,date,date_entry,check_button,current_row):
date_entry.destroy()
check_button.destroy()
self.delete_buttons.get(current_row).destroy()
self.db.delete_study_date(study_name,date)
def finalize_edit_study(self):
finalize_confirmation = tk_mb.askyesno(title="Save Info",message=f"Are you sure you want to save the info for {self.edit_study_picker_var.get()}?")
if finalize_confirmation:
self.db.update_study_info(self.edit_other_info_entry.get("1.0",tk.END),self.edit_study_picker_var.get())
#cursor.execute(f"""UPDATE study
# SET study_info = "{self.edit_other_info_entry.get("1.0",tk.END)}"
# WHERE study_name = "{self.edit_study_picker_var.get()}" """)
#connect.commit()
#cursor.execute(f"""SELECT study_id FROM study WHERE study_name = "{self.edit_study_picker_var.get()}" """)
#study_id = cursor.fetchone()[0]
study_id = self.db.get_study_id(self.edit_study_picker_var.get())
for index in range(0,len(self.edit_date_entries)):
date = self.edit_date_entries[index].get()
in_house = self.edit_in_house_variables[index].get()
self.db.update_study_date_times(date,in_house,study_id,self.original_dates[index])
#cursor.execute(f"""UPDATE Study_Date_Times SET date = "{date}", is_in_house = "{in_house}" WHERE study_id = "{study_id}" AND date = "{self.original_dates[index]}" """)
#connect.commit()
#cursor.execute(f"""UPDATE Participant_Date_Times SET date = "{date}", is_in_house = "{in_house}" WHERE study_id = "{study_id}" AND date= "{self.original_dates[index]}" """)
#connect.commit()
def add_more_study_dates(self,study_name):
self.current_changes = []
for entry in self.edit_date_entries:
self.current_changes.append(entry.get())
self.edit_study_frame.destroy()
self.open_edit_study=False
self.adding_study_dates_frame = tk.Frame(self.root)
self.adding_study_dates_frame.pack()
self.current_frame = self.adding_study_dates_frame
self.new_date_entry = tkcalendar.DateEntry(self.adding_study_dates_frame,selectmode="day")
self.new_date_entry.grid(row=1,column=0)
self.new_date_in_house_var = tk.IntVar()
in_house_check = tk.Checkbutton(self.adding_study_dates_frame,text="In-House Visit",variable=self.new_date_in_house_var,onvalue=1,offvalue=0)
in_house_check.grid(row=1,column=1)
self.new_dates = []
self.adding_study_dates_add_date_button = tk.Button(self.adding_study_dates_frame, text="Add Date", command=lambda:self.add_new_date(study_name,self.new_date_entry.get_date().strftime("%m-%d-%y"),self.new_date_in_house_var.get()))
self.adding_study_dates_add_date_button.grid(row=2,column=1)
self.return_to_edit_button = tk.Button(self.adding_study_dates_frame,text="Return to Study Info",command=lambda:self.open_frame(self.open_edit_study_window))
self.return_to_edit_button.grid(row=3,column=1)
self.new_dates_frame = tk.Frame(self.adding_study_dates_frame)
self.new_dates_frame.grid(row=2,column=0)
#NOTE current place of work - working on adding buttons update this function to use database class
def add_new_date(self,study_name,date,in_house):
in_house_text = "In House" if in_house == 1 else "Follow-Up Visit"
print("Testingggg")
#self.cursor.execute(F"""SELECT study_id FROM study WHERE study_name = '{study_name}' """)
#study_id = self.cursor.fetchone()[0]
study_id = self.db.get_study_id(study_name)
#date = self.new_date_entry.get_date().strftime("%m-%d-%y")
#in_house = self.new_date_in_house_var.get()
if date not in self.current_changes and date not in self.new_dates:
# self.cursor.execute(f"""INSERT INTO Study_Date_Times
# (study_id,date,is_in_house)
# VALUES ('{study_id}', '{date}', '{in_house}')""")
# self.connect.commit()
# self.cursor.execute(f"SELECT participant_id FROM Participant WHERE study_id = '{study_id}'")
# participants = self.cursor.fetchall()
# for participant in participants:
# self.cursor.execute(f"""INSERT INTO Participant_Date_Times
# (study_id,participant_id,date,is_in_house,time)
# VALUES('{study_id}','{participant[0]}','{date}','{in_house}','')""")
# self.connect.commit()
print("Pushing to database")
self.db.add_single_new_date_to_study(study_id,date,in_house)
print("Pushed to database")
new_label = tk.Label(self.new_dates_frame,text=f"{date}-{in_house_text}")
new_label.grid(row=len(self.new_dates))
self.new_dates.append(date)
tk_mb.showinfo(message="Date added successfully")
else:
tk_mb.showinfo(message="Sorry, that date already exists.")
def open_add_participant_study_picker_window(self):
self.add_participant_master_frame = tk.Frame(self.root)
self.add_participant_master_frame.pack()
self.current_frame = self.add_participant_master_frame
self.add_participant_study_picker_label = tk.Label(self.add_participant_master_frame,text="Select Study:")
self.add_participant_study_picker_label.grid(row=0,column=0)
self.add_participant_study_picker_var = tk.StringVar()
study_names = self.db.get_study_names()
if study_names:
self.add_participant_open = False
self.add_participant_study_picker = ttk.OptionMenu(self.add_participant_master_frame,self.add_participant_study_picker_var,"",*study_names,command=lambda _: self.option_menu_action(self.open_add_participant_window))
self.add_participant_study_picker.grid(row=1,column=0)
else:
self.empty_label = tk.Label(self.add_participant_master_frame,text="Sorry, there are no \nexisting studies")
self.empty_label.grid(row=1,column=0)
self.return_button = tk.Button(self.add_participant_master_frame,text="Back to Main Menu",command=lambda:self.open_frame(self.main_menu))
self.return_button.grid(row=2,column=0)
def open_add_participant_window(self,*args):
if self.add_participant_open:
self.add_participant_frame.destroy()
self.add_participant_open = True
self.add_participant_frame = tk.Frame(self.add_participant_master_frame)
self.add_participant_frame.grid(row=2,column=0)
#self.current_frame = self.add_participant_frame
self.add_participant_study_name = self.add_participant_study_picker_var.get()
self.add_participant_title_label = tk.Label(self.add_participant_frame,text=f"Add information to {self.add_participant_study_name} study")
self.add_participant_title_label.grid(row=0,column=0,columnspan=2)
self.add_participant_first_name_label = tk.Label(self.add_participant_frame,text="First Name:")
self.add_participant_first_name_label.grid(row=1,column=0)
self.add_participant_first_name_entry = tk.Entry(self.add_participant_frame)
self.add_participant_first_name_entry.grid(row=1,column=1)
self.add_participant_last_name_label = tk.Label(self.add_participant_frame,text="Last Name:")
self.add_participant_last_name_label.grid(row=2,column=0)
self.add_participant_last_name_entry = tk.Entry(self.add_participant_frame)
self.add_participant_last_name_entry.grid(row=2,column=1)
self.add_participant_intial_label = tk.Label(self.add_participant_frame,text="Initals:")
self.add_participant_intial_label.grid(row=3,column=0)
self.add_participant_initials_entry = tk.Entry(self.add_participant_frame)
self.add_participant_initials_entry.grid(row=3,column=1)
self.add_participant_birthday_label = tk.Label(self.add_participant_frame,text="Birthday:")
self.add_participant_birthday_label.grid(row=4,column=0)
self.add_participant_birthday_entry = tk.Entry(self.add_participant_frame)
self.add_participant_birthday_entry.grid(row=4,column=1,padx=5)
self.add_participant_other_info_label = tk.Label(self.add_participant_frame,text="Other Info:")
self.add_participant_other_info_label.grid(row=5,column=0,columnspan=2)
self.add_participant_other_info_entry = tk.Text(self.add_participant_frame,height=5,width=40)
self.add_participant_other_info_entry.grid(row=6,column=0,columnspan=2,padx=2)
self.add_participant_date_top_label = tk.Label(self.add_participant_frame,text="Date:")
self.add_participant_date_top_label.grid(row=0,column=2)
self.add_participant_time_top_label = tk.Label(self.add_participant_frame,text="Time:")
self.add_participant_time_top_label.grid(row=0,column=3)
#Finding all dates of study
study_dates = self.db.get_date_info_by_study(self.add_participant_study_name)
#cursor.execute(f"""SELECT date,is_in_house FROM Study_Date_times
# INNER JOIN study
# ON Study_Date_Times.study_id = study.study_id
# WHERE study.study_name = '{self.add_participant_study_name}'""")
#study_dates = cursor.fetchall()
self.date_dict = {}
current_row = 1
for date in study_dates:
if date[1] == 1:
in_house = "\n(In-House)"
else:
in_house = "\n(Follow-Up Visit)"
new_date_label = tk.Label(self.add_participant_frame,text=date[0] + in_house)
new_date_label.grid(row=current_row,column=2)
new_date_entry = tk.Entry(self.add_participant_frame)
new_date_entry.grid(row=current_row,column=3)
self.date_dict[date[0]] = [new_date_entry,date[1]]
current_row +=1
self.add_participant_exit_button = tk.Button(self.add_participant_frame,text="Back to Main Menu",command=lambda:self.open_frame(self.main_menu))
self.add_participant_exit_button.grid(row=7,column=0)
self.add_participant_finalize_button = tk.Button(self.add_participant_frame,text="Add Participant",command=self.add_participant_finalize)
self.add_participant_finalize_button.grid(row=7,column=1)
def add_participant_finalize(self):
first_name = self.add_participant_first_name_entry.get()
last_name = self.add_participant_last_name_entry.get()
initials = self.add_participant_initials_entry.get()
birthday = self.add_participant_birthday_entry.get()
other_info = self.add_participant_other_info_entry.get("1.0",tk.END).rstrip()
essential_info = [first_name,last_name,initials,birthday]
#cursor.execute(f"SELECT initials FROM participant WHERE study_id = {study_id}")
#all_initials = [initials[0] for initials in cursor.fetchall()]
#Find study ID for schedule table
#cursor.execute(f"""SELECT study_id FROM study WHERE study_name = '{self.add_participant_study_name}' """)
#study_id = cursor.fetchone()[0]
if "" in essential_info:
tk_mb.showinfo(message="Make sure all fields are filled out!")
else:
study_id = self.db.get_study_id(self.add_participant_study_name)
all_initials = self.db.get_initials(study_id)
if initials in all_initials:
tk_mb.showinfo(message="Sorry, those initials already exist in this study")
else:
for date in self.date_dict:
if self.date_dict.get(date)[0].get() == "":
tk_mb.showinfo(message="Make sure all dates have a set time")
return
self.db.add_participant(study_id,first_name,last_name,initials,birthday,other_info,self.date_dict)
tk_mb.showinfo(message=f"Participant {initials} has been added to the study")
#cursor.execute(f"""INSERT INTO Participant (study_id,first_name,last_name,initials,birthday,other_info)
# VALUES({study_id}, '{first_name}','{last_name}','{initials}','{birthday}',"{other_info}") """)
#connect.commit()
#cursor.execute(f"""SELECT participant_id FROM Participant WHERE initials = '{initials}' """)
#participant_id = cursor.fetchone()[0]
#for date in self.date_dict:
# time = self.date_dict.get(date)[0].get()
# in_house = self.date_dict.get(date)[1]
# cursor.execute(f"""INSERT INTO Participant_Date_Times
# (study_id,participant_id,date,time,is_in_house)
# VALUES ('{study_id}','{participant_id}','{date}','{time}','{in_house}') """)
# connect.commit()
def open_edit_participant_study_picker_window(self):
self.edit_participant_pickers_frame = tk.Frame(self.root)
self.edit_participant_pickers_frame.pack()
self.current_frame = self.edit_participant_pickers_frame
study_names = self.db.get_study_names()
if study_names:
self.edit_participant_study_picker_label = tk.Label(self.edit_participant_pickers_frame,text="Select Study:")
self.edit_participant_study_picker_label.grid(row=0,column=0)
self.edit_participant_study_picker_var = tk.StringVar()
self.edit_participant_study_picker = tk.OptionMenu(self.edit_participant_pickers_frame,self.edit_participant_study_picker_var,*study_names,command=self.open_edit_participant_intials_picker)
self.edit_participant_study_picker.grid(row=1,column=0)
self.edit_participant_initials_picker_open = False
self.open_participant_edit_button_placed = False
else:
self.empty_label = tk.Label(self.edit_participant_pickers_frame,text="Sorry, there are no \nexisting studies")
self.empty_label.grid(row=1,column=0)
self.edit_participant_exit_button = tk.Button(self.edit_participant_pickers_frame,text="Back to Main Menu",command=lambda:self.open_frame(self.main_menu))
self.edit_participant_exit_button.grid(row=5,column=0)
def open_edit_participant_intials_picker(self,*args):
#if self.edit_participant_initials_picker_open:
# self.edit_participant_initials_picker_frame.destroy()
#if self.open_participant_edit_button_placed:
# self.open_edit_participant_button.config(text=f"Edit {self.edit_participant_initials_picker_var.get()}'s Info")
self.edit_participant_initials_picker_open = True
study_id = self.db.get_study_id(self.edit_participant_study_picker_var.get())
#cursor.execute(f"""SELECT study_id FROM study WHERE study_name = "{self.edit_participant_study_picker_var.get()}" """)
#study_id = cursor.fetchone()[0]
self.delete_widgets(self.edit_participant_initials_widgets)
self.edit_participant_initials_widget = []
initials = self.db.get_initials(study_id)
if initials: #If there are initials returned (IE if there are any participants in the study)
#cursor.execute(f"SELECT initials FROM Participant WHERE study_id = {study_id}")
#participants = [participant[0] for participant in cursor.fetchall()]
self.edit_participant_initials_label = tk.Label(self.edit_participant_pickers_frame,text="Select Participant:")
self.edit_participant_initials_label.grid(row=2,column=0)
self.edit_participant_initials_widgets.append(self.edit_participant_initials_label)
self.edit_participant_initials_picker_var = tk.StringVar()
self.edit_participant_initials_picker = tk.OptionMenu(self.edit_participant_pickers_frame,self.edit_participant_initials_picker_var,*initials,command=self.place_edit_participant_button)
self.edit_participant_initials_picker.grid(row=3,column=0)
self.edit_participant_initials_widgets.append(self.edit_participant_initials_picker)
else:
self.no_participants_label = tk.Label(self.edit_participant_pickers_frame, text=f"No participants found\nfor {self.edit_participant_study_picker_var.get()}")
self.no_participants_label.grid(row=2,rowspan=1,column=0)
self.edit_participant_initials_widgets.append(self.no_participants_label)
def place_edit_participant_button(self,*args):
self.open_participant_edit_button_placed = True
self.open_edit_participant_button = tk.Button(self.edit_participant_pickers_frame,text=f"Edit {self.edit_participant_initials_picker_var.get()}'s Info",command=lambda:self.open_frame(self.open_edit_participant_info_window))
self.open_edit_participant_button.grid(row=4,column=0)
self.edit_participant_initials_widgets.append(self.open_edit_participant_button)
def open_edit_participant_info_window(self):
self.edit_participant_info_frame = tk.Frame(self.root)
self.edit_participant_info_frame.pack()
self.current_frame = self.edit_participant_info_frame
participant_info = self.db.get_all_participant_info(self.edit_participant_initials_picker_var.get())
#cursor.execute(f"""SELECT * FROM participant WHERE initials = "{self.edit_participant_initials_picker_var.get()}" """)
#participant_info= cursor.fetchall()[0]
self.edit_participant_id = participant_info[0]
first_name = participant_info[1]
last_name = participant_info[2]
initials = participant_info[3]
birthday = participant_info[4]
other_info = participant_info[5]
date_info = self.db.get_date_info_by_participant(self.edit_participant_id)
#cursor.execute(f"""SELECT date,time,is_in_house FROM participant_date_times WHERE participant_id = {self.edit_participant_id}""")
#date_info = cursor.fetchall()
self.participant_initials_label = tk.Label(self.edit_participant_info_frame,text=f"Participant {initials}")
self.participant_initials_label.grid(row=0,column=0,columnspan=2)
first_name_label = tk.Label(self.edit_participant_info_frame,text="First Name:")
self.edit_first_name_entry = tk.Entry(self.edit_participant_info_frame)
self.edit_first_name_entry.insert(0,first_name)
last_name_label = tk.Label(self.edit_participant_info_frame,text="Last Name:")
self.edit_last_name_entry = tk.Entry(self.edit_participant_info_frame)
self.edit_last_name_entry.insert(0,last_name)
initials_label = tk.Label(self.edit_participant_info_frame,text="Initials:")
self.edit_initials_entry = tk.Entry(self.edit_participant_info_frame)
self.edit_initials_entry.insert(0,initials)
birthday_label = tk.Label(self.edit_participant_info_frame,text="Birthday:")
self.edit_birthday_entry = tk.Entry(self.edit_participant_info_frame)
self.edit_birthday_entry.insert(0,birthday)
other_info_label = tk.Label(self.edit_participant_info_frame,text="Other Info:")
self.edit_other_info_entry = tk.Text(self.edit_participant_info_frame,height=5,width=40)
self.edit_other_info_entry.insert(tk.END,other_info)
first_name_label.grid(row=1,column=0)
last_name_label.grid(row=2,column=0)
initials_label.grid(row=3,column=0)
birthday_label.grid(row=4,column=0)
other_info_label.grid(row=5,column=0,columnspan=2)
self.edit_first_name_entry.grid(row=1,column=1)
self.edit_last_name_entry.grid(row=2,column=1)
self.edit_initials_entry.grid(row=3,column=1)
self.edit_birthday_entry.grid(row=4,column=1)
self.edit_other_info_entry.grid(row=6,column=0,columnspan=2)
self.edit_participant_times_frame = tk.Frame(self.edit_participant_info_frame)
self.edit_participant_times_frame.grid(row=7,column=0,columnspan=2)
self.edit_participant_times_dict = {}
current_row = 0
for day in date_info:
date = day[0]
time = day[1]
in_house = "\nIn House"
if day[2] == 0:
in_house = "\nFollow-Up Visit"
new_date_label = tk.Label(self.edit_participant_times_frame,text=f"{date}{in_house}")
new_date_label.grid(row=current_row,column=0)
new_time_entry = tk.Entry(self.edit_participant_times_frame)
new_time_entry.grid(row=current_row,column=1)
new_time_entry.insert(0,time)
self.edit_participant_times_dict[date] = new_time_entry
current_row += 1
save_participant_edits_button = tk.Button(self.edit_participant_info_frame,text="Save",command=self.finalize_edit_participant)
save_participant_edits_button.grid(row=8,column=0,columnspan=2)
back_to_main_menu_button = tk.Button(self.edit_participant_info_frame,text="Back to Main Menu",command=lambda:self.open_frame(self.main_menu))
back_to_main_menu_button.grid(row=9,column=0)
back_to_pickers_button = tk.Button(self.edit_participant_info_frame,text="Select Other Participant",command=lambda:self.open_frame(self.open_edit_participant_study_picker_window))
back_to_pickers_button.grid(row=9,column=1)
def finalize_edit_participant(self):
#Retrieve all Info
first_name_input = self.edit_first_name_entry.get()
last_name_input = self.edit_last_name_entry.get()
initials_input = self.edit_initials_entry.get()
birthday_input = self.edit_birthday_entry.get()
other_info_input = self.edit_other_info_entry.get("1.0",tk.END).rstrip()
self.db.update_participant_column(self.edit_participant_id,first_name_input,"first_name")
self.db.update_participant_column(self.edit_participant_id,last_name_input,"last_name")
self.db.update_participant_column(self.edit_participant_id,initials_input,"initials")
self.db.update_participant_column(self.edit_participant_id,birthday_input,"birthday")
self.db.update_participant_column(self.edit_participant_id,other_info_input,"other_info")
# cursor.execute(f"""UPDATE Participant
# SET first_name = '{first_name_input}'
# WHERE participant_id = {self.edit_participant_id}""")
# connect.commit()
# cursor.execute(f"""UPDATE Participant
# SET last_name = '{last_name_input}'
# WHERE participant_id = {self.edit_participant_id} """)
# connect.commit()
# cursor.execute(f"""UPDATE Participant
# SET initials = '{initials_input}'
# WHERE participant_id = {self.edit_participant_id} """)
# connect.commit()
# cursor.execute(f"""UPDATE Participant
# SET birthday = '{birthday_input}'
# WHERE participant_id = {self.edit_participant_id} """)
# connect.commit()
# cursor.execute(f"""UPDATE Participant
# SET other_info = "{other_info_input}"
# WHERE participant_id = {self.edit_participant_id} """)
# connect.commit()
for date in self.edit_participant_times_dict:
time = self.edit_participant_times_dict.get(date).get()
self.db.update_participant_date_times(self.edit_participant_id,date,time)
#Update rows in
#cursor.execute(f"""UPDATE Participant_Date_Times
# SET time = '{time}'
# WHERE participant_id = {self.edit_participant_id} AND date = '{date}'""")
#connect.commit()
tk_mb.showinfo(message=f"Succesfully edited participant {initials_input}'s information")
#self.back_to_edit_participant_pickers()
lambda:self.open_frame(self.open_edit_participant_study_picker_window)
def open_view_participant_study_picker_window(self):
self.root.geometry("")
self.view_participant_pickers_frame = tk.Frame(self.root)
self.view_participant_pickers_frame.pack()
##########
self.current_frame = self.view_participant_pickers_frame
study_names = self.db.get_study_names()
if study_names:
self.view_participant_study_picker_label = tk.Label(self.view_participant_pickers_frame,text="Select Study:")
self.view_participant_study_picker_label.grid(row=0,column=0)
self.view_participant_study_picker_var = tk.StringVar()
self.view_participant_study_picker = tk.OptionMenu(self.view_participant_pickers_frame,self.view_participant_study_picker_var,*study_names,command=self.open_view_participant_initials_picker)
self.view_participant_study_picker.grid(row=1,column=0)
else:
self.empty_label = tk.Label(self.view_participant_pickers_frame,text="Sorry, there are no \nexisting studies")
self.empty_label.grid(row=1,column=0)
self.view_participant_exit_button = tk.Button(self.view_participant_pickers_frame,text="Back to Main Menu",command=lambda:self.open_frame(self.main_menu))
self.view_participant_exit_button.grid(row=5,column=0)
def open_view_participant_initials_picker(self,*args):
#if self.view_participant_initials_picker_open:
#self.view_participant_initials_picker_frame.destroy()
#if self.open_participant_view_button_placed:
# self.open_view_participant_button.config(text=f"View{self.view_participant_initials_picker_var.get()}'s Info")
self.delete_widgets(self.view_participant_initials_widgets)
self.view_participant_initials_widgets = []
self.view_participant_initials_picker_open = True
study_id = self.db.get_study_id(self.view_participant_study_picker_var.get())
initials = self.db.get_initials(study_id)
if initials:
#cursor.execute(f"""SELECT study_id FROM study WHERE study_name = "{self.view_participant_study_picker_var.get()}" """)
#study_id = cursor.fetchone()[0]
#cursor.execute(f"SELECT initials FROM Participant WHERE study_id = {study_id}")
#participants = [participant[0] for participant in cursor.fetchall()]
self.view_participant_initials_label = tk.Label(self.view_participant_pickers_frame,text="Select Participant:")
self.view_participant_initials_label.grid(row=2,column=0)
self.view_participant_initials_widgets.append(self.view_participant_initials_label)
self.view_participant_initials_picker_var = tk.StringVar()
self.view_participant_initials_picker = tk.OptionMenu(self.view_participant_pickers_frame,self.view_participant_initials_picker_var,*initials,command=self.place_view_participant_button)
self.view_participant_initials_picker.grid(row=3,column=0)
self.view_participant_initials_widgets.append(self.view_participant_initials_picker)
else:
self.no_participants_label = tk.Label(self.view_participant_pickers_frame,text=f"No participants found\nfor {self.view_participant_study_picker_var.get()}")
self.no_participants_label.grid(row=2,column=0)
self.view_participant_initials_widgets.append(self.no_participants_label)
def place_view_participant_button(self,*args):
self.open_participant_view_button_placed = True
self.open_view_participant_button = tk.Button(self.view_participant_pickers_frame,text=f"View{self.view_participant_initials_picker_var.get()}'s Info",command=lambda:self.open_frame(self.open_view_participant_info_window))
self.open_view_participant_button.grid(row=4,column=0)
self.view_participant_initials_widgets.append(self.open_view_participant_button)
def open_view_participant_info_window(self):
self.view_participant_info_frame = tk.Frame(self.root)
self.view_participant_info_frame.grid(row=0,column=0)
self.current_frame = self.view_participant_info_frame
participant_info = self.db.get_all_participant_info(self.view_participant_initials_picker_var.get())
#cursor.execute(f"""SELECT * FROM participant WHERE initials = "{self.view_participant_initials_picker_var.get()}" """)
#participant_info= cursor.fetchall()[0]
self.view_participant_id = participant_info[0]
first_name = participant_info[1]
last_name = participant_info[2]
initials = participant_info[3]
birthday = participant_info[4]
other_info = participant_info[5]
date_info = self.db.get_date_info_by_participant(self.view_participant_id)
#cursor.execute(f"""SELECT date,time,is_in_house FROM participant_date_times WHERE participant_id = {self.view_participant_id}""")
#date_info = cursor.fetchall()
self.participant_initials_label = tk.Label(self.view_participant_info_frame,text=f"Participant {initials}")
self.participant_initials_label.grid(row=0,column=0,columnspan=2)
first_name_label = tk.Label(self.view_participant_info_frame,text=f"First Name: {first_name}")
last_name_label = tk.Label(self.view_participant_info_frame,text=f"Last Name: {last_name}")
initials_label = tk.Label(self.view_participant_info_frame,text=f"Initials: {initials}")
birthday_label = tk.Label(self.view_participant_info_frame,text=f"Birthday: {birthday}")
other_info_label = tk.Label(self.view_participant_info_frame,text=f"Other Info:")
self.view_other_info_entry = tk.Text(self.view_participant_info_frame,height=7,width=35)
self.view_other_info_entry.insert(tk.END,other_info)
self.view_other_info_entry.config(state=tk.DISABLED)
first_name_label.grid(row=1,column=0)
last_name_label.grid(row=2,column=0)
initials_label.grid(row=3,column=0)
birthday_label.grid(row=4,column=0)
other_info_label.grid(row=5,column=0)