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 })
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 } )
def createform1(request, medical_record_number): logging.debug("createform1 invoked") # this code path is when the user's POSTed to us if request.method == 'POST': # set up the form object form = FormDateTimeForm(request.POST) # if the form is valid, do this stuff if form.is_valid(): logging.debug("Form is valid") # this grabs the specific patient record based on the url (from urls.py) patient = Patient.all().filter('medical_record_number =', medical_record_number).get() # pull out the data from the form date_of_visit = form.cleaned_data['date_of_visit'] start_time = form.cleaned_data['start_time'] end_time = form.cleaned_data['end_time'] #TODO: figure out how to ensure uniqueness # create a Form object with that data formobject = Form(date_of_visit = date_of_visit, start_time_of_visit = start_time, end_time_of_visit = end_time, patient = patient) # save the object to the datastore formobject.put() logging.debug("Saved form to the datastore") # this calls the template createform2.html and passes the form object and the new form we're going to use #return render_to_response(request, "createform2.html", # { "formobject" : formobject } #) return HttpResponseRedirect("/dorkdoc/patient/" + medical_record_number + "/form/create/step2/" + str(formobject.key())) else: logging.debug("Form isn't valid!") # this code path is when the user GETs this URL else: # create a blank form object form = FormDateTimeForm() # this passes the form data to the create form 1 template return render_to_response(request, 'createform1.html', { 'medical_record_number' : medical_record_number, 'form' : form } )