Esempio n. 1
0
def viewPatients():
    form = SearchPatientsForm(current_user.get_id())
    form2 = PaginationForm(1)

    rowsBreadCrumb = [{"href": "/", "name":"Inicio"}]

    if request.args.get('deleteElem') is not None:
        mongoClient["patients"].delete_one({"id": int(request.args.get('deleteElem'))})
        flash("Paciente eliminado correctamente", "info")

    if form.validate_on_submit() is not True:
        form.name.data = ""
        form.surname1.data = ""
        form.surname2.data = ""
        form.age.data = ""
        form.pageNumber.data = 1
        form.patterns.data = ""
        form.genders.data = ""

    queryResult = searchPatients(form, int(form.pageNumber.data))
    form2 = PaginationForm(queryResult["numberPages"])
    form2.pagination.data = form.pageNumber.data

    return render_template('patients/viewPatients.html', form=form, form2=form2, \
        rowPatients=queryResult["rows"], therapistLiteral=therapistLiteral, \
        numberTotalRows=queryResult["numberTotalRows"], numberPages=queryResult["numberPages"], \
        rowsBreadCrumb=rowsBreadCrumb)
Esempio n. 2
0
def linkPatternsPatient(idPatient):
    form = SearchPatternsForm(current_user.get_id())
    form2 = PaginationForm(1)

    cursorPatient = mongoClient["patients"].find_one({"therapist":current_user.get_id(), "id": idPatient})

    patientInfo  = {"id": idPatient, "name":cursorPatient["name"], "surname1":cursorPatient["surname1"], \
        "surname2":cursorPatient["surname2"], "age":int(cursorPatient["age"]), "gender":cursorPatient["gender"]}

    rowsBreadCrumb = [{"href": "/", "name":"Inicio"}, {"href": "/verPacientes", "name":"Ver pacientes"}, \
        {"href": "/verPaciente/" + str(idPatient), "name": cursorPatient["name"] + " " + cursorPatient["surname1"]}]


    #Link patterns to patient
    if request.args.get("pattIds") is not None:
        pattIds = list(map(int, request.args.get("pattIds").split(",")))
        mongoClient["patients"].update_one({"id":idPatient}, {"$push": {"patterns":{"$each" : pattIds}} })
        flash("Pautas vinculadas al paciente correctamente", "success")

    if form.validate_on_submit() is False:
        form.name.data = ""
        form.patients.data = []
        form.groups.data = []
        form.intensities.data = []
        form.pageNumber.data = "1"

    queryResult = searchPatterns(form, int(form.pageNumber.data), {"type":"patients", "id":idPatient})
    form2 = PaginationForm(queryResult["numberPages"])
    form2.pagination.data = form.pageNumber.data

    return render_template('patients/linkPatternsPatient.html', form=form, form2=form2, rowPatterns=queryResult["rows"], \
        therapistLiteral=therapistLiteral, numberTotalRows=queryResult["numberTotalRows"], \
        numberPages=queryResult["numberPages"], patientInfo=patientInfo, rowsBreadCrumb=rowsBreadCrumb)
