Example #1
0
def ANMIvrForOverdueServices_Exotel(mode=1, target=1):
    #mode = 1 Due
    #mode = 2 OverDue
    #mode = 3 Both
    if target == 1:
        benef_type = ANCBenef
    elif target == 2:
        benef_type = IMMBenef

    timezone = 'Asia/Kolkata'
    tz = pytz.timezone(timezone)
    today = utcnow_aware().replace(tzinfo=tz)
    date_then = today.replace(hour=12, minute=0, day=1, second=0).date()
    from sms.sender import SendVoiceCall

    #Voice call for ANC
    if mode == 1:
        benefs = benef_type.objects.filter(due_events__date=date_then).distinct()
    elif mode ==2:
        benefs = benef_type.objects.filter(odue_events__date=date_then).distinct()
    else:
        abenefs = benef_type.objects.filter(odue_events__date=date_then).distinct() & ANCBenef.objects.filter(due_events__date=date_then).distinct()
    anms = CareProvider.objects.filter(beneficiaries__in=benefs).distinct()
    
    callerid = ""
    app_url = settings.EXOTEL_APP_URL
    for anm in amns:
        try:
            connect_customer_to_app(customer_no=due_anms.notify_number, callerid=callerid, app_url=app_url)
        except:
            sys.exec_info()[0]
Example #2
0
def CallWrapper_Exotel(id, role, type, demo_phone=None):
    timezone = 'Asia/Kolkata'
    tz = pytz.timezone(timezone)
    today = utcnow_aware().replace(tzinfo=tz)

    try:
        if role == 'ANM':
            anm = CareProvider.objects.get(id=int(id))
            phone = anm.phone
            benefs = Beneficiary.objects.filter(careprovider=anm)
            count, string = services_processor(benefs=benefs, type=type, mode=1)
        else:
            asha = CareGiver.objects.get(id=int(id))
            phone = asha.phone
            benefs = Beneficiary.objects.filter(caregiver=asha)
            count, string = services_processor(benefs=benefs, type=type, mode=1)
    except:
        print 'd'
        return 'ANM/ASHA does not exist'
    subcenter = benefs[0].subcenter if benefs else None

    string = unicode(string)
    if len(string) > 20:
        string = string[0:20] + u"आदि " 
    sms_text = u"आपके क्षेत्र में शेष सर्विसेज- \n"+string+u"प्रेषक,\n मुख्य चिकित्साधिकारी, झाँसी"
    if demo_phone:
        phone = demo_phone
    #Send SMS
    sms_text_hexlified = toHex(sms_text)
    #print sms_text_hexlified
    try:
        SendSMSUnicode(recNum=phone, msgtxt=sms_text_hexlified, senderId='CMOJHS')
    except:
        pass
    #Send Exotel Call here
    custom_field = str(id)+"_"+role+"_"+type
    callback_url = "http://niramayh.com/subcenter/exotel/update/"
    import time
    time.sleep(.33)
    response = connect_customer_to_app(customer_no=phone, callerid="01130017630", CustomField=custom_field, callback_url=callback_url)
    result = response.text
    j_result = json.loads(result)
    try:
        call = j_result.get('Call')
        sid = call.get('Sid') if call else None
        status = call.get('Status') if call else None
        if not sid:
            return None
    except:
        return None
    #update call status here
    try: 
        marker = ExotelCallStatus.objects.get(sid=sid)
    except ObjectDoesNotExist:
        marker = ExotelCallStatus.objects.create(sid=sid, status=status, uid = int(id),\
         role=role, mode=type, subcenter = subcenter, date_initiated = today.date(), dt_updated = utcnow_aware())
    return marker