Commit 1194a69d authored by HERBERT Ryan's avatar HERBERT Ryan
Browse files

controllers/ default file patient results_file restructured quries in...

controllers/ default file patient results_file restructured quries in controllers to use new database structure
parent d1ddaf64
......@@ -181,7 +181,8 @@ def get_data():
if not auth.can_view_patient(request.vars["patient"]):
error += "you do not have permission to consult this patient ("+str(request.vars["patient"])+")"
query = db( ( db.fused_file.patient_id == request.vars["patient"] )
query = db( ( db.fused_file.sample_set_id == db.patient.sample_set_id)
& ( db.patient.id == request.vars["patient"] )
& ( db.fused_file.config_id == request.vars["config"] )
).select(db.fused_file.ALL)
for row in query :
......@@ -216,7 +217,8 @@ def get_data():
data["samples"]["db_key"].append('')
## récupération des infos stockées sur la base de données
query = db( ( db.patient.id == db.sequence_file.patient_id )
query = db( ( db.patient.sample_set_id == db.sample_set_membership.sample_set_id)
& ( db.sequence_file.id == db.sample_set_membership.sequence_file_id)
& ( db.results_file.sequence_file_id == db.sequence_file.id )
& ( db.patient.id == request.vars["patient"] )
& ( db.results_file.config_id == request.vars["config"] )
......@@ -260,7 +262,9 @@ def get_custom_data():
for id in request.vars["custom"] :
log.debug("id = '%s'" % str(id))
sequence_file_id = db.results_file[id].sequence_file_id
patient_id =db.sequence_file[sequence_file_id].patient_id
patient_id = db((db.sample_set_membership.sequence_file_id == sequence_file_id)
& (db.patient.sample_set_id == db.sample_set_membership.sample_set_id)
).select(db.patient.id).first()
if not auth.can_view_patient(patient_id):
error += "you do not have permission to consult this patient ("+str(patient_id)+")"
......@@ -279,7 +283,13 @@ def get_custom_data():
for id in request.vars["custom"] :
sequence_file_id = db.results_file[id].sequence_file_id
patient_id = db.sequence_file[sequence_file_id].patient_id
patient_id = db((db.sequence_file.id == sequence_file_id)
& (db.sample_set_membership.sequence_file_id == db.sequence_file.id)
& (db.sample_set.id == db.sample_set_membership.sample_set_id)
& (db.sample_set.sample_type == 'patient')
& (db.patient.sample_set_id == db.sample_set.id)
).select(db.patient.id).first()
config_id = db.results_file[id].config_id
patient_name = vidjil_utils.anon_ids(patient_id)
filename = db.sequence_file[sequence_file_id].filename
......
......@@ -19,7 +19,12 @@ def add():
elif not auth.can_upload_file(request.vars['id']):
return error_message("you don't have right to upload files")
else:
query = db((db.sequence_file.patient_id==request.vars['id'])).select()
query = db((db.patient.id == request.vars['id'])
&(db.sample_set.id == db.patient.sample_set_id)
&(db.sample_set.sample_type == 'patient')
&(db.sample_set_membership.sample_set_id == db.sample_set.id)
&(db.sequence_file.id == db.sample_set_membership.sequence_file_id)
).select(db.sequence_file.ALL)
if len(query) != 0 :
pcr = query[0].pcr
sequencer = query[0].sequencer
......@@ -44,7 +49,12 @@ def add_form():
error += " missing filename"
if error=="" :
query = db((db.sequence_file.patient_id==request.vars['patient_id'])).select()
query = db((db.patient.id == request.vars['patient_id'])
&(db.sample_set.id == db.patient.sample_set_id)
&(db.sample_set.sample_type == 'patient')
&(db.sample_set_membership.sample_set_id == db.sample_set.id)
&(db.sequence_file.id == db.sample_set_membership.sequence_file_id)
).select(db.sequence_file.ALL)
for row in query :
if row.filename == request.vars['filename'] :
return error_message("this sequence file already exists for this patient")
......@@ -115,7 +125,12 @@ def edit_form():
filename=filename,
provider=auth.user_id)
patient_id = db.sequence_file[request.vars["id"]].patient_id
patient_id = db((db.sequence_file.id == request.vars["id"])
&(db.sample_set_membership.sequence_file_id == db.sequence_file.id)
&(db.sample_set.id == db.sample_set_membership.sample_set_id)
&(db.sample_set.sample_type == 'patient')
&(db.patient.sample_set_id == db.sample_set.id)
).select(db.patient.id).first().id
res = {"file_id" : request.vars['id'],
"redirect": "patient/info",
......@@ -135,7 +150,12 @@ def upload():
error += "no sequence file with this id"
if not error:
patient_id = db.sequence_file[request.vars["id"]].patient_id
patient_id = db((db.sequence_file.id == request.vars["id"])
&(db.sample_set_membership.sequence_file_id == db.sequence_file.id)
&(db.sample_set.id == db.sample_set_membership.sample_set_id)
&(db.sample_set.sample_type == 'patient')
&(db.patient.sample_set_id == db.sample_set.id)
).select(db.patient.id).first()
mes += "file %s (%s): " % (request.vars['id'], patient_id)
res = {"message": mes + "processing uploaded file",
"redirect": "patient/info",
......
......@@ -43,12 +43,14 @@ def info():
config_name = db.config[request.vars["config_id"]].name
fused = db(
(db.fused_file.patient_id == patient)
(db.patient.id == patient)
& (db.patient.sample_set_id == db.fused_file.sample_set_id)
& (db.fused_file.config_id == config_id)
)
analysis = db(
db.analysis_file.patient_id == patient
(db.patient.id == patient)
& (db.patient.sample_set_id == db.analysis_file.sample_set_id)
).select(orderby=~db.analysis_file.analyze_date)
......@@ -74,7 +76,10 @@ def info():
query =[]
query2 = db(
(db.sequence_file.patient_id==db.patient.id)
(db.sequence_file.id == db.sample_set_membership.sequence_file_id)
& (db.sample_set_membership.sample_set_id == db.sample_set.id)
& (db.sample_set.sample_type == 'patient')
& (db.sample_set.id == db.patient.sample_set_id)
& (db.patient.id==request.vars["id"])
).select(
left=db.results_file.on(
......@@ -92,7 +97,10 @@ def info():
else:
query = db(
(db.sequence_file.patient_id==db.patient.id)
(db.sequence_file.id == db.sample_set_membership.sequence_file_id)
& (db.sample_set_membership.sample_set_id == db.sample_set.id)
& (db.sample_set.sample_type == 'patient')
& (db.sample_set.id == db.patient.sample_set_id)
& (db.patient.id==request.vars["id"])
).select(
left=db.results_file.on(
......@@ -148,7 +156,9 @@ def custom():
q = ((auth.accessible_query('read', db.patient))
& (auth.accessible_query('read', db.config))
& (db.patient.id==request.vars["patient_id"])
& (db.sequence_file.patient_id==db.patient.id)
& (db.sample_set.id == db.patient.sample_set_id)
& (db.sample_set_membership.sample_set_id == db.sample_set.id)
& (db.sequence_file.id == db.sample_set_membership.sequence_file_id)
& (db.results_file.sequence_file_id==db.sequence_file.id)
& (db.results_file.data_file != '')
& (db.config.id==db.results_file.config_id)
......@@ -157,7 +167,9 @@ def custom():
else:
q = ((auth.accessible_query('read', db.patient))
& (auth.accessible_query('read', db.config))
& (db.sequence_file.patient_id==db.patient.id)
& (db.sample_set.id == db.patient.sample_set_id)
& (db.sample_set_membership.sample_set_id == db.sample_set.id)
& (db.sequence_file.id == db.sample_set_membership.sequence_file_id)
& (db.results_file.sequence_file_id==db.sequence_file.id)
& (db.results_file.data_file != '')
& (db.config.id==db.results_file.config_id)
......@@ -167,9 +179,9 @@ def custom():
query = db(q).select(
db.patient.id, db.patient.info, db.patient.first_name, db.patient.last_name, db.results_file.id, db.results_file.config_id, db.sequence_file.sampling_date,
db.sequence_file.pcr, db.config.name, db.results_file.run_date, db.results_file.data_file, db.sequence_file.filename,
db.sequence_file.patient_id, db.sequence_file.data_file, db.sequence_file.id, db.sequence_file.info,
db.sequence_file.data_file, db.sequence_file.id, db.sequence_file.info,
db.sequence_file.size_file,
orderby = ~db.sequence_file.patient_id|db.sequence_file.id|db.results_file.run_date,
orderby = ~db.patient.id|db.sequence_file.id|db.results_file.run_date,
groupby = myGroupBy
)
......@@ -263,7 +275,7 @@ def stats():
except:
row_result_json = []
fused_file = db((db.fused_file.patient_id == row.sequence_file.patient_id) & (db.fused_file.config_id == row.results_file.config_id)).select(orderby = ~db.fused_file.id, limitby=(0,1))
fused_file = db((db.fused_file.sample_set_id == row.sample_set.id) & (db.fused_file.config_id == row.results_file.config_id)).select(orderby = ~db.fused_file.id, limitby=(0,1))
if len(fused_file) > 0 and fused_file[0].sequence_file_list is not None:
sequence_file_list = fused_file[0].sequence_file_list.split('_')
try:
......@@ -375,7 +387,9 @@ def index():
result[row.patient.id]['creator'] = row.auth_user.last_name
query2 = db(
db.patient.id == db.sequence_file.patient_id
(db.patient.sample_set_id == db.sample_set.id)
&(db.sample_set_membership.sample_set_id == db.sample_set.id)
&(db.sequence_file.id == db.sample_set_membership.sequence_file_id)
).select(
db.patient.id, db.sequence_file.size_file
)
......@@ -385,7 +399,7 @@ def index():
result[row.patient.id]['size'] += row.sequence_file.size_file
query3 = db(
(db.patient.id == db.fused_file.patient_id) &
(db.patient.sample_set_id == db.fused_file.sample_set_id) &
(db.fused_file.config_id == db.config.id) &
(auth.accessible_query('read', db.config) | auth.accessible_query('admin', db.config) )
).select(
......@@ -606,15 +620,21 @@ def confirm():
#
def delete():
if (auth.can_modify_patient(request.vars["id"]) ):
sample_set_id = db.patient[request.vars["id"]].sample_set_id
#delete data file
query = db( (db.sequence_file.patient_id==request.vars["id"])).select()
query = db( (db.sample_set_membership.sample_set_id == sample_set_id)
& (db.sequence_file.id == db.sample_set_membership.sequence_file_id)
).select(db.sequence_file.id)
for row in query :
db(db.results_file.sequence_file_id == row.id).delete()
sample_set_id = db.patient[request.vars["id"]].sample_set_id
#delete sequence file
db(db.sequence_file.patient_id == request.vars["id"]).delete()
query = db((db.sequence_file.id == db.sample_set_membership.sequence_file_id)
& (db.sample_set_membership.sample_set_id == sample_set_id)
).select(db.sequence_file.id)
for row in query :
db(db.sequence_file.id == row.id).delete()
#delete patient
db(db.patient.id == request.vars["id"]).delete()
......
......@@ -14,7 +14,8 @@ def index():
query = db(
(db.results_file.sequence_file_id==db.sequence_file.id)
& (db.sequence_file.patient_id==db.patient.id)
& (db.sequence_file.id==db.sample_set_membership.sequence_file_id)
& (db.sample_set_membership.sample_set_id==db.patient.sample_set_id)
& (db.results_file.config_id==db.config.id)
).select(
orderby = ~db.results_file.run_date
......@@ -74,14 +75,24 @@ def run_all():
## display run page result
## need ["results_file_id"]
def info():
if (auth.can_modify_patient(db.sequence_file[db.results_file[request.vars["results_file_id"]].sequence_file_id].patient_id ) ):
patient_id = db((db.sequence_file.id == db.results_file.sequence_file_id)
&(db.results_file.id == request.vars["results_file_id"])
&(db.sample_set_membership.sequence_file_id == db.sequence_file.id)
&(db.patient.sample_set_id == db.sample_set_membership.sample_set_id)
).select(db.patient.id).first().id
if (auth.can_modify_patient(patient_id)):
return dict(message=T('result info'))
else :
res = {"message": "acces denied"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def confirm():
if (auth.can_modify_patient(db.sequence_file[db.results_file[request.vars["results_file_id"]].sequence_file_id].patient_id )
patient_id = db((db.sequence_file.id == db.results_file.sequence_file_id)
&(db.results_file.id == request.vars["results_file_id"])
&(db.sample_set_membership.sequence_file_id == db.sequence_file.id)
&(db.patient.sample_set_id == db.sample_set_membership.sample_set_id)
).select(db.patient.id).first().id
if (auth.can_modify_patient(patient_id)
& auth.can_process_file()):
return dict(message=T('result confirm'))
else :
......@@ -90,24 +101,37 @@ def confirm():
#
def delete():
if (auth.can_modify_patient(db.sequence_file[db.results_file[request.vars["results_file_id"]].sequence_file_id].patient_id )
sample_set_id = db((db.sequence_file.id == db.results_file.sequence_file_id)
&(db.results_file.id == request.vars["results_file_id"])
&(db.sample_set_membership.sequence_file_id == db.sequence_file.id)
).select(db.sample_set_membership.sample_set_id).first().sample_set_id
patient_id = db(db.patient.sample_set_id == db.sample_set_membership.sample_set_id).select(db.patient.id).first().id
if (auth.can_modify_patient(patient_id)
& auth.can_process_file()):
config_id = db.results_file[request.vars["results_file_id"]].config_id
patient_id = db.sequence_file[db.results_file[request.vars["results_file_id"]].sequence_file_id].patient_id
# TODO is this necessary ?
patient_id = db((db.sequence_file.id == db.results_file.sequence_file_id)
&(db.results_file.id == request.vars["results_file_id"])
&(db.sample_set_membership.sequence_file_id == db.sequence_file.id)
&(db.patient.sample_set_id == db.sample_set_membership.sample_set_id)
).select(db.patient.id).first().id
#delete results_file
db(db.results_file.id == request.vars["results_file_id"]).delete()
#delete fused_file
count = db((db.patient.id == patient_id) &
(db.sequence_file.patient_id == db.patient.id) &
count = db((db.patient.id == patient_id) &
(db.patient.sample_set_id == db.sample_set_membership.sample_set_id) &
(db.sequence_file.id == db.sample_set_membership.sequence_file_id) &
(db.sequence_file.id == db.results_file.sequence_file_id) &
(db.results_file.config_id == config_id)
).count()
if count == 0 :
db((db.fused_file.patient_id == patient_id ) &
db((db.fused_file.sample_set_id == sample_set_id) &
(db.fused_file.config_id == config_id)
).delete()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment