Exemple #1
0
    def getSuggestions(self, userid):
        print("getSuggestions")
        userList = dbHandler.getUserList(userid)
        suggestionList = {}
        elList = []
        for el in userList:
            elList.append(dbHandler.getElementByID(el[1])[0])

        diseasesClass = []
        for el in elList:
            diseasesClass.extend(self.search_diseasesByClass(el[1]))

        userInfo = dbHandler.getUserInfo(userid)[0]
        country = userInfo[3]

        diseasesCountry = []

        if country:
            diseasesCountry = self.search_diseaseByCountry(country)

        suggestionList["class"] = diseasesClass
        suggestionList["country"] = diseasesCountry
        suggestionList["risks"] = self.search_predispositions(
            userInfo[6], userInfo[8], userInfo[5], userInfo[7])

        return suggestionList
Exemple #2
0
def home():
    logged_in = session.get('logged_in')
    if logged_in:
        info = {}
        diseaseInfo = ""
        diseaseName = ""
        diseaseTreatment = ""

        name = []
        symptoms = []
        treatment = []
        hasCauses = []
        causeOf = []
        image = ""

        info["symptoms"] = symptoms
        info["treatment"] = treatment
        info["hasCauses"] = hasCauses
        info["causeOf"] = causeOf
        info["info"] = diseaseInfo
        info["name"] = name
        info["image"] = image

        diseaseInfo = False

        userList = []
        userListDb = dbHandler.getUserList(session.get("userid"))
        for l in userListDb:
            el = dbHandler.getElementByID(l[1])
            userList.append(el[0][1])

        b = True
        i = 0
        mostVisited = []
        visited = dbHandler.getElements("disease")
        while b == True:
            if i < 5 and len(visited) > i:
                mostVisited.append(visited[i][1])
                i = i + 1
            else:
                b = False

        suggestions = {}
        s = Sparql()
        suggestions = s.getSuggestions(session.get("userid"))

        if request.method == "GET":
            diseaseName = request.args.get("diseaseName")
            diseaseSymptoms = request.args.get("symptoms")
            diseaseTreatment = request.args.get("treatment")
            diseaseCauses = request.args.get("causes")
            diseaseType = request.args.get("type")
            diseaseCountry = request.args.get("country")
            diseaseClimate = request.args.get("climate")
            diseaseFood = request.args.get("food")
            first = True

            if (type(diseaseName) == str and len(diseaseName) != 0):
                s = Sparql()
                info = s.search_name(diseaseName)
                dbHandler.addElement(diseaseName, "disease")
                session["diseaseName"] = diseaseName
                diseaseInfo = True
                dbHandler.addVisitedDisease(session.get("userid"), diseaseName,
                                            "disease")

            if (type(diseaseSymptoms) == str and len(diseaseSymptoms) != 0):
                s = Sparql()
                if first == True:
                    info = s.search_symptoms(diseaseSymptoms)
                    first = False
                else:
                    infoTemp = s.search_symptoms(diseaseSymptoms)
                    info["name"] = list(
                        set(info["name"]).intersection(infoTemp["name"]))
                symptoms = diseaseSymptoms.split(", ")
                for s in symptoms:
                    dbHandler.addElement(s, "symptom")

            if (type(diseaseTreatment) == str and len(diseaseTreatment) != 0):
                s = Sparql()

                if first == True:
                    info = s.search_treatment(diseaseTreatment)
                    first = False
                else:
                    infoTemp = s.search_treatment(diseaseTreatment)
                    info["name"] = list(
                        set(info["name"]).intersection(infoTemp["name"]))

                treatments = diseaseTreatment.split(", ")
                for t in treatments:
                    dbHandler.addElement(t, "treatment")

            if (type(diseaseCauses) == str and len(diseaseCauses) != 0):
                s = Sparql()

                if first == True:
                    info = s.search_bycauses(diseaseCauses)
                    first = False
                else:
                    infoTemp = s.search_bycauses(diseaseCauses)
                    info["name"] = list(
                        set(info["name"]).intersection(infoTemp["name"]))

                causes = diseaseCauses.split(", ")
                for c in causes:
                    dbHandler.addElement(c, "causes")

            if (type(diseaseType) == str and len(diseaseType) != 0):
                s = Sparql()
                if first == True:
                    info = s.search_bytype(diseaseType)
                    first = False
                else:
                    infoTemp = s.search_bytype(diseaseType)
                    info["name"] = list(
                        set(info["name"]).intersection(infoTemp["name"]))
                types = diseaseType.split(", ")
                for t in types:
                    dbHandler.addElement(t, "types")

            if (type(diseaseCountry) == str and len(diseaseCountry) != 0):
                s = Sparql()
                if first == True:
                    info["name"] = s.search_diseaseByCountry(diseaseCountry)
                    first = False
                else:
                    infoTemp = s.search_diseaseByCountry(diseaseCountry)
                    info["name"] = list(
                        set(info["name"]).intersection(infoTemp))

                dbHandler.addElement(diseaseCountry, "country")

            if (type(diseaseClimate) == str and len(diseaseClimate) != 0):
                s = Sparql()

                if first == True:
                    info["name"] = s.search_diseaseByClimate(diseaseClimate)
                    first = False
                else:
                    infoTemp = s.search_diseaseByClimate(diseaseClimate)
                    info["name"] = list(
                        set(info["name"]).intersection(infoTemp))

                dbHandler.addElement(diseaseClimate, "climate")

            if (type(diseaseFood) == str and len(diseaseFood) != 0):
                s = Sparql()

                if first == True:
                    info["name"] = s.search_diseaseByFood(diseaseFood)
                    first = False
                else:
                    infoTemp = s.search_diseaseByFood(diseaseFood)
                    info["name"] = list(
                        set(info["name"]).intersection(infoTemp))

                dbHandler.addElement(diseaseFood, "food")

            return render_template("home.html",
                                   username=session.get("username"),
                                   disease=info["name"],
                                   symptoms=info["symptoms"],
                                   treatment=info["treatment"],
                                   hasCauses=info["hasCauses"],
                                   causeOf=info["causeOf"],
                                   info=info["info"],
                                   image=info["image"],
                                   userList=userList,
                                   visited=mostVisited,
                                   suggestions=suggestions,
                                   diseaseInfo=diseaseInfo)

        if request.method == "POST":
            dbHandler.addElementInList(session.get("userid"),
                                       session.get("diseaseName"), "disease")
            userList.append(session.get("diseaseName"))
            return render_template("home.html",
                                   userList=userList,
                                   visited=mostVisited,
                                   suggestions=suggestions)
    else:
        return redirect(url_for('index'))
