-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainWindow.py
301 lines (245 loc) · 11.3 KB
/
mainWindow.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
from tkinter import *
from tkinter import messagebox
from PIL import Image, ImageTk
from dbInteraction import DBInteraction
from searchDB import SearchWindow
db = DBInteraction()
db.create_tables()
f = open('stored_p_id.txt', 'r')
stored_p_id = int(f.read())
current_p_id = -1
img_new = None
# ===================================================================================================
# =================================== MESSAGE BOX FUNCTIONALITIES ===================================
# ===================================================================================================
def clear_all():
name_box.delete(0.0, END)
age_box.delete(0.0, END)
gender_box.delete(0.0, END)
last_visit_box.delete(0.0, END)
allergies_box.delete(0.0, END)
diseases_conditions_box.delete(0.0, END)
med_history_box.delete(0.0, END)
add_comments_box.delete(0.0, END)
patient_box.delete(0, END)
def enable_all():
name_box.configure(state="normal", background="white")
age_box.configure(state="normal", background="white")
gender_box.configure(state="normal", background="white")
last_visit_box.configure(state="normal", background="white")
allergies_box.configure(state="normal", background="white")
diseases_conditions_box.configure(state="normal", background="white")
med_history_box.configure(state="normal", background="white")
add_comments_box.configure(state="normal", background="white")
def disable_all():
name_box.configure(state="disabled", background="alice blue")
age_box.configure(state="disabled", background="alice blue")
gender_box.configure(state="disabled", background="alice blue")
last_visit_box.configure(state="disabled", background="alice blue")
allergies_box.configure(state="disabled", background="alice blue")
diseases_conditions_box.configure(state="disabled", background="alice blue")
med_history_box.configure(state="disabled", background="alice blue")
add_comments_box.configure(state="disabled", background="alice blue")
# ===================================================================================================
# ============================= INITIALIZATION OF BASIC WINDOW ELEMENTS =============================
# ===================================================================================================
def new():
new_patient = str(name_box.get(0.0, END))
global stored_p_id
if new_patient != "" and new_patient != "\n":
db.insert_data(
int(stored_p_id),
str(name_box.get(0.0, END)).strip("\n"),
str(age_box.get(0.0, END)).strip("\n"),
str(gender_box.get(0.0, END)).strip("\n"),
str(last_visit_box.get(0.0, END)).strip("\n"),
str(allergies_box.get(0.0, END)).strip("\n"),
str(diseases_conditions_box.get(0.0, END)).strip("\n"),
str(med_history_box.get(0.0, END)).strip("\n"),
str(add_comments_box.get(0.0, END)).strip("\n")
)
stored_p_id += 1
global f
f.close()
f = open('stored_p_id.txt', 'w')
f.write(str(stored_p_id))
f.close()
f = open('stored_p_id.txt', 'r')
messagebox.showinfo(title="Confirmation", message="New Patient Successfully Added")
clear_all()
else:
messagebox.showinfo(title="System Error", message="Error: Addition Unsuccessful")
def get_entry():
temp_p_id = patient_box.get()
try:
temp_p_id = int(temp_p_id)
except ValueError:
patient_box.delete(0, END)
patient_box.insert(0, "Invalid Input")
return -1
return int(temp_p_id)
def load():
global stored_p_id
query = get_entry()
if 0 < query < stored_p_id:
db.load_data(query)
enable_all()
clear_all()
global current_p_id
current_p_id = query
name_box.insert(0.0, str(db.name))
age_box.insert(0.0, int(db.age))
gender_box.insert(0.0, str(db.gender))
last_visit_box.insert(0.0, str(db.lastVisit))
allergies_box.insert(0.0, str(db.allergies))
diseases_conditions_box.insert(0.0, str(db.diseases))
med_history_box.insert(0.0, str(db.history))
add_comments_box.insert(0.0, str(db.comments))
disable_all()
global img_new
load_new = Image.open("DefaultProfilePic.png")
try:
load_new = Image.open(str(current_p_id) + ".png")
except FileNotFoundError:
pass
finally:
render_new = ImageTk.PhotoImage(load_new)
img_new = Label(root, image=render_new, relief=SUNKEN)
img_new.image = render_new
img_new.place(x=50, y=50)
else:
patient_box.delete(0, END)
patient_box.insert(0, "Invalid Input")
def update():
global current_p_id
db.update_data(
int(current_p_id),
str(name_box.get(0.0, END)).strip("\n"),
str(age_box.get(0.0, END)).strip("\n"),
str(gender_box.get(0.0, END)).strip("\n"),
str(last_visit_box.get(0.0, END)).strip("\n"),
str(allergies_box.get(0.0, END)).strip("\n"),
str(diseases_conditions_box.get(0.0, END)).strip("\n"),
str(med_history_box.get(0.0, END)).strip("\n"),
str(add_comments_box.get(0.0, END)).strip("\n")
)
if current_p_id != -1:
messagebox.showinfo(title="Confirmation", message="Patient Information\nSuccessfully Updated")
else:
messagebox.showinfo(title="System Error", message="Error: Update Unsuccessful")
disable_all()
def reset():
global current_p_id
current_p_id = -1
enable_all()
clear_all()
global img_new
img_new.pack_forget()
load_again_img = Image.open("DefaultProfilePic.png")
render_again = ImageTk.PhotoImage(load_again_img)
img_again = Label(root, image=render_again, relief=SUNKEN)
img_again.image = render_again
img_again.place(x=50, y=50)
def search():
SearchWindow()
# ===================================================================================================
# ============================= INITIALIZATION OF BASIC WINDOW ELEMENTS =============================
# ===================================================================================================
root = Tk()
root.wm_title("Medical Database v2.0")
root.geometry("1250x800")
root.maxsize(width=1250, height=800)
header = Label(root, font="Georgia 20", text="Internal Medical Database", relief=GROOVE, bd=5)
header.pack(fill=X, anchor=N)
load_img = Image.open("DefaultProfilePic.png")
render = ImageTk.PhotoImage(load_img)
img = Label(root, image=render, relief=SUNKEN)
img.image = render
img.place(x=50, y=50)
# ===================================================================================================
# =============================== GENERAL PATIENT INFORMATION WINDOWS ===============================
# ===================================================================================================
general_info = Frame(root, relief=GROOVE, bd=5)
general_info.place(x=650, y=50, width=550, height=200)
general_info_heading = Label(root, font="Georgia 14 bold", text="General Information")
general_info_heading.place(x=660, y=60)
name_heading = Label(root, font="Georgia 12", text="Name:")
name_heading.place(x=660, y=100)
name_box = Text(root, font="Georgia 12", width=35, height=1)
name_box.place(x=780, y=100)
age_heading = Label(root, font="Georgia 12", text="Age:")
age_heading.place(x=660, y=130)
age_box = Text(root, font="Georgia 12", width=35, height=1)
age_box.place(x=780, y=130)
gender_heading = Label(root, font="Georgia 12", text="Gender:")
gender_heading.place(x=660, y=160)
gender_box = Text(root, font="Georgia 12", width=35, height=1)
gender_box.place(x=780, y=160)
last_visit_heading = Label(root, font="Georgia 12", text="Last Visit:")
last_visit_heading.place(x=660, y=190)
last_visit_box = Text(root, font="Georgia 12", width=35, height=1)
last_visit_box.place(x=780, y=190)
# ===================================================================================================
# ================================== PROGRAM FUNCTIONALITY WIDGETS ==================================
# ===================================================================================================
id_label = Label(root, font="Georgia 14 bold", text="Patient ID")
id_label.place(x=320, y=50)
patient_box = Entry(root, font="Georgia 14")
patient_box.place(x=320, y=85)
new_btn = Button(root, text="New", command=new)
new_img = PhotoImage(file=r"Button Icons\new.png")
new_btn.config(image=new_img)
new_btn.place(x=335, y=120)
load_btn = Button(root, text="Load", command=load)
load_img = PhotoImage(file=r"Button Icons\load.png")
load_btn.config(image=load_img)
load_btn.place(x=415, y=120)
edit_btn = Button(root, text="Edit", command=enable_all)
edit_img = PhotoImage(file=r"Button Icons\edit.png")
edit_btn.config(image=edit_img)
edit_btn.place(x=495, y=120)
save_btn = Button(root, text="Update", command=update)
save_img = PhotoImage(file=r"Button Icons\save.png")
save_btn.config(image=save_img)
save_btn.place(x=335, y=190)
reset_btn = Button(root, text="Reset/Clear", command=reset)
reset_img = PhotoImage(file=r"Button Icons\clear.png")
reset_btn.config(image=reset_img)
reset_btn.place(x=415, y=190)
search_btn = Button(root, text="Search", command=search)
search_img = PhotoImage(file=r"Button Icons\search.png")
search_btn.config(image=search_img)
search_btn.place(x=495, y=190)
# ===================================================================================================
# =============================== SPECIFIC PATIENT INFORMATION WINDOWS ==============================
# ===================================================================================================
allergies = Frame(root, relief=GROOVE, bd=5)
allergies.place(x=50, y=260, width=550, height=200)
allergies_heading = Label(root, font="Georgia 14 bold", text="Allergies")
allergies_heading.place(x=60, y=270)
allergies_box = Text(root, font="Georgia 12", width=50, height=7)
allergies_box.place(x=70, y=310)
diseases_conditions = Frame(root, relief=GROOVE, bd=5)
diseases_conditions.place(x=650, y=260, width=550, height=200)
diseases_conditions_heading = Label(root, font="Georgia 14 bold", text="Diseases/Conditions")
diseases_conditions_heading.place(x=660, y=270)
diseases_conditions_box = Text(root, font="Georgia 12", width=50, height=7)
diseases_conditions_box.place(x=670, y=310)
med_history = Frame(root, relief=GROOVE, bd=5)
med_history.place(x=50, y=470, width=550, height=200)
med_history_heading = Label(root, font="Georgia 14 bold", text="Medical/Treatment History")
med_history_heading.place(x=60, y=480)
med_history_box = Text(root, font="Georgia 12", width=50, height=7)
med_history_box.place(x=70, y=520)
add_comments = Frame(root, relief=GROOVE, bd=5)
add_comments.place(x=650, y=470, width=550, height=200)
add_comments_heading = Label(root, font="Georgia 14 bold", text="Additional Comments")
add_comments_heading.place(x=660, y=480)
add_comments_box = Text(root, font="Georgia 12", width=50, height=7)
add_comments_box.place(x=670, y=520)
# ===================================================================================================
# ================================= CLOSING ALL CONNECTIONS AND FILES ===============================
# ===================================================================================================
root.mainloop()
db.shutdown()
f.close()