Ejemplo n.º 1
0
    def test_change_before_start_rp(self):
        now = datetime.utcnow()
        back7, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=7))
        back14, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=14))
        org = self.setup_org_qbs(rp_name='v2', retired_as_of=back14)
        org_id = org.id
        self.setup_org_qbs(org=org, rp_name='v3')
        self.consent_with_org(org_id=org_id, setdate=back7)
        user = db.session.merge(self.test_user)
        gen = ordered_qbs(user)

        # expect everything in v3
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        assert (
            expect_baseline.questionnaire_bank.research_protocol.name == 'v3')
        for n in (3, 6, 9, 15, 18, 21, 30):
            qbd = next(gen)
            assert visit_name(qbd) == 'Month {}'.format(n)
            assert qbd.questionnaire_bank.research_protocol.name == 'v3'

        with pytest.raises(StopIteration):
            next(gen)
Ejemplo n.º 2
0
    def test_change_before_start_rp_w_result(self):
        now = datetime.utcnow()
        back7, nowish = associative_backdate(now=now,
                                             backdate=relativedelta(months=7))
        back14, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=14))
        org = self.setup_org_qbs(rp_name='v2', retired_as_of=back14)
        org_id = org.id
        self.setup_org_qbs(org=org, rp_name='v3')
        self.consent_with_org(org_id=org_id, setdate=back7)

        # submit a mock response for baseline QB on old RP
        # which should result in v2 for baseline and v3 thereafter
        qb_name = "CRV Baseline v2"
        baseline = QuestionnaireBank.query.filter(
            QuestionnaireBank.name == qb_name).one()
        mock_qr('epic_26_v2', qb=baseline, iteration=None)

        user = db.session.merge(self.test_user)
        gen = ordered_qbs(user)

        # expect everything in v3 post baseline
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        assert (
            expect_baseline.questionnaire_bank.research_protocol.name == 'v2')
        for n in (3, 6, 9, 15, 18, 21, 30):
            qbd = next(gen)
            assert visit_name(qbd) == 'Month {}'.format(n)
            assert qbd.questionnaire_bank.research_protocol.name == 'v3'

        with pytest.raises(StopIteration):
            next(gen)
Ejemplo n.º 3
0
    def test_indef_change_before_start_rp_w_result(self):
        now = datetime.utcnow()
        back7, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=7))
        back14, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=14))
        org = self.setup_org_qbs(
            rp_name='v2', retired_as_of=back14, include_indef=True)
        org_id = org.id
        self.setup_org_qbs(
            org=org, rp_name='v3', include_indef=True)
        self.consent_with_org(org_id=org_id, setdate=back7)

        # submit a mock response for indef QB on old RP
        # which should result in v2
        qb_name = "indef_v2"
        i_v2 = QuestionnaireBank.query.filter(
            QuestionnaireBank.name == qb_name).one()
        mock_qr("irondemog_v2", qb=i_v2, iteration=None)

        user = db.session.merge(self.test_user)
        gen = ordered_qbs(user, classification='indefinite')

        # expect only v2 given submission
        expect_v2 = next(gen)
        assert (
            expect_v2.questionnaire_bank.research_protocol.name == 'v2')

        with pytest.raises(StopIteration):
            next(gen)
Ejemplo n.º 4
0
    def test_change_before_start_rp(self):
        now = datetime.utcnow()
        back7, nowish = associative_backdate(now=now,
                                             backdate=relativedelta(months=7))
        back14, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=14))
        org = self.setup_org_qbs(rp_name='v2', retired_as_of=back14)
        org_id = org.id
        self.setup_org_qbs(org=org, rp_name='v3')
        self.consent_with_org(org_id=org_id, setdate=back7)
        user = db.session.merge(self.test_user)
        gen = ordered_qbs(user)

        # expect everything in v3
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        assert (
            expect_baseline.questionnaire_bank.research_protocol.name == 'v3')
        for n in (3, 6, 9, 15, 18, 21, 30):
            qbd = next(gen)
            assert visit_name(qbd) == 'Month {}'.format(n)
            assert qbd.questionnaire_bank.research_protocol.name == 'v3'

        with pytest.raises(StopIteration):
            next(gen)
Ejemplo n.º 5
0
    def test_indef_change_before_start_rp_w_result(self):
        now = datetime.utcnow()
        back7, nowish = associative_backdate(now=now,
                                             backdate=relativedelta(months=7))
        back14, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=14))
        org = self.setup_org_qbs(rp_name='v2',
                                 retired_as_of=back14,
                                 include_indef=True)
        org_id = org.id
        self.setup_org_qbs(org=org, rp_name='v3', include_indef=True)
        self.consent_with_org(org_id=org_id, setdate=back7)

        # submit a mock response for indef QB on old RP
        # which should result in v2
        qb_name = "indef_v2"
        i_v2 = QuestionnaireBank.query.filter(
            QuestionnaireBank.name == qb_name).one()
        mock_qr("irondemog_v2", qb=i_v2, iteration=None)

        user = db.session.merge(self.test_user)
        gen = ordered_qbs(user, classification='indefinite')

        # expect only v2 given submission
        expect_v2 = next(gen)
        assert (expect_v2.questionnaire_bank.research_protocol.name == 'v2')

        with pytest.raises(StopIteration):
            next(gen)
    def test_aggregate_response_timepoints(self):
        # generate a few mock qr's from various qb iterations, confirm
        # time points.

        nineback, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9, hours=1))
        self.bless_with_basics(
            setdate=nineback, local_metastatic='metastatic')
        instrument_id = 'eortc'
        for months_back in (0, 3, 6, 9):
            backdate, _ = associative_backdate(
                now=now, backdate=relativedelta(months=months_back))
            mock_qr(instrument_id=instrument_id, timestamp=backdate)

        # add staff user w/ same org association for bundle creation

        staff = self.add_user(username='******')
        staff.organizations.append(Organization.query.filter(
                Organization.name == 'metastatic').one())
        self.promote_user(staff, role_name=ROLE.STAFF.value)
        staff = db.session.merge(staff)
        bundle = aggregate_responses(
            instrument_ids=[instrument_id], current_user=staff)
        expected = {'Baseline', 'Month 3', 'Month 6', 'Month 9'}
        found = [i['timepoint'] for i in bundle['entry']]
        assert set(found) == expected
