def display_new_patient(request): ''' Display the new patient page and process submitted new-patient forms. ''' user = request.user # Only workers may add new patients. if not hasattr(user, "worker"): return HttpResponseServerError() if request.method == 'POST': form = NewPatientForm(request.POST, request.FILES) if form.is_valid(): first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] gps_coordinates = form.cleaned_data['gps_coordinates'] address = form.cleaned_data['address'] date_of_birth = form.cleaned_data['date_of_birth'] phone_number = form.cleaned_data['phone_number'] health_id = form.cleaned_data['health_id'] sex = form.cleaned_data['sex'] email = form.cleaned_data['email'] patient_pic = form.cleaned_data['patient_pic'] try: patient = Patient(first_name=first_name, last_name=last_name, gps_coordinates=gps_coordinates, address=address, date_of_birth=date_of_birth, phone=phone_number, health_id=health_id, gender=sex, email=email, patient_pic=patient_pic) patient.save() except IntegrityError: return HttpResponseServerError() return HttpResponseRedirect("/patient/" + str(patient.id)) else: # The page has just been entered and so the form hasn't # been submitted yet. form = NewPatientForm() return render_to_response('newPatient.html', { 'form': form, 'viewer': request.user }, context_instance=RequestContext(request))
def display_new_patient(request): ''' Display the new patient page and process submitted new-patient forms. ''' user = request.user # Only workers may add new patients. if not hasattr(user, "worker"): return HttpResponseServerError() if request.method == 'POST': form = NewPatientForm(request.POST, request.FILES) if form.is_valid(): first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] gps_coordinates = form.cleaned_data['gps_coordinates'] address = form.cleaned_data['address'] date_of_birth = form.cleaned_data['date_of_birth'] phone_number = form.cleaned_data['phone_number'] health_id = form.cleaned_data['health_id'] sex = form.cleaned_data['sex'] email = form.cleaned_data['email'] patient_pic = form.cleaned_data['patient_pic'] try: patient = Patient( first_name=first_name, last_name=last_name, gps_coordinates=gps_coordinates, address=address, date_of_birth=date_of_birth, phone=phone_number, health_id=health_id, gender=sex, email=email, patient_pic=patient_pic) patient.save() except IntegrityError: return HttpResponseServerError() return HttpResponseRedirect("/patient/" + str(patient.id)) else: # The page has just been entered and so the form hasn't # been submitted yet. form = NewPatientForm() return render_to_response('newPatient.html', {'form': form, 'viewer': request.user}, context_instance=RequestContext(request))
def create_new_patient_m(request): data = is_worker(request) if not data: json_response = json.dumps({"success": "false", "type": "notWorker"}) return HttpResponse(json_response, mimetype='application/json') form = NewPatientForm(data) if form.is_valid(): first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] gps_coordinates = form.cleaned_data['gps_coordinates'] address = form.cleaned_data['address'] date_of_birth = form.cleaned_data['date_of_birth'] phone_number = form.cleaned_data['phone_number'] health_id = form.cleaned_data['health_id'] photo_link = form.cleaned_data['photo_link'] sex = form.cleaned_data['sex'] email = form.cleaned_data['email'] try: patient = Patient( first_name=first_name, last_name=last_name, gps_coordinates=gps_coordinates, address=address, date_of_birth=date_of_birth, phone=phone_number, health_id=health_id, gender=sex, email=email, photo_link=photo_link) patient.save() except IntegrityError: json_response = json.dumps({"success": "false", "type": "IntegrityError"}) return HttpResponse(json_response, mimetype='application/json') json_response = json.dumps({"success": "true", "type": "newPatient", "patient_id": str(patient.id)}) return HttpResponse(json_response, mimetype='application/json') else: json_response = json.dumps({"success": "false", "type": "invalidForm"}) return HttpResponse(json_response, mimetype='application/json')