def register(request): # If there's a user logged in, require them to log out if request.user.is_authenticated(): return redirect('manual_logout') # If it's post, the user has sent us their info and we need to try to set them up if request.method == 'POST': success = False user_form = UserForm(data=request.POST) if user_form.is_valid(): # Save the user and associate it with a new Doctor user = user_form.save() user.set_password(user.password) user.save() doctor = Doctor() doctor.user = user doctor.save() success = True # Registration done, let's get out of here. # (note: I'm not actually sure whether it'd be more appropriate to # have a new view for the result and redirect to it. That sort of thing # seems common, but this seems simpler) return render(request, 'registration_report.html', {'success': success, 'user_form': user_form}) # Otherwise we diplay the form for them to fill out and post to us else: return render(request, 'register.html', {'user_form': UserForm()})
def add_human(): name = request.form.get("doctor_name") surname = request.form.get("doctor_surname") tc = request.form.get("doctor_tc") password = request.form.get("doctor_password") email = request.form.get("doctor_email") authorize = request.form.get("authorize_select") city = request.form.get("city_select_add") district = request.form.get("district_select_add") address = Place(city=city, district=district).get_objects()[0] human = Human(tc=tc).get_object() if human is None: human = Human(tc=tc, password=password, authorize=authorize, name=name, surname=surname, mail=email, address=address) human.save() if authorize == 'doctor': workdays = str() day_list = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] for i, day in enumerate(day_list): if request.form.get(day) == "on": workdays += str(i + 1) expertise = request.form.get("doctor_expertise") hospital_id = request.form.get("hospital_select_add") hospital = Hospital(id=hospital_id).get_object() doctor = Doctor(human=human).get_object() if doctor is None: doctor = Doctor(human=human, workdays=workdays, expertise=expertise, hospital=hospital) doctor.save() # else doctor is already created return redirect(url_for(views.admin_humans_page.__name__))
def register(request): if request.session.get('patient_mode'): return redirect('kiosk') # If there's a user logged in, require them to log out if request.user.is_authenticated(): return redirect('manual_logout') # If it's post, the user has sent us their info and we need to try to set them up if request.method == 'POST': success = False user_form = UserForm(data=request.POST) if user_form.is_valid(): # Save the user and associate it with a new Doctor user = user_form.save() user.set_password(user.password) user.save() doctor = Doctor() doctor.user = user doctor.save() success = True # Registration done, let's get out of here. # (note: I'm not actually sure whether it'd be more appropriate to # have a new view for the result and redirect to it. That sort of thing # seems common, but this seems simpler) return render(request, 'registration_report.html', { 'success': success, 'user_form': user_form }) # Otherwise we diplay the form for them to fill out and post to us else: return render(request, 'register.html', {'user_form': UserForm()})
def signup(request): """ Sign Up Page, uses built in Sign-Up """ if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') name = form.cleaned_data.get('name') category = form.cleaned_data.get('category') user = authenticate(username=username, password=raw_password) if category == "doctor": doctor = Doctor(user=user, name=name) doctor.save() if category == "pharmacist": pharmacist = Pharmacist(user=user, name=name) pharmacist.save() if category == "patient": patient = Patient(user=user, name=name) patient.save() login(request, user) return redirect('/pharm/profile') else: form = SignUpForm() return render(request, 'pharmeasyflow/signup.html', {'form': form})
def post(self): response = Doctor.objects.filter( email=request.form['email']).count() if response == 0: doctor = Doctor() for key in request.form: doctor[str(key)] = request.form[str(key)] print doctor.first_name body = {} if request.form.has_key('email'): body['email'] = request.form['email'] if request.form.has_key('area'): body['area'] = request.form['area'] if request.form.has_key('city'): body['city'] = request.form['city'] if request.form.has_key('specialization'): doctor.specialization = [] doctor.specialization.append( request.form['specialization']) body['specialization'] = request.form['specialization'] if request.form.has_key('education'): doctor.education = [] doctor.education.append(request.form['education']) doctor.save() es.create( index='test', doc_type='doctor', id=doctor.id, body=body) return jsonify(status=True) return jsonify(status=False)
def register_doc(request, doc_id): filter = {'id': doc_id} data = data_from_url(request, 'https://drchrono.com/api/doctors', filter)[0] doc = Doctor() doc.first_name = data['first_name'] doc.last_name = data['last_name'] doc.doctor_id = doc_id doc.total_wait_time = 0 doc.total_patients = 0 doc.save()
def save_user(doctor_data): user = User.objects.create_user( id=doctor_data['id'], username=doctor_data['username'], ) doctor = Doctor( first_name=doctor_data['first_name'], last_name=doctor_data['last_name'], user=user, ) if Doctor.objects.filter(pk=user).exists(): doctor.save(update_fields=['first_name', 'last_name']) else: doctor.save() return user
def save_user(doctor, access_token): """ :param doctor: :param access_token: :return: saved user and doctor objects which can be used for performing operations """ user = User.objects.create_user( id=doctor['id'], username=doctor['username'], ) doctor = Doctor( first_name=doctor['first_name'], last_name=doctor['last_name'], user=user, token=access_token, ) if Doctor.objects.filter(pk=user).exists(): doctor.save(update_fields=['first_name', 'last_name']) else: doctor.save() return doctor, user