Esempio n. 3
0
def linkGroupsPattern(idPattern):

    form = SearchGroupsForm(current_user.get_id())
    form2 = PaginationForm(1)

    cursorPattern = mongoClient["patterns"].find_one({"id":idPattern})

    rowsBreadCrumb = [{"href": "/", "name":"Inicio"}, {"href": "/verPautas", "name":"Ver pautas"}, \
        {"href": "/verPauta/" + str(idPattern), "name": cursorPattern["name"]}]

    cursorPattern = mongoClient["patterns"].find_one({"therapist":current_user.get_id(), "id": idPattern})

    intensity1 = "Sí" if 1 in cursorPattern["intensities"] else "No"
    intensity2 = "Sí" if 2 in cursorPattern["intensities"] else "No"
    intensity3 = "Sí" if 3 in cursorPattern["intensities"] else "No"
    intensity4 = "Sí" if 4 in cursorPattern["intensities"] else "No"

    patternInfo  = {"id": idPattern, "name":cursorPattern["name"], "description":cursorPattern["description"], 
        "intensity1":intensity1, "intensity2":intensity2, "intensity3":intensity3, "intensity4":intensity4}        

    if request.args.get('deleteElem') is not None:
        mongoClient["groups"].delete_one({"id": int(request.args.get('deleteElem'))})
        flash("Grupo de pautas eliminado correctamente", "info")    

    if form.validate_on_submit() is not True:
        form.name.data = ""
        form.patients.data = ""
        form.patterns.data = ""
        form.pageNumber.data = "1"

    queryResult = searchGroups(form, int(form.pageNumber.data))

    return render_template('patterns/linkGroupsPattern.html', form=form, form2=form2, rowGroups=queryResult["rows"], \
        therapistLiteral=therapistLiteral, numberTotalRows=queryResult["numberTotalRows"], \
        numberPages=queryResult["numberPages"], rowsBreadCrumb=rowsBreadCrumb, patternInfo=patternInfo)
Esempio n. 4
0
def linkPatternsGroup(idGroup):
    form = SearchPatternsForm(current_user.get_id())
    form2 = PaginationForm(1)

    cursorGroup = mongoClient["groups"].find_one({
        "therapist":
        current_user.get_id(),
        "id":
        idGroup
    })

    groupInfo = {"id": idGroup, "name": cursorGroup["name"]}

    rowsBreadCrumb = [{"href": "/", "name":"Inicio"}, {"href": "/verGrupos", "name":"Ver grupos"}, \
        {"href": "/verGrupo/" + str(idGroup), "name": cursorGroup["name"]}]

    #Link patterns to group
    if request.args.get("pattIds") is not None:
        pattIds = list(map(int, request.args.get("pattIds").split(",")))
        mongoClient["groups"].update_one(
            {"id": idGroup}, {"$push": {
                "patterns": {
                    "$each": pattIds
                }
            }})
        flash("Pautas vinculadas al grupo correctamente", "success")
        return redirect(urlPrefix +
                        url_for('groups.viewGroup', idGroup=idGroup))

    if form.validate_on_submit() is False:
        form.name.data = ""
        form.patients.data = []
        form.groups.data = []
        form.intensities.data = []
        form.pageNumber.data = "1"

    queryResult = searchPatterns(form, int(form.pageNumber.data), {
        "type": "groups",
        "id": idGroup
    })
    form2 = PaginationForm(queryResult["numberPages"])
    form2.pagination.data = form.pageNumber.data

    return render_template('groups/linkPatternsGroup.html', form=form, form2=form2, rowPatterns=queryResult["rows"], \
        therapistLiteral=therapistLiteral, numberTotalRows=queryResult["numberTotalRows"], \
        numberPages=queryResult["numberPages"], groupInfo=groupInfo, rowsBreadCrumb=rowsBreadCrumb)