Ejemplo n.º 7
0
    def test_change_before_start_rp_w_result(self):
        now = datetime.utcnow()
        back7, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=7))
        back14, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=14))
        org = self.setup_org_qbs(rp_name='v2', retired_as_of=back14)
        org_id = org.id
        self.setup_org_qbs(org=org, rp_name='v3')
        self.consent_with_org(org_id=org_id, setdate=back7)

        # submit a mock response for baseline QB on old RP
        # which should result in v2 for baseline and v3 thereafter
        qb_name = "CRV Baseline v2"
        baseline = QuestionnaireBank.query.filter(
            QuestionnaireBank.name == qb_name).one()
        mock_qr('epic_26_v2', qb=baseline, iteration=None)

        user = db.session.merge(self.test_user)
        gen = ordered_qbs(user)

        # expect everything in v3 post baseline
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        assert (
            expect_baseline.questionnaire_bank.research_protocol.name == 'v2')
        for n in (3, 6, 9, 15, 18, 21, 30):
            qbd = next(gen)
            assert visit_name(qbd) == 'Month {}'.format(n)
            assert qbd.questionnaire_bank.research_protocol.name == 'v3'

        with pytest.raises(StopIteration):
            next(gen)
Ejemplo n.º 8
0
    def test_aggregate_response_timepoints(self):
        # generate a few mock qr's from various qb iterations, confirm
        # time points.

        nineback, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9, hours=1))
        self.bless_with_basics(
            setdate=nineback, local_metastatic='metastatic')
        instrument_id = 'eortc'
        for months_back in (0, 3, 6, 9):
            backdate, _ = associative_backdate(
                now=now, backdate=relativedelta(months=months_back))
            mock_qr(instrument_id=instrument_id, timestamp=backdate)

        # add staff user w/ same org association for bundle creation

        staff = self.add_user(username='******')
        staff.organizations.append(Organization.query.filter(
                Organization.name == 'metastatic').one())
        self.promote_user(staff, role_name=ROLE.STAFF.value)
        staff = db.session.merge(staff)
        bundle = aggregate_responses(
            instrument_ids=[instrument_id], current_user=staff)
        expected = {'Baseline', 'Month 3', 'Month 6', 'Month 9'}
        found = [i['timepoint'] for i in bundle['entry']]
        assert set(found) == expected
Ejemplo n.º 9
0
    def test_permissions(self):
        """Shouldn't get results from orgs outside view permissions"""

        # Generate a few patients from different orgs
        org1_name, org2_name = 'test_org1', 'test_org2'
        org1 = Organization(name=org1_name)
        org2 = Organization(name=org2_name)
        with SessionScope(db):
            db.session.add(org1)
            db.session.add(org2)
            db.session.commit()
        org1 = db.session.merge(org1)
        org1_id = org1.id
        self.setup_org_qbs(org1)
        org2 = db.session.merge(org2)
        self.setup_org_qbs(org2)

        user2 = self.add_user('user2')
        user3 = self.add_user('user3')
        user4 = self.add_user('user4')
        with SessionScope(db):
            db.session.add(user2)
            db.session.add(user3)
            db.session.add(user4)
            db.session.commit()
        user2 = db.session.merge(user2)
        user3 = db.session.merge(user3)
        user4 = db.session.merge(user4)

        now = datetime.utcnow()
        back15, nowish = associative_backdate(now, relativedelta(days=15))
        back45, nowish = associative_backdate(now, relativedelta(days=45))
        back115, nowish = associative_backdate(now, relativedelta(days=115))
        self.bless_with_basics(user=user2,
                               setdate=back15,
                               local_metastatic=org1_name)
        self.bless_with_basics(user=user3,
                               setdate=back45,
                               local_metastatic=org1_name)
        self.bless_with_basics(user=user4,
                               setdate=back115,
                               local_metastatic=org2_name)

        self.test_user = db.session.merge(self.test_user)
        self.promote_user(role_name=ROLE.STAFF.value)
        self.login()
        response = self.client.get("/api/report/questionnaire_status")
        assert response.status_code == 200

        # with zero orgs in common, should see empty result set
        assert response.json['total'] == 0

        # Add org to staff to see results from matching patiens (2&3)
        self.consent_with_org(org_id=org1_id)
        response = self.client.get("/api/report/questionnaire_status")
        assert response.status_code == 200
        assert response.json['total'] == 2
