Exemple #1
0
    def test_should_show_previous_submissions_in_old_format_after_change_date_format(
            self):
        eid_field = TextField(label="What is associated entity?",
                              code="EID",
                              name="What is associatéd entity?",
                              entity_question_flag=True,
                              ddtype=self.ddtype)
        rp_field = DateField(label="Report date",
                             code="RD",
                             name="What is réporting date?",
                             date_format="dd.mm.yyyy",
                             event_time_field_flag=True,
                             ddtype=self.ddtype)

        form_model = FormModelBuilder(self.manager, ['clinic'],
                                      form_code='cli001').add_fields(
                                          eid_field, rp_field).build()

        self.submit_data({
            'form_code': 'cli001',
            'EID': 'cid001',
            'RD': '12.12.2012'
        })

        rp_field = DateField(label="Report date",
                             code="RD",
                             name="What is réporting date?",
                             date_format="mm.yyyy",
                             event_time_field_flag=True,
                             ddtype=self.ddtype)
        self._edit_fields(form_model, rp_field)
        self.submit_data({
            'form_code': 'cli001',
            'EID': 'cid001',
            'RD': '08.2012'
        })

        rp_field = DateField(label="Report date",
                             code="RD",
                             name="What is réporting date?",
                             date_format="mm.dd.yyyy",
                             event_time_field_flag=True,
                             ddtype=self.ddtype)
        self._edit_fields(form_model, rp_field)
        self.submit_data({
            'form_code': 'cli001',
            'EID': 'cid001',
            'RD': '12.24.2012'
        })

        submissions = successful_submissions(self.manager,
                                             form_model.form_code)
        analyzer = SubmissionAnalyzer(form_model, self.manager, self.org_id,
                                      submissions)
        values = analyzer.get_raw_values()
        reporting_periods = map(lambda value: value[2], values)

        self.assertIn('08.2012', reporting_periods)
        self.assertIn('12.12.2012', reporting_periods)
        self.assertIn('12.24.2012', reporting_periods)
    def test_should_get_successful_submissions(self):
        submissions = self.submission_builder.build_two_successful_submissions()
        self.submission_builder.build_two_error_submission()

        success_submissions = successful_submissions(self.manager, FORM_CODE)

        self.assertEqual(2, len(success_submissions))

        self._assertSubmissionsEqual(submissions, success_submissions)
Exemple #3
0
    def test_should_should_get_fields_values_after_question_count_changed(
            self):
        eid_field = TextField(label="What is associated entity?",
                              code="EID",
                              name="What is associatéd entity?",
                              entity_question_flag=True,
                              ddtype=self.ddtype)
        rp_field = DateField(label="Report date",
                             code="RD",
                             name="What is réporting date?",
                             date_format="dd.mm.yyyy",
                             event_time_field_flag=True,
                             ddtype=self.ddtype)
        symptoms_field = TextField(label="Zhat are symptoms?",
                                   code="SY",
                                   name="Zhat are symptoms?",
                                   ddtype=self.ddtype)
        gps = TextField(label="What is your blood group?",
                        code="GPS",
                        name="What is your gps?",
                        ddtype=self.ddtype)
        form_model = FormModelBuilder(self.manager, ['clinic'],
                                      form_code='cli001').add_fields(
                                          eid_field, rp_field, symptoms_field,
                                          gps).build()

        self.submit_data({
            'form_code': 'cli001',
            'EID': 'cid001',
            'RD': '12.12.2012',
            'SY': 'Fever',
            'GPS': 'NewYork'
        })

        form_model.create_snapshot()
        form_model.delete_field("SY")
        form_model.save()

        self.submit_data({
            'form_code': 'cli001',
            'EID': 'cid001',
            'RD': '12.12.2012',
            'GPS': '1,1'
        })

        submissions = successful_submissions(self.manager,
                                             form_model.form_code)
        analyzer = SubmissionAnalyzer(form_model, self.manager, self.org_id,
                                      submissions)
        values = analyzer.get_raw_values()

        self.assertEqual(['1,1'], values[0][5:])
        self.assertEqual(['NewYork'], values[1][5:])
