Skip to content

Commit

Permalink
no smoke, adding logging and tests looking for why the test system tr…
Browse files Browse the repository at this point in the history
…ied to send a "reminder" to an all opted-out patient's clinician.
  • Loading branch information
pbugni committed May 1, 2024
1 parent 86d6942 commit e9b5811
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
6 changes: 6 additions & 0 deletions portal/trigger_states/empro_messages.py
Expand Up @@ -109,6 +109,12 @@ def staff_emails(patient, hard_triggers, opted_out_domains, initial_notification
# All triggered were opted out of - pick up different email template
app_text_name += " all opted out"
opt_in_domains = []
if not initial_notification:
# seen on test, no idea how - include details in exception
msg = (f"Patient {patient.id} all opted out: {opted_out_domains} "
f"shouldn't be eligible for a reminder!")
current_app.logger.error(msg)
app_text_name = 'empro clinician trigger notification all opted out'
elif opted_out_domains:
app_text_name += " partially opted out"
opt_in_domains = list(set(hard_triggers) - set(opted_out_domains))
Expand Down
70 changes: 70 additions & 0 deletions tests/fixtures/trigger_state.py
Expand Up @@ -22,6 +22,76 @@ def mock_triggers():
}


@fixture
def mock_opted_out_triggers():
# pulled from test db, user 4231, id 1063 as of 4/30/24
return {
"domain": {
"sad": {
"ironman_ss.17": "hard",
"ironman_ss.18": "hard",
"ironman_ss.19": "hard",
"_total_opted_out": 1,
"_opt_out_this_visit": True,
"_sequential_hard_trigger_count": 3},
"anxious": {
"ironman_ss.11": "hard",
"ironman_ss.12": "hard",
"ironman_ss.13": "hard",
"_sequential_hard_trigger_count": 3},
"fatigue": {
"ironman_ss.9": "hard",
"ironman_ss.10": "hard",
"_sequential_hard_trigger_count": 3},
"insomnia": {
"ironman_ss.7": "hard",
"ironman_ss.8": "hard",
"_sequential_hard_trigger_count": 1},
"joint_pain": {
"ironman_ss.4": "hard",
"ironman_ss.5": "hard",
"ironman_ss.6": "hard",
"_sequential_hard_trigger_count": 3},
"discouraged": {
"ironman_ss.14": "hard",
"ironman_ss.15": "hard",
"ironman_ss.16": "hard",
"_sequential_hard_trigger_count": 3},
"general_pain": {
"ironman_ss.1": "soft",
"ironman_ss.2": "soft",
"ironman_ss.3": "soft",
"_sequential_hard_trigger_count": 0},
"social_isolation": {
"ironman_ss.20": "hard",
"_total_opted_out": 1,
"_opt_out_this_visit": True,
"_sequential_hard_trigger_count": 3}
},
"source": {
"qb_id": 115,
"qnr_id": 4841,
"authored": "2024-04-25T19:24:57Z",
"qb_iteration": 1},
"actions": {
"email": [
{"context": "patient thank you", "timestamp": "2024-04-25T19:25:32.151704Z", "email_message_id": 214811},
{"context": "initial staff alert", "timestamp": "2024-04-25T19:25:32.481573Z", "email_message_id": 214812},
{"context": "initial staff alert", "timestamp": "2024-04-25T19:25:32.739550Z", "email_message_id": 214813},
{"context": "initial staff alert", "timestamp": "2024-04-25T19:25:32.939555Z", "email_message_id": 214814},
{"context": "initial staff alert", "timestamp": "2024-04-25T19:25:33.155603Z", "email_message_id": 214815},
{"context": "initial staff alert", "timestamp": "2024-04-25T19:25:33.391523Z", "email_message_id": 214816},
{"context": "initial staff alert", "timestamp": "2024-04-25T19:25:33.628547Z", "email_message_id": 214817},
{"context": "initial staff alert", "timestamp": "2024-04-25T19:25:33.846962Z", "email_message_id": 214818},
{"context": "initial staff alert", "timestamp": "2024-04-25T19:25:34.069484Z", "email_message_id": 214819}]
},
"resolution": {
"qnr_id": 4842,
"authored": "2024-04-25T19:26:51Z",
"qb_iteration": None},
"action_state": "completed"
}

@fixture
def processed_ts(initialized_patient, mock_triggers):
user_id = db.session.merge(initialized_patient).id
Expand Down
10 changes: 10 additions & 0 deletions tests/test_trigger_states.py
Expand Up @@ -319,3 +319,13 @@ def test_subsequent_reminder_skips_weekends(initialized_patient):
# until Monday
assert ts.reminder_due(as_of_date=datetime.strptime(
"2021-02-15T12:00:00Z", "%Y-%m-%dT%H:%M:%SZ"))


def test_counts_from_db_triggers(initialized_patient, mock_opted_out_triggers):
user_id = db.session.merge(initialized_patient).id
ts = TriggerState(user_id=user_id, triggers=mock_opted_out_triggers)
opted_out_domains = ts.opted_out_domains()
hard_triggers = ts.hard_trigger_list()
assert set(["sad", "social_isolation"]) == set(opted_out_domains)
assert 7 == len(hard_triggers)
assert (set(hard_triggers) - set(opted_out_domains))

0 comments on commit e9b5811

Please sign in to comment.