Ejemplo n.º 10
0
    def test_permissions(self):
        """Shouldn't get results from orgs outside view permissions"""

        # Generate a few patients from different orgs
        org1_name, org2_name = 'test_org1', 'test_org2'
        org1 = Organization(name=org1_name)
        org2 = Organization(name=org2_name)
        with SessionScope(db):
            db.session.add(org1)
            db.session.add(org2)
            db.session.commit()
        org1 = db.session.merge(org1)
        org1_id = org1.id
        self.setup_org_qbs(org1)
        org2 = db.session.merge(org2)
        self.setup_org_qbs(org2)

        user2 = self.add_user('user2')
        user3 = self.add_user('user3')
        user4 = self.add_user('user4')
        with SessionScope(db):
            db.session.add(user2)
            db.session.add(user3)
            db.session.add(user4)
            db.session.commit()
        user2 = db.session.merge(user2)
        user3 = db.session.merge(user3)
        user4 = db.session.merge(user4)

        now = datetime.utcnow()
        back15, nowish = associative_backdate(now, relativedelta(days=15))
        back45, nowish = associative_backdate(now, relativedelta(days=45))
        back115, nowish = associative_backdate(now, relativedelta(days=115))
        self.bless_with_basics(
            user=user2, setdate=back15, local_metastatic=org1_name)
        self.bless_with_basics(
            user=user3, setdate=back45, local_metastatic=org1_name)
        self.bless_with_basics(
            user=user4, setdate=back115, local_metastatic=org2_name)

        self.test_user = db.session.merge(self.test_user)
        self.promote_user(role_name=ROLE.STAFF.value)
        self.login()
        response = self.client.get("/api/report/questionnaire_status")
        assert response.status_code == 200

        # with zero orgs in common, should see empty result set
        assert response.json['total'] == 0

        # Add org to staff to see results from matching patiens (2&3)
        self.consent_with_org(org_id=org1_id)
        response = self.client.get("/api/report/questionnaire_status")
        assert response.status_code == 200
        assert response.json['total'] == 2
    def test_user_current_qb(self):
        crv = self.setup_org_qbs()
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=3))
        self.bless_with_basics(setdate=backdate)
        self.test_user = db.session.merge(self.test_user)
        self.test_user.organizations.append(crv)

        self.login()
        resp = self.client.get('/api/user/{}/'
                               'questionnaire_bank'.format(TEST_USER_ID))
        assert resp.status_code == 200
        assert (resp.json['questionnaire_bank']['name']
                == 'CRV_recurring_3mo_period v2')

        dt = (nowish - relativedelta(months=2)).strftime('%Y-%m-%d')
        resp2 = self.client.get('/api/user/{}/questionnaire_bank?as_of_date='
                                '{}'.format(TEST_USER_ID, dt))
        assert resp2.status_code == 200
        assert (resp2.json['questionnaire_bank']['name']
                == 'CRV Baseline v2')

        # User's trigger was only 3 months ago.  At 4 months should
        # return a valid empty
        dt = (nowish - relativedelta(months=4)).strftime('%Y-%m-%d')
        resp3 = self.client.get('/api/user/{}/questionnaire_bank?as_of_date='
                                '{}'.format(TEST_USER_ID, dt))
        assert resp3.status_code == 200
        assert not resp3.json['questionnaire_bank']
    def test_localized_as_of_date(self):
        # backdating consent beyond expired and the status lookup date
        # within a valid window should show available assessments.

        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=3))
        self.bless_with_basics(setdate=backdate)
        self.mark_localized()
        # backdate so the baseline q's have expired
        mock_qr(instrument_id='epic26',
                status='in-progress',
                doc_id='doc-26',
                timestamp=backdate)

        self.test_user = db.session.merge(self.test_user)
        as_of_date = backdate + relativedelta(days=2)
        a_s = AssessmentStatus(user=self.test_user, as_of_date=as_of_date)
        assert a_s.overall_status == "In Progress"

        # with only epic26 started, should see results for both
        # instruments_needing_full_assessment and insturments_in_progress
        assert \
            {'eproms_add', 'comorb'} ==\
            set(a_s.instruments_needing_full_assessment())
        assert ['doc-26'] == a_s.instruments_in_progress()
Ejemplo n.º 13
0
    def test_user_current_qb(self):
        crv = self.setup_org_qbs()
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=3))
        self.bless_with_basics(setdate=backdate)
        self.test_user = db.session.merge(self.test_user)
        self.test_user.organizations.append(crv)

        self.login()
        resp = self.client.get('/api/user/{}/'
                               'questionnaire_bank'.format(TEST_USER_ID))
        assert resp.status_code == 200
        assert (resp.json['questionnaire_bank']['name'] ==
                'CRV_recurring_3mo_period v2')

        dt = (nowish - relativedelta(months=2)).strftime('%Y-%m-%d')
        resp2 = self.client.get('/api/user/{}/questionnaire_bank?as_of_date='
                                '{}'.format(TEST_USER_ID, dt))
        assert resp2.status_code == 200
        assert (resp2.json['questionnaire_bank']['name'] == 'CRV Baseline v2')

        # User's trigger was only 3 months ago.  At 4 months should
        # return a valid empty
        dt = (nowish - relativedelta(months=4)).strftime('%Y-%m-%d')
        resp3 = self.client.get('/api/user/{}/questionnaire_bank?as_of_date='
                                '{}'.format(TEST_USER_ID, dt))
        assert resp3.status_code == 200
        assert not resp3.json['questionnaire_bank']