Exemple #4
0
    def test_should_get_statistic_result_after_option_value_changed(self):
        """
            Function to test getting statistic result of submissions after option value changed.
            question name ordered by field
            options ordered by count(desc),option(alphabetic)
            total = submission count of this question
        """
        eid_field = TextField(label="What is associated entity?",
                              code="EID",
                              name="What is associatéd entity?",
                              entity_question_flag=True,
                              ddtype=self.ddtype)
        blood_type_field = SelectField(label="What is your blood group?",
                                       code="BG",
                                       name="What is your blood group?",
                                       options=[("Type 1", "a"),
                                                ("Type 2", "b")],
                                       single_select_flag=True,
                                       ddtype=self.ddtype)

        form_model = FormModelBuilder(self.manager, ['clinic'],
                                      form_code='cli001').add_fields(
                                          eid_field, blood_type_field).build()

        self.submit_data({'form_code': 'cli001', 'EID': 'cid001', 'BG': 'a'})

        blood_type_field = SelectField(label="What is your blood group?",
                                       code="BG",
                                       name="What is your blood group?",
                                       options=[("O+", "a"), ("O-", "b"),
                                                ("AB", "c"), ("B+", "d")],
                                       single_select_flag=True,
                                       ddtype=self.ddtype)
        self._edit_fields(form_model, blood_type_field)
        self.submit_data({'form_code': 'cli001', 'EID': 'cid001', 'BG': 'a'})

        submissions = successful_submissions(self.manager,
                                             form_model.form_code)
        analyzer = SubmissionAnalyzer(form_model, self.manager, self.org_id,
                                      submissions)
        statistics = analyzer.get_analysis_statistics()

        expected = [[
            "What is your blood group?", field_attributes.SELECT_FIELD, 2,
            [["O+", 1], ['Type 1', 1], ["AB", 0], ["B+", 0], ["O-", 0]]
        ]]
        self.assertEqual(expected, statistics)
Exemple #5
0
    def test_should_get_statistic_result_after_answer_type_changed_from_word_to_mc(
            self):
        eid_field = TextField(label="What is associated entity?",
                              code="EID",
                              name="What is associatéd entity?",
                              entity_question_flag=True,
                              ddtype=self.ddtype)
        blood_type_field = TextField(label="What is your blood group?",
                                     code="BG",
                                     name="What is your blood group?",
                                     ddtype=self.ddtype)

        form_model = FormModelBuilder(self.manager, ['clinic'],
                                      form_code='cli001').add_fields(
                                          eid_field, blood_type_field).build()
        self.submit_data({
            'form_code': 'cli001',
            'EID': 'cid001',
            'BG': 'unknown'
        })

        blood_type_field = SelectField(label="What is your blood group?",
                                       code="BG",
                                       name="What is your blood group?",
                                       options=[("O+", "a"), ("O-", "b"),
                                                ("AB", "c"), ("B+", "d")],
                                       single_select_flag=False,
                                       ddtype=self.ddtype)
        self._edit_fields(form_model, blood_type_field)
        self.submit_data({'form_code': 'cli001', 'EID': 'cid001', 'BG': 'ab'})

        submissions = successful_submissions(self.manager,
                                             form_model.form_code)
        analyzer = SubmissionAnalyzer(form_model, self.manager, self.org_id,
                                      submissions)
        statistics = analyzer.get_analysis_statistics()

        expected = [[
            "What is your blood group?", field_attributes.MULTISELECT_FIELD, 2,
            [["O+", 1], ["O-", 1], ['unknown', 1], ["AB", 0], ["B+", 0]]
        ]]
        self.assertEqual(expected, statistics)
