Exemplo n.º 1
0
def fire_ivr_survey_event(reminder, handler, recipients, verified_numbers):
    if handler.recipient == RECIPIENT_CASE:
        # If there are no recipients, just move to the next reminder event
        if len(recipients) == 0:
            return True
        
        # If last_fired is None, it means that the reminder fired for the first time on a timeout interval. So we can
        # skip the lookup for the answered call since no call went out yet.
        if reminder.last_fired is not None and reminder.callback_try_count > 0 and CallLog.answered_call_exists(recipients[0].doc_type, recipients[0].get_id, reminder.last_fired):
            reminder.skip_remaining_timeouts = True
            return True
        verified_number = verified_numbers[recipients[0].get_id]
        if verified_number is not None:
            if initiate_outbound_call(verified_number, reminder.current_event.form_unique_id, handler.submit_partial_forms, handler.include_case_side_effects, handler.max_question_retries):
                return True
            else:
                reminder = CaseReminder.get(reminder._id)
                reminder.error_retry_count += 1
                if reminder.error_retry_count > getattr(settings, "IVR_OUTBOUND_RETRIES", DEFAULT_OUTBOUND_RETRIES):
                    return True
                else:
                    reminder.next_fire += timedelta(minutes=getattr(settings, "IVR_OUTBOUND_RETRY_INTERVAL", DEFAULT_OUTBOUND_RETRY_INTERVAL))
                    reminder.save()
                    return False
        else:
            raise_error(reminder, ERROR_NO_VERIFIED_NUMBER)
            return False
    else:
        # TODO: Implement ivr survey for RECIPIENT_USER, RECIPIENT_OWNER, and RECIPIENT_SURVEY_SAMPLE
        return False
Exemplo n.º 2
0
def fire_ivr_survey_event(reminder, handler, recipients, verified_numbers,
                          logged_event):
    domain_obj = Domain.get_by_name(reminder.domain, strict=True)
    for recipient in recipients:
        initiate_call = True
        if reminder.callback_try_count > 0 and reminder.event_initiation_timestamp:
            initiate_call = not CallLog.answered_call_exists(
                recipient.doc_type, recipient.get_id,
                reminder.event_initiation_timestamp,
                CaseReminderHandler.get_now())

        if initiate_call:
            if (isinstance(recipient, CommCareCase)
                    and not handler.force_surveys_to_use_triggered_case):
                case_id = recipient.get_id
            else:
                case_id = reminder.case_id
            verified_number, unverified_number = get_recipient_phone_number(
                reminder, recipient, verified_numbers)
            if verified_number:
                initiate_outbound_call.delay(
                    recipient,
                    reminder.current_event.form_unique_id,
                    handler.submit_partial_forms,
                    handler.include_case_side_effects,
                    handler.max_question_retries,
                    logged_event.pk,
                    verified_number=verified_number,
                    case_id=case_id,
                    case_for_case_submission=handler.
                    force_surveys_to_use_triggered_case,
                    timestamp=CaseReminderHandler.get_now(),
                )
            elif domain_obj.send_to_duplicated_case_numbers and unverified_number:
                initiate_outbound_call.delay(
                    recipient,
                    reminder.current_event.form_unique_id,
                    handler.submit_partial_forms,
                    handler.include_case_side_effects,
                    handler.max_question_retries,
                    logged_event.pk,
                    unverified_number=unverified_number,
                    case_id=case_id,
                    case_for_case_submission=handler.
                    force_surveys_to_use_triggered_case,
                    timestamp=CaseReminderHandler.get_now(),
                )
            else:
                # initiate_outbound_call will create the subevent automatically,
                # so since we're not initiating the call here, we have to create
                # the subevent explicitly in order to log the error.
                logged_subevent = logged_event.create_subevent(
                    handler, reminder, recipient)
                logged_subevent.error(MessagingEvent.ERROR_NO_PHONE_NUMBER)
Exemplo n.º 3
0
def fire_ivr_survey_event(reminder, handler, recipients, verified_numbers, logged_event):
    domain_obj = Domain.get_by_name(reminder.domain, strict=True)
    for recipient in recipients:
        initiate_call = True
        if reminder.callback_try_count > 0 and reminder.event_initiation_timestamp:
            initiate_call = not CallLog.answered_call_exists(
                recipient.doc_type, recipient.get_id,
                reminder.event_initiation_timestamp,
                CaseReminderHandler.get_now())

        if initiate_call:
            if (isinstance(recipient, CommCareCase) and
                not handler.force_surveys_to_use_triggered_case):
                case_id = recipient.get_id
            else:
                case_id = reminder.case_id
            verified_number, unverified_number = get_recipient_phone_number(
                reminder, recipient, verified_numbers)
            if verified_number:
                initiate_outbound_call.delay(
                    recipient,
                    reminder.current_event.form_unique_id,
                    handler.submit_partial_forms,
                    handler.include_case_side_effects,
                    handler.max_question_retries,
                    logged_event.pk,
                    verified_number=verified_number,
                    case_id=case_id,
                    case_for_case_submission=handler.force_surveys_to_use_triggered_case,
                    timestamp=CaseReminderHandler.get_now(),
                )
            elif domain_obj.send_to_duplicated_case_numbers and unverified_number:
                initiate_outbound_call.delay(
                    recipient,
                    reminder.current_event.form_unique_id,
                    handler.submit_partial_forms,
                    handler.include_case_side_effects,
                    handler.max_question_retries,
                    logged_event.pk,
                    unverified_number=unverified_number,
                    case_id=case_id,
                    case_for_case_submission=handler.force_surveys_to_use_triggered_case,
                    timestamp=CaseReminderHandler.get_now(),
                )
            else:
                # initiate_outbound_call will create the subevent automatically,
                # so since we're not initiating the call here, we have to create
                # the subevent explicitly in order to log the error.
                logged_subevent = logged_event.create_subevent(handler, reminder, recipient)
                logged_subevent.error(MessagingEvent.ERROR_NO_PHONE_NUMBER)