Ejemplo n.º 14
0
    def test_user_current_qb(self):
        crv = self.setup_qbs()
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=3))
        self.bless_with_basics(setdate=backdate)
        self.test_user.organizations.append(crv)
        self.test_user = db.session.merge(self.test_user)

        self.login()
        resp = self.client.get('/api/user/{}/'
                               'questionnaire_bank'.format(TEST_USER_ID))
        self.assert200(resp)
        self.assertEqual(resp.json['questionnaire_bank']['name'],
                         'CRV_recurring_3mo_period v2')

        dt = (nowish - relativedelta(months=2)).strftime('%Y-%m-%d')
        resp2 = self.client.get('/api/user/{}/questionnaire_bank?as_of_date='
                                '{}'.format(TEST_USER_ID, dt))
        self.assert200(resp2)
        self.assertEqual(resp2.json['questionnaire_bank']['name'],
                         'CRV Baseline v2')

        dt = (nowish - relativedelta(months=4)).strftime('%Y-%m-%d')
        resp3 = self.client.get('/api/user/{}/questionnaire_bank?as_of_date='
                                '{}'.format(TEST_USER_ID, dt))
        self.assert200(resp3)
        self.assertFalse(resp3.json['questionnaire_bank'])
    def test_initial_recur_baseline_done(self):
        # backdate to be within the first recurrence window

        backdate, nowish = associative_backdate(now=now,
                                                backdate=relativedelta(
                                                    months=3, days=2))
        self.bless_with_basics(setdate=backdate)
        self.mark_metastatic()

        # add baseline QNRs, as if submitted nearly 3 months ago, during
        # baseline window
        backdated = nowish - relativedelta(months=2, days=25)
        baseline = QuestionnaireBank.query.filter_by(name='metastatic').one()
        for instrument in metastatic_baseline_instruments:
            mock_qr(instrument, qb=baseline, timestamp=backdated)

        self.test_user = db.session.merge(self.test_user)
        # Check status during baseline window
        a_s_baseline = AssessmentStatus(user=self.test_user,
                                        as_of_date=backdated)
        assert a_s_baseline.overall_status == "Completed"
        assert not a_s_baseline.instruments_needing_full_assessment()

        # Whereas "current" status for the initial recurrence show due.
        a_s = AssessmentStatus(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == "Due"

        # in the initial window w/ no questionnaires submitted
        # should include all from initial recur
        assert set(a_s.instruments_needing_full_assessment()) == metastatic_3
    def test_initial_recur_baseline_done(self):
        # backdate to be within the first recurrence window

        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=3, days=2))
        self.bless_with_basics(
            setdate=backdate, local_metastatic='metastatic')

        # add baseline QNRs, as if submitted nearly 3 months ago, during
        # baseline window
        backdated = nowish - relativedelta(months=2, days=25)
        baseline = QuestionnaireBank.query.filter_by(
            name='metastatic').one()
        for instrument in metastatic_baseline_instruments:
            mock_qr(instrument, qb=baseline, timestamp=backdated)

        self.test_user = db.session.merge(self.test_user)
        # Check status during baseline window
        a_s_baseline = QB_Status(
            user=self.test_user, as_of_date=backdated)
        assert a_s_baseline.overall_status == OverallStatus.completed
        assert not a_s_baseline.instruments_needing_full_assessment()

        # Whereas "current" status for the initial recurrence show due.
        a_s = QB_Status(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == OverallStatus.due

        # in the initial window w/ no questionnaires submitted
        # should include all from initial recur
        assert set(a_s.instruments_needing_full_assessment()) == metastatic_3
Ejemplo n.º 17
0
 def test_boundary_overdue(self):
     self.login()
     backdate, nowish = associative_backdate(
         now=now, backdate=relativedelta(months=3, hours=-1))
     self.bless_with_basics(
         setdate=backdate, local_metastatic='localized')
     self.test_user = db.session.merge(self.test_user)
     a_s = QB_Status(user=self.test_user, as_of_date=nowish)
     assert a_s.overall_status == OverallStatus.overdue
 def test_boundary_overdue(self):
     self.login()
     backdate, nowish = associative_backdate(
         now=now, backdate=relativedelta(months=3, hours=-1))
     self.bless_with_basics(
         setdate=backdate, local_metastatic='localized')
     self.test_user = db.session.merge(self.test_user)
     a_s = QB_Status(user=self.test_user, as_of_date=nowish)
     assert a_s.overall_status == OverallStatus.overdue
    def test_visit_9mo(self):
        crv = self.setup_org_qbs()
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9))
        self.bless_with_basics(setdate=backdate)
        self.test_user = db.session.merge(self.test_user)
        self.test_user.organizations.append(crv)

        qstats = QB_Status(self.test_user, nowish + timedelta(hours=1))
        qbd = qstats.current_qbd()
        assert visit_name(qbd) == "Month 9"
 def test_boundary_expired(self):
     "At expired, should be expired"
     self.login()
     backdate, nowish = associative_backdate(now=now,
                                             backdate=relativedelta(
                                                 months=3, hours=1))
     self.bless_with_basics(setdate=backdate)
     self.mark_localized()
     self.test_user = db.session.merge(self.test_user)
     a_s = AssessmentStatus(user=self.test_user, as_of_date=nowish)
     assert a_s.overall_status == 'Expired'
Ejemplo n.º 21
0
    def test_visit_9mo(self):
        crv = self.setup_org_qbs()
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9))
        self.bless_with_basics(setdate=backdate)
        self.test_user = db.session.merge(self.test_user)
        self.test_user.organizations.append(crv)

        qstats = QB_Status(self.test_user, nowish + timedelta(hours=1))
        qbd = qstats.current_qbd()
        assert visit_name(qbd) == "Month 9"
Ejemplo n.º 22
0
    def test_visit_9mo(self):
        crv = self.setup_qbs()
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9))
        self.bless_with_basics(setdate=backdate)
        self.test_user.organizations.append(crv)
        self.test_user = db.session.merge(self.test_user)

        qbd = QuestionnaireBank.most_current_qb(self.test_user,
                                                as_of_date=nowish +
                                                timedelta(hours=1))
        self.assertEqual("Month 9", visit_name(qbd))
 def test_boundary_in_progress_expired(self):
     self.login()
     backdate, nowish = associative_backdate(now=now,
                                             backdate=relativedelta(
                                                 months=3, hours=1))
     self.bless_with_basics(setdate=backdate)
     self.mark_localized()
     for instrument in localized_instruments:
         mock_qr(instrument_id=instrument, status='in-progress')
     self.test_user = db.session.merge(self.test_user)
     a_s = AssessmentStatus(user=self.test_user, as_of_date=nowish)
     assert a_s.overall_status == 'Partially Completed'
 def test_boundary_in_progress_expired(self):
     self.login()
     backdate, nowish = associative_backdate(
         now=now, backdate=relativedelta(months=3, hours=1))
     self.bless_with_basics(
         setdate=backdate, local_metastatic='localized')
     for instrument in localized_instruments:
         mock_qr(
             instrument_id=instrument, status='in-progress',
             timestamp=nowish-relativedelta(days=1))
     self.test_user = db.session.merge(self.test_user)
     a_s = QB_Status(user=self.test_user, as_of_date=nowish)
     assert a_s.overall_status == OverallStatus.partially_completed