Esempio n. 5
0
def viewPattern(idPattern):

    if mongoClient["patterns"].count_documents({"therapist":current_user.get_id(), "id":idPattern}) == 0:
        flash("No existe la pauta especificada", "error")
        return redirect(urlPrefix + url_for('general.index'))

    cursorPattern = mongoClient["patterns"].find_one({"therapist":current_user.get_id(), "id": idPattern})

    intensity1 = "Sí" if 1 in cursorPattern["intensities"] else "No"
    intensity2 = "Sí" if 2 in cursorPattern["intensities"] else "No"
    intensity3 = "Sí" if 3 in cursorPattern["intensities"] else "No"
    intensity4 = "Sí" if 4 in cursorPattern["intensities"] else "No"

    patternInfo  = {"id": idPattern, "name":cursorPattern["name"], "description":cursorPattern["description"], 
        "intensity1":intensity1, "intensity2":intensity2, "intensity3":intensity3, "intensity4":intensity4}

    rowsBreadCrumb = [{"href": "/", "name":"Inicio"}, {"href": "/verPautas", "name":"Ver pautas"}]
    
    #UNLINK patient
    if request.args.get("unlinkPati") is not None:
        mongoClient["patients"].update_one({"id":int(request.args.get("unlinkPati"))}, {"$pull": \
            {"patterns": idPattern}})
        flash("Paciente desvinculado correctamente.", "success")

    #UNLINK group
    if request.args.get("unlinkGroup") is not None:
        mongoClient["groups"].update_one({"id":int(request.args.get("unlinkGroup"))}, {"$pull": \
            {"patterns": idPattern}})
        flash("Grupo desvinculado correctamente.", "success")            

    #LINK patients
    if request.args.get("linkPatis") is not None:
        patients = list(map(int, request.args.get("linkPatis").split(",")))
        mongoClient["patients"].update_many({"id": {"$in": list(map(int, patients))}}, \
            {"$push": {"patterns":idPattern}})
        flash("Pacientes vinculados correctamente.", "success")            
            
    #LINK groups
    if request.args.get("linkGroups") is not None:
        groups = list(map(int, request.args.get("linkGroups").split(",")))
        mongoClient["groups"].update_many({"id": {"$in": list(map(int, groups))}}, \
            {"$push": {"patterns":idPattern}})
        flash("Grupos vinculados correctamente.", "success")
        
    form = PaginationForm(1)
    form2 = PaginationForm2(1)
    form3 = PatientSelectForm([current_user.get_id(), idPattern])
    form4 = GroupSelectForm([current_user.get_id(), idPattern])

    queryResultGroups = searchGroupsPattern(idPattern, 1)
    queryResultPatients = searchPatientsPattern(idPattern, 1)

    return render_template('patterns/viewPattern.html', therapistLiteral=therapistLiteral, patternInfo=patternInfo, \
        rowsGroups=queryResultGroups["rows"], rowsPatients=queryResultPatients["rows"], form=form, form2=form2, \
        form3=form3, form4=form4, pagesGroups=queryResultGroups["numberPages"], \
        pagesPatients=queryResultPatients["numberPages"], numberRowsPatient=queryResultPatients["numberTotalRows"], \
        numberRowsGroup=queryResultGroups["numberTotalRows"], rowsBreadCrumb=rowsBreadCrumb)
Esempio n. 6
0
def linkPatientsPattern(idPattern):
    form = SearchPatientsForm(current_user.get_id())
    form2 = PaginationForm(1)

    cursorPattern = mongoClient["patterns"].find_one({"therapist":current_user.get_id(), "id": idPattern})

    intensity1 = "Sí" if 1 in cursorPattern["intensities"] else "No"
    intensity2 = "Sí" if 2 in cursorPattern["intensities"] else "No"
    intensity3 = "Sí" if 3 in cursorPattern["intensities"] else "No"

    patternInfo  = {"id": idPattern, "name":cursorPattern["name"], "description":cursorPattern["description"], 
        "intensity1":intensity1, "intensity2":intensity2, "intensity3":intensity3}

    rowsBreadCrumb = [{"href": "/", "name":"Inicio"}, {"href": "/verPautas", "name":"Ver pautas"}, \
        {"href": "/verPauta/" + str(idPattern), "name": cursorPattern["name"]}]

    #Link pattern to patients
    if request.args.get("patiIds") is not None:
        patiIds = list(map(int, request.args.get("patiIds").split(",")))

        for pati in patiIds:
            mongoClient["patients"].update_one({"id":int(pati)}, { "$push": {"patterns": idPattern}})

        flash("Pautas vinculadas al paciente correctamente", "success")

    if form.validate_on_submit() is not True:
        form.name.data = ""
        form.surname1.data = ""
        form.surname2.data = ""
        form.age.data = ""
        form.genders.data = ""
        form.patterns.data = ""
        form.pageNumber.data = "1"


    queryResult = searchPatients(form, int(form.pageNumber.data), {"type":"patterns", "id":idPattern})
    form2 = PaginationForm(queryResult["numberPages"])
    form2.pagination.data = form.pageNumber.data

    return render_template('patterns/linkPatientsPattern.html', form=form, form2=form2, rowPatients=queryResult["rows"], \
        therapistLiteral=therapistLiteral, numberTotalRows=queryResult["numberTotalRows"], \
        numberPages=queryResult["numberPages"], rowsBreadCrumb=rowsBreadCrumb, patternInfo=patternInfo)
