def diagnose_cb(): user_session = get_session(redis,request.values.get('CallSid')) symptom = urllib.unquote(request.args.get('symptom')) print symptom resp = twilio.twiml.Response() digit_pressed = request.values.get('Digits', None) if digit_pressed == "1": user_session['symptom_whitelist'].append(symptom) set_session(redis,request.values.get('CallSid'), user_session) else: user_session['symptom_blacklist'].append(symptom) set_session(redis,request.values.get('CallSid'), user_session) diseases = symptomelimination.calculate_probability_for_disease(user_session['location'], user_session['symptom_whitelist']) # its for the case that no user input is made (so people will not have a disease without symptom) if len(user_session['symptom_whitelist']) == 0: for disease in diseases: disease['probability'] = 0 diseases = sorted(diseases, cmp=lambda x, y: cmp(y['probability'],x['probability'])) for disease in diseases: print helpers.get_name_for_disease(disease['disease']), disease['probability'] if user_session['question_count'] >= 3 and diseases[0]['probability'] > 0.8: resp.say("We have determined there is a high probability you have {0}".format(helpers.get_name_for_disease(diseases[0]['disease'])),**default_ops) resp.say("We suggest you seek medical attention as soon as possible",**default_ops) resp.hangup() redis.delete(request.values.get('CallSid')) elif user_session['question_count'] >= 7: resp.say("Sorry, we are unable to determine what you are sick with.",**default_ops) resp.redirect('/ems') else: resp.redirect('/diagnose') return str(resp)
def hello_monkey(): body = request.values.get('Body', None) result = body.replace(' ',',').split(',') if( len(result) > 1 ): location = helpers.get_code_for_country(result[0]) symptoms = [] for i in range(1, len(result)): symptoms.append(helpers.get_highst_score_symptom(result[i])) symptoms = list(set(symptoms)) diseases = symptomelimination.calculate_probability_for_disease(location,symptoms) for disease in diseases: print helpers.get_name_for_disease(disease['disease']), disease['probability'] diseases = sorted(diseases, cmp=lambda x, y: cmp(y['probability'],x['probability'])) message = "We have determined there is a high probability you have {0}".format(helpers.get_name_for_disease(diseases[0]['disease'])) else: number = helpers.get_phone_for_country(helpers.get_code_for_country(body)) message = "Your emergency number is: " + number resp = twilio.twiml.Response() resp.sms(message) return str(resp)