This repository was archived by the owner on May 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDISWithMarkup.py
More file actions
executable file
·129 lines (106 loc) · 4.24 KB
/
DISWithMarkup.py
File metadata and controls
executable file
·129 lines (106 loc) · 4.24 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
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
#!/usr/bin/env python
"""Report listing summaries containing specified markup.
"""
from datetime import date
from cdrcgi import Controller, Reporter
from cdrapi import db
from cdrapi.docs import Doc
class Control(Controller):
"""Top-level logic for the report."""
# The bogus revision level type of "other" is added to catch
# the situation when Insertion/Deletion markup has been added
# without a valid (i.e. None) revision level
TYPES = "publish", "approved", "proposed", "rejected", "other"
SUBTITLE = "Drug Summaries with Markup"
DOCTYPE = "DrugInformationSummary"
TODAY = date.today().strftime("%B %d, %Y")
def build_tables(self):
if not self.types:
self.show_form()
cols = ["ID", "Summary"]
for markup_type in self.TYPES:
if markup_type in self.types:
cols.append(markup_type.title())
query = db.Query("query_term t", "t.doc_id", "t.value").unique()
query.join("query_term a", "a.doc_id = t.doc_id")
query.where(f"t.path = '/{self.DOCTYPE}/Title'")
query.where(f"a.path = '/{self.DOCTYPE}/DrugInfoMetaData/Audience'")
query.where("a.value = 'Patients'")
rows = query.order("t.value").execute(self.cursor).fetchall()
summaries = [Summary(self, *row) for row in rows]
rows = [summary.row for summary in summaries if summary.in_scope]
return Reporter.Table(rows, columns=cols, caption=self.caption)
def populate_form(self, page):
"""Add the fields to the form.
Pass:
page - HTMLPage object to which the fields are attached.
"""
fieldset = page.fieldset("Type of mark-up to Include")
for value in self.TYPES:
fieldset.append(page.checkbox("type", value=value, checked=True))
page.form.append(fieldset)
@property
def caption(self):
"""Display string for the top of the report's table."""
return f"Count of Revision Level Markup - {date.today()}"
@property
def types(self):
"User-selected types, validated and sorted correctly."""
if not hasattr(self, "_types"):
types = self.fields.getlist("type")
for markup_type in types:
if markup_type not in self.TYPES:
self.bail()
self._types = [t for t in self.TYPES if t in types]
return self._types
class Summary:
"""Information about a PDQ Cancer Information Summary document."""
TAGS = "Insertion", "Deletion"
URL = "QcReport.py?DocId=CDR{}&Session=guest&DocVersion=-1"
def __init__(self, control, doc_id, title):
"""Assemble the counts needed for the report."""
self.__control = control
self.__id = doc_id
self.__title = title
self.__counts = {}
for markup_type in control.TYPES:
self.__counts[markup_type] = 0
doc = Doc(control.session, id=doc_id)
for tag in self.TAGS:
for node in doc.root.iter(tag):
self.__counts[node.get("RevisionLevel", "other")] += 1
@property
def id(self):
"""Unique ID for the summary document."""
return self.__id
@property
def title(self):
"""Summary document's title."""
return self.__title
@property
def row(self):
"""Assemble the report row for this summary."""
if not hasattr(self, "_row"):
self._row = [self.link, self.title]
for markup_type in self.__control.types:
count = self.__counts[markup_type]
if count:
self._row.append(Reporter.Cell(count, center=True))
else:
self._row.append("")
return self._row
@property
def link(self):
"""Cell containing a link to the QC report for this summary."""
url = self.URL.format(self.id)
return Reporter.Cell(self.id, href=url, center=True)
@property
def in_scope(self):
"""Does this have any reportable markup?"""
for markup_type in self.__control.types:
if self.__counts[markup_type]:
return True
return False
if __name__ == "__main__":
"""Don't run if this script is loaded as a module."""
Control().run()