Exemple #1
0
    def test_completed_older_rp(self):
        """If current qb completed on older rp, should show as done"""
        fourmonthsago = now - timedelta(days=120)
        weekago = now - timedelta(weeks=1)
        twoweeksago = now - timedelta(weeks=2)
        org = self.setup_qbs(rp_name='v2', retired_as_of=weekago)
        org_id = org.id
        self.setup_qbs(org=org, rp_name='v3')

        self.test_user.organizations.append(org)
        audit = Audit(user_id=TEST_USER_ID, subject_id=TEST_USER_ID)
        uc = UserConsent(user_id=TEST_USER_ID,
                         organization_id=org_id,
                         audit=audit,
                         agreement_url='http://no.com',
                         acceptance_date=fourmonthsago)
        with SessionScope(db):
            db.session.add(audit)
            db.session.add(uc)
            db.session.commit()

        # Two weeks ago, still on rp v2, should be in 3mo recurrence
        user = db.session.merge(self.test_user)
        a_s = AssessmentStatus(user=user, as_of_date=twoweeksago)
        v2qb = a_s.qb_data.qbd.questionnaire_bank
        self.assertEqual('CRV_recurring_3mo_period v2',
                         a_s.qb_data.qbd.questionnaire_bank.name)
        self.assertEqual('CRV_recurring_3mo_period v2', a_s.qb_name)
        self.assertEqual(['epic26_v2'],
                         a_s.instruments_needing_full_assessment())

        # Now, should still be rp v3, 3mo recurrence
        a_s = AssessmentStatus(user=user, as_of_date=now)
        self.assertEqual('CRV_recurring_3mo_period v3',
                         a_s.qb_data.qbd.questionnaire_bank.name)
        self.assertEqual(['epic26_v3'],
                         a_s.instruments_needing_full_assessment())

        # Complete the questionnaire from the 3mo v2 QB
        mock_qr('epic26_v2', timestamp=twoweeksago, qb=v2qb, iteration=0)

        # Two weeks ago, should be completed
        user = db.session.merge(user)
        a_s = AssessmentStatus(user=user, as_of_date=twoweeksago)
        self.assertEqual('Completed', a_s.overall_status)

        # Current should also be completed, even tho protocol changed
        a_s = AssessmentStatus(user=user, as_of_date=now)
        self.assertEqual('Completed', a_s.overall_status)

        # Should see both as candidates
        qbds = QuestionnaireBank.qbs_for_user(user,
                                              classification='recurring',
                                              as_of_date=now)
        self.assertEqual(len(qbds), 2)
 def test_no_start_date(self):
     # W/O a biopsy (i.e. event start date), no questionnaries
     self.promote_user(role_name=ROLE.PATIENT.value)
     # toggle default setup - set biopsy false for test user
     self.login()
     self.test_user = db.session.merge(self.test_user)
     self.test_user.save_observation(codeable_concept=CC.BIOPSY,
                                     value_quantity=CC.FALSE_VALUE,
                                     audit=Audit(user_id=TEST_USER_ID,
                                                 subject_id=TEST_USER_ID),
                                     status='final',
                                     issued=None)
     assert not QuestionnaireBank.qbs_for_user(
         self.test_user, 'baseline', as_of_date=now)
    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
        assert QuestionnaireBank.qbs_for_user(self.test_user,
                                              'baseline',
                                              as_of_date=datetime.utcnow())

        # 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_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
        assert QuestionnaireBank.qbs_for_user(self.test_user,
                                              'baseline',
                                              as_of_date=datetime.utcnow())

        # 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_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
        assert QuestionnaireBank.qbs_for_user(self.test_user,
                                              'baseline',
                                              as_of_date=datetime.utcnow())

        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_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_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
        assert not QuestionnaireBank.qbs_for_user(
            self.test_user, 'baseline', as_of_date=datetime.utcnow())

        # shouldn't generate a message either
        mock_qr(instrument_id='epic26')
        update_patient_loop(update_cache=False, queue_messages=True)
        expected = Communication.query.first()
        assert not expected
Exemple #8
0
    def test_outdated_done_indef(self):
        """Confirm completed indefinite counts after RP switch"""

        # boiler plate to create baseline and indef with retired RP
        yesterday = now - timedelta(days=1)
        weekago = now - timedelta(weeks=1)
        org, rp2, rp2_id = self.setup_org_n_rp(org_name='testorg',
                                               rp_name='v2',
                                               retired_as_of=yesterday)
        org, rp3, rp3_id = self.setup_org_n_rp(org=org, rp_name='v3')
        org_id = org.id
        self.test_user.organizations.append(org)
        audit = Audit(user_id=TEST_USER_ID, subject_id=TEST_USER_ID)
        uc = UserConsent(user_id=TEST_USER_ID,
                         organization_id=org_id,
                         audit=audit,
                         agreement_url='http://no.com',
                         acceptance_date=weekago)
        with SessionScope(db):
            db.session.add(audit)
            db.session.add(uc)
            db.session.commit()

        self.setup_qb(questionnaire_name='epic23',
                      qb_name='baseline v2',
                      classification='baseline',
                      rp_id=rp2_id)
        self.setup_qb(questionnaire_name='epic26',
                      qb_name='baseline v3',
                      classification='baseline',
                      rp_id=rp3_id)
        qb2_indef = self.setup_qb(questionnaire_name='irondemog',
                                  qb_name='indef v2',
                                  classification='indefinite',
                                  rp_id=rp2_id)
        self.setup_qb(questionnaire_name='irondemog_v3',
                      qb_name='indef v3',
                      classification='indefinite',
                      rp_id=rp3_id)

        # for today, should get the v3 baseline
        user = db.session.merge(self.test_user)
        a_s = AssessmentStatus(user=user, as_of_date=now)
        self.assertEqual(
            ['epic26', 'irondemog_v3'],
            a_s.instruments_needing_full_assessment(classification='all'))

        # create done QNR for indefinite dated prior to rp transition
        # belonging to older qb - confirm that clears indef work as of then
        mock_qr('irondemog', timestamp=weekago, qb=qb2_indef)
        user = db.session.merge(self.test_user)
        a_s = AssessmentStatus(user=user, as_of_date=weekago)
        self.assertEqual([],
                         a_s.instruments_needing_full_assessment(
                             classification='indefinite'))

        # move forward in time; user should no longer need indefinite, even
        # tho RP changed
        qb2_indef = db.session.merge(qb2_indef)
        self.assertEqual(
            [qb2_indef],
            QuestionnaireBank.qbs_for_user(user,
                                           classification='indefinite',
                                           as_of_date=now))
        a_s = AssessmentStatus(user=user, as_of_date=now)
        self.assertEqual([],
                         a_s.instruments_needing_full_assessment(
                             classification='indefinite'))
        self.assertEqual(
            ['epic26'],
            a_s.instruments_needing_full_assessment(classification='all'))