@@ -27,23 +27,26 @@ def update():
2727@click .option ("--new-email" , type = click .STRING , required = False , help = "New email" )
2828@click .option ("--new-name" , type = click .STRING , required = False , help = "New name" )
2929@click .option ("--new-institution" , type = click .STRING , required = False , help = "New institution" )
30- def contact (href , email , new_href , new_email , new_name , new_institution ):
30+ @click .option ("--new-role" , multiple = True , help = "New role(s)" )
31+ def contact (href , email , new_href , new_email , new_name , new_institution , new_role ):
3132 """Update contact person for a group of patients."""
3233
3334 # Validate exactly one identifier
3435 if bool (href ) == bool (email ):
3536 raise click .UsageError ("You must provide EITHER --href or --email" )
3637
3738 # Validate at least one field to update
38- if not any ([new_href , new_email , new_name , new_institution ]):
39+ if not any ([new_href , new_email , new_name , new_institution , new_role ]):
3940 click .echo (
4041 "Provide at least a field you wish to update: "
4142 "--new-href / --new-email / --new-name / --new-institution"
4243 )
4344 return
4445
4546 # Build query
46- query = {HREF_FIELD : {"$regex" : href }} if href else {"contact.email" : email }
47+ query = {"contact.email" : email }
48+ if href :
49+ query = {HREF_FIELD : {"$regex" : href }}
4750
4851 database = current_app .db
4952 matching_patients = patients (database = database , match_query = query )
@@ -64,7 +67,7 @@ def contact(href, email, new_href, new_email, new_name, new_institution):
6467 if new_href :
6568 if EMAIL_REGEX .match (new_href ) and not new_href .startswith ("mailto:" ):
6669 new_href = f"mailto:{ new_href } "
67- if not href_validate (new_href ):
70+ elif not href_validate (new_href ):
6871 LOG .error (
6972 "Provided href does not have a valid schema. Provide either a URL (http://.., https://..) or an email address (mailto:..)"
7073 )
@@ -76,6 +79,8 @@ def contact(href, email, new_href, new_email, new_name, new_institution):
7679 set_options ["contact.name" ] = new_name
7780 if new_institution :
7881 set_options ["contact.institution" ] = new_institution
82+ if new_role :
83+ set_options ["contact.roles" ] = list (new_role )
7984
8085 # Confirm and update
8186 patient_count = len (list (matching_patients ))
0 commit comments