Esempio n. 7
0
def index():

    if request.args.get('noty') is "1":
        flash("Paciente registrado correctamente", "success")

    print("[DEBUG] Therapist id:")
    print(current_user.get_id())

    #Count of the three types of elements for the given therapist
    totalNumberPatients = mongoClient["patients"]\
        .count_documents({"therapist":current_user.get_id()})
    totalNumberPatterns = mongoClient["patterns"]\
        .count_documents({"therapist":current_user.get_id()})
    totalNumberGroups = mongoClient["groups"]\
        .count_documents({"therapist":current_user.get_id()})

    totalNumberElements = {"patients":totalNumberPatients, "patterns":totalNumberPatterns, \
        "groups":totalNumberGroups}

    form = SearchPatientsForm(current_user.get_id())
    form2 = PaginationForm(1)

    if form.validate_on_submit() is not True:
        form.name.data = ""
        form.surname1.data = ""
        form.surname2.data = ""
        form.age.data = ""
        form.pageNumber.data = 1
        form.patterns.data = ""
        form.genders.data = ""

    queryResult = searchPatients(form, int(form.pageNumber.data))
    form2 = PaginationForm(queryResult["numberPages"])
    form2.pagination.data = form.pageNumber.data

    return render_template('general/index.html', therapistLiteral=therapistLiteral, \
        form=form, form2=form2,  rowPatients=queryResult["rows"], \
        numberPages=queryResult["numberPages"], numberTotalRows=queryResult["numberTotalRows"], \
        totalNumberElements=totalNumberElements)
Esempio n. 8
0
def viewPatterns():
    therapistLiteral = "{} {} {}".format(current_user.get_name(), current_user.get_surname1(), \
        current_user.get_surname2())
    form = SearchPatternsForm(current_user.get_id())
    form2 = PaginationForm(1)

    if form.validate_on_submit():
        form.submitDone.data = 1

        queryResult = searchPatterns(form, int(form.pageNumber.data))
        form2 = PaginationForm(queryResult["numberPages"])
        form2.pagination.data = form.pageNumber.data

        return render_template('viewPatterns.html', form=form, form2=form2, rowPatterns=queryResult["rows"], \
            therapistLiteral=therapistLiteral, numberTotalRows=queryResult["numberTotalRows"], \
            numberPages=queryResult["numberPages"])
    else:
        form.submitDone.data = 0
        return render_template('viewPatterns.html',
                               form=form,
                               form2=form2,
                               therapistLiteral=therapistLiteral)
Esempio n. 9
0
def viewPatterns():

    rowsBreadCrumb = [{"href": "/", "name":"Inicio"}]

    form = SearchPatternsForm(current_user.get_id())
    form2 = PaginationForm(1)

    #Delete element
    if request.args.get('deleteElem') != None:
        deletePattern = int(request.args.get('deleteElem'))
        mongoClient["patterns"].delete_one({"id": deletePattern})

        cursor = mongoClient["patients"].find({"patterns":deletePattern})
        
        for cur in cursor:
            if mongoClient["updatePatternsAndroid"].count_documents({"communicationToken":cur["communicationToken"], "operation":"delete"}) == 0:
                mongoClient["updatePatternsAndroid"].insert_one({"communicationToken":cur["communicationToken"], "operation":"delete", "patterns":[deletePattern]})
            else:
                mongoClient["updatePatternsAndroid"].update_one({"communicationToken":cur["communicationToken"], "operation":"delete"}, {"$push":{"patterns":deletePattern}})   
        
        flash("Pauta eliminada correctamente", "info")

    #Set form values to zero on first load
    if form.validate_on_submit() != True:
        form.name.data = ""
        form.patients.data = ""
        form.intensities.data = ""
        form.groups.data = ""
        form.pageNumber.data = "1"


    queryResult = searchPatterns(form, int(form.pageNumber.data))
    form2 = PaginationForm(queryResult["numberPages"])
    form2.pagination.data = form.pageNumber.data

    return render_template('patterns/viewPatterns.html', form=form, form2=form2, rowPatterns=queryResult["rows"], \
        therapistLiteral=therapistLiteral, numberTotalRows=queryResult["numberTotalRows"], \
        numberPages=queryResult["numberPages"], rowsBreadCrumb=rowsBreadCrumb)