Ejemplo n.º 25
0
 def test_boundary_in_progress_expired(self):
     self.login()
     backdate, nowish = associative_backdate(
         now=now, backdate=relativedelta(months=3, hours=1))
     self.bless_with_basics(
         setdate=backdate, local_metastatic='localized')
     for instrument in localized_instruments:
         mock_qr(
             instrument_id=instrument, status='in-progress',
             timestamp=nowish-relativedelta(days=1))
     self.test_user = db.session.merge(self.test_user)
     a_s = QB_Status(user=self.test_user, as_of_date=nowish)
     assert a_s.overall_status == OverallStatus.partially_completed
Ejemplo n.º 26
0
    def test_indef_change_before_start_rp(self):
        now = datetime.utcnow()
        back7, nowish = associative_backdate(now=now,
                                             backdate=relativedelta(months=7))
        back14, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=14))
        org = self.setup_org_qbs(rp_name='v2',
                                 retired_as_of=back14,
                                 include_indef=True)
        org_id = org.id
        self.setup_org_qbs(org=org, rp_name='v3', include_indef=True)
        self.consent_with_org(org_id=org_id, setdate=back7)

        user = db.session.merge(self.test_user)
        gen = ordered_qbs(user, classification='indefinite')

        # expect only v3
        expect_v3 = next(gen)
        assert (expect_v3.questionnaire_bank.research_protocol.name == 'v3')

        with pytest.raises(StopIteration):
            next(gen)
 def test_boundary_recurring_in_progress(self):
     self.login()
     backdate, nowish = associative_backdate(now=now,
                                             backdate=relativedelta(
                                                 months=6, hours=-1))
     self.bless_with_basics(setdate=backdate)
     self.mark_metastatic()
     for instrument in metastatic_3:
         mock_qr(instrument_id=instrument,
                 status='in-progress',
                 iteration=0)
     self.test_user = db.session.merge(self.test_user)
     a_s = AssessmentStatus(user=self.test_user, as_of_date=nowish)
     assert a_s.overall_status == 'In Progress'
Ejemplo n.º 28
0
    def test_indef_change_before_start_rp(self):
        now = datetime.utcnow()
        back7, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=7))
        back14, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=14))
        org = self.setup_org_qbs(
            rp_name='v2', retired_as_of=back14, include_indef=True)
        org_id = org.id
        self.setup_org_qbs(
            org=org, rp_name='v3', include_indef=True)
        self.consent_with_org(org_id=org_id, setdate=back7)

        user = db.session.merge(self.test_user)
        gen = ordered_qbs(user, classification='indefinite')

        # expect only v3
        expect_v3 = next(gen)
        assert (
            expect_v3.questionnaire_bank.research_protocol.name == 'v3')

        with pytest.raises(StopIteration):
            next(gen)
Ejemplo n.º 29
0
    def test_change_midstream_results_rp(self):
        now = datetime.utcnow()
        back1, nowish = associative_backdate(now=now,
                                             backdate=relativedelta(months=1))
        back10, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=10))
        org = self.setup_org_qbs(rp_name='v2', retired_as_of=back1)
        org_id = org.id
        self.setup_org_qbs(org=org, rp_name='v3')
        self.consent_with_org(org_id=org_id, setdate=back10)

        # submit a mock response for 9 month QB on old RP
        # which should result in v2 for up to 9 month and v3 thereafter
        qb_name = "CRV_recurring_3mo_period v2"
        nineMo = QuestionnaireBank.query.filter(
            QuestionnaireBank.name == qb_name).one()
        mock_qr('epic_26_v2', qb=nineMo, iteration=1)

        user = db.session.merge(self.test_user)
        gen = ordered_qbs(user)

        # expect baseline and 3 month in v2, rest in v3
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        assert (
            expect_baseline.questionnaire_bank.research_protocol.name == 'v2')
        for n in (3, 6, 9):
            qbd = next(gen)
            assert visit_name(qbd) == 'Month {}'.format(n)
            assert qbd.questionnaire_bank.research_protocol.name == 'v2'
        for n in (15, 18, 21, 30):
            qbd = next(gen)
            assert visit_name(qbd) == 'Month {}'.format(n)
            assert qbd.questionnaire_bank.research_protocol.name == 'v3'

        with pytest.raises(StopIteration):
            next(gen)
Ejemplo n.º 30
0
    def test_change_midstream_results_rp(self):
        now = datetime.utcnow()
        back1, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=1))
        back10, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=10))
        org = self.setup_org_qbs(rp_name='v2', retired_as_of=back1)
        org_id = org.id
        self.setup_org_qbs(org=org, rp_name='v3')
        self.consent_with_org(org_id=org_id, setdate=back10)

        # submit a mock response for 9 month QB on old RP
        # which should result in v2 for up to 9 month and v3 thereafter
        qb_name = "CRV_recurring_3mo_period v2"
        nineMo = QuestionnaireBank.query.filter(
            QuestionnaireBank.name == qb_name).one()
        mock_qr('epic_26_v2', qb=nineMo, iteration=1)

        user = db.session.merge(self.test_user)
        gen = ordered_qbs(user)

        # expect baseline and 3 month in v2, rest in v3
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        assert (
            expect_baseline.questionnaire_bank.research_protocol.name == 'v2')
        for n in (3, 6, 9):
            qbd = next(gen)
            assert visit_name(qbd) == 'Month {}'.format(n)
            assert qbd.questionnaire_bank.research_protocol.name == 'v2'
        for n in (15, 18, 21, 30):
            qbd = next(gen)
            assert visit_name(qbd) == 'Month {}'.format(n)
            assert qbd.questionnaire_bank.research_protocol.name == 'v3'

        with pytest.raises(StopIteration):
            next(gen)
