Exemple #1
0
    def test_missed_pnc_visit_to_ls(self, language_code_patch):
        c = CustomContent(custom_content_id='ICDS_MISSED_PNC_VISIT_TO_LS')

        schedule_instance = CaseTimedScheduleInstance(
            domain=self.domain,
            case_id=self.ccs_record_case.case_id,
        )

        c.set_context(schedule_instance=schedule_instance)

        language_code_patch.return_value = ENGLISH
        self.assertEqual(
            c.get_list_of_messages(self.user3),
            [
                "AWC awc1 has not reported a visit during the PNC within one week of delivery for Sam"
            ],
        )
Exemple #2
0
    def test_missed_cf_visit_to_ls(self, language_code_patch):
        c = CustomContent(custom_content_id='ICDS_MISSED_CF_VISIT_TO_LS')

        schedule_instance = CaseTimedScheduleInstance(
            domain=self.domain,
            case_id=self.ccs_record_case.case_id,
        )

        c.set_context(schedule_instance=schedule_instance)

        language_code_patch.return_value = ENGLISH
        self.assertEqual(
            c.get_list_of_messages(self.user3),
            [
                "AWC awc1 has not reported a visit during complementary feeding initiation period for Sam"
            ],
        )
Exemple #3
0
    def test_child_illness_reported(self, language_code_patch):
        c = CustomContent(custom_content_id='ICDS_CHILD_ILLNESS_REPORTED')

        schedule_instance = CaseTimedScheduleInstance(
            domain=self.domain,
            case_id=self.child_person_case.case_id,
        )

        c.set_context(schedule_instance=schedule_instance)

        language_code_patch.return_value = ENGLISH
        self.assertEqual(
            c.get_list_of_messages(self.user3),
            [
                "AWC awc1 has reported illness for the child Joe. Please ensure that AWW follows up with mother "
                "immediately"
            ],
        )
    def test_mobile_worker_recipients_with_user_data_filter(self):
        schedule = TimedSchedule.create_simple_daily_schedule(
            self.domain,
            TimedEvent(time=time(9, 0)),
            SMSContent(message={'en': 'Hello'})
        )
        schedule.user_data_filter = {'role': ['nurse']}
        schedule.save()

        instance = CaseTimedScheduleInstance(
            domain=self.domain,
            timed_schedule_id=schedule.schedule_id,
            recipient_type='Group',
            recipient_id=self.group2.get_id
        )
        self.assertEqual(
            self.user_ids(instance.expand_recipients()),
            [self.mobile_user4.get_id, self.mobile_user5.get_id]
        )
    def test_expand_location_recipients_with_descendants(self):
        schedule = TimedSchedule.create_simple_daily_schedule(
            self.domain,
            TimedEvent(time=time(9, 0)),
            SMSContent(message={'en': 'Hello'})
        )
        schedule.include_descendant_locations = True
        schedule.save()

        instance = CaseTimedScheduleInstance(
            domain=self.domain,
            timed_schedule_id=schedule.schedule_id,
            recipient_type='Location',
            recipient_id=self.state_location.location_id
        )
        self.assertItemsEqual(
            self.user_ids(instance.expand_recipients()),
            [self.mobile_user.get_id, self.mobile_user2.get_id]
        )
