Exemple #1
0
    def test_questionnaire_banks_recurs(self):
        # set up a few recurring instances
        initial_recur = Recur(days_to_start=90,
                              days_in_cycle=90,
                              days_till_termination=720)
        every_six_thereafter = Recur(days_to_start=720, days_in_cycle=180)

        metastatic_org = Organization(name='metastatic')
        questionnaire = Questionnaire(name='test_q')
        with SessionScope(db):
            db.session.add(initial_recur)
            db.session.add(every_six_thereafter)
            db.session.add(metastatic_org)
            db.session.add(questionnaire)
            db.session.commit()

        initial_recur = db.session.merge(initial_recur)
        every_six_thereafter = db.session.merge(every_six_thereafter)
        metastatic_org_id = db.session.merge(metastatic_org).id

        # with bits in place, setup a recurring QB
        mr_qb = QuestionnaireBank(name='metastatic_recurring',
                                  classification='recurring',
                                  organization_id=metastatic_org_id)
        questionnaire = db.session.merge(questionnaire)
        recurs = [initial_recur, every_six_thereafter]

        qbq = QuestionnaireBankQuestionnaire(questionnaire=questionnaire,
                                             days_till_due=1,
                                             days_till_overdue=30,
                                             rank=1,
                                             recurs=recurs)
        mr_qb.questionnaires.append(qbq)

        # confirm persistence of this questionnaire bank includes the bits
        # added above
        results = mr_qb.as_json()

        copy = QuestionnaireBank.from_json(results)
        self.assertEquals(copy.name, mr_qb.name)
        copy_q = copy.questionnaires[0]
        self.assertEquals(copy_q.recurs, [initial_recur, every_six_thereafter])

        # now, modify the persisted form, remove one recur and add another
        new_recur = Recur(days_to_start=900,
                          days_in_cycle=180,
                          days_till_termination=1800)
        results['questionnaires'][0]['recurs'] = [
            initial_recur.as_json(),
            new_recur.as_json()
        ]
        updated_copy = QuestionnaireBank.from_json(results)

        self.assertEquals(
            [r.as_json() for r in updated_copy.questionnaires[0].recurs],
            [r.as_json() for r in (initial_recur, new_recur)])
    def test_import(self):
        org, rp, rp_id = self.setup_org_n_rp()
        rp_name = rp.name
        q1 = self.add_questionnaire(name='q1')
        q2 = self.add_questionnaire(name='q2')
        org, q1, q2 = map(db.session.merge, (org, q1, q2))

        data = {
            'resourceType': 'QuestionnaireBank',
            'research_protocol': {'reference': ('api/research_protocol/'
                                                '{}').format(rp_name)},
            'start': '{"days": 0}',
            'overdue': '{"weeks": 1}',
            'expired': '{"days": 30}',
            'questionnaires': [
                {
                    'rank': 2,
                    'questionnaire': {
                        'reference': 'api/questionnaire/{}?system={}'.format(
                            q1.name, TRUENTH_QUESTIONNAIRE_CODE_SYSTEM)}
                },
                {
                    'rank': 1,
                    'questionnaire': {
                        'reference': 'api/questionnaire/{}?system={}'.format(
                            q2.name, TRUENTH_QUESTIONNAIRE_CODE_SYSTEM)}
                }
            ],
            'id': 1,
            'name': 'bank',
            'classification': 'baseline'
        }
        qb = QuestionnaireBank.from_json(data)
        assert len(qb.questionnaires) == 2
        assert qb.research_protocol_id == rp_id
