Commit a4a1a5ba authored by Mikaël Salson's avatar Mikaël Salson
Browse files

modules/vidjil_utils: anon_ids now take a list of sample set IDs

This allows to speed up queries when we have many sample sets
parent c8168b0e
...@@ -260,7 +260,7 @@ def get_data(): ...@@ -260,7 +260,7 @@ def get_data():
if (sample_set.sample_type == defs.SET_TYPE_PATIENT): if (sample_set.sample_type == defs.SET_TYPE_PATIENT):
for row in db( db.patient.sample_set_id == request.vars["sample_set_id"] ).select() : for row in db( db.patient.sample_set_id == request.vars["sample_set_id"] ).select() :
log_reference_id = row.id log_reference_id = row.id
patient_name = vidjil_utils.anon_ids(row.id) patient_name = vidjil_utils.anon_ids([row.id])[0]
data["dataFileName"] = patient_name + " (" + config_name + ")" data["dataFileName"] = patient_name + " (" + config_name + ")"
data["info"] = db.patient[row.id].info data["info"] = db.patient[row.id].info
data["patient_id"] = row.id data["patient_id"] = row.id
...@@ -401,7 +401,7 @@ def get_custom_data(): ...@@ -401,7 +401,7 @@ def get_custom_data():
patient_run = db(db[sample_set.sample_type].sample_set_id == sample_set.id).select().first() patient_run = db(db[sample_set.sample_type].sample_set_id == sample_set.id).select().first()
config_id = db.results_file[id].config_id config_id = db.results_file[id].config_id
name = vidjil_utils.anon_ids(patient_run.id) if sample_set.sample_type == defs.SET_TYPE_PATIENT else patient_run.name name = vidjil_utils.anon_ids([patient_run.id])[0] if sample_set.sample_type == defs.SET_TYPE_PATIENT else patient_run.name
filename = db.sequence_file[sequence_file_id].filename filename = db.sequence_file[sequence_file_id].filename
data["samples"]["original_names"].append(name + "_" + filename) data["samples"]["original_names"].append(name + "_" + filename)
data["samples"]["timestamp"].append(str(db.sequence_file[sequence_file_id].sampling_date)) data["samples"]["timestamp"].append(str(db.sequence_file[sequence_file_id].sampling_date))
......
...@@ -13,7 +13,7 @@ if request.env.http_origin: ...@@ -13,7 +13,7 @@ if request.env.http_origin:
def anon_names(data): def anon_names(data):
for row in data: for row in data:
# TODO use helper ? # TODO use helper ?
row.name = vidjil_utils.anon_ids(row.id) row.name = vidjil_utils.anon_ids([row.id])[0]
return data return data
def get_data_list(table): def get_data_list(table):
...@@ -72,7 +72,7 @@ def index(): ...@@ -72,7 +72,7 @@ def index():
orderby=~db.user_log.created) orderby=~db.user_log.created)
for row in query: for row in query:
if row.patient.first_name is not None: if row.patient.first_name is not None:
row.names = vidjil_utils.anon_ids(row.user_log.record_id) row.names = vidjil_utils.anon_ids([row.user_log.record_id])[0]
else: else:
row.names = row.run.name row.names = row.run.name
return dict(query=query, return dict(query=query,
......
...@@ -162,7 +162,7 @@ def get_sample_name(sample_set_id): ...@@ -162,7 +162,7 @@ def get_sample_name(sample_set_id):
if patient_or_run is None: if patient_or_run is None:
return None return None
if sample.sample_type == defs.SET_TYPE_PATIENT: if sample.sample_type == defs.SET_TYPE_PATIENT:
return vidjil_utils.anon_ids(patient_or_run.id) return vidjil_utils.anon_ids([patient_or_run.id])[0]
return patient_or_run.name return patient_or_run.name
def get_set_group(sid): def get_set_group(sid):
......
...@@ -87,14 +87,18 @@ def anon_birth(patient_id, user_id): ...@@ -87,14 +87,18 @@ def anon_birth(patient_id, user_id):
else: else:
return age return age
def anon_ids(patient_id): def anon_ids(patient_ids, can_view = None):
'''Anonymize patient name. Only the 'anon' access see the full patient name.''' '''Anonymize patient name. Only the 'anon' access see the full patient name.
patient_ids is a list of patient IDs
'''
db = current.db db = current.db
auth=current.auth auth=current.auth
patient = db.patient[patient_id] patients = db(db.patient.id.belongs(patient_ids)).select(db.patient.sample_set_id,
db.patient.first_name,
db.patient.last_name)
return display_names(patient.sample_set_id, patient.first_name, patient.last_name) return [display_names(p.sample_set_id, p.first_name, p.last_name, can_view) for p in patients]
def anon_names(sample_set_id, first_name, last_name, can_view=None): def anon_names(sample_set_id, first_name, last_name, can_view=None):
''' '''
......
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