|
a |
|
b/scripts/EligibilityBulletPointsSuccessful.py |
|
|
1 |
#start with first demarcator |
|
|
2 |
#have a flag that indicates if you've hit demarcator, if flag = 0, append cell to list |
|
|
3 |
#remove words followed by colon |
|
|
4 |
#when you hit colon, start deleting from end of buffer until reaching space |
|
|
5 |
# search for either space space space heifen space or space space space number . |
|
|
6 |
# keep scanning cell until you hit a demarcator, then add everything into a bullet point |
|
|
7 |
|
|
|
8 |
import csv |
|
|
9 |
|
|
|
10 |
bulletFile = open("InclusionExclusionBulletPoint.tsv","w",encoding="latin-1") |
|
|
11 |
|
|
|
12 |
with open("EligibilityCriteriaDocument.txt","r",encoding="latin-1") as tsvFile: |
|
|
13 |
tsvContents = csv.reader(tsvFile, delimiter='\t') |
|
|
14 |
goodCount = 0 |
|
|
15 |
count = 0 |
|
|
16 |
for row in tsvContents: |
|
|
17 |
count +=1 |
|
|
18 |
#if count!= 60567: |
|
|
19 |
#continue |
|
|
20 |
inclusion = row[10] |
|
|
21 |
exclusion = row[11] |
|
|
22 |
nctNumber = row[1] |
|
|
23 |
intervention = row[4] |
|
|
24 |
condition = row[3] |
|
|
25 |
gender = row[5] |
|
|
26 |
age = row[6] |
|
|
27 |
nctNumber = str(nctNumber) |
|
|
28 |
intervention = str(intervention) |
|
|
29 |
condition = str(condition) |
|
|
30 |
gender = str(gender) |
|
|
31 |
age = str(age) |
|
|
32 |
inclusionList = [] |
|
|
33 |
exclusionList = [] |
|
|
34 |
flag = 0 |
|
|
35 |
buffer = "" |
|
|
36 |
inclusion = str(inclusion) |
|
|
37 |
exclusion = str(exclusion) |
|
|
38 |
for i in range(len(inclusion)): |
|
|
39 |
|
|
|
40 |
if inclusion[i] == ":": |
|
|
41 |
k= i-1 |
|
|
42 |
while inclusion[k] != " ": |
|
|
43 |
k -= 1 |
|
|
44 |
buffer = buffer[:k] |
|
|
45 |
#print(inclusion) |
|
|
46 |
continue |
|
|
47 |
|
|
|
48 |
if i+4 < len(inclusion) and inclusion[i] == " " and inclusion[i+1] == " " and inclusion[i+2] == " " and inclusion[i+3] == "-" and inclusion[i+4] == " ": |
|
|
49 |
if flag == 1: |
|
|
50 |
inclusionList.append(buffer.strip(" ")) |
|
|
51 |
bulletFile.write(nctNumber + "\t" + condition + "\t" + "indication" + "\t" + buffer.strip(" ") + "\t" + intervention + "\n") |
|
|
52 |
buffer = "" |
|
|
53 |
i = i+4 |
|
|
54 |
|
|
|
55 |
flag = 1 |
|
|
56 |
continue |
|
|
57 |
|
|
|
58 |
if i+4 < len(inclusion) and inclusion[i] == " " and inclusion[i+1] == " " and inclusion[i+2] == " " and inclusion[i+3].isdigit(): |
|
|
59 |
k = i+4 |
|
|
60 |
|
|
|
61 |
while inclusion[k].isdigit(): |
|
|
62 |
k += 1 |
|
|
63 |
|
|
|
64 |
if inclusion[k] == ".": |
|
|
65 |
if flag == 1: |
|
|
66 |
inclusionList.append(buffer.strip(" ")) |
|
|
67 |
bulletFile.write(nctNumber + "\t" + condition + "\t" + "indication" + "\t" + buffer.strip(" ") + "\t" + intervention + "\n") |
|
|
68 |
buffer = "" |
|
|
69 |
i = k+1 |
|
|
70 |
flag = 1 |
|
|
71 |
continue |
|
|
72 |
|
|
|
73 |
|
|
|
74 |
buffer += inclusion[i] |
|
|
75 |
|
|
|
76 |
if flag == 0: |
|
|
77 |
inclusionList.append(inclusion) |
|
|
78 |
bulletFile.write(nctNumber + "\t" + condition + "\t" + "indication" + "\t" + inclusion + "\t" + intervention + "\n") |
|
|
79 |
|
|
|
80 |
else: |
|
|
81 |
inclusionList.append(buffer.strip(" ")) |
|
|
82 |
bulletFile.write(nctNumber + "\t" + condition + "\t" + "indication" + "\t" + buffer.strip(" ") + "\t" + intervention + "\n") |
|
|
83 |
goodCount += 1 |
|
|
84 |
|
|
|
85 |
bulletFile.write(nctNumber + "\t" + condition + "\t" + "indication" + "\t" + gender + "\t" + intervention + "\n") |
|
|
86 |
bulletFile.write(nctNumber + "\t" + condition + "\t" + "indication" + "\t" + age + "\t" + intervention + "\n") |
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
#write id number \t indication \t item \n to the file wherever you do inclusionlist.append |
|
|
91 |
|
|
|
92 |
|
|
|
93 |
flag = 0 |
|
|
94 |
buffer = "" |
|
|
95 |
for i in range(len(exclusion)): |
|
|
96 |
|
|
|
97 |
if exclusion[i] == ":": |
|
|
98 |
k= i-1 |
|
|
99 |
while exclusion[k] != " ": |
|
|
100 |
k -= 1 |
|
|
101 |
buffer = buffer[:k] |
|
|
102 |
#print(exclusion) |
|
|
103 |
continue |
|
|
104 |
|
|
|
105 |
if i+4 < len(exclusion) and exclusion[i] == " " and exclusion[i+1] == " " and exclusion[i+2] == " " and exclusion[i+3] == "-" and exclusion[i+4] == " ": |
|
|
106 |
if flag == 1: |
|
|
107 |
exclusionList.append(buffer.strip(" ")) |
|
|
108 |
bulletFile.write(nctNumber + "\t" + condition + "\t" + "counterindication" + "\t" + buffer.strip(" ") + "\t" + intervention + "\n") |
|
|
109 |
|
|
|
110 |
buffer = "" |
|
|
111 |
i = i+4 |
|
|
112 |
|
|
|
113 |
flag = 1 |
|
|
114 |
continue |
|
|
115 |
|
|
|
116 |
if i+4 < len(exclusion) and exclusion[i] == " " and exclusion[i+1] == " " and exclusion[i+2] == " " and exclusion[i+3].isdigit(): |
|
|
117 |
k = i+4 |
|
|
118 |
|
|
|
119 |
while exclusion[k].isdigit(): |
|
|
120 |
k += 1 |
|
|
121 |
|
|
|
122 |
if exclusion[k] == ".": |
|
|
123 |
if flag == 1: |
|
|
124 |
exclusionList.append(buffer.strip(" ")) |
|
|
125 |
bulletFile.write(nctNumber + "\t" + condition + "\t" + "counterindication" + "\t" + buffer.strip(" ") + "\t" + intervention + "\n") |
|
|
126 |
|
|
|
127 |
buffer = "" |
|
|
128 |
i = k+1 |
|
|
129 |
flag = 1 |
|
|
130 |
continue |
|
|
131 |
|
|
|
132 |
|
|
|
133 |
buffer += exclusion[i] |
|
|
134 |
|
|
|
135 |
if flag == 0: |
|
|
136 |
exclusionList.append(exclusion) |
|
|
137 |
bulletFile.write(nctNumber + "\t" + condition + "\t" + "counterindication" + "\t" + exclusion + "\t" + intervention + "\n") |
|
|
138 |
|
|
|
139 |
|
|
|
140 |
else: |
|
|
141 |
exclusionList.append(buffer.strip(" ")) |
|
|
142 |
bulletFile.write(nctNumber + "\t" + condition + "\t" + "counterindication" + "\t" + buffer.strip(" ") + "\t" + intervention + "\n") |
|
|
143 |
goodCount += 1 |
|
|
144 |
#copy paste, replace "inclusion" with "exclusion" |
|
|
145 |
|
|
|
146 |
#write id number \t indication \t item \n to the file wherever you do exclusionlist.append |
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
#take row[0] for id number |
|
|
152 |
|
|
|
153 |
#print(inclusionList) |
|
|
154 |
#write to new file |
|
|
155 |
# id \t inclusion/exclusion \t item \n |
|
|
156 |
|
|
|
157 |
|
|
|
158 |
bulletFile.close() |
|
|
159 |
|
|
|
160 |
|