Esempio n. 10
0
    def get(self):
        pagination_form = PaginationForm(meta=dict(csrf=False))
        type = request.values.get('type')
        if not type:
            return dict(code=400, msg='error params', data=None)

        # 由于需要通过子查询当前用户是否点赞,稍微复杂,因此不用orm,手写sql
        key = ('id', 'title', 'content', 'contact', 'type', 'phone', 'image',
               'updated_time', 'like')
        sql = text("""
SELECT
    p.id,
    p.title,
    p.content,
    p.contact,
    p.type,
    p.phone,
    p.image,
    p.updated_time,
    IFNULL(( SELECT `status` FROM likes WHERE user_id = :user_id AND post_id = p.id), 0) AS 'like'
FROM
    posts p
WHERE p.type = :type
AND p.deleted = FALSE
LIMIT :start, :per_page
        """)
        posts = db.engine.execute(
            sql,
            type=type,
            start=pagination_form.per_page.data *
            (pagination_form.page.data - 1),
            per_page=pagination_form.per_page.data,
            user_id=current_user.id if current_user.is_authenticated else 0,
        ).fetchall()

        current_num = len(posts)
        if current_num < pagination_form.per_page.data:
            total_num = len(posts)
        else:
            total_num = PostModel.get_query().filter_by(type=type).count()
        return dict(code=200,
                    msg='success',
                    data=dict(
                        data=[dict(zip(key, _)) for _ in posts],
                        pagination=dict(
                            current_page=pagination_form.page.data,
                            current_num=current_num,
                            total_page=ceil(total_num /
                                            pagination_form.per_page.data),
                            total_num=total_num)))
Esempio n. 11
0
def get_user():
    """
    分页获得所有用户
    :return:
    """
    pagniate_form = PaginationForm(meta=dict(csrf=False))
    users = UserModel.query.filter_by(deleted=False)\
        .paginate(**pagniate_form.form)
    return dict(code=200,
                msg='success',
                data=dict(data=[_.asdict() for _ in users.items],
                          pagination=dict(current_page=users.page,
                                          current_num=len(users.items),
                                          total_page=users.pages,
                                          total_num=users.total)))
Esempio n. 12
0
def viewPattern(idPattern):

    if mongoClient["patterns"].count_documents({
            "therapist":
            current_user.get_id(),
            "id":
            idPattern
    }) == 0:
        flash("No existe la pauta especificada", "error")
        return redirect(url_for('index'))

    cursorPattern = mongoClient["patterns"].find_one({
        "therapist":
        current_user.get_id(),
        "id":
        idPattern
    })

    intensity1 = "Sí" if 1 in cursorPattern["intensities"] else "no"
    intensity2 = "Sí" if 2 in cursorPattern["intensities"] else "no"
    intensity3 = "Sí" if 3 in cursorPattern["intensities"] else "no"

    patternInfo = {
        "id": idPattern,
        "name": cursorPattern["name"],
        "description": cursorPattern["description"],
        "intensity1": intensity1,
        "intensity2": intensity2,
        "intensity3": intensity3
    }

    therapistLiteral = "{} {} {}".format(current_user.get_name(), current_user.get_surname1(), \
        current_user.get_surname2())

    form = PaginationForm(1)
    form2 = PaginationForm2(1)

    queryResultGroups = searchGroupsPattern(idPattern, 1)
    queryResultPatients = searchPatientsPattern(idPattern, 1)

    return render_template('viewPattern.html', therapistLiteral=therapistLiteral, patternInfo=patternInfo,
        rowsGroups=queryResultGroups["rows"], rowsPatients=queryResultPatients["rows"], form=form, form2=form2, \
        idPattern=idPattern, pagesGroups=queryResultGroups["numberPages"], \
        pagesPatients=queryResultPatients["numberPages"], numberRowsPatient=queryResultPatients["numberTotalRows"], \
        numberRowsGroup=queryResultGroups["numberTotalRows"])