Exemple #3
0
    def generate_question(self, userID):
        question = {}
        question["question"] = ""
        question["correctAnswer"] = ""
        question["answers"] = []
        userList = dbHandler.getUserList(userID)
        userList.extend(dbHandler.getUserVisitedList(userID))

        if len(userList) > 0:
            n = randint(0, len(userList) - 1)
            dID = userList[n][1]
            dName = dbHandler.getElementByID(dID)[0][1]
            disease = self.search_name(dName)
            elements = dbHandler.getElements("disease")

            n = randint(0, len(elements) - 1)
            while elements[n][1] == dName:
                n = randint(0, len(elements) - 1)
            d1 = elements[n][1]
            n = randint(0, len(elements) - 1)
            while elements[n][1] == dName and elements[n][1] != d1:
                n = randint(0, len(elements) - 1)
            d2 = elements[n][1]

            question["correctAnswer"] = dName
            question["answers"] = [d1, d2, dName]

            ok = False
            while ok == False:
                n = randint(1, 4)
                if n == 1 and len(disease["symptoms"]) > 0:
                    for s in disease["symptoms"]:
                        question["question"] = question["question"] + ", " + s
                    question[
                        "question"] = "Which disease has the following symptoms: " + question[
                            "question"][2:] + "?"
                    ok = True
                    return question

                if n == 2 and len(disease["info"]) > 0:

                    sentences = disease["info"].split(". ")
                    n = randint(0, len(sentences) - 1)
                    while dName.lower() in sentences[n]:
                        n = randint(0, len(sentences) - 1)
                    m = n
                    while m == n:
                        m = randint(0, len(sentences) - 1)
                    question[
                        "question"] = sentences[m] + ". " + sentences[n] + "."
                    ok = True
                    return question

                if n == 3 and len(disease["treatment"]) > 0:
                    for t in disease["treatment"]:
                        question["question"] = question["question"] + ", " + t
                    question[
                        "question"] = "Which disease has the following treatment: " + question[
                            "question"][2:] + "?"
                    ok = True
                    return question

                if n == 4 and len(disease["hasCauses"]) > 0:
                    for c in disease["hasCauses"]:
                        question["question"] = question["question"] + ", " + c
                    question[
                        "question"] = "Which disease has the following causes: " + question[
                            "question"][2:] + "?"
                    ok = True
                    return question