Commit e9a07d37 authored by Mikaël Salson's avatar Mikaël Salson Committed by Vidjil Team
Browse files

vidjil_utils: two versions of patient name anonymization

One which directly takes the names in parameters (avoiding DB calls), another
taking te patient ID. The former is the recommended when the function is called many times.

Additionnally if the last parameter of anon_names is provided no DB call is performed.
parent 544c502b
......@@ -78,15 +78,26 @@ def anon_birth(patient_id, user_id):
return age
def anon(patient_id, user_id):
def anon_ids(patient_id):
'''Anonymize patient name. Only the 'anon' access see the full patient name.'''
db = current.db
last_name = db.patient[patient_id].last_name
first_name = db.patient[patient_id].first_name
if auth.has_permission("anon", "patient", patient_id, user_id):
return anon_names(patient_id, first_name, last_name)
def anon_names(patient_id, first_name, last_name, can_view=None):
Anonymize the given names of the patient whose ID is patient_id.
This function performs at most one db call (to know if we can see
the patient's personal informations). None is performed if can_view
is provided (to tell if one can view the patient's personal informations)
if can_view or (can_view == None and auth.can_view_patient_info(patient_id)):
name = last_name + " " + first_name
Supports Markdown
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