-
Notifications
You must be signed in to change notification settings - Fork 1
/
modalityctr.py
313 lines (295 loc) · 13.9 KB
/
modalityctr.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# Modality controllers
from py4web import action, request, abort, redirect, URL, Field, response # add response to throw http error 400
from yatl.helpers import A, XML, OPTION, CAT
from .common import db, session, T, cache, auth, logger, authenticated, unauthenticated, flash
from pydal.validators import CRYPT # to encrypt passwords
from py4web.utils.form import Form, FormStyleBulma, FormStyleBootstrap4 # added import Field Form and FormStyleBulma to get form working
from py4web.utils.grid import Grid
# import settings
from .settings import LOCAL_URL, APP_NAME, ASSETS_FOLDER, MACHINES_FOLDER, NEW_INSTALLATION, TIMEOFFSET, ENV_STATUS
# import userful
from .useful import dropdownSelect, rows2json, getMembershipId
# get standard index in db for patient/user profile
# TODO remove try and check if new installation
if "NEW_INSTALLATION" in globals():
if NEW_INSTALLATION == True:
pass
else:
mdId = db(db.modality.modality_name == 'MD').select(db.modality.id).first().id
gpId = db(db.modality.modality_name == 'GP').select(db.modality.id).first().id
genderId = {
db(db.gender.sex == 'Male').select(db.gender.id).first().id : "Male",
db(db.gender.sex == 'Female').select(db.gender.id).first().id : "Female",
db(db.gender.sex == 'Other').select(db.gender.id).first().id : "Other" }
else:
# TODO: create an array for practitioners in modalities
mdId = db(db.modality.modality_name == 'MD').select(db.modality.id).first().id
gpId = db(db.modality.modality_name == 'GP').select(db.modality.id).first().id
genderId = {
db(db.gender.sex == 'Male').select(db.gender.id).first().id : "Male",
db(db.gender.sex == 'Female').select(db.gender.id).first().id : "Female",
db(db.gender.sex == 'Other').select(db.gender.id).first().id : "Other" }
# tono controller
@action('tono')
@action('modalityCtr/tono/<wlId>')
@action.uses(session, auth, db,'modalityCtr/tono.html')
def tono(wlId):
"""
The 'tono' function is used to retrieve necessary information for encoding tonometry.
It fetches details on a specific worklist, along with information on the provider and senior associated with that worklist.
Args:
wlId (str): The ID of the worklist from which to retrieve information.
Returns:
dict: A dictionary containing local information including:
- Information on the specific worklist
- Information on the provider and senior linked to the worklist
- Information about the authenticated user
- Environment constants like 'env_status', 'timeOffset', and 'hosturl'
Note:
Decorators
'tono':
'modalityCtr/tono/<wlId>': endpoint
'uses' decorators from py4web to specify its behavior and dependencies.
"""
env_status = ENV_STATUS
timeOffset = TIMEOFFSET
app_name = APP_NAME
hosturl = LOCAL_URL
user = auth.get_user()
genderObj = genderId # used in patient-bar
wldb = db.worklist
wlDict = db(wldb.id == wlId).select(wldb.ALL,db.auth_user.ALL, db.modality.modality_name,
join=[
db.auth_user.on(db.auth_user.id == wldb.id_auth_user),
db.modality.on(db.modality.id == wldb.modality_dest),
]
).as_json()
providerDict = db(wldb.id == wlId).select(db.auth_user.ALL,
left = db.auth_user.on(db.auth_user.id == wldb.provider)).as_json()
seniorDict = db(wldb.id == wlId).select(db.auth_user.ALL,
left = db.auth_user.on(db.auth_user.id == wldb.senior)).as_json()
return locals()
# autorx controller
@action('autorx')
@action('modalityCtr/autorx/<wlId>')
@action.uses(session, auth, db,'modalityCtr/autorx.html')
def autorx(wlId):
env_status = ENV_STATUS
timeOffset = TIMEOFFSET
app_name = APP_NAME
app_name = APP_NAME
hosturl = LOCAL_URL
user = auth.get_user()
genderObj = genderId # used in patient-bar
wldb = db.worklist
patientId = db(db.worklist.id == wlId).select(db.worklist.id_auth_user).first().id_auth_user
wlDict = db(wldb.id == wlId).select(wldb.ALL,db.auth_user.ALL, db.modality.modality_name,
join=[
db.auth_user.on(db.auth_user.id == wldb.id_auth_user),
db.modality.on(db.modality.id == wldb.modality_dest),
]
).as_json()
providerDict = db(wldb.id == wlId).select(db.auth_user.ALL,
left = db.auth_user.on(db.auth_user.id == wldb.provider)).as_json()
seniorDict = db(wldb.id == wlId).select(db.auth_user.ALL,
left = db.auth_user.on(db.auth_user.id == wldb.senior)).as_json()
qFar = db.optotype.distance == 'far'
qClose = db.optotype.distance == 'close'
optoFarOptions = dropdownSelect(db.optotype, db.optotype.fields[2],1,'index', qFar)
optoCloseOptions = dropdownSelect(db.optotype, db.optotype.fields[2],1,'index', qClose)
statusRxOptions = dropdownSelect(db.status_rx, db.status_rx.fields[1],'index')
statusRxIndex = db(db.status_rx).select(db.status_rx.id,db.status_rx.status).as_json()
return locals()
def initFields(wlId,table,lat=""):
"""
Initialize fields in view and get values or return empty string "" if None
filter laterality if necessary
return a dictionary used in array for view
Args:
wlId (str): The ID of the worklist from which to retrieve information.
table(str): table containing fields content
lat(str): laterality if applicable, "" if not
Returns:
items(dict)
dictionary containing ffield content relative to laterality if applicable
exported with [[ = XML(field['description']) ]] in view
"""
fieldsArr= db[table].fields
if lat == "":
query = db(db[table].id_worklist == wlId)
else:
query = db((db[table].id_worklist == wlId) & (db[table].laterality == lat))
items = {}
if query.count() > 0:
items = query.select().first()
# remove 'None' when empty fields
for item in items:
if items[item] == None:
items[item] = ""
else :
for i in range(len(fieldsArr)):
items[fieldsArr[i]]=""
return items
### md controller
@action('md')
@action('modalityCtr/md/<wlId>')
@action.uses(session, auth.user, db,'modalityCtr/md.html')
def md(wlId):
env_status = ENV_STATUS
timeOffset = TIMEOFFSET
app_name = APP_NAME
modalityController = 'md'
import base64
from datetime import datetime
response.headers['Cross-Origin-Embedder-Policy']='require-corp'
response.headers['Cross-Origin-Opener-Policy']='same-origin'
hosturl = LOCAL_URL
user = auth.get_user()
userMembership = db(db.membership.id == user['membership']).select(db.membership.membership).first()['membership']
userHierarchy = db(db.membership.id == user['membership']).select(db.membership.hierarchy).first()['hierarchy']
if userHierarchy >= 3:
redirect(URL('worklist'))
db.auth_user.password.readable = False
db.auth_user.password.writable = False
genderObj = genderId # used in patient-bar
wldb = db.worklist
wlDict = db(wldb.id == wlId).select(wldb.ALL,db.auth_user.ALL, db.modality.modality_name,
join=[
db.auth_user.on(db.auth_user.id == wldb.id_auth_user),
db.modality.on(db.modality.id == wldb.modality_dest),
]
).as_json()
providerDict = db(wldb.id == wlId).select(db.auth_user.ALL,
left = db.auth_user.on(db.auth_user.id == wldb.provider)).as_json()
seniorDict = db(wldb.id == wlId).select(db.auth_user.ALL,
left = db.auth_user.on(db.auth_user.id == wldb.senior)).as_json()
patientId = db(db.worklist.id == wlId).select(db.worklist.id_auth_user).first().id_auth_user
userdb = db.auth_user
mdHistory = db((db.worklist.modality_dest == mdId) & (db.worklist.id_auth_user == patientId)).select().as_json()
modalityDict = {}
rows = db(db.modality.id_modality_controller==db.modality_controller.id).select()
for row in rows:
modalityDict[row.modality.modality_name]=row.modality_controller.modality_controller_name
# init all fields
currentHx = initFields(wlId,'current_hx')
antRight = initFields(wlId,'ant_biom','right')
postRight = initFields(wlId,'post_biom','right')
antLeft = initFields(wlId,'ant_biom','left')
postLeft = initFields(wlId,'post_biom','left')
motility = initFields(wlId,'motility')
phoria = initFields(wlId,'phoria')
pupils = initFields(wlId,'pupils')
ccx = initFields(wlId,'ccx')
ccxR = initFields(wlId,'ccx','right')
ccxL = initFields(wlId,'ccx','left')
followup = initFields(wlId,'followup')
billing = initFields(wlId,'billing')
mddb=db.md_params # TODO: if details from doctor is not provided, return "Please provide provider details"
mdParams= db(mddb.id_auth_user == user['id']).select(mddb.id_auth_user,mddb.inami,mddb.email,mddb.officename,mddb.officeaddress,mddb.officezip,mddb.officetown,mddb.officeurl,mddb.officephone,mddb.companynum,mddb.companyname,mddb.companyiban,mddb.companyaddress).first().as_dict()
userDict = db(db.auth_user.id == user['id']).select(db.auth_user.first_name,db.auth_user.last_name).first().as_dict()
# glasses assets
axe_img_path = ASSETS_FOLDER+'/images/assets/glassesrx/axe.jpg'
logo_img_path = ASSETS_FOLDER+'/images/assets/glassesrx/logo.jpg'
axe64 = base64.b64encode(open(axe_img_path, "rb").read())
logo64 = base64.b64encode(open(logo_img_path, "rb").read())
return locals()
@action('gp')
@action('modalityCtr/gp/<wlId>')
@action.uses(session, auth.user, db,'modalityCtr/gp.html')
def gp(wlId):
env_status = ENV_STATUS
timeOffset = TIMEOFFSET
app_name = APP_NAME
modalityController = 'gp'
import base64
from datetime import datetime
response.headers['Cross-Origin-Embedder-Policy']='require-corp'
response.headers['Cross-Origin-Opener-Policy']='same-origin'
hosturl = LOCAL_URL
user = auth.get_user()
userMembership = db(db.membership.id == user['membership']).select(db.membership.membership).first()['membership']
userHierarchy = db(db.membership.id == user['membership']).select(db.membership.hierarchy).first()['hierarchy']
if userHierarchy >= 3:
redirect(URL('worklist'))
db.auth_user.password.readable = False
db.auth_user.password.writable = False
genderObj = genderId # used in patient-bar
wldb = db.worklist
wlDict = db(wldb.id == wlId).select(wldb.ALL,db.auth_user.ALL, db.modality.modality_name,
join=[
db.auth_user.on(db.auth_user.id == wldb.id_auth_user),
db.modality.on(db.modality.id == wldb.modality_dest),
]
).as_json()
providerDict = db(wldb.id == wlId).select(db.auth_user.ALL,
left = db.auth_user.on(db.auth_user.id == wldb.provider)).as_json()
seniorDict = db(wldb.id == wlId).select(db.auth_user.ALL,
left = db.auth_user.on(db.auth_user.id == wldb.senior)).as_json()
patientId = db(db.worklist.id == wlId).select(db.worklist.id_auth_user).first().id_auth_user
userdb = db.auth_user
# get history from previous main consultations for GP
mdHistory = db((db.worklist.modality_dest == gpId) & (db.worklist.id_auth_user == patientId)).select().as_json()
modalityDict = {}
rows = db(db.modality.id_modality_controller==db.modality_controller.id).select()
for row in rows:
modalityDict[row.modality.modality_name]=row.modality_controller.modality_controller_name
# init all fields
currentHx = initFields(wlId,'current_hx')
soap = initFields(wlId,'soap')
inspection = initFields(wlId,'inspection')
auscultation = initFields(wlId,'auscultation')
palpation = initFields(wlId,'palpation')
percussion = initFields(wlId,'percussion')
neuro = initFields(wlId,'neuro')
motility = initFields(wlId,'motility')
phoria = initFields(wlId,'phoria')
pupils = initFields(wlId,'pupils')
ccx = initFields(wlId,'ccx')
followup = initFields(wlId,'followup')
billing = initFields(wlId,'billing')
mddb=db.md_params
mdParams= db(mddb.id_auth_user == user['id']).select(mddb.id_auth_user,mddb.inami,mddb.email,mddb.officename,mddb.officeaddress,mddb.officezip,mddb.officetown,mddb.officeurl,mddb.officephone,mddb.companynum,mddb.companyname,mddb.companyiban,mddb.companyaddress).first().as_dict()
userDict = db(db.auth_user.id == user['id']).select(db.auth_user.first_name,db.auth_user.last_name).first().as_dict()
logo_img_path = ASSETS_FOLDER+'/images/assets/glassesrx/logo.jpg'
logo64 = base64.b64encode(open(logo_img_path, "rb").read())
return locals()
# biometry controller
@action('lenstar')
@action('modalityCtr/lenstar/<wlId>')
@action.uses(session, auth, db,'modalityCtr/lenstar.html')
def lenstar(wlId):
env_status = ENV_STATUS
timeOffset = TIMEOFFSET
app_name = APP_NAME
hosturl = LOCAL_URL
user = auth.get_user()
genderObj = genderId # used in patient-bar
wldb = db.worklist
patientId = db(db.worklist.id == wlId).select(db.worklist.id_auth_user).first().id_auth_user
wlDict = db(wldb.id == wlId).select(wldb.ALL,db.auth_user.ALL, db.modality.modality_name,
join=[
db.auth_user.on(db.auth_user.id == wldb.id_auth_user),
db.modality.on(db.modality.id == wldb.modality_dest),
]
).as_json()
providerDict = db(wldb.id == wlId).select(db.auth_user.ALL,
left = db.auth_user.on(db.auth_user.id == wldb.provider)).as_json()
seniorDict = db(wldb.id == wlId).select(db.auth_user.ALL,
left = db.auth_user.on(db.auth_user.id == wldb.senior)).as_json()
return locals()
# helloworld controller
@action('hello')
@action('modalityCtr/hello')
@action.uses(session, auth, db,'modalityCtr/hello.html')
def hello():
env_status = ENV_STATUS
timeOffset = TIMEOFFSET
app_name = APP_NAME
import base64
hosturl = LOCAL_URL
database = db._tables
user = auth.get_user()
# userId = db(db.worklist.id == wlId).select(db.worklist.id_auth_user).first().id_auth_user
userId = "1"
string = "Hello World!"
return locals()