-
Notifications
You must be signed in to change notification settings - Fork 1
/
searchMatch.py
363 lines (286 loc) · 12 KB
/
searchMatch.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
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Copyright© Shelby Thomas 04/2020
from guizero import App, Text, TextBox, PushButton,Box, ListBox, Window,CheckBox
import re
import nltk.data
import csv
from screeninfo import get_monitors
import ssl
import sys
from dates import date_match
screen_width = 1920
screen_ratio = 1.7
platform = sys.platform
rt = 3
# For Mac need to check this for exceptions
# If it's not win32 assume it's a MAC. Resolution information not
# available.
if (platform == 'win32'):
for m in get_monitors():
print(str(m))
print(m.width)
screen_width = m.width
screen_ratio = float(m.width)/m.height
#
if(screen_width == 1920):
rt = 1
elif(screen_ratio < 2):
rt = 1
elif(screen_ratio > 2):
rt = 2
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
nltk.download('punkt')
resolution = [{
"app_height":1300,
"app_width":1000,
"lbox_height":700,
"lbox_width":500,
"fullsen_height":15,
"fullsen_width":"full",
"text_box":14,
"form_box":12,
"select_box":15,
"result_box":11,
"button_pady": 10
},
{
"app_height":975,
"app_width":750,
"lbox_height":225,
"lbox_width":375,
"fullsen_height":11,
"fullsen_width":"full",
"text_box":11,
"form_box":10,
"select_box":12,
"result_box":12,
"button_pady":1
},
{
"app_height":1075,
"app_width":750,
"lbox_height":325,
"lbox_width":375,
"fullsen_height":11,
"fullsen_width":"full",
"text_box":11,
"form_box":10,
"select_box":12,
"result_box":12,
"button_pady": 2
},
{
"app_height":1075,
"app_width":750,
"lbox_height":325,
"lbox_width":375,
"fullsen_height":11,
"fullsen_width":"full",
"text_box":12,
"form_box":13,
"select_box":14,
"result_box":14,
"button_pady": 2
}
]
app = App(height=resolution[rt]['app_height'],width= resolution[rt]['app_width'] ,title="Search and Match",bg="#ffffff")
term_dict = {}
def dispay_full(value):
display_str = "\n\n".join(value)
fullsen.value = display_str
fullsen.font="Corbel"
fullsen.text_size = resolution[rt]['result_box']
rdict = {}
def pval(val,listbox):
val_list = rdict[val]
listbox.value = rdict[val] # This is a list of values for listbox to match
str_list = []
for sen_val in val_list:
subterm_list_raw = term_dict[(sen_val, val)]
# The subterm list array may have duplicates
# (TODO)shelby: Clarify why does it have dups?
subterm_list = list(set(subterm_list_raw))
for term in subterm_list:
term_replace = "►"+term+"◄"
sen_val = sen_val.replace(term, term_replace)
print (sen_val)
str_list.append(sen_val)
display_str = "\n\n".join(str_list)
fullsen.font="Open Sans"
fullsen.value = display_str
btn_list = []
lbox_list = []
def analyze():
ldict = {}
result = []
rdict.clear()
term_dict.clear()
if(len(btn_list) > 0):
for btn in btn_list:
btn.destroy()
btn_list.clear()
if(len(lbox_list) > 0):
for lbox in lbox_list:
lbox.destroy()
lbox_list.clear()
with open('conditions.csv', newline='') as f:
reader = csv.reader(f)
data = list(reader)
for line in data:
#line[1] = line[1].replace(" ","")
ldict[line[0]] = line[1:][0].split(',')
data = text_box.value
data_lower = data.lower()
tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')
if(preprocess_checkbox.value == 0):
remove_history = re.sub('past medical history: diagnosis.*?drug use',' drug use ',data_lower, flags=re.DOTALL)
remove_physicala = re.sub('physical exam.*?assessment/plan','. ASSESSMENT',remove_history, flags=re.DOTALL)
remove_complete = re.sub('physical exam.*?assessment and plan','. ASSESSMENT',remove_physicala, flags=re.DOTALL)
sentence_list = tokenizer.tokenize(remove_complete)
else:
sentence_list = tokenizer.tokenize(data_lower)
for sentence in sentence_list:
for (key,terms) in ldict.items():
for term in terms:
fixed_word = term.lower()
# If have a special date character $date$
# Insert the found dates into the ldict array as a term
if fixed_word == "$date$":
ldict[key].extend(date_match)
continue
if fixed_word in sentence:
dup_check = [key,sentence]
# If a sub term comes up we save it
if (sentence,key) in term_dict:
term_dict[(sentence,key)].append(fixed_word)
else:
term_dict[(sentence,key)] = [fixed_word]
if dup_check not in result:
result.append([key, sentence])
if key in rdict:
rdict[key].append(sentence)
else:
rdict[key] = [sentence]
lbox_list.append(ListBox(form_box, items=sentence_list, width="fill" ,height= resolution[rt]['lbox_height'],command=dispay_full,multiselect=True,scrollbar=True ))
lbox_list[0].bg="#C8D7E9"
counter = 0
btn = ""
for(k,vl) in ldict.items():
if(counter < 4):
if k in rdict:
if(platform != 'win32'):
btn = PushButton(button_box_r1, align="left",width="10",text=str("█"+k),command=pval,pady=resolution[rt]['button_pady'] )
else:
btn = PushButton(button_box_r1, align="left",width="10",text=k,command=pval,pady=resolution[rt]['button_pady'] )
btn.update_command(pval, [k, lbox_list[0] ])
btn.bg ="#9EF844"
else:
btn = PushButton(button_box_r1, align="left",width="10",text=k,pady=resolution[rt]['button_pady'])
btn.bg ="#F84446"
elif(counter < 8):
if k in rdict:
if(platform != 'win32'):
btn = PushButton(button_box_r2, align="left",width="10",text=str("█"+k),command=pval,pady=resolution[rt]['button_pady'] )
else:
btn = PushButton(button_box_r2, align="left",width="10",text=k,command=pval,pady=resolution[rt]['button_pady'] )
btn.update_command(pval, [k, lbox_list[0] ])
btn.bg ="#9EF844"
else:
btn = PushButton(button_box_r2, align="left",width="10",text=k,pady=resolution[rt]['button_pady'])
btn.bg ="#F84446"
elif(counter < 12):
if k in rdict:
if(platform != 'win32'):
btn = PushButton(button_box_r3, align="left",width="10",text=str("█"+k),command=pval,pady=resolution[rt]['button_pady'] )
else:
btn = PushButton(button_box_r3, align="left",width="10",text=k,command=pval,pady=resolution[rt]['button_pady'] )
btn.update_command(pval, [k, lbox_list[0] ])
btn.bg ="#9EF844"
else:
btn = PushButton(button_box_r3, align="left",width="10",text=k,pady=resolution[rt]['button_pady'])
btn.bg ="#F84446"
elif(counter < 16):
if k in rdict:
if(platform != 'win32'):
btn = PushButton(button_box_r4, align="left",width="10",text=str("█"+k),command=pval,pady=resolution[rt]['button_pady'] )
else:
btn = PushButton(button_box_r4, align="left",width="10",text=k,command=pval,pady=resolution[rt]['button_pady'] )
btn.update_command(pval, [k, lbox_list[0] ])
btn.bg ="#9EF844"
else:
btn = PushButton(button_box_r4, align="left",width="10",text=k,pady=resolution[rt]['button_pady'])
btn.bg ="#F84446"
elif(counter < 20):
if k in rdict:
if(platform != 'win32'):
btn = PushButton(button_box_r5, align="left",width="10",text=str("█"+k),command=pval,pady=resolution[rt]['button_pady'] )
else:
btn = PushButton(button_box_r5, align="left",width="10",text=k,command=pval,pady=resolution[rt]['button_pady'] )
btn.update_command(pval, [k, lbox_list[0] ])
btn.bg ="#9EF844"
else:
btn = PushButton(button_box_r5, align="left",width="10",text=k,pady=resolution[rt]['button_pady'])
btn.bg ="#F84446"
elif(counter < 24):
if k in rdict:
if(platform != 'win32'):
btn = PushButton(button_box_r6, align="left",width="10",text=str("█"+k),command=pval,pady=resolution[rt]['button_pady'] )
else:
btn = PushButton(button_box_r6, align="left",width="10",text=k,command=pval,pady=resolution[rt]['button_pady'] )
btn.update_command(pval, [k,lbox_list[0]])
btn.bg ="#9EF844"
else:
btn = PushButton(button_box_r6, align="left",width="10",text=k,pady=resolution[rt]['button_pady'])
btn.bg ="#F84446"
elif(counter < 28):
if k in rdict:
if(platform != 'win32'):
btn = PushButton(button_box_r7, align="left",width="10",text=str("█"+k),command=pval,pady=resolution[rt]['button_pady'] )
else:
btn = PushButton(button_box_r7, align="left",width="10",text=k,command=pval,pady=resolution[rt]['button_pady'] )
btn.update_command(pval, [k,lbox_list[0]])
btn.bg ="#9EF844"
else:
btn = PushButton(button_box_r7, align="left",width="10",text=k,pady=resolution[rt]['button_pady'])
btn.bg ="#F84446"
elif(counter < 32):
if k in rdict:
if(platform != 'win32'):
btn = PushButton(button_box_r8, align="left",width="10",text=str("█"+k),command=pval,pady=resolution[rt]['button_pady'] )
else:
btn = PushButton(button_box_r8, align="left",width="10",text=k,command=pval,pady=resolution[rt]['button_pady'] )
btn.update_command(pval, [k,lbox_list[0]])
btn.bg ="#9EF844"
else:
btn = PushButton(button_box_r8, align="left",width="10",text=k,pady=resolution[rt]['button_pady'])
btn.bg ="#F84446"
counter += 1
btn_list.append(btn)
title_box = Box(app, width="fill", align="top", border=True)
text_box = TextBox(title_box, text="Copy paste text here and hit ANALYZE",width="100", height="5",multiline='True')
text_box.font = "Corbel"
text_box.text_size = resolution[rt]['select_box']
preprocess_checkbox = CheckBox(app, text="Analyze Raw Data",command=analyze)
analyzebutton = PushButton(title_box, text="Analyze")
analyzebutton.when_clicked = analyze
button_box_r1 = Box(app, align="top", border=True)
button_box_r2 = Box(app, align="top", border=True)
button_box_r3 = Box(app, align="top", border=True)
button_box_r4 = Box(app, align="top", border=True)
button_box_r5 = Box(app, align="top", border=True)
button_box_r6 = Box(app, align="top", border=True)
button_box_r7 = Box(app, align="top", border=True)
button_box_r8 = Box(app, align="top", border=True)
form_box = Box(app,width="fill", border=True)
form_box.text_size= resolution[rt]['form_box']
select_box = Box(app,width="fill", border=True)
select_box.text_size= resolution[rt]['select_box']
fullsen = TextBox(select_box,width="fill",height= resolution[rt]['fullsen_height'] ,text="",multiline=True,scrollbar=True)
app.display()