Exemplo n.º 1
0
def editCaseData(id):
    # Initialize form from forms.py
    form = CaseForm()

    # get values for this row from the database
    sql = f"SELECT * FROM case_no WHERE case_id = '{id}'"
    res = db.query(sql)

    # if form is sent back (POST) to the server
    if form.validate_on_submit():
        # capture data from form
        form_data = form.data
        # build SQL query to update case table
        qry = db.case_update_sql(form_data)
        # update table with new data
        try:
            db.insert(qry)
        except:
            flash('Not able to update case record', 'warning')
            return render_template(f'edit-case-data.html',
                                   template_form=form,
                                   id=id)
        # redirect user to case updated page
        return redirect(f'/case_updated/{form.case_id.data}')

    # populate values to the form
    form.case_id.data = res[0][0]
    form.patient_id.data = res[0][1]
    form.county_id.data = res[0][2]
    form.hospital_id.data = res[0][3]
    form.status.data = res[0][4]
    form.hospital_name.data = res[0][5]

    return render_template('edit-case-data.html', template_form=form, id=id)
Exemplo n.º 2
0
def case_create():
    global db
    case_form_create = CaseForm()
    if case_form_create.validate_on_submit():
        form_data = case_form_create.data
        qry = db.case_insert_sql(form_data)
        db.insert(qry)
        return redirect(f'/case_created/{case_form_create.case_id.data}')
    return render_template('case_create.html', template_form=case_form_create)
Exemplo n.º 3
0
def case():
    result = []
    form = CaseForm()
    cases = Case.query.all()
    for case in cases:
        result.append([case.id, case.name, case.version])
    return render_template('cases.html', rows=result, form=form)
Exemplo n.º 4
0
def insert_case():
    form = CaseForm()
    name = form.name.data
    version = form.version.data
    case = Case(name=name, version=version)
    db.session.add(case)
    db.session.commit()
    return redirect('/case')
Exemplo n.º 5
0
def create_case(request):

    if request.method =='POST':
        form = CaseForm(request.POST, request.FILES) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            new_case = form.save(commit=False)
            new_case.created_by = request.user
            new_case.save()
            return HttpResponseRedirect("/user/all")
        else:
            return render_to_response("user_views/user_create_case.html", {"form":form},
                               context_instance=RequestContext(request))


    else:
        form = CaseForm()
        return render_to_response("user_views/user_create_case.html", {"form":form},
                               context_instance=RequestContext(request))
Exemplo n.º 6
0
def edit_case(request, case_id):

    case = get_object_or_404(Case,pk=case_id)

    if request.method =='POST':
        if case.created_by == request.user:
            form = CaseForm(request.POST, request.FILES, instance=case) # A form bound to the POST data
            if form.is_valid(): # All validation rules pass
                form.save()
                messages.success(request, 'Case Updated')
                return HttpResponseRedirect("/user/all")
            else:
                return render_to_response("user_views/user_create_case.html", {"form":form, "edit":case.id},
                               context_instance=RequestContext(request))


    else:

        if case.created_by == request.user:
            form = CaseForm(instance=case)
            return render_to_response("user_views/user_create_case.html", {"form":form, "edit":case.id},
                                context_instance=RequestContext(request))
        else:
            raise Http404