Skip to content

Commit d367a21

Browse files
northwestwitchChiara Rasi
andauthored
Add user roles to patient's contact and update conftest file (#383)
* Add user roles to patient's contact and update conftest file * Reformat * Simplify code * tiny fix in test --------- Co-authored-by: Chiara Rasi <rasi.chiara@gmacil.com>
1 parent 40b8a39 commit d367a21

4 files changed

Lines changed: 27 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
## [unpublished]
22
### Added
33
- `email` and `additionalContacts` in API reference json schema (#380)
4+
- Allow assigning contact `roles` using the cli (#383)
45
### Changed
56
- Updated versions of external actions and MongoDB in GitHub workflows (#374)
67
- Allow updating contact's email and href separately using the command line (#381)
8+
- Conftest file to reflect a patient's contact with email, roles and additionalContacts (#383)
79
### Fixed
810
- Fixed typo on conda installation docs (#373)
911

patientMatcher/cli/update.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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))

tests/cli/test_update.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
NEW_EMAIL = "new.email@mail.com"
99
NEW_NAME = "New Name"
1010
TEST_INST = "Test Institution"
11+
TEST_ROLES = ["clinician", "researcher"]
1112

1213

1314
@responses.activate
@@ -67,6 +68,10 @@ def test_update_contact_success(mock_app, gpx4_patients, monkeypatch):
6768
NEW_NAME,
6869
"--new-institution",
6970
TEST_INST,
71+
"--new-role",
72+
TEST_ROLES[0],
73+
"--new-role",
74+
TEST_ROLES[1],
7075
],
7176
)
7277

@@ -80,6 +85,7 @@ def test_update_contact_success(mock_app, gpx4_patients, monkeypatch):
8085
assert updated_patient[0]["contact"]["email"] == NEW_EMAIL
8186
assert updated_patient[0]["contact"]["name"] == NEW_NAME
8287
assert updated_patient[0]["contact"]["institution"] == TEST_INST
88+
assert updated_patient[0]["contact"]["roles"] == TEST_ROLES
8389

8490

8591
def test_update_contact_validation(mock_app, gpx4_patients):

tests/conftest.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
"SGOL1": "ENSG00000129810",
3939
}
4040

41+
PATIENT_CONTACT = {
42+
"href": "https://someurl.com",
43+
"email": "user@mail.com",
44+
"institution": "Test institution",
45+
"name": "Test User",
46+
"roles": ["clinician", "researcher"],
47+
}
48+
4149

4250
@pytest.fixture
4351
def mock_symbol_2_ensembl():
@@ -126,11 +134,8 @@ def test_node():
126134
def entrez_gene_patient():
127135
"""Returns a test patient with an entrez gene ID"""
128136
patient = {
129-
"contact": {
130-
"href": "mailto:someuser@mail.com",
131-
"institution": "Test institution",
132-
"name": "Test user",
133-
},
137+
"contact": PATIENT_CONTACT,
138+
"additionalContacts": [PATIENT_CONTACT],
134139
"disorders": [],
135140
"features": [
136141
{"id": "HP:0001263", "label": "Global developmental delay", "observed": "yes"},

0 commit comments

Comments
 (0)