Example #1
0
 def create_new_instance_for_recipient(self, recipient_type, recipient_id):
     if self.model_instance:
         instance = CaseAlertScheduleInstance.copy_for_recipient(
             self.model_instance, recipient_type, recipient_id)
         self.handle_existing_instance(instance)
         return instance
     else:
         return CaseAlertScheduleInstance.create_for_recipient(
             self.schedule,
             recipient_type,
             recipient_id,
             move_to_next_event_not_in_the_past=False,
             case_id=self.case.case_id,
             rule_id=self.rule.pk,
             last_reset_case_property_value=self.reset_case_property_value,
         )
Example #2
0
    def create_new_instance_for_recipient(self, recipient_type, recipient_id):
        if self.model_instance:
            instance = CaseAlertScheduleInstance.copy_for_recipient(
                self.model_instance, recipient_type, recipient_id)

            if self.action_definition.reset_case_property_name:
                handle_case_alert_schedule_instance_reset(
                    instance, self.schedule, self.reset_case_property_value)

            return instance
        else:
            return CaseAlertScheduleInstance.create_for_recipient(
                self.schedule,
                recipient_type,
                recipient_id,
                move_to_next_event_not_in_the_past=False,
                case_id=self.case.case_id,
                rule_id=self.rule.pk,
                last_reset_case_property_value=self.reset_case_property_value,
            )
Example #3
0
    def create_new_instance_for_recipient(self, recipient_type, recipient_id):
        if self.model_instance:
            instance = CaseAlertScheduleInstance.copy_for_recipient(
                self.model_instance,
                recipient_type,
                recipient_id
            )

            if self.action_definition.reset_case_property_name:
                handle_case_alert_schedule_instance_reset(instance, self.schedule, self.reset_case_property_value)

            return instance
        else:
            return CaseAlertScheduleInstance.create_for_recipient(
                self.schedule,
                recipient_type,
                recipient_id,
                move_to_next_event_not_in_the_past=False,
                case_id=self.case.case_id,
                rule_id=self.rule.pk,
                last_reset_case_property_value=self.reset_case_property_value,
            )
Example #4
0
    existing_instances = {
        (instance.recipient_type, instance.recipient_id): instance
        for instance in get_case_alert_schedule_instances_for_schedule(case.case_id, schedule)
    }

    if existing_instances:
        # Don't refresh AlertSchedules that have already been sent
        # to avoid sending old alerts to new recipients
        return

    recipients = set(convert_to_tuple_of_tuples(action_definition.recipients))
    for recipient_type, recipient_id in recipients:
        instance = CaseAlertScheduleInstance.create_for_recipient(
            schedule,
            recipient_type,
            recipient_id,
            move_to_next_event_not_in_the_past=False,
            case_id=case.case_id,
            rule_id=rule.pk
        )
        save_case_schedule_instance(instance)


def refresh_case_timed_schedule_instances(case, schedule, action_definition, rule, start_date=None):
    """
    :param case: the CommCareCase/SQL
    :param schedule: the TimedSchedule
    :param action_definition: the CreateScheduleInstanceActionDefinition that is
    causing the schedule instances to be refreshed
    :param rule: the AutomaticUpdateRule that is causing the schedule instances
    to be refreshed