|
a |
|
b/rx_preprocess.py |
|
|
1 |
from loader import get_data, save |
|
|
2 |
from rx_classes import get_rx_classes |
|
|
3 |
from multiprocessing.dummy import Pool |
|
|
4 |
|
|
|
5 |
NTHREADS = 6 |
|
|
6 |
|
|
|
7 |
def preprocess_medications(num_patients): |
|
|
8 |
for i in range(num_patients): |
|
|
9 |
print "\nPreprocessing Medications - " + str(i) + " - progress: ", |
|
|
10 |
p = get_data([i])[0] |
|
|
11 |
|
|
|
12 |
for (i, m) in enumerate(p['Med']): |
|
|
13 |
if i%100 == 0: |
|
|
14 |
print ", " + str(i) + '/' + str(len(p['Med'])), |
|
|
15 |
(name, rxclasses) = get_rx_classes(m['Medication'], include_name=True) |
|
|
16 |
m['RXNORM_NAME'] = name |
|
|
17 |
m['RXNORM_CLASSES'] = rxclasses |
|
|
18 |
|
|
|
19 |
save(p) |
|
|
20 |
|
|
|
21 |
def preprocess_medications_parallel(patient_range): |
|
|
22 |
pool = Pool(NTHREADS) |
|
|
23 |
pool.map(preprocess, patient_range) |
|
|
24 |
|
|
|
25 |
def preprocess(i): |
|
|
26 |
print "\nPreprocessing Medications - " + str(i) |
|
|
27 |
p = get_data([i])[0] |
|
|
28 |
|
|
|
29 |
for (i, m) in enumerate(p['Med']): |
|
|
30 |
(name, rxclasses) = get_rx_classes(m['Medication'], include_name=True) |
|
|
31 |
m['RXNORM_NAME'] = name |
|
|
32 |
m['RXNORM_CLASSES'] = rxclasses |
|
|
33 |
|
|
|
34 |
save(p) |
|
|
35 |
|
|
|
36 |
def remove_medication_preprocessing(num_patients): |
|
|
37 |
for i in range(num_patients): |
|
|
38 |
print "Removing Medication Preprocessing - " + str(i) |
|
|
39 |
p = get_data([i])[0] |
|
|
40 |
|
|
|
41 |
for m in p['Med']: |
|
|
42 |
del m['RXNORM_NAME'] |
|
|
43 |
del m['RXNORM_CLASSES'] |
|
|
44 |
|
|
|
45 |
save(p) |
|
|
46 |
|
|
|
47 |
if __name__ == "__main__": |
|
|
48 |
#preprocess_medications(1056) |
|
|
49 |
preprocess_medications_parallel(range(220,1056)) |