示例#1
0
def holler_back(request):    
    
    t = tomorrow()
    # Get these credentials from http://twilio.com/user/account
    reminders_to_send = ArchimedesRiskAssessment.objects.filter(followup_date = t,
                                                                follow_up_complete=False)
    for i in reminders_to_send:
        print i.patient_id
        try:
            up = UserProfile.objects.get(patient_id=i.patient_id)
            
            #send a text message
            if up.preferred_contact_method == "sms" and \
               up.mobile_phone_number:
                send_sms_twilio(settings.SMS_REMINDER_MESSAGE,
                                up.mobile_phone_number)
                i.follow_up_complete = True
                i.save()
            
            #send an email if they prefer
            if up.preferred_contact_method == "email" and \
               up.user.email:
                msg = """
                %s
                
                %s/pharmacy/coupon/%s/%s/%s
                """ % (settings.EMAIL_REMINDER_BODY, settings.HOSTNAME_URL,
                       i.origin,  i.destination, i.patient_id)
                
                send_mail(settings.EMAIL_REMINDER_SUBJECT , msg,
                          settings.DEFAULT_FROM_EMAIL,
                          [up.user.email,], fail_silently=False)
                
                
                send_sms_twilio(settings.SMS_REMINDER_MESSAGE,
                                up.mobile_phone_number)
                i.follow_up_complete = True
                i.save()
                
            
            
        except(UserProfile.DoesNotExist):
            pass
            
    
        #send_sms_twilio("hello", "+13046853137")
    
    
    #client = TwilioRestClient(settings.TWILIO_SID, settings.TWILIO_AUTH_TOKEN)
    # Make the call
    #call = client.calls.create(to="+13046853137", # Any phone number
    #from_=settings.TWILIO_DEFAULT_FROM , # Must be a valid Twilio number
    #url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
    #print call.sid
    return HttpResponse("OK")
示例#2
0
def holler_back(request):

    t = tomorrow()
    # Get these credentials from http://twilio.com/user/account
    reminders_to_send = ArchimedesRiskAssessment.objects.filter(
        followup_date=t, follow_up_complete=False)
    for i in reminders_to_send:
        print i.patient_id
        try:
            up = UserProfile.objects.get(patient_id=i.patient_id)

            #send a text message
            if up.preferred_contact_method == "sms" and \
               up.mobile_phone_number:
                send_sms_twilio(settings.SMS_REMINDER_MESSAGE,
                                up.mobile_phone_number)
                i.follow_up_complete = True
                i.save()

            #send an email if they prefer
            if up.preferred_contact_method == "email" and \
               up.user.email:
                msg = """
                %s
                
                %s/pharmacy/coupon/%s/%s/%s
                """ % (settings.EMAIL_REMINDER_BODY, settings.HOSTNAME_URL,
                       i.origin, i.destination, i.patient_id)

                send_mail(settings.EMAIL_REMINDER_SUBJECT,
                          msg,
                          settings.DEFAULT_FROM_EMAIL, [
                              up.user.email,
                          ],
                          fail_silently=False)

                send_sms_twilio(settings.SMS_REMINDER_MESSAGE,
                                up.mobile_phone_number)
                i.follow_up_complete = True
                i.save()

        except (UserProfile.DoesNotExist):
            pass

        #send_sms_twilio("hello", "+13046853137")

    #client = TwilioRestClient(settings.TWILIO_SID, settings.TWILIO_AUTH_TOKEN)
    # Make the call
    #call = client.calls.create(to="+13046853137", # Any phone number
    #from_=settings.TWILIO_DEFAULT_FROM , # Must be a valid Twilio number
    #url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
    #print call.sid
    return HttpResponse("OK")
示例#3
0
def cron_adherence_send(request,cron_key):       
    if cron_key != settings.CRON_KEY:
        return HttpResponse("Forbidden", status=401)
    
    a = SMSAdherenceTransaction.objects.filter(sent=False,
                                          reminder_time__lte=datetime.now())
    twilio_tx_list=[]
    if a:
        for i in a:
            d=send_sms_twilio(i.schedule.message,
                                   i.schedule.patient.mobile_phone_number)
            i.twilio_id=d['twilio_id']
            twilio_tx_list.append(d)
            i.sent=True
            i.save()
            
    jsonstr={"code": "200",
            "message": "Adherence transactions sent. Here is the list",
            "transaction_datetime" : strftime("%Y-%m-%d %H:%M:%S", gmtime()),
            "results": twilio_tx_list}
                
    jsonstr=json.dumps(jsonstr, indent = 4,)
    return HttpResponse(jsonstr, mimetype="text/plain")
    
    #Otherwise there was nothing to process.
    jsonstr={"code": "200",
             "message": "No adherence transactions were required to be sent at this time",
             "transaction_datetime" : strftime("%Y-%m-%d %H:%M:%S", gmtime()), 
             "results": ()}
                
    jsonstr=json.dumps(jsonstr, indent = 4,)
    return HttpResponse(jsonstr, mimetype="text/plain")
示例#4
0
def cron_adherence_send(request, cron_key):
    if cron_key != settings.CRON_KEY:
        return HttpResponse("Forbidden", status=401)

    a = SMSAdherenceTransaction.objects.filter(
        sent=False, reminder_time__lte=datetime.now())
    twilio_tx_list = []
    if a:
        for i in a:
            d = send_sms_twilio(i.schedule.message,
                                i.schedule.patient.mobile_phone_number)
            i.twilio_id = d['twilio_id']
            twilio_tx_list.append(d)
            i.sent = True
            i.save()

    jsonstr = {
        "code": "200",
        "message": "Adherence transactions sent. Here is the list",
        "transaction_datetime": strftime("%Y-%m-%d %H:%M:%S", gmtime()),
        "results": twilio_tx_list
    }

    jsonstr = json.dumps(
        jsonstr,
        indent=4,
    )
    return HttpResponse(jsonstr, mimetype="text/plain")

    #Otherwise there was nothing to process.
    jsonstr = {
        "code": "200",
        "message":
        "No adherence transactions were required to be sent at this time",
        "transaction_datetime": strftime("%Y-%m-%d %H:%M:%S", gmtime()),
        "results": ()
    }

    jsonstr = json.dumps(
        jsonstr,
        indent=4,
    )
    return HttpResponse(jsonstr, mimetype="text/plain")
示例#5
0
 def save(self):
     send_sms_twilio(self.cleaned_data['message'],
                     self.cleaned_data['to'])
示例#6
0
 def save(self):
     send_sms_twilio(self.cleaned_data['message'], self.cleaned_data['to'])