Example #1
0
def add(request, cont=False):
    if request.method == "POST":
        form = PatientForm(request.POST)

        if form.is_valid():
            patient = Patient.from_form(form)

            if cont:
                return redirect("patient:add_prescription", id=patient.id)

            patient.dirty = False
            patient.save()

            return redirect('index')
    else:
        try:
            patient = Patient.objects.get(dirty=True)
        except Patient.DoesNotExist:
            patient = None

        if patient:
            return redirect("patient:continue_patient", id=patient.id)

        form = PatientForm()

    return render_to_response("patient/add.html",
                               locals(),
                               context_instance=RequestContext(request))
Example #2
0
def edit(request, id):
    patient = get_object_or_404(Patient, pk=id)

    if request.method == "POST":
        form = PatientForm(request.POST)

        if form.is_valid():
            patient = Patient.from_form(form, patient=patient)
            patient.save()

            return redirect("%s#%s" % (reverse("patient:show_patient", args=(id,)), request.GET.get("forward", "")))
    else:
        form = PatientForm.from_patient(patient)

    url_attachment = request.GET.get("forward", None)

    return render_to_response("patient/edit.html",
                              locals(),
                              context_instance=RequestContext(request))