Exemple #3
0
    def test_import(self):
        org, rp, rp_id = self.setup_org_n_rp()
        rp_name = rp.name
        q1 = self.add_questionnaire(name='q1')
        q2 = self.add_questionnaire(name='q2')
        org, q1, q2 = map(db.session.merge, (org, q1, q2))

        data = {
            'resourceType':
            'QuestionnaireBank',
            'research_protocol': {
                'reference': ('api/research_protocol/'
                              '{}').format(rp_name)
            },
            'start':
            '{"days": 0}',
            'overdue':
            '{"weeks": 1}',
            'expired':
            '{"days": 30}',
            'questionnaires': [{
                'rank': 2,
                'questionnaire': {
                    'reference':
                    'api/questionnaire/{}?system={}'.format(
                        q1.name, TRUENTH_QUESTIONNAIRE_CODE_SYSTEM)
                }
            }, {
                'rank': 1,
                'questionnaire': {
                    'reference':
                    'api/questionnaire/{}?system={}'.format(
                        q2.name, TRUENTH_QUESTIONNAIRE_CODE_SYSTEM)
                }
            }],
            'id':
            1,
            'name':
            'bank',
            'classification':
            'baseline'
        }
        qb = QuestionnaireBank.from_json(data)
        assert len(qb.questionnaires) == 2
        assert qb.research_protocol_id == rp_id
Exemple #4
0
    def test_import_followup(self):
        intervention = Intervention(name='testy', description='simple')
        q1 = self.add_questionnaire(name='q1')
        q2 = self.add_questionnaire(name='q2')
        with SessionScope(db):
            db.session.add(intervention)
            db.session.commit()
        intervention, q1, q2 = map(db.session.merge, (intervention, q1, q2))

        data = {
            'resourceType':
            'QuestionnaireBank',
            'intervention': {
                'reference': 'api/intervention/{}'.format(intervention.name)
            },
            'expired':
            '{"days": 104}',
            'start':
            '{"days": 76}',
            'questionnaires': [{
                'rank': 2,
                'questionnaire': {
                    'reference':
                    'api/questionnaire/{}?system={}'.format(
                        q1.name, TRUENTH_QUESTIONNAIRE_CODE_SYSTEM)
                }
            }, {
                'rank': 1,
                'questionnaire': {
                    'reference':
                    'api/questionnaire/{}?system={}'.format(
                        q2.name, TRUENTH_QUESTIONNAIRE_CODE_SYSTEM)
                }
            }],
            'id':
            1,
            'name':
            u'bank',
            'classification':
            'followup'
        }
        qb = QuestionnaireBank.from_json(data)
        self.assertEqual(2, len(qb.questionnaires))
Exemple #5
0
    def test_import(self):
        org = Organization(name='org')
        q1 = Questionnaire(name='q1')
        q2 = Questionnaire(name='q2')
        with SessionScope(db):
            db.session.add(org)
            db.session.add(q1)
            db.session.add(q2)
            db.session.commit()
        org, q1, q2 = map(db.session.merge, (org, q1, q2))
        q2_id = q2.id

        data = {
            'resourceType':
            'QuestionnaireBank',
            'organization': {
                'reference': 'api/organization/{}'.format(org.id)
            },
            'questionnaires': [{
                'days_till_overdue': 30,
                'days_till_due': 5,
                'rank': 2,
                'questionnaire': {
                    'reference': 'api/questionnaire/{}'.format(q1.name)
                }
            }, {
                'days_till_overdue': 30,
                'days_till_due': 5,
                'rank': 1,
                'questionnaire': {
                    'reference': 'api/questionnaire/{}'.format(q2.name)
                }
            }],
            'id':
            1,
            'name':
            u'bank',
            'classification':
            'baseline'
        }
        qb = QuestionnaireBank.from_json(data)
        self.assertEquals(2, len(qb.questionnaires))
