def send_weekly_usage_reminder(self):
     users = User.objects.filter(Q(role__icontains=USER_TYPE_CHEW) | Q(role__icontains=USER_TYPE_MIDWIFE)) \
         .exclude(Q(username__icontains='vht') | Q(username__icontains='mid'))
     phone_numbers = ["+256" + user.phone[1:] for user in users]
     message_body = 'Please remember to use the GetIn app to map girls, ' \
                    'follow up on appointments and call the girls. GETIN TEAM '
     send_sms_message(message_body, phone_numbers,
                      APP_USAGE_REMINDER_MESSAGES, 300)
 def send_health_messages(self):
     """
     Sends health messages to pregnant girls every Wednesday at 12pm
     """
     pregnant_girls = Girl.objects.filter(
         last_menstruation_date__gte=self.current_date -
         self.nine_months_date)
     phone_numbers = [
         "+256" + girl.phone_number[1:] for girl in pregnant_girls
     ]
     send_sms_message(self.get_random_health_messages(), phone_numbers)
Exemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     try:
         receiver_ids = request.data.get('receiver_ids')
         phone_numbers = [
             "+256" + User.objects.get(id=receiver_id).phone[1:]
             for receiver_id in receiver_ids
         ]
         send_sms_message(request.data.get('message'), phone_numbers,
                          GENERAL_MESSAGE)
         return Response({'result': 'success'})
     except Exception as e:
         return Response({'result': 'failure'})
    def send_missed_appointment_reminder_one_day_after(self):
        appointments = Appointment.objects.filter(
            Q(date__lt=self.current_date)
            & Q(date__gte=self.current_date - timezone.timedelta(days=1))
            & Q(status__in=[EXPECTED, MISSED])
            & Q(girl__last_menstruation_date__gte=self.current_date -
                self.nine_months_date))

        for appointment in appointments:
            yesterday = self.current_date - timezone.timedelta(days=1)
            # skip days that are not yesterday
            if appointment.date.day != yesterday.day:
                continue

            firebase_device_ids = list({
                appointment.user.firebase_device_id,
                appointment.girl.user.firebase_device_id
            })
            health_workers_ids = list(
                {appointment.user.id, appointment.girl.user.id})

            message_title = "GetIn ANC reminder"
            message_body = de_emojify(
                appointment.girl.first_name
            ) + " " + de_emojify(
                appointment.girl.last_name
            ) + " has missed ANC visit yesterday. Please call or visit her to find out the reason why she missed. From GETIN TEAM"

            # only send notification and sms if the user has never received. this prevents spamming
            if not NotificationLog.objects.filter(
                    Q(appointment=appointment) & Q(stage=AFTER)):
                send_firebase_notification(firebase_device_ids, message_title,
                                           message_body)
                phone_numbers = [
                    "+256" + User.objects.get(id=receiver_id).phone[1:]
                    for receiver_id in health_workers_ids
                ]
                send_sms_message(message_body, phone_numbers)
                NotificationLog(appointment=appointment, stage=AFTER).save()
    def send_appointment_sms_to_eligible_girls(self):
        girl_today_phone_numbers = []
        girl_tomorrow_phone_numbers = []
        girl_three_days_phone_numbers = []
        sms_logger("#started# ",
                   " today, tomorrow, three days before date notifier")
        appointments = Appointment.objects.filter(
            Q(date__lte=self.current_date + timezone.timedelta(days=4))
            & Q(date__gte=self.current_date - timezone.timedelta(days=1))
            & Q(status=EXPECTED)
            & Q(girl__last_menstruation_date__gte=self.current_date -
                self.nine_months_date))

        for appointment in appointments:
            if appointment.date.day == self.current_date.day:
                girl_today_phone_numbers.append(
                    "+256" + appointment.girl.phone_number[1:])
            elif appointment.date.day == (timezone.now() +
                                          timezone.timedelta(days=1)).day:
                girl_tomorrow_phone_numbers.append(
                    "+256" + appointment.girl.phone_number[1:])
            elif appointment.date.day == (timezone.now() +
                                          timezone.timedelta(days=3)).day:
                girl_three_days_phone_numbers.append(
                    "+256" + appointment.girl.phone_number[1:])

        girl_today_message = "Today is the due day for your ANC visit, your midwife is waiting to receive you at the health facility. From GETIN TEAM"
        girl_tomorrow_message = "Your next ANC visit is due tomorrow, please don't forget to attend your appointment for the safety of your unborn baby. From GETIN TEAM"
        girl_three_days_message = "Your next ANC visit is due in 3 days, please don't forget to attend your appointment for the safety of your unborn baby. From GETIN TEAM"
        send_sms_message(girl_today_message,
                         list(filter(None, set(girl_today_phone_numbers))))
        send_sms_message(girl_tomorrow_message,
                         list(filter(None, set(girl_tomorrow_phone_numbers))))
        send_sms_message(
            girl_three_days_message,
            list(filter(None, set(girl_three_days_phone_numbers))))