Esempio n. 13
0
def viewGroup(idGroup):

    if mongoClient["groups"].count_documents({
            "therapist": current_user.get_id(),
            "id": idGroup
    }) == 0:
        flash("No existe el grupo de pautas especificado", "error")
        return redirect(url_for('index'))

    therapistLiteral = "{} {} {}".format(current_user.get_name(), current_user.get_surname1(), \
        current_user.get_surname2())
    therapist = current_user.get_id()

    form = PaginationForm(1)
    form2 = PaginationForm2(1)

    cursorGroup = mongoClient["groups"].find_one({
        "therapist":
        current_user.get_id(),
        "id":
        idGroup
    })

    groupInfo = {
        "id": idGroup,
        "name": cursorGroup["name"],
        "description": cursorGroup["description"]
    }

    queryResultPatients = searchPatientsGroup(idGroup, 1)
    queryResultPatterns = searchPatternsGroup(idGroup, 1)


    return render_template('viewGroup.html', therapistLiteral=therapistLiteral, groupInfo=groupInfo,
        form=form, form2=form2, idGroup=idGroup, rowsPatients=queryResultPatients["rows"], \
        pagesPatients=queryResultPatients["numberPages"], numberRowsPatient=queryResultPatients["numberTotalRows"], \
        rowsPatterns=queryResultPatterns["rows"], pagesPatterns=queryResultPatterns["numberPages"], \
        numberRowsPattern=queryResultPatterns["numberTotalRows"])

    return render_template('viewGroup.html',
                           rowPatterns=rowPatterns,
                           therapistLiteral=therapistLiteral)
    def get(self):
        """
        获得所有留言
        :return:
        """
        comment_form = CommentForm(meta=dict(csrf=False))
        paginate_form = PaginationForm(meta=dict(csrf=False))

        query: BaseQuery = CommentModel.query.filter_by(
            post_id=comment_form.post_id.data)
        pagination = query.paginate(page=paginate_form.page.data,
                                    per_page=paginate_form.per_page.data)

        return dict(code=200,
                    msg='success',
                    data=dict(data=[_.asdict() for _ in pagination.items],
                              pagination=dict(current_page=pagination.page,
                                              current_num=len(
                                                  pagination.items),
                                              total_page=pagination.pages,
                                              total_num=pagination.total)))
Esempio n. 15
0
def viewGroups():

    rowsBreadCrumb = [{"href": "/", "name": "Inicio"}]

    if request.args.get('deleteElem') is not None:
        mongoClient["groups"].delete_one(
            {"id": int(request.args.get('deleteElem'))})
        flash("Grupo de pautas eliminado correctamente", "info")

    form = SearchGroupsForm(current_user.get_id())

    if form.validate_on_submit() is not True:
        form.name.data = ""
        form.patterns.data = ""
        form.pageNumber.data = "1"

    queryResult = searchGroups(form, int(form.pageNumber.data))
    form2 = PaginationForm(queryResult["numberPages"])
    form2.pagination.data = form.pageNumber.data

    return render_template('groups/viewGroups.html', form=form, form2=form2, rowGroups=queryResult["rows"], \
        therapistLiteral=therapistLiteral, numberTotalRows=queryResult["numberTotalRows"], \
        numberPages=queryResult["numberPages"], rowsBreadCrumb=rowsBreadCrumb)
