예제 #1
0
    def test_withdrawn(self):
        # qbs should halt beyond withdrawal
        crv = self.setup_org_qbs()
        crv_id = crv.id
        # consent 17 months in past
        backdate = datetime.utcnow() - relativedelta(months=17)
        self.test_user.organizations.append(crv)
        self.consent_with_org(org_id=crv_id, setdate=backdate)

        # withdraw user now, which should provide result
        # in QBs prior to 17 months.

        user = db.session.merge(self.test_user)
        withdraw_consent(user=user,
                         org_id=crv_id,
                         acting_user=user,
                         acceptance_date=datetime.utcnow())
        gen = ordered_qbs(user=user)

        # expect each in order despite overlapping nature
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        for n in (3, 6, 9, 15):
            assert visit_name(next(gen)) == 'Month {}'.format(n)

        with pytest.raises(StopIteration):
            next(gen)
    def test_withdrawn(self):
        # qbs should halt beyond withdrawal
        crv = self.setup_org_qbs()
        crv_id = crv.id
        # consent 17 months in past
        backdate = datetime.utcnow() - relativedelta(months=17)
        self.test_user = db.session.merge(self.test_user)
        self.test_user.organizations.append(crv)
        self.consent_with_org(org_id=crv_id, setdate=backdate)

        # withdraw user now, which should provide result
        # in QBs prior to 17 months.

        user = db.session.merge(self.test_user)
        withdraw_consent(
            user=user, org_id=crv_id, acting_user=user,
            acceptance_date=datetime.utcnow())
        gen = ordered_qbs(user=user)

        # expect each in order despite overlapping nature
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        for n in (3, 6, 9, 15):
            assert visit_name(next(gen)) == 'Month {}'.format(n)

        with pytest.raises(StopIteration):
            next(gen)
예제 #3
0
 def test_empty(self):
     # Basic case, without org, empty list
     self.setup_org_qbs()
     user = db.session.merge(self.test_user)
     gen = ordered_qbs(user=user)
     with pytest.raises(StopIteration):
         next(gen)
    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)
예제 #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)
예제 #6
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)
예제 #7
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)
 def test_empty(self):
     # Basic case, without org, empty list
     self.setup_org_qbs()
     user = db.session.merge(self.test_user)
     gen = ordered_qbs(user=user)
     with pytest.raises(StopIteration):
         next(gen)
    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)
예제 #10
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)
예제 #11
0
    def test_full_list(self):
        crv = self.setup_org_qbs()
        self.bless_with_basics()  # pick up a consent, etc.
        self.test_user = db.session.merge(self.test_user)
        self.test_user.organizations.append(crv)

        gen = ordered_qbs(user=self.test_user)

        # expect each in order despite overlapping nature
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        for n in (3, 6, 9, 15, 18, 21, 30):
            assert visit_name(next(gen)) == 'Month {}'.format(n)

        with pytest.raises(StopIteration):
            next(gen)
예제 #12
0
    def test_full_list(self):
        crv = self.setup_org_qbs()
        self.bless_with_basics()  # pick up a consent, etc.
        self.test_user = db.session.merge(self.test_user)
        self.test_user.organizations.append(crv)

        gen = ordered_qbs(user=self.test_user)

        # expect each in order despite overlapping nature
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        for n in (3, 6, 9, 15, 18, 21, 30):
            assert visit_name(next(gen)) == 'Month {}'.format(n)

        with pytest.raises(StopIteration):
            next(gen)
예제 #13
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)
예제 #14
0
    def test_intervention_list(self):
        self.setup_intervention_qbs()
        self.bless_with_basics()  # pick up a consent, etc.
        # user with biopsy should return biopsy date
        self.login()
        user = db.session.merge(self.test_user)
        user.save_observation(
            codeable_concept=CC.BIOPSY, value_quantity=CC.TRUE_VALUE,
            audit=Audit(user_id=TEST_USER_ID, subject_id=TEST_USER_ID),
            status='', issued=None)
        user = db.session.merge(self.test_user)

        gen = ordered_qbs(user=user)

        # expect all intervention QBs - baseline then every 3mos
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        for n in (3, 9, 15, 21, 27):
            assert visit_name(next(gen)) == 'Month {}'.format(n)

        with pytest.raises(StopIteration):
            next(gen)
예제 #15
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)
예제 #16
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)
예제 #17
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)
예제 #18
0
    def test_intervention_list(self):
        self.setup_intervention_qbs()
        self.bless_with_basics()  # pick up a consent, etc.
        # user with biopsy should return biopsy date
        self.login()
        user = db.session.merge(self.test_user)
        user.save_observation(codeable_concept=CC.BIOPSY,
                              value_quantity=CC.TRUE_VALUE,
                              audit=Audit(user_id=TEST_USER_ID,
                                          subject_id=TEST_USER_ID),
                              status='',
                              issued=None)
        user = db.session.merge(self.test_user)

        gen = ordered_qbs(user=user)

        # expect all intervention QBs - baseline then every 3mos
        expect_baseline = next(gen)
        assert visit_name(expect_baseline) == 'Baseline'
        for n in (3, 9, 15, 21, 27):
            assert visit_name(next(gen)) == 'Month {}'.format(n)

        with pytest.raises(StopIteration):
            next(gen)