Ejemplo n.º 31
0
    def test_secondary_recur_due(self):

        # backdate so baseline q's have expired, and we are within the
        # second recurrence window
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=6, hours=1))
        self.bless_with_basics(
            setdate=backdate, local_metastatic='metastatic')
        self.test_user = db.session.merge(self.test_user)
        a_s = QB_Status(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == OverallStatus.due

        # w/ no questionnaires submitted
        # should include all from second recur
        assert set(a_s.instruments_needing_full_assessment()) == metastatic_4
    def test_secondary_recur_due(self):

        # backdate so baseline q's have expired, and we are within the
        # second recurrence window
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=6, hours=1))
        self.bless_with_basics(
            setdate=backdate, local_metastatic='metastatic')
        self.test_user = db.session.merge(self.test_user)
        a_s = QB_Status(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == OverallStatus.due

        # w/ no questionnaires submitted
        # should include all from second recur
        assert set(a_s.instruments_needing_full_assessment()) == metastatic_4
    def test_all_expired_old_tx(self):
        self.login()
        # backdate outside of baseline window (which uses consent date)
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=4, hours=1))
        self.bless_with_basics(
            setdate=backdate, local_metastatic='localized')

        # provide treatment date outside of all recurrences
        tx_date = datetime(2000, 3, 12, 0, 0, 00, 000000)
        self.add_procedure(code='7', display='Focal therapy',
                           system=ICHOM, setdate=tx_date)

        self.test_user = db.session.merge(self.test_user)
        a_s = QB_Status(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == OverallStatus.expired
Ejemplo n.º 34
0
    def test_all_expired_old_tx(self):
        self.login()
        # backdate outside of baseline window (which uses consent date)
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=4, hours=1))
        self.bless_with_basics(
            setdate=backdate, local_metastatic='localized')

        # provide treatment date outside of all recurrences
        tx_date = datetime(2000, 3, 12, 0, 0, 00, 000000)
        self.add_procedure(code='7', display='Focal therapy',
                           system=ICHOM, setdate=tx_date)

        self.test_user = db.session.merge(self.test_user)
        a_s = QB_Status(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == OverallStatus.expired
    def test_boundary_recurring_in_progress(self):
        self.login()
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=6, hours=-1))
        self.bless_with_basics(
            setdate=backdate, local_metastatic='metastatic')
        mr3_qb = QuestionnaireBank.query.filter_by(
            name='metastatic_recurring3').first()

        for instrument in metastatic_3:
            mock_qr(
                instrument_id=instrument, status='in-progress',
                qb=mr3_qb, timestamp=nowish, iteration=0)
        self.test_user = db.session.merge(self.test_user)
        a_s = QB_Status(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == OverallStatus.in_progress
Ejemplo n.º 36
0
    def test_boundary_recurring_in_progress(self):
        self.login()
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=6, hours=-1))
        self.bless_with_basics(
            setdate=backdate, local_metastatic='metastatic')
        mr3_qb = QuestionnaireBank.query.filter_by(
            name='metastatic_recurring3').first()

        for instrument in metastatic_3:
            mock_qr(
                instrument_id=instrument, status='in-progress',
                qb=mr3_qb, timestamp=nowish, iteration=0)
        self.test_user = db.session.merge(self.test_user)
        a_s = QB_Status(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == OverallStatus.in_progress
Ejemplo n.º 37
0
    def test_2nd_recur_due(self):

        # backdate so baseline q's have expired, and we within the 2nd
        # recurrence window
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9, hours=1))
        self.bless_with_basics(
            setdate=backdate, local_metastatic='metastatic')
        self.test_user = db.session.merge(self.test_user)
        a_s = QB_Status(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == OverallStatus.due

        # in the initial window w/ no questionnaires submitted
        # should include all from initial recur
        assert set(a_s.instruments_needing_full_assessment()) == metastatic_3

        # however, we should be looking at iteration 2 (zero index)!
        assert a_s.current_qbd().iteration == 1
    def test_2nd_recur_due(self):

        # backdate so baseline q's have expired, and we within the 2nd
        # recurrence window
        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9, hours=1))
        self.bless_with_basics(
            setdate=backdate, local_metastatic='metastatic')
        self.test_user = db.session.merge(self.test_user)
        a_s = QB_Status(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == OverallStatus.due

        # in the initial window w/ no questionnaires submitted
        # should include all from initial recur
        assert set(a_s.instruments_needing_full_assessment()) == metastatic_3

        # however, we should be looking at iteration 2 (zero index)!
        assert a_s.current_qbd().iteration == 1
    def test_site_ids(self):
        # bless org w/ expected identifier type
        wanted_system = 'http://pcctc.org/'
        unwanted_system = 'http://other.org/'
        self.app.config['REPORTING_IDENTIFIER_SYSTEMS'] = [wanted_system]
        id_value = '146-11'
        org = Organization.query.filter(
            Organization.name == 'metastatic').one()
        id1 = Identifier(
            system=wanted_system, use='secondary', value=id_value)
        id2 = Identifier(
            system=unwanted_system, use='secondary', value=id_value)
        org.identifiers.append(id1)
        org.identifiers.append(id2)

        with SessionScope(db):
            db.session.commit()

        nineback, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9, hours=1))
        self.bless_with_basics(
            setdate=nineback, local_metastatic='metastatic')
        instrument_id = 'eortc'
        mock_qr(instrument_id=instrument_id)

        # add staff user w/ same org association for bundle creation

        staff = self.add_user(username='******')
        staff.organizations.append(Organization.query.filter(
                Organization.name == 'metastatic').one())
        self.promote_user(staff, role_name=ROLE.STAFF.value)
        staff = db.session.merge(staff)
        bundle = aggregate_responses(
            instrument_ids=[instrument_id], current_user=staff)
        id1 = db.session.merge(id1)
        assert 1 == len(bundle['entry'])
        assert (1 ==
                len(bundle['entry'][0]['subject']['careProvider']))
        assert (1 ==
                len(bundle['entry'][0]['subject']['careProvider'][0]
                    ['identifier']))
        assert (id1.as_fhir() ==
                bundle['entry'][0]['subject']['careProvider'][0]
                ['identifier'][0])
