-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapap.py
More file actions
executable file
·66 lines (59 loc) · 1.76 KB
/
apap.py
File metadata and controls
executable file
·66 lines (59 loc) · 1.76 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
from pySPL import DrugLabel
from utils import file_list
import csv
from datetime import date
filename = "output" + date.today().strftime("%d%m%y") + ".csv"
with open(filename, 'wb') as f:
#pipe delimiter is so we can use commas elsewhere; nobody uses pipes and excel/google docs do not care
writer = csv.writer(f,delimiter="|")
#writes header row. need to keep this the same as how it's written below
writer.writerow(
["distributor",
"drug name",
"ndc",
"label type",
"dosage form",
"marketing start date",
"revision date",
"warfarin mentioned?",
"warfarin section",
"warfarin time",
"#actives",
"actives",
"url",
])
count = 1
skipped = 0
for xml_label in file_list:
print "label ",count," of ",len(file_list),"(%s)" % xml_label.split("/")[-1]
label = DrugLabel(xml_label)
# exceptions:
# skip kits
if label.dosage_form() == "KIT" or label.dosage_form() == "BULK INGREDIENT" or label.label_type() == "BULK INGREDIENT":
print "passing on %s - kit or bulk ingredient" % xml_label.split("/")[-1]
skipped += 1
pass
# skip propoxyphene-containing drugs as per Dr. Horn's advice
elif 'propoxyphene' in label.actives() or 'PROPOXYPHENE' in label.actives() or 'Propoxyphene' in label.actives():
print "passing on %s - contains propoxyphene" % xml_label.split("/")[-1]
skipped += 1
pass
else:
writer.writerow([
label.distributor(),
label.name(),
label.ndc(),
label.label_type(),
label.dosage_form(),
label.start_date(),
label.revision_date(),
label.test_word("warfarin"),
label.get_word_section("warfarin"),
label.get_word_time("warfarin"),
len(label.actives()),
label.actives(),
label.build_url(),
])
count+=1
print "success! (skipped %s labels)" %skipped
f.close()