Exemplo n.º 4
0
def fire_ivr_survey_event(reminder, handler, recipients, verified_numbers):
    domain_obj = Domain.get_by_name(reminder.domain, strict=True)
    for recipient in recipients:
        initiate_call = True
        if reminder.callback_try_count > 0 and reminder.event_initiation_timestamp:
            initiate_call = not CallLog.answered_call_exists(
                recipient.doc_type, recipient.get_id,
                reminder.event_initiation_timestamp,
                CaseReminderHandler.get_now())

        if initiate_call:
            if (isinstance(recipient, CommCareCase)
                    and not handler.force_surveys_to_use_triggered_case):
                case_id = recipient.get_id
            else:
                case_id = reminder.case_id
            verified_number, unverified_number = get_recipient_phone_number(
                reminder, recipient, verified_numbers)
            if verified_number:
                initiate_outbound_call.delay(
                    recipient,
                    reminder.current_event.form_unique_id,
                    handler.submit_partial_forms,
                    handler.include_case_side_effects,
                    handler.max_question_retries,
                    verified_number=verified_number,
                    case_id=case_id,
                    case_for_case_submission=handler.
                    force_surveys_to_use_triggered_case,
                    timestamp=CaseReminderHandler.get_now(),
                )
            elif domain_obj.send_to_duplicated_case_numbers and unverified_number:
                initiate_outbound_call.delay(
                    recipient,
                    reminder.current_event.form_unique_id,
                    handler.submit_partial_forms,
                    handler.include_case_side_effects,
                    handler.max_question_retries,
                    unverified_number=unverified_number,
                    case_id=case_id,
                    case_for_case_submission=handler.
                    force_surveys_to_use_triggered_case,
                    timestamp=CaseReminderHandler.get_now(),
                )
            else:
                #No phone number to send to
                pass

    return True
Exemplo n.º 5
0
def fire_ivr_survey_event(reminder, handler, recipients, verified_numbers):
    domain_obj = Domain.get_by_name(reminder.domain, strict=True)
    for recipient in recipients:
        initiate_call = True
        if reminder.callback_try_count > 0 and reminder.event_initiation_timestamp:
            initiate_call = not CallLog.answered_call_exists(
                recipient.doc_type, recipient.get_id,
                reminder.event_initiation_timestamp,
                CaseReminderHandler.get_now())

        if initiate_call:
            if (isinstance(recipient, CommCareCase) and
                not handler.force_surveys_to_use_triggered_case):
                case_id = recipient.get_id
            else:
                case_id = reminder.case_id
            verified_number, unverified_number = get_recipient_phone_number(
                reminder, recipient, verified_numbers)
            if verified_number:
                initiate_outbound_call.delay(
                    recipient,
                    reminder.current_event.form_unique_id,
                    handler.submit_partial_forms,
                    handler.include_case_side_effects,
                    handler.max_question_retries,
                    verified_number=verified_number,
                    case_id=case_id,
                    case_for_case_submission=handler.force_surveys_to_use_triggered_case,
                    timestamp=CaseReminderHandler.get_now(),
                )
            elif domain_obj.send_to_duplicated_case_numbers and unverified_number:
                initiate_outbound_call.delay(
                    recipient,
                    reminder.current_event.form_unique_id,
                    handler.submit_partial_forms,
                    handler.include_case_side_effects,
                    handler.max_question_retries,
                    unverified_number=unverified_number,
                    case_id=case_id,
                    case_for_case_submission=handler.force_surveys_to_use_triggered_case,
                    timestamp=CaseReminderHandler.get_now(),
                )
            else:
                #No phone number to send to
                pass

    return True
Exemplo n.º 6
0
def fire_ivr_survey_event(reminder, handler, recipients, verified_numbers):
    if handler.recipient == RECIPIENT_CASE:
        # If there are no recipients, just move to the next reminder event
        if len(recipients) == 0:
            return True

        # If last_fired is None, it means that the reminder fired for the first time on a timeout interval. So we can
        # skip the lookup for the answered call since no call went out yet.
        if reminder.last_fired is not None and reminder.callback_try_count > 0 and CallLog.answered_call_exists(
                recipients[0].doc_type, recipients[0].get_id,
                reminder.last_fired):
            reminder.skip_remaining_timeouts = True
            return True
        verified_number = verified_numbers[recipients[0].get_id]
        if verified_number is not None:
            if initiate_outbound_call(verified_number,
                                      reminder.current_event.form_unique_id,
                                      handler.submit_partial_forms,
                                      handler.include_case_side_effects,
                                      handler.max_question_retries):
                return True
            else:
                reminder = CaseReminder.get(reminder._id)
                reminder.error_retry_count += 1
                if reminder.error_retry_count > getattr(
                        settings, "IVR_OUTBOUND_RETRIES",
                        DEFAULT_OUTBOUND_RETRIES):
                    return True
                else:
                    reminder.next_fire += timedelta(minutes=getattr(
                        settings, "IVR_OUTBOUND_RETRY_INTERVAL",
                        DEFAULT_OUTBOUND_RETRY_INTERVAL))
                    reminder.save()
                    return False
        else:
            raise_error(reminder, ERROR_NO_VERIFIED_NUMBER)
            return False
    else:
        # TODO: Implement ivr survey for RECIPIENT_USER, RECIPIENT_OWNER, and RECIPIENT_SURVEY_SAMPLE
        return False