-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAmbiguousEVSDrugConcepts.py
72 lines (60 loc) · 2.29 KB
/
AmbiguousEVSDrugConcepts.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
#!/usr/bin/env python3
"""Show EVS concepts linked by more than one active CDR drug index term.
"""
from datetime import datetime
from functools import cached_property
from cdrapi.docs import Doc
from cdrcgi import Controller, HTMLPage
from nci_thesaurus import EVS
class Control(Controller):
"""Top-level logic for the script."""
SUBTITLE = "EVS Drug Concepts Used By More Than One CDR Drug Term"
LOGNAME = "ambiguous-evs-drug-concepts"
def show_form(self):
"""Skip the form."""
self.show_report()
def show_report(self):
opts = dict(
banner=self.title,
subtitle=self.subtitle,
body_classes="report",
buttons=[],
session=self.session,
action=self.script,
control=self,
)
page = HTMLPage(self.title, **opts)
opts = dict(Filter="set:QC Term Set")
for concept in sorted(self.concepts.values()):
page.form.append(page.B.H3(f"{concept.name} ({concept.code})"))
if concept.definitions:
page.form.append(page.B.P(concept.definitions[0]))
ul = page.B.UL()
ids = self.evs.linked_concepts[concept.code]
docs = [Doc(self.session, id=id) for id in ids]
for doc in sorted(docs):
opts["DocId"] = doc.id
url = self.make_url("Filter.py", **opts)
link = page.B.A(doc.cdr_id, href=url, target="_blank")
ul.append(page.B.LI(f"{doc.title} (", link, ")"))
page.form.append(ul)
elapsed = datetime.now() - self.started
count = len(self.concepts)
footnote = page.B.P(f"{count} concepts; elapsed: {elapsed}")
footnote.set("class", "report-footer text-green")
page.form.append(footnote)
page.send()
@cached_property
def concepts(self):
"""Concepts associated with more than one CDR document."""
codes = []
for code, ids in self.evs.linked_concepts.items():
if len(ids) > 1:
codes.append(code)
return self.evs.fetchmany(codes)
@cached_property
def evs(self):
"""Access to common EVS utilities."""
return EVS()
if __name__ == "__main__":
Control().run()