def test_custom_content(self): for cls in ( AlertScheduleInstance, TimedScheduleInstance, CaseAlertScheduleInstance, CaseTimedScheduleInstance, ): content = CustomContent(custom_content_id='TEST') content.set_context(schedule_instance=cls()) self.assertEqual(content.get_list_of_messages(self.user), ['Message 1', 'Message 2'])
def test_custom_content(self): for cls in ( AlertScheduleInstance, TimedScheduleInstance, CaseAlertScheduleInstance, CaseTimedScheduleInstance, ): content = CustomContent(custom_content_id='TEST') content.set_context(schedule_instance=cls()) self.assertEqual(content.get_list_of_messages(self.user), ['Message 1', 'Message 2'])
def test_child_vaccinations_complete(self, language_code_patch): c = CustomContent(custom_content_id='ICDS_CHILD_VACCINATIONS_COMPLETE') schedule_instance = CaseTimedScheduleInstance( domain=self.domain, case_id=self.child_tasks_case.case_id, ) language_code_patch.return_value = ENGLISH self.assertEqual( c.get_list_of_messages(self.user1, schedule_instance), ["Congratulations! You've given all the vaccines to Joe"], )
def test_cf_visits_complete(self): c = CustomContent(custom_content_id='ICDS_CF_VISITS_COMPLETE') schedule_instance = CaseTimedScheduleInstance( domain=self.domain, case_id=self.ccs_record_case.case_id, ) c.set_context(schedule_instance=schedule_instance) self.assertEqual( c.get_list_of_messages(self.user1), ["Congratulations! You've done all the Complementary Feeding Visits for Sam"], )
def test_missed_pnc_visit_to_ls(self): 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) 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"], )
def test_missed_cf_visit_to_ls(self): 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) self.assertEqual( c.get_list_of_messages(self.user3), ["AWC awc1 has not reported a visit during complementary feeding initiation period for Sam"], )
def test_child_illness_reported(self): 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) 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_static_negative_growth_indicator_with_red_status(self): c = CustomContent( custom_content_id='ICDS_STATIC_NEGATIVE_GROWTH_MESSAGE') schedule_instance = CaseTimedScheduleInstance( domain=self.domain, case_id=self.red_child_health_case.case_id, ) # Current weight is less than previous, but grade is red, so no messages are sent submit_growth_form(self.domain, self.red_child_health_case.case_id, '10.1', '9.9') self.assertEqual( c.get_list_of_messages(self.mother_person_case, schedule_instance), [])
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, ) language_code_patch.return_value = ENGLISH self.assertEqual( c.get_list_of_messages(self.user3, schedule_instance), [ "AWC awc1 has not reported a visit during complementary feeding initiation period for Sam" ], )
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, ) language_code_patch.return_value = ENGLISH self.assertEqual( c.get_list_of_messages(self.user3, schedule_instance), [ "AWC awc1 has not reported a visit during the PNC within one week of delivery for Sam" ], )
def test_cf_visits_complete(self, language_code_patch): c = CustomContent(custom_content_id='ICDS_CF_VISITS_COMPLETE') schedule_instance = CaseTimedScheduleInstance( domain=self.domain, case_id=self.ccs_record_case.case_id, ) language_code_patch.return_value = ENGLISH self.assertEqual( c.get_list_of_messages(self.user1, schedule_instance), [ "Congratulations! You've done all the Complementary Feeding Visits for Sam" ], )
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, ) c.set_context(schedule_instance=schedule_instance) # 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), []) # 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), [ "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), [ "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), [ "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 create_aww_indicator_4(domain): with transaction.atomic(): # Monthly schedule for the last day of the month schedule = TimedSchedule.create_simple_monthly_schedule( domain, TimedEvent(time=time(9, 30)), [-1], CustomContent(custom_content_id='ICDS_DPT3_AND_MEASLES_ARE_DUE'), total_iterations=TimedSchedule.REPEAT_INDEFINITELY ) schedule.default_language_code = 'hin' schedule.custom_metadata = {'icds_indicator': 'aww_4'} schedule.save() rule = AutomaticUpdateRule.objects.create( domain=domain, name="AWW #4: DPT3 and Measles Vaccinations Due", case_type='tasks', active=True, deleted=False, filter_on_server_modified=False, server_modified_boundary=None, migrated=True, workflow=AutomaticUpdateRule.WORKFLOW_SCHEDULING, ) rule.add_criteria( CustomMatchDefinition, name='ICDS_CONSIDER_CASE_FOR_DPT3_AND_MEASLES_REMINDER', ) rule.add_action( CreateScheduleInstanceActionDefinition, timed_schedule_id=schedule.schedule_id, recipients=(('Owner', None),), )
def create_aww_indicator_6(domain): with transaction.atomic(): schedule = TimedSchedule.create_simple_daily_schedule( domain, TimedEvent(time=time(9, 0)), CustomContent(custom_content_id='ICDS_CF_VISITS_COMPLETE'), total_iterations=1, ) schedule.default_language_code = 'hin' schedule.custom_metadata = {'icds_indicator': 'aww_6'} schedule.save() rule = AutomaticUpdateRule.objects.create( domain=domain, name="AWW #6: CF Visits Complete", case_type='ccs_record', active=True, deleted=False, filter_on_server_modified=False, server_modified_boundary=None, migrated=True, workflow=AutomaticUpdateRule.WORKFLOW_SCHEDULING, ) for i in [1, 2, 3, 4, 5, 6, 7]: rule.add_criteria( MatchPropertyDefinition, property_name='cf%s_date' % i, match_type=MatchPropertyDefinition.MATCH_HAS_VALUE, ) rule.add_action( CreateScheduleInstanceActionDefinition, timed_schedule_id=schedule.schedule_id, recipients=(('Owner', None),), )
def test_static_negative_growth_indicator_with_red_status(self): c = CustomContent(custom_content_id='ICDS_STATIC_NEGATIVE_GROWTH_MESSAGE') schedule_instance = CaseTimedScheduleInstance( domain=self.domain, case_id=self.red_child_health_case.case_id, ) c.set_context(schedule_instance=schedule_instance) # Current weight is less than previous, but grade is red, so no messages are sent submit_growth_form(self.domain, self.red_child_health_case.case_id, '10.1', '9.9') self.assertEqual( c.get_list_of_messages(self.mother_person_case), [] )
def create_beneficiary_indicator_2(domain): with transaction.atomic(): schedule = TimedSchedule.create_simple_daily_schedule( domain, TimedEvent(time=time(9, 0)), CustomContent(custom_content_id='ICDS_STATIC_NEGATIVE_GROWTH_MESSAGE'), total_iterations=1 ) schedule.default_language_code = 'hin' schedule.custom_metadata = {'icds_indicator': 'beneficiary_2'} schedule.save() rule = AutomaticUpdateRule.objects.create( domain=domain, name="Beneficiary #2: Static / Negative Weight Indicator", case_type='child_health', active=True, deleted=False, filter_on_server_modified=False, server_modified_boundary=None, migrated=True, workflow=AutomaticUpdateRule.WORKFLOW_SCHEDULING, ) rule.add_criteria( MatchPropertyDefinition, property_name='static_negative_growth_time', match_type=MatchPropertyDefinition.MATCH_HAS_VALUE, ) rule.add_action( CreateScheduleInstanceActionDefinition, timed_schedule_id=schedule.schedule_id, recipients=(('CustomRecipient', 'ICDS_MOTHER_PERSON_CASE_FROM_CHILD_HEALTH_CASE'),), reset_case_property_name='static_negative_growth_time', )
def create_ls_indicator_4a(domain): with transaction.atomic(): schedule = TimedSchedule.create_simple_daily_schedule( domain, TimedEvent(time=time(9, 0)), CustomContent(custom_content_id='ICDS_CHILD_ILLNESS_REPORTED'), total_iterations=1, ) schedule.default_language_code = 'hin' schedule.custom_metadata = {'icds_indicator': 'ls_4a'} schedule.save() rule = AutomaticUpdateRule.objects.create( domain=domain, name="LS #4a: Child Fever Reported in Exclusive Breastfeeding form", case_type='person', active=True, deleted=False, filter_on_server_modified=False, server_modified_boundary=None, migrated=True, workflow=AutomaticUpdateRule.WORKFLOW_SCHEDULING, ) rule.add_criteria( MatchPropertyDefinition, property_name='last_reported_fever_date', match_type=MatchPropertyDefinition.MATCH_HAS_VALUE, ) rule.add_action( CreateScheduleInstanceActionDefinition, timed_schedule_id=schedule.schedule_id, recipients=(('CustomRecipient', 'ICDS_SUPERVISOR_FROM_AWC_OWNER'),), reset_case_property_name='last_reported_fever_date', )
def test_cf_visits_complete(self): c = CustomContent(custom_content_id='ICDS_CF_VISITS_COMPLETE') schedule_instance = CaseTimedScheduleInstance( domain=self.domain, case_id=self.ccs_record_case.case_id, ) c.set_context(schedule_instance=schedule_instance) self.assertEqual( c.get_list_of_messages(self.user1), [ "Congratulations! You've done all the Complementary Feeding Visits for Sam" ], )
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, ) language_code_patch.return_value = ENGLISH self.assertEqual( c.get_list_of_messages(self.user3, schedule_instance), [ "AWC awc1 has reported illness for the child Joe. Please ensure that AWW follows up with mother " "immediately" ], )
def test_missed_pnc_visit_to_ls(self): 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) 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" ], )
def test_missed_cf_visit_to_ls(self): 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) self.assertEqual( c.get_list_of_messages(self.user3), [ "AWC awc1 has not reported a visit during complementary feeding initiation period for Sam" ], )
def test_custom_content(self): for cls in ( AlertScheduleInstance, TimedScheduleInstance, CaseAlertScheduleInstance, CaseTimedScheduleInstance, ): with patch('corehq.messaging.scheduling.models.content.send_sms_for_schedule_instance') as patched: schedule_instance = cls() CustomContent(custom_content_id='TEST').send(self.user, schedule_instance) patched.assert_has_calls([ call(schedule_instance, self.user, '9990000000000', 'Message 1'), call(schedule_instance, self.user, '9990000000000', 'Message 2'), ])
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, ) c.set_context(schedule_instance=schedule_instance) # 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), [] ) # 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), ["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), ["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), ["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 create_ls_indicator_4b(domain): with transaction.atomic(): schedule = TimedSchedule.create_simple_daily_schedule( domain, time(9, 0), CustomContent(custom_content_id='ICDS_CHILD_ILLNESS_REPORTED'), total_iterations=1, start_offset=7, ) schedule.default_language_code = 'hin' schedule.custom_metadata = {'icds_indicator': 'ls_4b'} schedule.save() rule = AutomaticUpdateRule.objects.create( domain=domain, name="LS #4b: Child Illness Reported in Referral Form", case_type='person', active=True, deleted=False, filter_on_server_modified=False, server_modified_boundary=None, migrated=True, workflow=AutomaticUpdateRule.WORKFLOW_SCHEDULING, ) rule.add_criteria( MatchPropertyDefinition, property_name='last_referral_date', match_type=MatchPropertyDefinition.MATCH_HAS_VALUE, ) rule.add_criteria( MatchPropertyDefinition, property_name='referral_health_problem', match_type=MatchPropertyDefinition.MATCH_HAS_VALUE, ) rule.add_criteria( MatchPropertyDefinition, property_name='dob', match_type=MatchPropertyDefinition.MATCH_DAYS_BEFORE, property_value='-2192', ) rule.add_action( CreateScheduleInstanceActionDefinition, timed_schedule_id=schedule.schedule_id, recipients=(('CustomRecipient', 'ICDS_SUPERVISOR_FROM_AWC_OWNER'), ), reset_case_property_name='last_referral_date', )
def create_ls_indicator_3(domain): with transaction.atomic(): schedule = TimedSchedule.create_simple_daily_schedule( domain, time(9, 0), CustomContent(custom_content_id='ICDS_MISSED_CF_VISIT_TO_LS'), total_iterations=1, start_offset=1, ) schedule.default_language_code = 'hin' schedule.custom_metadata = {'icds_indicator': 'ls_3'} schedule.save() rule = AutomaticUpdateRule.objects.create( domain=domain, name="LS #3: Missed CF #1", case_type='ccs_record', active=True, deleted=False, filter_on_server_modified=False, server_modified_boundary=None, migrated=True, workflow=AutomaticUpdateRule.WORKFLOW_SCHEDULING, ) rule.add_criteria( MatchPropertyDefinition, property_name='cf1_date', match_type=MatchPropertyDefinition.MATCH_HAS_NO_VALUE, ) rule.add_action( CreateScheduleInstanceActionDefinition, timed_schedule_id=schedule.schedule_id, recipients=(('CustomRecipient', 'ICDS_SUPERVISOR_FROM_AWC_OWNER'), ), scheduler_module_info=CreateScheduleInstanceActionDefinition. SchedulerModuleInfo( enabled=True, app_id='48cc1709b7f62ffea24cc6634a004745', form_unique_id='84ea09b6aa5aba125ec82bf2bb8dfa44cc5ea150', visit_number=0, window_position=VISIT_WINDOW_END, ), )
def _create_ls_indicator_5(domain, visit_num): with transaction.atomic(): schedule = TimedSchedule.create_simple_daily_schedule( domain, TimedEvent(time=time(9, 0)), CustomContent(custom_content_id='ICDS_MISSED_PNC_VISIT_TO_LS'), total_iterations=1, start_offset=1, ) schedule.default_language_code = 'hin' schedule.custom_metadata = {'icds_indicator': 'ls_5'} schedule.save() rule = AutomaticUpdateRule.objects.create( domain=domain, name="LS #5: Missed PNC #%s" % visit_num, case_type='ccs_record', active=True, deleted=False, filter_on_server_modified=False, server_modified_boundary=None, migrated=True, workflow=AutomaticUpdateRule.WORKFLOW_SCHEDULING, ) rule.add_criteria( MatchPropertyDefinition, property_name='pnc%s_date' % visit_num, match_type=MatchPropertyDefinition.MATCH_HAS_NO_VALUE, ) rule.add_action( CreateScheduleInstanceActionDefinition, timed_schedule_id=schedule.schedule_id, recipients=(('CustomRecipient', 'ICDS_SUPERVISOR_FROM_AWC_OWNER'), ), scheduler_module_info=CreateScheduleInstanceActionDefinition. SchedulerModuleInfo( enabled=True, app_id='48cc1709b7f62ffea24cc6634a004745', form_unique_id='f55da33c32fb41489d5082b7b3acfe43c739e988', visit_number=visit_num - 1, window_position=VISIT_WINDOW_END, ), )
def create_aww_indicator_5(domain): with transaction.atomic(): schedule = TimedSchedule.create_simple_daily_schedule( domain, TimedEvent(time=time(9, 0)), CustomContent( custom_content_id='ICDS_CHILD_VACCINATIONS_COMPLETE'), total_iterations=1, ) schedule.default_language_code = 'hin' schedule.custom_metadata = {'icds_indicator': 'aww_5'} schedule.save() rule = AutomaticUpdateRule.objects.create( domain=domain, name="AWW #5: Child Vaccinations Complete", case_type='tasks', active=True, deleted=False, filter_on_server_modified=False, server_modified_boundary=None, migrated=True, workflow=AutomaticUpdateRule.WORKFLOW_SCHEDULING, ) rule.add_criteria( MatchPropertyDefinition, property_name='tasks_type', property_value='child', match_type=MatchPropertyDefinition.MATCH_EQUAL, ) rule.add_criteria( MatchPropertyDefinition, property_name='immun_one_year_complete', property_value='yes', match_type=MatchPropertyDefinition.MATCH_EQUAL, ) rule.add_action( CreateScheduleInstanceActionDefinition, timed_schedule_id=schedule.schedule_id, recipients=(('Owner', None), ), )
def get_content(handler, event, translated=True): if handler.method == METHOD_SMS: if handler.custom_content_handler: return CustomContent(custom_content_id=handler.custom_content_handler) check_days_until(event.message) if translated: return SMSContent(message=event.message) else: return SMSContent(message={'*': get_single_dict_value(event.message)}) elif handler.method == METHOD_EMAIL: check_days_until(event.subject) check_days_until(event.message) if translated: return EmailContent(subject=event.subject, message=event.message) else: return EmailContent( subject={'*': get_single_dict_value(event.subject)}, message={'*': get_single_dict_value(event.message)}, ) elif handler.method == METHOD_SMS_SURVEY: if event.callback_timeout_intervals: if handler.submit_partial_forms: expire_after = sum(event.callback_timeout_intervals) reminder_intervals = event.callback_timeout_intervals[:-1] else: expire_after = SQLXFormsSession.MAX_SESSION_LENGTH reminder_intervals = event.callback_timeout_intervals submit_partially_completed_forms = handler.submit_partial_forms include_case_updates_in_partial_submissions = handler.include_case_side_effects else: expire_after = SQLXFormsSession.MAX_SESSION_LENGTH reminder_intervals = [] submit_partially_completed_forms = False include_case_updates_in_partial_submissions = False return SMSSurveyContent( form_unique_id=event.form_unique_id, expire_after=expire_after, reminder_intervals=reminder_intervals, submit_partially_completed_forms=submit_partially_completed_forms, include_case_updates_in_partial_submissions=include_case_updates_in_partial_submissions, ) elif handler.method == METHOD_IVR_SURVEY: return IVRSurveyContent( form_unique_id=event.form_unique_id, reminder_intervals=event.callback_timeout_intervals, submit_partially_completed_forms=handler.submit_partial_forms, include_case_updates_in_partial_submissions=handler.include_case_side_effects, max_question_attempts=handler.max_question_retries, ) elif handler.method == METHOD_SMS_CALLBACK: if translated: message = event.message else: message = {'*': get_single_dict_value(event.message)} return SMSCallbackContent( message=message, reminder_intervals=event.callback_timeout_intervals, ) else: raise ValueError("Unexpected method '%s'" % handler.method)