Esempio n. 16
0
def viewPatient(idPatient):
    if mongoClient["patients"].count_documents({"id":idPatient, "therapist":current_user.get_id()}) == 0:
        flash("No se ha encontrado el paciente indicado", "error")
        return redirect(urlPrefix + url_for('general.index'))

    cursorPatient = mongoClient["patients"].find_one({"id":idPatient, "therapist":current_user.get_id()})

    patientInfo  = {"id": idPatient, "name":cursorPatient["name"], "surname1":cursorPatient["surname1"], \
        "surname2":cursorPatient["surname2"], "age":int(cursorPatient["age"]), "gender":cursorPatient["gender"]}
        
    #Link patterns to patient
    if request.args.get("linkPattIds") is not None:
        pattIds = list(map(int, request.args.get("linkPattIds").split(",")))
        print(pattIds)
        mongoClient["patients"].update_one({"id":idPatient}, {"$push": {"patterns":{"$each" : pattIds}} })
        
        cursor = mongoClient["patients"].find_one({"id" : idPatient})
        communicationToken = cursor["communicationToken"]
        
        if mongoClient["updatePatternsAndroid"].count_documents({"communicationToken":communicationToken, "operation":"add"}) == 0:
            mongoClient["updatePatternsAndroid"].insert_one({"communicationToken":communicationToken, "operation":"add", "patterns":pattIds})
        else:
            mongoClient["updatePatternsAndroid"].update_one({"communicationToken":communicationToken, "operation":"add"}, {"$push": {"patterns":{"$each" : pattIds}}})
        
        flash("Pautas vinculadas al paciente correctamente", "success")

    form = EditPatientForm(current_user.get_id())
    form2 = GenericEditForm()
    form3 = PaginationForm(1)
    form4 = FilterByDateForm(current_user.get_id(), 1)
    form5 = SearchPatternsForm(current_user.get_id())
    form6 = PaginationForm(1)
    
    if form5.validate_on_submit() is False:
        form5.name.data = ""
        form5.patients.data = []
        form5.groups.data = []
        form5.intensities.data = []
        form5.pageNumber.data = "1"

    #Set default values of filter by date form

    #FROM
    if form4.date1.data == None:
        form4.date1.data = "2000-01-01"
        form4.time1.data = "00:00"

    if form4.time1.data == None:
        form4.time1.data = "00:00"

    #TO
    if form4.date2.data == None:
        form4.date2.data = "2050-01-01"
        form4.time2.data = "23:59"

    if form4.time2.data == None:
        form4.time2.data = "23:59"    

    rowsBreadCrumb = [{"href": "/", "name":"Inicio"}, {"href": "/verPacientes", "name":"Ver pacientes"}]

    #Unlink pattern
    if request.args.get("unlinkPatt") is not None:
        unlinkPatt = int(request.args.get("unlinkPatt"))
        
        mongoClient["patients"].update_one({"id":idPatient}, {"$pull": \
            {"patterns": unlinkPatt}})
        
        cursor = mongoClient["patients"].find_one({"id" : idPatient})
        communicationToken = cursor["communicationToken"]        
        
        if mongoClient["updatePatternsAndroid"].count_documents({"communicationToken":communicationToken, "operation":"delete"}) == 0:
            mongoClient["updatePatternsAndroid"].insert_one({"communicationToken":communicationToken, "operation":"delete", "patterns":[unlinkPatt]})
        else:
            mongoClient["updatePatternsAndroid"].update_one({"communicationToken":communicationToken, "operation":"delete"}, {"$push":{"patterns":unlinkPatt}})


    cursorPatient = mongoClient["patients"].find_one({"id":idPatient})
    
    #Get patient's patterns
    queryResultPatterns = searchPatternsPatient(idPatient, 1, "arr")

    #Get episodes from the patient
    #TODO: check if the 4 params of time should be "". Probably form4 should be passed as param
    rowEpisodes, numberRowsEpisodes, pagesEpisodes = getEpisodes(idPatient, "", "", "", "")
    
    queryResultLinkPatt = searchPatterns(form5, int(form5.pageNumber.data), {"type":"patients", "id":idPatient})
    form6 = PaginationForm(queryResultLinkPatt["numberPages"])
    form6.pagination.data = form5.pageNumber.data   

    return render_template('patients/viewPatient.html', therapistLiteral=therapistLiteral, \
        rowsPatterns=queryResultPatterns["rows"], form=form, form2=form2, \
        form3=form3, form4=form4, form5=form5, form6=form6, \
        pagesPatterns=queryResultPatterns["numberPages"], \
        numberRowsPattern=queryResultPatterns["numberTotalRows"], rowsBreadCrumb=rowsBreadCrumb, \
        patientInfo=patientInfo, rowEpisodes=rowEpisodes, numberRowsEpisodes=numberRowsEpisodes, \
        pagesEpisodes=pagesEpisodes, rowLinkPatt=queryResultLinkPatt["rows"], \
        numberTotalRowsLinkPatt=queryResultLinkPatt["numberTotalRows"], \
        numberPagesLinkPatt=queryResultLinkPatt["numberPages"])
