Esempio n. 1
0
def disease_predict():
    selected_symptoms = []
    if (request.form['Symptom1'] != "") and (request.form['Symptom1']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom1'])
    if (request.form['Symptom2'] != "") and (request.form['Symptom2']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom2'])
    if (request.form['Symptom3'] != "") and (request.form['Symptom3']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom3'])
    if (request.form['Symptom4'] != "") and (request.form['Symptom4']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom4'])
    if (request.form['Symptom5'] != "") and (request.form['Symptom5']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom5'])

    # disease_list = []
    # for i in range(7):
    #     disease = diseaseprediction.dosomething(selected_symptoms)
    #     disease_list.append(disease)
    # return render_template('disease_predict.html',disease_list=disease_list)
    disease = diseaseprediction.dosomething(selected_symptoms)
    return render_template('disease_predict.html',
                           disease=disease,
                           symptoms=symptoms)
def disease_predict():
    docs = db.collection('profileInfo').get()
    for doc in docs:
        dt=doc.to_dict()
        selected_symptoms = dt['Symptoms']
        if selected_symptoms==[]:
            print("Hrishi")
            uid= dt['Uid']
            data = {'HealthStatus': str("Fit")}
            db.collection('profileInfo').document(uid).set(data, merge=True)
            continue
                
        uid= dt['Uid']
        disease = diseaseprediction.dosomething(selected_symptoms)
        data = {'HealthStatus': str(disease[0])}
        db.collection('profileInfo').document(uid).set(data, merge=True)
        
        if dt['Mailed']==0:
            email = dt['EmailId']
            subject = "Healthy Us - Your Health Status"
            msg = "Hey there, as per our disease prediction algorithm there are chances you might have "+disease[0]+". Please consult a doctor for further medical analysis."
            message = Message(subject,sender="*****@*****.**",recipients=[email])
            message.body = msg
            mail.send(message)
            mailed_value = {'Mailed': 1}
            db.collection('profileInfo').document(uid).set(mailed_value, merge=True)
   
    return render_template('disease_predict.html')
Esempio n. 3
0
def home(req):
    predict = 'false'
    if len(chatrec) == 0:
        ques1 = {
            'type': 'ques',
            'sym': 'false',
            'msg': 'Hey, I am your helper what is your name'
        }

        chatrec.append(ques1)

    if len(sym) == 5:
        name = chatrec[1]
        disease = diseaseprediction.dosomething(sym)
        ques2 = {
            'type': 'ques',
            'sym': 'false',
            'predict': 'true',
            'msg': name['msg'] + ' You may have ' + str(disease[0])
        }
        predict = 'true'
        chatrec.append(ques2)
    elif (len(chatrec) >= 2):

        ques2 = {
            'type': 'ques',
            'sym': 'true',
            'msg': 'Symptoms ' + str(len(sym) + 1)
        }
        chatrec.append(ques2)
    return render(req, 'index.html', {
        'chat': chatrec,
        'symptoms': symptoms,
        'predict': predict
    })
Esempio n. 4
0
def disease_predict():
    selected_symptoms = []
    if (request.form['Symptom1'] != "") and (request.form['Symptom1']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom1'])
    if (request.form['Symptom2'] != "") and (request.form['Symptom2']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom2'])
    if (request.form['Symptom3'] != "") and (request.form['Symptom3']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom3'])
    if (request.form['Symptom4'] != "") and (request.form['Symptom4']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom4'])
    if (request.form['Symptom5'] != "") and (request.form['Symptom5']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom5'])
    if (request.form['Symptom6'] != "") and (request.form['Symptom6']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom6'])
    if (request.form['Symptom7'] != "") and (request.form['Symptom7']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom7'])

    # disease_list = []
    # for i in range(7):
    #     disease = diseaseprediction.dosomething(selected_symptoms)
    #     disease_list.append(disease)
    # return render_template('disease_predict.html',disease_list=disease_list)
    disease = diseaseprediction.dosomething(selected_symptoms)
    if (request.method == 'POST'):
        gender = request.form.get('gender')
        age = request.form.get('age')
        symptom1 = request.form.get('Symptom1')
        symptom2 = request.form.get('Symptom2')
        symptom3 = request.form.get('Symptom3')
        symptom4 = request.form.get('Symptom4')
        symptom5 = request.form.get('Symptom5')
        symptom6 = request.form.get('Symptom6')
        symptom7 = request.form.get('Symptom7')
        '''
        sno,Gender,Age,Symptom1...7,Disease
        '''

        entry = patient(Gender=gender,
                        Age=age,
                        Symptom1=symptom1,
                        Symptom2=symptom2,
                        Symptom3=symptom3,
                        Symptom4=symptom4,
                        Symptom5=symptom5,
                        Symptom6=symptom6,
                        Symptom7=symptom7,
                        Disease=disease[0])
        db.session.add(entry)
        db.session.commit()

    return render_template('disease_predict.html',
                           disease=disease,
                           symptoms=symptoms)
Esempio n. 5
0
def fly():
    selected_symptoms = []
    selected_users = request.form.getlist("users")
    disease = diseaseprediction.dosomething(selected_users)
    radius = session.get('radius')
    #a=session.get('zip')
    g = geocoder.ip('me')
    a = g.latlng
    geolocator = Nominatim(user_agent="specify_your_app_name_here")
    location = geolocator.geocode(a)
    sql1 = text('select lat from User')
    result1 = db.engine.execute(sql1)
    lats = [row[0] for row in result1]
    sql2 = text('select lng from User')
    result2 = db.engine.execute(sql2)
    lngs = [ro[0] for ro in result2]
    merged_list = [(lats[i], lngs[i]) for i in range(0, len(lats))]
    li = []
    for j in merged_list:
        b = (distance.distance(a, j).km)
        li.append(b)
    res = dict(zip(lats, li))
    sorted_x = sorted(res.items(), key=lambda kv: kv[1])
    re = [lis[0] for lis in sorted_x]
    ra = [lis[1] for lis in sorted_x]
    t = tuple(re)
    v = tuple(ra)
    for su in range(len(re)):
        query1 = "UPDATE User SET dist = '{}' WHERE lat = {}".format(
            v[su] + 10, t[su])
        #query = "select * from User where lat IN {}".format(t)
        sql4 = text(query1)
        result = db.engine.execute(sql4)
    sql5 = "select * from User order by ratings desc, dist asc"
    result5 = db.engine.execute(sql5)

    #app.logger.debug('A value for debugging')
    #users = User.query.all().filter_by(result1)
    #for i in re:
    #  query="select * from User where lat={};".format(i)
    # sql3=text(query)
    #result=db.engine.execute(sql3)
    #return f'{result.lat}'
    #worms=[x for x in result]
    return render_template('home.html',
                           result5=result5,
                           sorted_x=sorted_x,
                           selected_users=selected_users,
                           disease=disease)
Esempio n. 6
0
def disease_predict():
    selected_symptoms = []
    if (request.form['Symptom1'] != "") and (request.form['Symptom1']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom1'])
    if (request.form['Symptom2'] != "") and (request.form['Symptom2']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom2'])
    if (request.form['Symptom3'] != "") and (request.form['Symptom3']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom3'])
    if (request.form['Symptom4'] != "") and (request.form['Symptom4']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom4'])
    if (request.form['Symptom5'] != "") and (request.form['Symptom5']
                                             not in selected_symptoms):
        selected_symptoms.append(request.form['Symptom5'])

    disease = diseaseprediction.dosomething(selected_symptoms)
    with open('Book1.csv', mode='r') as infile:
        reader = csv.reader(infile)
        with open('Book1_new.csv', mode='w') as outfile:
            writer = csv.writer(outfile)
            mydict = {rows[0]: rows[1] for rows in reader}
            med = mydict[disease[0]]

    with open('Book2.csv', mode='r') as infile1:
        reader = csv.reader(infile1)
        with open('Book2_new.csv', mode='w') as outfile1:
            writer = csv.writer(outfile1)
            mydict1 = {rows[0]: rows[1] for rows in reader}
            home = mydict1[disease[0]]
    cur = mysql.connection.cursor()
    cur.execute("SELECT * from details")
    data1 = cur.fetchall()

    return render_template('disease_predict.html',
                           disease=disease,
                           symptoms=symptoms,
                           med=med,
                           home=home,
                           data1=data1)
Esempio n. 7
0
def makeWebhookResult(req):
    if req.get("queryResult").get("action") == "symptom":
        result = req.get("queryResult")
        parameters = result.get("parameters")
        symptom = parameters.get("symptom")
        disease = diseaseprediction.dosomething(symptom)
        print(disease)
        #speech = "you may have " + disease + ". Please, consult your doctor."
        #print(speech)
        if not disease:
            speech = "For further details Please click on the below link"
            disease = symptom[0]
        else:
            speech = "you may have " + disease + ". Please, consult your doctor."

        return {
            "fulfillmentText":
            speech,
            "fulfillmentMessages": [{
                "platform": "ACTIONS_ON_GOOGLE",
                "simpleResponses": {
                    "simpleResponses": [{
                        "textToSpeech": speech
                    }]
                }
            }, {
                "platform": "ACTIONS_ON_GOOGLE",
                "linkOutSuggestion": {
                    "destinationName":
                    "Details of disease",
                    "uri":
                    "https://www.webmd.com/search/search_results/default.aspx?query="
                    + disease
                }
            }, {
                "platform": "ACTIONS_ON_GOOGLE",
                "suggestions": {
                    "suggestions": [{
                        "title": "Predict disease"
                    }, {
                        "title": "Details about disease"
                    }, {
                        "title": "Know nearby hospitals"
                    }, {
                        "title": "Thank you"
                    }]
                }
            }]
        }
    if req.get("queryResult").get(
            "action") == "Detailsaboutsymptoms.Detailsaboutsymptoms-custom":
        result = req.get("queryResult")
        parameters = result.get("parameters")
        symptom = parameters.get("disease")
        speech = "For further details Please click on the below link"
        disease = symptom
        return {
            "fulfillmentText":
            speech,
            "fulfillmentMessages": [{
                "platform": "ACTIONS_ON_GOOGLE",
                "simpleResponses": {
                    "simpleResponses": [{
                        "textToSpeech": speech
                    }]
                }
            }, {
                "platform": "ACTIONS_ON_GOOGLE",
                "linkOutSuggestion": {
                    "destinationName":
                    "Details of disease",
                    "uri":
                    "https://www.webmd.com/search/search_results/default.aspx?query="
                    + disease
                }
            }, {
                "platform": "ACTIONS_ON_GOOGLE",
                "suggestions": {
                    "suggestions": [{
                        "title": "Predict disease"
                    }, {
                        "title": "Details about disease"
                    }, {
                        "title": "Know nearby hospitals"
                    }, {
                        "title": "Thank you"
                    }]
                }
            }]
        }
    if req.get("queryResult").get("action") == "google":
        result = req.get("queryResult")
        parameters = result.get("parameters")
        location = parameters.get("geo-city")
        hospital_name = []
        hospital_address = []
        speech = ""
        geocoderApi = herepy.GeocoderApi(
            'NYzvNeZQL5quJfEWEUccVGR-nXIIVt3PeFj1X11dWkw')
        placesApi = herepy.PlacesApi(
            'NYzvNeZQL5quJfEWEUccVGR-nXIIVt3PeFj1X11dWkw')

        response = geocoderApi.free_form(location)
        dict = response.as_dict()
        print(dict)
        position = dict['items'][0]['position']
        latitude = position['lat']
        longitude = position['lng']

        response = placesApi.category_places_at(
            [latitude, longitude],
            [herepy.PlacesCategory.hospital_health_care_facility])
        dict = response.as_dict()

        for i in range(0, 10):
            #print(places_result["results"])
            hospitalname = dict["results"]["items"][i]["title"]
            hospital_name.append(hospitalname)

            hospitaladdress = dict["results"]["items"][i]["vicinity"]
            hospital_address.append(hospitaladdress)

        for i in range(0, len(hospital_name)):
            speech += "<br/><br/>Hospital name: " + hospital_name[
                i] + "<br/>Hospital Address: " + hospital_address[i]
        return {
            "fulfillmentText":
            speech,
            "fulfillmentMessages": [{
                "platform": "ACTIONS_ON_GOOGLE",
                "simpleResponses": {
                    "simpleResponses": [{
                        "textToSpeech": speech
                    }]
                }
            }, {
                "platform": "ACTIONS_ON_GOOGLE",
                "suggestions": {
                    "suggestions": [{
                        "title": "Predict disease"
                    }, {
                        "title": "Details about disease"
                    }, {
                        "title": "Know nearby hospitals"
                    }, {
                        "title": "Thank you"
                    }]
                }
            }]
        }
Esempio n. 8
0
def home(req):
    predict = 'false'
    global response
    if len(chatrec) == 0:
        ques1 = {
            'type': 'ques',
            'sym': 'false',
            'predict': 'false',
            'msg': 'Hey, I am your helper Doctor! Ans the following Questions'
        }

        chatrec.append(ques1)

    if len(response) == 13:
        name = chatrec[1]
        #print(response)
        disease = diseaseprediction.dosomething(response)
        res = ""
        if disease[0] == 0:
            res = " Absence of heart disease in the patient "
        else:
            res = " Presence of heart disease in the patient "

        ques14 = {
            'type': 'ques',
            'sym': 'false',
            'predict': 'true',
            'msg': res
        }
        predict = 'true'
        chatrec.append(ques14)
    elif (len(chatrec) == 1):

        ques1 = {
            'type': 'ques',
            'sym': 'true',
            'predict': 'false',
            'msg': 'Q' + str(len(sym) + 1) + '. What is your Age:  '
        }
        chatrec.append(ques1)
    elif (len(chatrec) == 3):

        ques2 = {
            'type': 'ques',
            'sym': 'true',
            'predict': 'false',
            'msg': 'Q' + str(len(sym) + 1) + '. What is your Gender: '
        }
        chatrec.append(ques2)

    elif (len(chatrec) == 5):
        ques3 = {
            'type': 'ques',
            'sym': 'true',
            'predict': 'false',
            'msg':
            'Q' + str(len(sym) + 1) + '. Chest pain type ( in range 0-3 ): '
        }
        chatrec.append(ques3)
    elif (len(chatrec) == 7):

        ques4 = {
            'type': 'ques',
            'sym': 'true',
            'predict': 'false',
            'msg': 'Q' + str(len(sym) + 1) + '. Your resting blood pressure : '
        }
        chatrec.append(ques4)
    elif (len(chatrec) == 9):

        ques5 = {
            'type': 'ques',
            'sym': 'true',
            'predict': 'false',
            'msg': 'Q' + str(len(sym) + 1) + '. Serum cholestoral in mg/dl:  '
        }
        chatrec.append(ques5)

    elif (len(chatrec) == 11):

        ques6 = {
            'type':
            'ques',
            'sym':
            'true',
            'predict':
            'false',
            'msg':
            'Q' + str(len(sym) + 1) + '. fasting blood sugar > 120 mg/dl :  '
        }
        chatrec.append(ques6)
    elif (len(chatrec) == 13):

        ques7 = {
            'type':
            'ques',
            'sym':
            'true',
            'predict':
            'false',
            'msg':
            'Q' + str(len(sym) + 1) +
            '. resting electrocardiographic results (values 0,1,2): '
        }
        chatrec.append(ques7)

    elif (len(chatrec) == 15):

        ques8 = {
            'type': 'ques',
            'sym': 'true',
            'predict': 'false',
            'msg': 'Q' + str(len(sym) + 1) + '. Maximum heart rate achieved : '
        }
        chatrec.append(ques8)

    elif (len(chatrec) == 17):

        ques9 = {
            'type': 'ques',
            'sym': 'true',
            'predict': 'false',
            'msg': 'Q' + str(len(sym) + 1) + '. exercise induced angina : '
        }
        chatrec.append(ques9)

    elif (len(chatrec) == 19):

        ques10 = {
            'type':
            'ques',
            'sym':
            'true',
            'predict':
            'false',
            'msg':
            'Q' + str(len(sym) + 1) +
            ' oldpeak = ST depression induced by exercise relative to rest '
        }
        chatrec.append(ques10)

    elif (len(chatrec) == 21):

        ques11 = {
            'type':
            'ques',
            'sym':
            'true',
            'predict':
            'false',
            'msg':
            'Q' + str(len(sym) + 1) +
            '. the slope of the peak exercise ST segment: '
        }
        chatrec.append(ques11)

    elif (len(chatrec) == 23):

        ques12 = {
            'type':
            'ques',
            'sym':
            'true',
            'predict':
            'false',
            'msg':
            'Q' + str(len(sym) + 1) +
            '. number of major vessels (0-3) colored by flourosopy '
        }
        chatrec.append(ques12)

    elif (len(chatrec) == 25):

        ques13 = {
            'type':
            'ques',
            'sym':
            'true',
            'predict':
            'false',
            'msg':
            'Q' + str(len(sym) + 1) +
            '. thal: 3 = normal; 6 = fixed defect; 7 = reversable defect '
        }
        chatrec.append(ques13)

    return render(req, 'index.html', {
        'chat': chatrec,
        'symptoms': symptoms,
        'predict': predict
    })