Exemple #6
0
    def test_should_get_old_answer_for_submissions_which_is_submitted_before_other_changed_to_other(
            self):
        """
        Function to test get old answer for submissions which is submitted before answer type changed from other type(word, number, date, GPS) to other type
        """
        eid_field = TextField(label="What is associated entity?",
                              code="EID",
                              name="What is associatéd entity?",
                              entity_question_flag=True,
                              ddtype=self.ddtype)
        rp_field = DateField(label="Report date",
                             code="RD",
                             name="What is réporting date?",
                             date_format="dd.mm.yyyy",
                             event_time_field_flag=True,
                             ddtype=self.ddtype)
        symptoms_field = TextField(label="Zhat are symptoms?",
                                   code="SY",
                                   name="Zhat are symptoms?",
                                   ddtype=self.ddtype)
        gps = TextField(label="What is your blood group?",
                        code="GPS",
                        name="What is your gps?",
                        ddtype=self.ddtype)
        national_day_field = TextField(label="national day?",
                                       code="ND",
                                       name="national day",
                                       ddtype=self.ddtype)
        form_model = FormModelBuilder(self.manager, ['clinic'],
                                      form_code='cli001').add_fields(
                                          eid_field, rp_field, symptoms_field,
                                          gps, national_day_field).build()

        self.submit_data({
            'form_code': 'cli001',
            'EID': 'cid001',
            'RD': '12.12.2012',
            'SY': 'Fever',
            'GPS': 'NewYork',
            "ND": "oct 1"
        })

        gps = GeoCodeField(label="What is your blood group?",
                           code="GPS",
                           name="What is your gps?",
                           ddtype=self.ddtype)
        symptoms_field = IntegerField(label="Zhat are symptoms?",
                                      code="SY",
                                      name="Zhat are symptoms?",
                                      ddtype=self.ddtype)
        national_day_field = DateField(label="national day?",
                                       code="ND",
                                       name="national day",
                                       ddtype=self.ddtype,
                                       date_format="dd.mm.yyyy")

        self._edit_fields(form_model, gps, national_day_field, symptoms_field)
        self.submit_data({
            'form_code': 'cli001',
            'EID': 'cid001',
            'RD': '12.12.2012',
            'SY': '100',
            'GPS': '1,1',
            "ND": "01.10.2012"
        })

        submissions = successful_submissions(self.manager,
                                             form_model.form_code)
        analyzer = SubmissionAnalyzer(form_model, self.manager, self.org_id,
                                      submissions)
        values = analyzer.get_raw_values()

        self.assertEqual(['100', '1,1', '01.10.2012'], values[0][5:])
        self.assertEqual(['Fever', 'NewYork', 'oct 1'], values[1][5:])
Exemple #7
0
    def test_should_get_old_answer_for_submissions_which_is_submitted_before_other_changed_to_MC(
            self):
        """
        Function to test get old answer for submissions which is submitted before answer type changed from other type(word, number, date, GPS) to multiple choice/single choice
        """
        eid_field = TextField(label="What is associated entity?",
                              code="EID",
                              name="What is associatéd entity?",
                              entity_question_flag=True,
                              ddtype=self.ddtype)
        rp_field = DateField(label="Report date",
                             code="RD",
                             name="What is réporting date?",
                             date_format="dd.mm.yyyy",
                             event_time_field_flag=True,
                             ddtype=self.ddtype)
        symptoms_field = TextField(label="Zhat are symptoms?",
                                   code="SY",
                                   name="Zhat are symptoms?",
                                   ddtype=self.ddtype)
        blood_type_field = SelectField(label="What is your blood group?",
                                       code="BG",
                                       name="What is your blood group?",
                                       options=[("O+", "a"), ("O-", "b"),
                                                ("AB", "c"), ("B+", "d")],
                                       single_select_flag=True,
                                       ddtype=self.ddtype)

        form_model = FormModelBuilder(self.manager, ['clinic'],
                                      form_code='cli001').add_fields(
                                          eid_field, rp_field, symptoms_field,
                                          blood_type_field).build()
        self.submit_data({
            'form_code': 'cli001',
            'EID': 'cid001',
            'RD': '12.12.2012',
            'SY': 'Fever',
            'BG': 'b'
        })

        symptoms_field = SelectField(label="Zhat are symptoms?",
                                     code="SY",
                                     name="Zhat are symptoms?",
                                     options=[("Rapid weight loss", "a"),
                                              ("Dry cough", "b"),
                                              ("Pneumonia", "c"),
                                              ("Memory loss", "d"),
                                              ("Neurological disorders ", "e")
                                              ],
                                     single_select_flag=False,
                                     ddtype=self.ddtype)
        self._edit_fields(form_model, symptoms_field)
        self.submit_data({
            'form_code': 'cli001',
            'EID': 'cid001',
            'RD': '12.12.2012',
            'SY': 'ab',
            'BG': 'b'
        })

        submissions = successful_submissions(self.manager,
                                             form_model.form_code)
        analyzer = SubmissionAnalyzer(form_model, self.manager, self.org_id,
                                      submissions)
        values = analyzer.get_raw_values()

        self.assertEqual([['Rapid weight loss', 'Dry cough'], ['O-']],
                         values[0][5:])
        self.assertEqual(['Fever', ['O-']], values[1][5:])