def test_empty(self): # Base test system shouldn't generate any messages count_b4 = Communication.query.count() assert not count_b4 update_patient_loop(update_cache=False, queue_messages=True) count_after = Communication.query.count() assert count_b4 == count_after
def test_noworkdone_message(self): # At 14 days with no work started, should generate message mock_communication_request('localized', '{"days": 14}') # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics(backdate=relativedelta(days=14), local_metastatic='localized') update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert expected.user_id == TEST_USER_ID
def test_noworkdone_message(self): # At 14 days with no work started, should generate message mock_communication_request('localized', '{"days": 14}') # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics( backdate=relativedelta(days=14), local_metastatic='localized') update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert expected.user_id == TEST_USER_ID
def test_done_message(self): # At 14 days with all work done, should not generate message mock_communication_request('localized', '{"days": 14}') # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics(backdate=relativedelta(days=14), local_metastatic='localized') mock_qr(instrument_id='eproms_add') mock_qr(instrument_id='epic26') mock_qr(instrument_id='comorb') update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert not expected
def test_done_message(self): # At 14 days with all work done, should not generate message mock_communication_request('localized', '{"days": 14}') # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics( backdate=relativedelta(days=14), local_metastatic='localized') mock_qr(instrument_id='eproms_add') mock_qr(instrument_id='epic26') mock_qr(instrument_id='comorb') update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert not expected
def test_no_email(self): # User w/o email shouldn't trigger communication mock_communication_request('localized', '{"days": 14}') # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics(backdate=relativedelta(days=22), local_metastatic='localized') self.test_user = db.session.merge(self.test_user) self.test_user.email = NO_EMAIL_PREFIX with SessionScope(db): db.session.commit() update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query assert expected.count() == 0
def test_early(self): # Prior to days passing, no message should be generated mock_communication_request('symptom_tracker', '{"days": 90}') self.promote_user(role_name=ROLE.PATIENT.value) self.login() self.add_required_clinical_data(backdate=relativedelta(days=89)) self.test_user = db.session.merge(self.test_user) # Confirm test user qualifies for ST QB qbstatus = QB_Status(self.test_user, as_of_date=datetime.utcnow()) assert qbstatus.enrolled_in_classification('baseline') # Being a day short, shouldn't fire update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert not expected
def test_no_email(self): # User w/o email shouldn't trigger communication mock_communication_request('localized', '{"days": 14}') # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics( backdate=relativedelta(days=22), local_metastatic='localized') self.test_user = db.session.merge(self.test_user) self.test_user.email = NO_EMAIL_PREFIX with SessionScope(db): db.session.commit() update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query assert expected.count() == 0
def test_single_message(self): # With multiple time spaced CRs, only latest should send mock_communication_request('localized', '{"days": 7}') mock_communication_request('localized', '{"days": 14}') mock_communication_request('localized', '{"days": 21}') # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics( backdate=relativedelta(days=22), local_metastatic='localized') update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query assert expected.count() == 3 assert len([e for e in expected if e.status == 'preparation']) == 1 assert len([e for e in expected if e.status == 'suspended']) == 2
def test_single_message(self): # With multiple time spaced CRs, only latest should send mock_communication_request('localized', '{"days": 7}') mock_communication_request('localized', '{"days": 14}') mock_communication_request('localized', '{"days": 21}') # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics(backdate=relativedelta(days=22), local_metastatic='localized') update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query assert expected.count() == 3 assert len([e for e in expected if e.status == 'preparation']) == 1 assert len([e for e in expected if e.status == 'suspended']) == 2
def test_nearready_message(self): # At 13 days with all work in-progress, shouldn't generate message mock_communication_request('localized', '{"days": 14}') # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics(backdate=relativedelta(days=13)) self.promote_user(role_name=ROLE.PATIENT.value) self.mark_localized() mock_qr(instrument_id='eproms_add', status='in-progress') mock_qr(instrument_id='epic26', status='in-progress') mock_qr(instrument_id='comorb', status='in-progress') update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert not expected
def test_ready_message(self): # At 14 days with all work in-progress, should generate message mock_communication_request( 'localized', '{"days": 14}', communication_request_name="Symptom Tracker | 3 Mo Reminder (1)") # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics( backdate=relativedelta(days=14), local_metastatic='localized') mock_qr(instrument_id='eproms_add', status='in-progress') mock_qr(instrument_id='epic26', status='in-progress') mock_qr(instrument_id='comorb', status='in-progress') update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert expected.user_id == TEST_USER_ID
def test_ready_message(self): # At 14 days with all work in-progress, should generate message mock_communication_request( 'localized', '{"days": 14}', communication_request_name="Symptom Tracker | 3 Mo Reminder (1)") # Fake a user associated with localized org # and mark all baseline questionnaires as in-progress self.bless_with_basics(backdate=relativedelta(days=14), local_metastatic='localized') mock_qr(instrument_id='eproms_add', status='in-progress') mock_qr(instrument_id='epic26', status='in-progress') mock_qr(instrument_id='comorb', status='in-progress') update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert expected.user_id == TEST_USER_ID
def test_st_done(self): # Symptom Tracker QB with completed shouldn't fire mock_communication_request('symptom_tracker', '{"days": 90}') self.promote_user(role_name=ROLE.PATIENT.value) self.login() self.add_required_clinical_data(backdate=relativedelta(days=91)) self.test_user = db.session.merge(self.test_user) # Confirm test user qualifies for ST QB qbstatus = QB_Status(self.test_user, as_of_date=datetime.utcnow()) assert qbstatus.enrolled_in_classification('baseline') for instrument in symptom_tracker_instruments: mock_qr(instrument_id=instrument) # With all q's done, shouldn't generate a message update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert not expected
def test_procedure_update(self): # Newer procedure should alter trigger date and suspend message mock_communication_request('symptom_tracker', '{"days": 90}') self.promote_user(role_name=ROLE.PATIENT.value) self.login() self.add_required_clinical_data(backdate=relativedelta(days=91)) self.test_user = db.session.merge(self.test_user) # Confirm test user qualifies for ST QB qbstatus = QB_Status(self.test_user, as_of_date=datetime.utcnow()) assert qbstatus.enrolled_in_classification('baseline') # Add fresh procedure self.add_procedure('4', 'External beam radiation therapy', ICHOM) # New procedure date should suspend message update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert not expected
def test_st_metastatic(self): # Symptom Tracker QB on metastatic patient shouldn't qualify mock_communication_request('symptom_tracker', '{"days": 90}') self.promote_user(role_name=ROLE.PATIENT.value) self.login() self.add_required_clinical_data(backdate=relativedelta(days=91)) self.test_user = db.session.merge(self.test_user) self.test_user.save_observation( codeable_concept=CC.PCaLocalized, value_quantity=CC.FALSE_VALUE, audit=Audit(user_id=TEST_USER_ID, subject_id=TEST_USER_ID), status='final', issued=None) # Confirm test user doesn't qualify for ST QB qbstatus = QB_Status(self.test_user, as_of_date=datetime.utcnow()) assert not qbstatus.enrolled_in_classification('baseline') # shouldn't generate a message either update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert not expected
def test_st_metastatic(self): # Symptom Tracker QB on metastatic patient shouldn't qualify mock_communication_request('symptom_tracker', '{"days": 90}') self.promote_user(role_name=ROLE.PATIENT.value) self.login() self.add_required_clinical_data(backdate=relativedelta(days=91)) self.test_user = db.session.merge(self.test_user) self.test_user.save_observation(codeable_concept=CC.PCaLocalized, value_quantity=CC.FALSE_VALUE, audit=Audit(user_id=TEST_USER_ID, subject_id=TEST_USER_ID), status='final', issued=None) # Confirm test user doesn't qualify for ST QB qbstatus = QB_Status(self.test_user, as_of_date=datetime.utcnow()) assert not qbstatus.enrolled_in_classification('baseline') # shouldn't generate a message either update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert not expected
def test_st_undone(self): # Symptom Tracker QB with incompleted should generate communication mock_communication_request('symptom_tracker', '{"days": 30}') self.app.config['NO_CHALLENGE_WO_DATA'] = False self.promote_user(role_name=ROLE.PATIENT.value) self.login() self.add_required_clinical_data(backdate=relativedelta(days=31)) self.test_user = db.session.merge(self.test_user) self.test_user.birthdate = '1969-07-16' # Confirm test user qualifies for ST QB assert QuestionnaireBank.qbs_for_user(self.test_user, 'baseline', as_of_date=datetime.utcnow()) # With most q's undone, should generate a message mock_qr(instrument_id='epic26') a_s, _ = overall_assessment_status(TEST_USER_ID) assert 'In Progress' == a_s update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert expected
def test_st_undone(self): # Symptom Tracker QB with incompleted should generate communication mock_communication_request('symptom_tracker', '{"days": 30}') self.app.config['NO_CHALLENGE_WO_DATA'] = False self.promote_user(role_name=ROLE.PATIENT.value) self.login() self.add_required_clinical_data(backdate=relativedelta(days=31)) self.test_user = db.session.merge(self.test_user) self.test_user.birthdate = '1969-07-16' # Confirm test user qualifies for ST QB qstats = QB_Status(self.test_user, as_of_date=datetime.utcnow()) assert qstats.enrolled_in_classification('baseline') # With most q's undone, should generate a message mock_qr(instrument_id='epic26') invalidate_users_QBT(TEST_USER_ID) self.test_user = db.session.merge(self.test_user) qstats = QB_Status(self.test_user, as_of_date=datetime.utcnow()) assert OverallStatus.in_progress == qstats.overall_status update_patient_loop(update_cache=False, queue_messages=True) expected = Communication.query.first() assert expected