Ejemplo n.º 1
0
def createpatient(request):
    # this code path is when the user's POSTed to us
    if request.method == 'POST':
        # set up the form object
        form = PatientForm(request.POST)
        # if the form is valid, do this stuff
        if form.is_valid():
            # pull out the data from the form
            medical_record_number = form.cleaned_data['medical_record_number']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            #TODO: figure out how to ensure uniqueness
            # create a Patient object with that data
            patient = Patient(medical_record_number = medical_record_number,
                              first_name = first_name,
                              last_name = last_name)
            # save the object to the DB
            patient.put()
            # this grabs all the forms associated to that patient
            forms = Form.all().filter('patient =', patient.key())
            # this calls the template patient_detail.html and passes the patient and the forms
            return render_to_response(request, 'dorkdoc/patient_detail.html', 
                { 'patient' : patient,
                  'forms'   : forms
                }
            )
            
    # this code path is when the user GETs this URL
    else:
        # create a blank form object
        form = PatientForm()
    
    # this passes the form data to the createpatient template
    return render_to_response(request, 'createpatient.html', {'form' : form })
Ejemplo n.º 2
0
def patient(request, medical_record_number):
    # this grabs the specific patient record based on the url (from urls.py)
    patient = Patient.all().filter('medical_record_number =', medical_record_number).get()
    # this grabs all the forms associated to that patient
    forms = Form.all().filter('patient =', patient.key())
    # this calls the template patient_detail.html and passes the patient and the forms
    return render_to_response(request, 'dorkdoc/patient_detail.html', 
        { 'patient' : patient,
          'forms'   : forms
        }
    )