-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.py
85 lines (65 loc) · 2.44 KB
/
controllers.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
73
74
75
76
77
78
79
80
81
82
83
84
85
import web
import rprocessor
from core.risrecord import RISRecord
from interface.risconnector import RISConnector
from utils.logger import Logger
render = web.template.render('templates/', base='base')
class index:
def GET(self):
return render.index()
class faq:
def GET(self):
return render.faq()
class search:
"""gets the search variables, searches for associated records,
processes the records through the icd-cpt engine and returns results
"""
def GET(self):
# process search vars
i = web.input(status=[])
start = i.begin_date
end = i.end_date
statuses = i.status # array
sortby = i.sortby if hasattr(i, 'sortby') else 'date'
sortdir = i.sortdir if hasattr(i, 'sortdir') else 'desc'
page = int(i.page) if hasattr(i, 'page') else 1
# get records in model.Study object format
records = RISConnector().get_records(start, end)
# convert sql records into risrecord objects
risrecs = {}
for r in records:
acc = r.accession
if not risrecs.has_key(acc):
risrecs[acc] = RISRecord(
r.accession,
r.referring,
r.visit,
r.date
)
risrecs[acc].add_pair(r.icd, r.cpt)
#re-assign records to just risrecord objects
records = risrecs.values()
# call validate method on records
for r in records:
r.validatePairs()
# filter / sort items
records = rprocessor.filter(records, statuses)
records = rprocessor.sort(records, sortby, sortdir)
#get number of results before we paginate
total_pages = rprocessor.howManyPages(records)
num_results = len(records)
records = rprocessor.paginate(records, page)
# jsonize
json = ['{',
'"page":%d,' % page,
'"totalpages": %d,' % total_pages,
'"numresults":"%d",' % num_results,
'"records": ['
]
for i in range(len(records)):
json.append(records[i].json())
if(i + 1 < len(records)):
json.append(',')
json.append(']}')
web.header('Content-Type', 'application/json')
return ''.join(json)