Exemple #6
0
    def test_static_negative_growth_indicator(self):
        c = CustomContent(
            custom_content_id='ICDS_STATIC_NEGATIVE_GROWTH_MESSAGE')

        schedule_instance = CaseTimedScheduleInstance(
            domain=self.domain,
            case_id=self.child_health_case.case_id,
        )

        # Test when current weight is greater than previous
        submit_growth_form(self.domain, self.child_health_case.case_id, '10.1',
                           '10.4')
        self.assertEqual(
            c.get_list_of_messages(self.mother_person_case, schedule_instance),
            [])

        # Test when current weight is equal to previous
        submit_growth_form(self.domain, self.child_health_case.case_id, '10.1',
                           '10.1')
        self.assertEqual(
            c.get_list_of_messages(self.mother_person_case, schedule_instance),
            [
                "As per the latest records of your AWC, the weight of your child Joe has remained static in the last "
                "month. Please consult your AWW for necessary advice."
            ])

        # Test when current weight is less than previous
        submit_growth_form(self.domain, self.child_health_case.case_id, '10.1',
                           '9.9')
        self.assertEqual(
            c.get_list_of_messages(self.mother_person_case, schedule_instance),
            [
                "As per the latest records of your AWC, the weight of your child Joe has reduced in the last month. "
                "Please consult your AWW for necessary advice."
            ])

        # Test ignoring forms with the wrong xmlns
        update_case(self.domain, self.child_health_case.case_id,
                    {'property': 'value1'})
        update_case(self.domain, self.child_health_case.case_id,
                    {'property': 'value2'})
        update_case(self.domain, self.child_health_case.case_id,
                    {'property': 'value3'})
        update_case(self.domain, self.child_health_case.case_id,
                    {'property': 'value4'})
        update_case(self.domain, self.child_health_case.case_id,
                    {'property': 'value5'})
        update_case(self.domain, self.child_health_case.case_id,
                    {'property': 'value6'})
        update_case(self.domain, self.child_health_case.case_id,
                    {'property': 'value7'})
        update_case(self.domain, self.child_health_case.case_id,
                    {'property': 'value8'})
        update_case(self.domain, self.child_health_case.case_id,
                    {'property': 'value9'})
        update_case(self.domain, self.child_health_case.case_id,
                    {'property': 'value10'})

        self.assertEqual(
            c.get_list_of_messages(self.mother_person_case, schedule_instance),
            [
                "As per the latest records of your AWC, the weight of your child Joe has reduced in the last month. "
                "Please consult your AWW for necessary advice."
            ])
 def test_expand_group_recipients(self):
     instance = CaseTimedScheduleInstance(domain=self.domain,
                                          recipient_type='Group',
                                          recipient_id=self.group.get_id)
     self.assertEqual(self.user_ids(instance.expand_recipients()),
                      [self.mobile_user.get_id])
 def test_case_recipient(self):
     with create_case(self.domain, 'person') as case:
         instance = CaseTimedScheduleInstance(domain=self.domain, case_id=case.case_id, recipient_type='Self')
         self.assertTrue(is_commcarecase(instance.recipient))
         self.assertEqual(instance.recipient.case_id, case.case_id)
    def test_host_case_owner_location_parent(self):
        with create_test_case(self.domain, 'test-extension-case',
                              'name') as extension_case:
            with create_test_case(self.domain, 'test-host-case',
                                  'name') as host_case:

                update_case(self.domain,
                            host_case.case_id,
                            case_properties={
                                'owner_id': self.city_location.location_id
                            })
                set_parent_case(self.domain,
                                extension_case,
                                host_case,
                                relationship='extension')

                # Test the recipient is returned correctly
                instance = CaseTimedScheduleInstance(
                    domain=self.domain,
                    case_id=extension_case.case_id,
                    recipient_type=CaseScheduleInstanceMixin.
                    RECIPIENT_TYPE_CUSTOM,
                    recipient_id='HOST_CASE_OWNER_LOCATION_PARENT',
                )
                self.assertIsInstance(instance.recipient, SQLLocation)
                self.assertEqual(instance.recipient.location_id,
                                 self.state_location.location_id)

                # Test no parent location
                update_case(self.domain,
                            host_case.case_id,
                            case_properties={
                                'owner_id': self.country_location.location_id
                            })
                instance = CaseTimedScheduleInstance(
                    domain=self.domain,
                    case_id=extension_case.case_id,
                    recipient_type=CaseScheduleInstanceMixin.
                    RECIPIENT_TYPE_CUSTOM,
                    recipient_id='HOST_CASE_OWNER_LOCATION_PARENT',
                )
                self.assertIsNone(instance.recipient)

                # Test location that does not exist
                update_case(self.domain,
                            host_case.case_id,
                            case_properties={'owner_id': 'does-not-exist'})
                instance = CaseTimedScheduleInstance(
                    domain=self.domain,
                    case_id=extension_case.case_id,
                    recipient_type=CaseScheduleInstanceMixin.
                    RECIPIENT_TYPE_CUSTOM,
                    recipient_id='HOST_CASE_OWNER_LOCATION_PARENT',
                )
                self.assertIsNone(instance.recipient)

                # Test on a case that is not an extension case
                instance = CaseTimedScheduleInstance(
                    domain=self.domain,
                    case_id=host_case.case_id,
                    recipient_type=CaseScheduleInstanceMixin.
                    RECIPIENT_TYPE_CUSTOM,
                    recipient_id='HOST_CASE_OWNER_LOCATION_PARENT',
                )
                self.assertIsNone(instance.recipient)

                # Test with case id that doesn't exist
                instance = CaseTimedScheduleInstance(
                    domain=self.domain,
                    case_id='does-not-exist',
                    recipient_type=CaseScheduleInstanceMixin.
                    RECIPIENT_TYPE_CUSTOM,
                    recipient_id='HOST_CASE_OWNER_LOCATION_PARENT',
                )
                self.assertIsNone(instance.recipient)