Esempio n. 17
0
def viewGroup(idGroup):

    if mongoClient["groups"].count_documents({
            "therapist": current_user.get_id(),
            "id": idGroup
    }) == 0:
        flash("No existe el grupo de pautas especificado", "error")
        return redirect(urlPrefix + url_for('general.index'))

    #UNLINK pattern
    if request.args.get("unlinkPatt") is not None:
        mongoClient["groups"].update_one({"id":idGroup}, {"$pull": \
            {"patterns": int(request.args.get("unlinkPatt"))}})
        flash("Pauta desvinculada correctamente.", "success")

    #LINK patterns
    if request.args.get("linkPattIds") is not None:
        patterns = list(map(int, request.args.get("linkPattIds").split(",")))
        for patt in patterns:
            mongoClient["groups"].update_one({"id": idGroup}, \
                {"$push": {"patterns":patt}})
        flash("Pautas vinculadas correctamente.", "success")

    form = PaginationForm(1)
    form2 = PaginationForm2(1)

    form3 = SearchPatternsForm(current_user.get_id())
    form4 = PaginationForm(1)

    if form3.validate_on_submit() is False:
        form3.name.data = ""
        form3.patients.data = []
        form3.groups.data = []
        form3.intensities.data = []
        form3.pageNumber.data = "1"

    queryResultLinkPatt = searchPatterns(form3, int(form3.pageNumber.data), {
        "type": "groups",
        "id": idGroup
    })
    form4 = PaginationForm(queryResultLinkPatt["numberPages"])
    form4.pagination.data = form3.pageNumber.data

    cursorGroup = mongoClient["groups"].find_one({
        "therapist":
        current_user.get_id(),
        "id":
        idGroup
    })

    groupInfo = {
        "id": idGroup,
        "name": cursorGroup["name"],
        "description": cursorGroup["description"]
    }

    rowsBreadCrumb = [{
        "href": "/",
        "name": "Inicio"
    }, {
        "href": "/verPacientes",
        "name": "Ver pacientes"
    }]

    queryResultPatterns = searchPatternsGroup(idGroup, 1)

    return render_template('groups/viewGroup.html', therapistLiteral=therapistLiteral, groupInfo=groupInfo,
        form=form, form2=form2, form3=form3, form4=form4, idGroup=idGroup, rowsPatterns=queryResultPatterns["rows"], \
        pagesPatterns=queryResultPatterns["numberPages"], numberRowsPattern=queryResultPatterns["numberTotalRows"], \
        rowsBreadCrumb=rowsBreadCrumb, rowLinkPatt=queryResultLinkPatt["rows"], \
        numberTotalRowsLinkPatt=queryResultLinkPatt["numberTotalRows"], \
        numberPagesLinkPatt=queryResultLinkPatt["numberPages"])