Exemple #6
0
    def test_questionnaire_banks_recurs(self):
        # only one recurrence per qb allowed at this time
        initial_recur = Recur(start='{"days": 90}',
                              cycle_length='{"days": 90}',
                              termination='{"days": 720}')
        every_six_thereafter = Recur(start='{"days": 720}',
                                     cycle_length='{"days": 180}')

        rp = ResearchProtocol(name='proto')
        with SessionScope(db):
            db.session.add(rp)
            db.session.commit()
        rp = db.session.merge(rp)
        rp_id = rp.id

        metastatic_org = Organization(name='metastatic')
        metastatic_org.research_protocols.append(rp)
        questionnaire = self.add_questionnaire(name='test_q')
        with SessionScope(db):
            db.session.add(initial_recur)
            db.session.add(every_six_thereafter)
            db.session.add(metastatic_org)
            db.session.add(questionnaire)
            db.session.commit()

        initial_recur = db.session.merge(initial_recur)
        every_six_thereafter = db.session.merge(every_six_thereafter)

        # with bits in place, setup a recurring QB
        recurs = [initial_recur, every_six_thereafter]
        mr_qb = QuestionnaireBank(name='metastatic_recurring',
                                  classification='recurring',
                                  research_protocol_id=rp_id,
                                  start='{"days": 0}',
                                  overdue='{"days": 1}',
                                  expired='{"days": 30}',
                                  recurs=recurs)
        questionnaire = db.session.merge(questionnaire)

        qbq = QuestionnaireBankQuestionnaire(questionnaire=questionnaire,
                                             rank=1)
        mr_qb.questionnaires.append(qbq)
        with SessionScope(db):
            db.session.add(mr_qb)
            db.session.commit()
        mr_qb, initial_recur, every_six_thereafter = map(
            db.session.merge, (mr_qb, initial_recur, every_six_thereafter))

        # confirm persistence of this questionnaire bank includes the bits
        # added above
        results = mr_qb.as_json()

        copy = QuestionnaireBank.from_json(results)
        assert copy.name == mr_qb.name
        assert copy.recurs == [initial_recur, every_six_thereafter]

        # now, modify the persisted form, remove one recur and add another
        new_recur = Recur(start='{"days": 900}',
                          cycle_length='{"days": 180}',
                          termination='{"days": 1800}')
        results['recurs'] = [initial_recur.as_json(), new_recur.as_json()]
        updated_copy = QuestionnaireBank.from_json(results)

        assert ([r.as_json() for r in updated_copy.recurs
                 ] == [r.as_json() for r in (initial_recur, new_recur)])
    def test_questionnaire_banks_recurs(self):
        # only one recurrence per qb allowed at this time
        initial_recur = Recur(
            start='{"days": 90}', cycle_length='{"days": 90}',
            termination='{"days": 720}')
        every_six_thereafter = Recur(
            start='{"days": 720}', cycle_length='{"days": 180}')

        rp = ResearchProtocol(name='proto')
        with SessionScope(db):
            db.session.add(rp)
            db.session.commit()
        rp = db.session.merge(rp)
        rp_id = rp.id

        metastatic_org = Organization(name='metastatic')
        metastatic_org.research_protocols.append(rp)
        questionnaire = self.add_questionnaire(name='test_q')
        with SessionScope(db):
            db.session.add(initial_recur)
            db.session.add(every_six_thereafter)
            db.session.add(metastatic_org)
            db.session.add(questionnaire)
            db.session.commit()

        initial_recur = db.session.merge(initial_recur)
        every_six_thereafter = db.session.merge(every_six_thereafter)

        # with bits in place, setup a recurring QB
        recurs = [initial_recur, every_six_thereafter]
        mr_qb = QuestionnaireBank(
            name='metastatic_recurring',
            classification='recurring',
            research_protocol_id=rp_id,
            start='{"days": 0}', overdue='{"days": 1}',
            expired='{"days": 30}',
            recurs=recurs)
        questionnaire = db.session.merge(questionnaire)

        qbq = QuestionnaireBankQuestionnaire(
            questionnaire=questionnaire, rank=1)
        mr_qb.questionnaires.append(qbq)
        with SessionScope(db):
            db.session.add(mr_qb)
            db.session.commit()
        mr_qb, initial_recur, every_six_thereafter = map(
            db.session.merge, (mr_qb, initial_recur, every_six_thereafter))

        # confirm persistence of this questionnaire bank includes the bits
        # added above
        results = mr_qb.as_json()

        copy = QuestionnaireBank.from_json(results)
        assert copy.name == mr_qb.name
        assert copy.recurs == [initial_recur, every_six_thereafter]

        # now, modify the persisted form, remove one recur and add another
        new_recur = Recur(
            start='{"days": 900}',
            cycle_length='{"days": 180}',
            termination='{"days": 1800}')
        results['recurs'] = [
            initial_recur.as_json(), new_recur.as_json()]
        updated_copy = QuestionnaireBank.from_json(results)

        assert ([r.as_json() for r in updated_copy.recurs]
                == [r.as_json() for r in (initial_recur, new_recur)])