コード例 #1
0
ファイル: routes.py プロジェクト: asdrgil/tfm-server
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)
コード例 #2
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)
コード例 #3
0
ファイル: routes.py プロジェクト: asdrgil/tfm-server
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)
コード例 #4
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"])
コード例 #5
0
ファイル: routes.py プロジェクト: asdrgil/tfm-server
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"])