Ejemplo n.º 40
0
    def test_site_ids(self):
        # bless org w/ expected identifier type
        wanted_system = 'http://pcctc.org/'
        unwanted_system = 'http://other.org/'
        self.app.config['REPORTING_IDENTIFIER_SYSTEMS'] = [wanted_system]
        id_value = '146-11'
        org = Organization.query.filter(
            Organization.name == 'metastatic').one()
        id1 = Identifier(
            system=wanted_system, use='secondary', value=id_value)
        id2 = Identifier(
            system=unwanted_system, use='secondary', value=id_value)
        org.identifiers.append(id1)
        org.identifiers.append(id2)

        with SessionScope(db):
            db.session.commit()

        nineback, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=9, hours=1))
        self.bless_with_basics(
            setdate=nineback, local_metastatic='metastatic')
        instrument_id = 'eortc'
        mock_qr(instrument_id=instrument_id)

        # add staff user w/ same org association for bundle creation

        staff = self.add_user(username='******')
        staff.organizations.append(Organization.query.filter(
                Organization.name == 'metastatic').one())
        self.promote_user(staff, role_name=ROLE.STAFF.value)
        staff = db.session.merge(staff)
        bundle = aggregate_responses(
            instrument_ids=[instrument_id], current_user=staff)
        id1 = db.session.merge(id1)
        assert 1 == len(bundle['entry'])
        assert (1 ==
                len(bundle['entry'][0]['subject']['careProvider']))
        assert (1 ==
                len(bundle['entry'][0]['subject']['careProvider'][0]
                    ['identifier']))
        assert (id1.as_fhir() ==
                bundle['entry'][0]['subject']['careProvider'][0]
                ['identifier'][0])
    def test_metastatic_as_of_date(self):
        # backdating consent beyond expired and the status lookup date
        # within a valid window should show available assessments.

        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=3))
        self.bless_with_basics(setdate=backdate, local_metastatic='metastatic')

        # backdate so the baseline q's have expired
        mock_qr(instrument_id='epic23', status='in-progress', doc_id='doc-23',
                timestamp=backdate)

        self.test_user = db.session.merge(self.test_user)
        as_of_date = backdate + relativedelta(days=2)
        a_s = QB_Status(user=self.test_user, as_of_date=as_of_date)
        assert a_s.overall_status == OverallStatus.in_progress

        # with only epic26 started, should see results for both
        # instruments_needing_full_assessment and instruments_in_progress
        assert ['doc-23'] == a_s.instruments_in_progress()
        assert a_s.instruments_needing_full_assessment()
    def test_localized_overdue(self):
        # if the user completed something on time, and nothing else
        # is due, should see the thank you message.

        backdate, nowish = associative_backdate(now=now,
                                                backdate=relativedelta(
                                                    months=3, hours=1))
        self.bless_with_basics(setdate=backdate)
        self.mark_localized()
        # backdate so the baseline q's have expired
        mock_qr(instrument_id='epic26', status='in-progress')

        self.test_user = db.session.merge(self.test_user)
        a_s = AssessmentStatus(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == "Partially Completed"

        # with all q's expired,
        # instruments_needing_full_assessment and instruments_in_progress
        # should be empty
        assert not a_s.instruments_needing_full_assessment()
        assert not a_s.instruments_in_progress()
Ejemplo n.º 43
0
    def test_metastatic_as_of_date(self):
        # backdating consent beyond expired and the status lookup date
        # within a valid window should show available assessments.

        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=3))
        self.bless_with_basics(setdate=backdate, local_metastatic='metastatic')

        # backdate so the baseline q's have expired
        mock_qr(instrument_id='epic23', status='in-progress', doc_id='doc-23',
                timestamp=backdate)

        self.test_user = db.session.merge(self.test_user)
        as_of_date = backdate + relativedelta(days=2)
        a_s = QB_Status(user=self.test_user, as_of_date=as_of_date)
        assert a_s.overall_status == OverallStatus.in_progress

        # with only epic26 started, should see results for both
        # instruments_needing_full_assessment and instruments_in_progress
        assert ['doc-23'] == a_s.instruments_in_progress()
        assert a_s.instruments_needing_full_assessment()
    def test_initial_recur_due(self):

        # backdate so baseline q's have expired, and we within the first
        # recurrence window
        backdate, nowish = associative_backdate(now=now,
                                                backdate=relativedelta(
                                                    months=3, hours=1))
        self.bless_with_basics(setdate=backdate)
        self.mark_metastatic()
        self.test_user = db.session.merge(self.test_user)
        a_s = AssessmentStatus(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == "Due"

        # in the initial window w/ no questionnaires submitted
        # should include all from initial recur
        assert \
            set(a_s.instruments_needing_full_assessment()) ==\
            metastatic_3

        # confirm iteration 0
        assert a_s.qb_data.qbd.iteration == 0
    def test_localized_overdue(self):
        # if the user completed something on time, and nothing else
        # is due, should see the thank you message.

        backdate, nowish = associative_backdate(
            now=now, backdate=relativedelta(months=3, hours=1))
        self.bless_with_basics(
            setdate=backdate, local_metastatic='localized')

        # backdate so the baseline q's have expired
        mock_qr(
            instrument_id='epic26', status='in-progress', timestamp=backdate)

        self.test_user = db.session.merge(self.test_user)
        a_s = QB_Status(user=self.test_user, as_of_date=nowish)
        assert a_s.overall_status == OverallStatus.partially_completed

        # with all q's expired,
        # instruments_needing_full_assessment and instruments_in_progress
        # should be empty
        assert not a_s.instruments_needing_full_assessment()
        assert not a_s.instruments_in_progress()
Ejemplo n.º 46
0
    def test_results(self):
        from portal.system_uri import TRUENTH_EXTERNAL_STUDY_SYSTEM

        # Generate a few patients with differing results
        org = self.setup_org_qbs()
        org_id, org_name = org.id, org.name
        user2 = self.add_user('user2')
        user3 = self.add_user('user3')
        user4 = self.add_user('user4')
        with SessionScope(db):
            db.session.add(user2)
            db.session.add(user3)
            db.session.add(user4)
            db.session.commit()
        user2 = db.session.merge(user2)
        user3 = db.session.merge(user3)
        user4 = db.session.merge(user4)
        user4_id = user4.id

        self.add_user_identifier(
            user=user2, system=TRUENTH_EXTERNAL_STUDY_SYSTEM,
            value='study user 2')
        self.add_user_identifier(
            user=user3, system=TRUENTH_EXTERNAL_STUDY_SYSTEM,
            value='study user 3')

        now = datetime.utcnow()
        back15, nowish = associative_backdate(now, relativedelta(days=15))
        back45, nowish = associative_backdate(now, relativedelta(days=45))
        back115, nowish = associative_backdate(now, relativedelta(days=115))
        self.bless_with_basics(
            user=user2, setdate=back15, local_metastatic=org_name)
        self.bless_with_basics(
            user=user3, setdate=back45, local_metastatic=org_name)
        self.bless_with_basics(
            user=user4, setdate=back115, local_metastatic=org_name)

        # submit a mock response for all q's in 3 mo qb
        # which should result in completed status for user4
        qb_name = "CRV_recurring_3mo_period v2"
        threeMo = QuestionnaireBank.query.filter(
            QuestionnaireBank.name == qb_name).one()

        for q in threeMo.questionnaires:
            q = db.session.merge(q)
            mock_qr(
                q.name, qb=threeMo, iteration=0, user_id=user4_id,
                timestamp=back15, entry_method=EC.INTERVIEW_ASSISTED)

        self.test_user = db.session.merge(self.test_user)
        self.promote_user(role_name=ROLE.STAFF.value)
        self.consent_with_org(org_id=org_id)
        self.login()
        response = self.client.get("/api/report/questionnaire_status")
        assert response.status_code == 200

        # expect baseline for each plus 3 mo for user4
        assert response.json['total'] == 4
        expect = {'Due', 'Overdue', 'Completed', 'Expired'}
        found = set([item['status'] for item in response.json['entry']])
        assert expect == found
        # the one done should have entry method set above
        for item in response.json['entry']:
            if item['status'] == 'Completed':
                assert item['entry_method'] == 'interview_assisted'
            else:
                assert 'entry_method' not in item
Ejemplo n.º 47
0
    def test_results(self):
        from portal.system_uri import TRUENTH_EXTERNAL_STUDY_SYSTEM

        # Generate a few patients with differing results
        org = self.setup_org_qbs()
        org_id, org_name = org.id, org.name
        user2 = self.add_user('user2')
        user3 = self.add_user('user3')
        user4 = self.add_user('user4')
        with SessionScope(db):
            db.session.add(user2)
            db.session.add(user3)
            db.session.add(user4)
            db.session.commit()
        user2 = db.session.merge(user2)
        user3 = db.session.merge(user3)
        user4 = db.session.merge(user4)
        user4_id = user4.id

        self.add_user_identifier(user=user2,
                                 system=TRUENTH_EXTERNAL_STUDY_SYSTEM,
                                 value='study user 2')
        self.add_user_identifier(user=user3,
                                 system=TRUENTH_EXTERNAL_STUDY_SYSTEM,
                                 value='study user 3')

        now = datetime.utcnow()
        back15, nowish = associative_backdate(now, relativedelta(days=15))
        back45, nowish = associative_backdate(now, relativedelta(days=45))
        back115, nowish = associative_backdate(now, relativedelta(days=115))
        self.bless_with_basics(user=user2,
                               setdate=back15,
                               local_metastatic=org_name)
        self.bless_with_basics(user=user3,
                               setdate=back45,
                               local_metastatic=org_name)
        self.bless_with_basics(user=user4,
                               setdate=back115,
                               local_metastatic=org_name)

        # submit a mock response for all q's in 3 mo qb
        # which should result in completed status for user4
        qb_name = "CRV_recurring_3mo_period v2"
        threeMo = QuestionnaireBank.query.filter(
            QuestionnaireBank.name == qb_name).one()

        for q in threeMo.questionnaires:
            q = db.session.merge(q)
            mock_qr(q.name,
                    qb=threeMo,
                    iteration=0,
                    user_id=user4_id,
                    timestamp=back15)

        self.test_user = db.session.merge(self.test_user)
        self.promote_user(role_name=ROLE.STAFF.value)
        self.consent_with_org(org_id=org_id)
        self.login()
        response = self.client.get("/api/report/questionnaire_status")
        assert response.status_code == 200

        # expect baseline for each plus 3 mo for user4
        assert response.json['total'] == 4
        expect = {'Due', 'Overdue', 'Completed', 'Expired'}
        found = set([item['status'] for item in response.json['entry']])
        assert expect == found