Esempio n. 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)])
Esempio n. 2
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)])