def post(self, request): titlePk = request.POST.get("Title", "") firstName = request.POST.get('FirstName', '') lastName = request.POST.get('LastName', '') default_time_exam = request.POST.get('DefaultExampTime', 20) #Make some checks title = Title.objects.get(pk=titlePk) doctor = Doctor(title=title, first_name=firstName, last_name=lastName, default_exam_time=default_time_exam) doctor.save() return redirect(doctors)
def doctor_registration(token): if current_user.is_authenticated: return redirect(url_for('main.index')) doctor = Doctor.verify_registration_token(token) if not doctor or doctor.password_hash: return redirect(url_for('main.index')) form = DoctorRegistrationForm(doctor.email) if form.validate_on_submit(): doctor.username = form.username.data doctor.email = form.email.data doctor.first_name = form.first_name.data doctor.second_name = form.second_name.data doctor.set_password(form.password.data) if not os.path.exists('uploads/{}'.format(doctor.username)): os.mkdir('uploads/{}'.format(doctor.username)) doctor.uploads_path = os.path.join(current_app.config['UPLOAD_PATH'], doctor.username) db.session.commit() if not os.path.exists('uploads/{}'.format(doctor.username)): os.mkdir('uploads/{}'.format(doctor.username)) flash('Поздравляем с регистрацией!') return redirect(url_for('auth.login')) elif request.method == 'GET': form.email.data = doctor.email return render_template('auth/register.html', title='Регистрация доктора', form=form)
def register(): name = Admins.query.filter(Admins.name == session.get('username')).first() if name: form = RegisterdocForm() if form.validate_on_submit(): # 根据表单数据创建User对象 u = Doctor( name=form.name.data, password=form.password.data, age=form.age.data, tel=form.tel.data, intr=form.intr.data, dirc=form.dirc.data, addr=form.addr.data, # identify=1, ) # 然后保存到数据库中 db.session.add(u) # 此时还没有提交,所以新用户没有id值,需要手动提交 db.session.commit() # 准备token # 发送激活邮件 # token = u.generate_activate_token() # url = url_for('user.activate', token=token, _external=True) # send_mail(form.email.data, '账户激活', 'activate', username=form.username.data, url=url) flash('医生已注册') return redirect(url_for('admin.index')) return render_template('admin/register.html', form=form) else: flash('请到对应页面登录') session.pop('username', None) return redirect(url_for('main.index'))
def post(self, request, *args, **kwargs): form = SignUpForm(request.POST) if form.is_valid(): user = User() user.password = make_password(form.cleaned_data['password']) user.username = form.cleaned_data['username'] user.first_name = form.cleaned_data['first_name'] user.last_name = form.cleaned_data['last_name'] user.email = form.cleaned_data['email'] user.save() doctor = Doctor(user=user) doctor.save() return HttpResponseRedirect(reverse('app:login')) else: return render(request, 'app/doctor/doctor_signup.haml', {'form': form})
def signUpDoctor(current_user): if current_user.account_verified == 0: return make_response('Forbidden: First confirm your account', 403) if current_user.rol != 2: return make_response('Forbidden: Access is denied', 403) hospital = Hospital.query\ .filter_by(id_user = current_user.id)\ .first() data = request.json #USER TABLE INFORMATION TO INSERT num_doc = data['num_doc'] email = data['email'] password = data['password'] telphone = data['telphone'] uuidunique = uuid.uuid4() account_verified = 1 rol = 3 new_user = User( num_doc, email, telphone, generate_password_hash(password, method='sha256'), uuidunique, account_verified, rol) # GO INSERT USER db.session.add(new_user) db.session.commit() hospital = Hospital.query\ .filter_by(id_user = current_user.id)\ .first() print(hospital) #FIND NEW USER user = User.query\ .filter_by(num_doc = num_doc)\ .first() #DOCTOR TABLE INFORMATION TO INSERT name = data['name'] address = data['address'] password_changed = 0 id_medicalspecialty = data['id_medicalspecialty'] birthdate = datetime.strptime(data['birthdate'], '%d/%m/%y') id_user = user.id id_hospital = hospital.id if not data or not name or not address or not id_medicalspecialty or not birthdate: return make_response('Doctor information incomplete', 422) new_doctor = Doctor(name, address, birthdate, password_changed, id_medicalspecialty, id_user, id_hospital) db.session.add(new_doctor) db.session.commit() return jsonify({'message' : 'Doctor registered and verified successfully'}), 201
def register(choice): if current_user.is_authenticated: return redirect(url_for('home')) idd = token_hex(16) if(choice=='doctor'): idd = 'D'+idd form = DoctorRegister() if form.validate_on_submit(): user = Doctor(id = idd, full_name=form.name.data, email=form.email.data, city=form.city.data, phone=form.phone.data, address=form.address.data, qual=form.qual.data, fees=form.fees.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) else: idd = 'P'+idd form = PatientRegister() if form.validate_on_submit(): user = Patient(id=idd, full_name=form.name.data, email=form.email.data, city=form.city.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) return render_template('register.html', choice=choice, form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = RegistrationForm() if form.validate_on_submit(): try: doc = Doctor(name=form.name.data, email=form.email.data, registration_number=form.registration_number.data) db.session.add(doc) doc.set_password(form.password.data) db.session.commit() flash('Congratulations, you have succesfully registered.') return redirect(url_for('auth.login')) except Exception as e: flash('Error registering: ' + str(e)) return redirect(url_for('auth.register')) return render_template('auth/register.html', title='Register', form=form)
def add_or_get_doctor(): """ POST: Add a doctor to the database given the name GET: List all doctors and their reviews :return: a json object of the post or get request """ if request.method == "POST": try: # Create a doctor obj by accessing the json found in the request name = request.json['doctor']['name'] new_doctor = Doctor(name=name) doctor_dict = dict() doctor_dict['id'] = new_doctor.id doctor_dict['name'] = new_doctor.name # Add the doctor and commit it to the database db.session.add(new_doctor) db.session.commit() return jsonify({'Added': doctor_dict}) except ProgrammingError: return 'Tried Posting information when the db was no created' elif request.method == "GET": try: # List all the doctors results = dict() # all doctors all_doctors = Doctor.query.all() for doctor in all_doctors: doctor_dict = dict() doctor_dict['name'] = doctor.name doctor_dict['id'] = doctor.id doctor_dict['reviews'] = [] results[doctor.id] = doctor_dict # all reviews all_reviews = Review.query.all() for review in all_reviews: review_dict = dict() review_dict['id'] = review.id review_dict['doctor_id'] = review.doctor_id review_dict['description'] = review.description for doctor_json in results: if review.doctor_id == results[doctor_json]['id']: results[doctor_json]['reviews'].append(review_dict) return jsonify(results) except ProgrammingError: return 'Error: Tried retrieving information when the db was not created'
def docregister(): if current_user.is_authenticated: return redirect(url_for('home')) form = DocRegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') doctor = Doctor(fullname=form.fullname.data, email=form.email.data, tel=form.tel.data, password=hashed_password) db.session.add(doctor) db.session.commit() flash('Your account has been created! You can now log in', 'success') return redirect(url_for('doclogin')) return render_template('docregister.html', title='Register', form=form)
def reset_password(token): if current_user.is_authenticated: return redirect(url_for('main.index')) doc = Doctor.verify_reset_password_token(token) if not doc: return redirect(url_for('main.index')) form = ResetPasswordForm() if form.validate_on_submit(): doc.set_password(form.password.data) db.session.commit() flash('Your password has been reset') return redirect(url_for('auth.login')) return render_template('auth/reset_password.html', form=form)
def test_patient_has_doctor(self): d1 = Doctor(name = 'Stefan') d2 = Doctor(name = 'Dan') p1 = Patient(first_name = 'Kelsey') p2 = Patient(first_name = 'Josh') db.session.add_all([d1, d2, p1, p2]) db.session.commit() self.assertEqual(p1.doctors.all(), []) self.assertEqual(p2.doctors.all(), []) p1.add_doctor(d1) db.session.commit() self.assertTrue(p1.has_doctor(d1)) self.assertEqual(p1.doctors.count(), 1) self.assertEqual(p1.doctors.first().name, 'Stefan') self.assertFalse(p2.has_doctor(d1)) self.assertEqual(p2.doctors.count(), 0) p1.add_doctor(d2) db.session.commit() doctors = p1.get_all_doctors().all() self.assertEqual(doctors, [d1, d2]) p1.remove_doctor(d1) db.session.commit() self.assertFalse(p1.has_doctor(d1)) self.assertTrue(p1.has_doctor(d2)) self.assertEqual(p1.doctors.count(), 1) p1.remove_doctor(d2) db.session.commit() self.assertFalse(p1.has_doctor(d2)) self.assertEqual(p1.doctors.count(), 0)
def add_doctor(): # if current_user.is_authenticated: # return redirect(url_for('main.index')) form = AddDoctorForm() if form.validate_on_submit(): doctor = Doctor( first_name=form.first_name.data, second_name=form.second_name.data, phone_number=form.phone_number.data, patronymic=form.patronymic.data, ) db.session.add(doctor) db.session.commit() flash('Новый доктор добавлен') return redirect(url_for('patasys.index')) return render_template('patasys/add_doctor.html', title='Add doctor', form=form)
def register_doctor(): company = Company.query.filter_by(id=current_user.id).first() if company.doctor: return redirect(url_for('main.company', username=current_user.username)) form = RegisterDoctorForm() if form.validate_on_submit(): doctor = Doctor(email=form.email.data, company_id=current_user.id, role='doctor') db.session.add(doctor) db.session.commit() send_doctor_registration_email(doctor, company) flash('Письмо отправлено на почту доктору') return redirect(url_for('main.company', username=current_user.username)) return render_template('auth/register_doctor.html', title='Зарегистрировать доктора', form=form)
def newDoc(): form = newDoctor() if form.validate_on_submit(): clinicData = form.clinic.data #split serial from name by underscore seperator clinicData = clinicData.split('__') doctor = Doctor(clinicName=clinicData[0], clinicSerialNum=clinicData[1], first=form.first.data, middle=form.middle.data, last=form.last.data, phone=form.phone.data, email=form.email.data, note=form.note.data, doctorSerialNum=randomStringDigits(8)) db.session.add(doctor) db.session.commit() flash('Added doctor to database') return redirect(url_for('newDoc')) return render_template('doctorForm.html', title='New Doctor', form=form, entry='')
def test_query_circle(): docot_obj = Doctor.objects().first() print(docot_obj.name) circle = SocialCircle.objects(doctor=docot_obj).first() print(circle.circle_name) print(circle.doctor.name)
def test_doctor_has_patient(self): d1 = Doctor(name = 'Gabi') d2 = Doctor(name = 'Dan') p1 = Patient(first_name = 'Josh', age = 22) p2 = Patient(first_name = 'Kelsey', age = 27) db.session.add_all([d1, d2, p1, p2]) db.session.commit() self.assertEqual(d1.patients.all(), []) self.assertEqual(d2.patients.all(), []) d1.add_patient(p1) db.session.commit() self.assertTrue(d1.has_patient(p1)) self.assertEqual(d1.patients.count(), 1) self.assertEqual(d1.patients.first().first_name, 'Josh') self.assertFalse(d2.has_patient(p1)) self.assertEqual(d2.patients.count(), 0) d1.add_patient(p2) db.session.commit() patients = d1.get_all_patients().all() self.assertEqual(patients, [p1, p2]) d1.remove_patient(p1) db.session.commit() self.assertFalse(d1.has_patient(p1)) self.assertTrue(d1.has_patient(p2)) self.assertEqual(d1.patients.count(), 1) d1.remove_patient(p2) db.session.commit() self.assertFalse(d1.has_patient(p2)) self.assertEqual(d1.patients.count(), 0)
def test_password_hashing(self): d = Doctor(name = 'Dan') d.set_password('foo') self.assertFalse(d.check_password('bar')) self.assertTrue(d.check_password('foo'))
def newreport(): form = NewReportForm() if form.validate_on_submit(): #See if the medication is in db yet med_options = form.med_id.data.split(",") for med_id in med_options: if not Medication.query.get(med_id) and med_id: print("didn't see this med, adding") m = Medication(report_id=form.report_id.data, med_id=med_id) db.session.add(m) db.session.commit() print("added meds: ", Medication.query.get(med_id)) #DOCTOR CHECK #NEED TO CREATE DOCTOR W/ GIVEN INFO if not Doctor.query.get( form.doc_id.data ) and form.doc_name.data and form.doc_address.data: print("didn't see this doc, adding") d = Doctor(doc_id=form.doc_id.data, doc_name=form.doc_name.data, address=form.doc_address.data) db.session.add(d) db.session.commit() print("added doc: ", Doctor.query.get(form.doc_id.data)) #IF DOC GIVEN BUT NEW ADDY: Create HOP and DEPO if not Hospital.query.get( form.doc_address.data) and form.hospital_name.data: print("didn't see this hospital, adding") h = Hospital(hospital_name=form.hospital_name.data, address=form.doc_address.data) db.session.add(h) dep = Department(address=form.doc_address.data, department_name=form.department_name.data) db.session.add(dep) db.session.commit() print("add hop :", Hospital.query.get(form.doc_address.data)) #BUT IF HOP and DEPO INFO not available elif not Hospital.query.get(form.doc_address.data): return render_template( 'newreport.html', title='New Report', form=form, error="New Hospital Detected: Please Include All Info") #THIS SHOULD BE IF WE HAVE HOSPITAL INFO if not Department.query.get( form.doc_address.data) and form.department_name.data: print("didn't see this department, adding") dep = Department(address=form.doc_address.data, department_name=form.department_name.data) db.session.add(dep) db.session.commit() print("add depo :", Hospital.query.get(form.doc_address.data)) elif not Department.query.get(form.doc_address.data): return render_template( 'newreport.html', title='New Report', form=form, error="New Department Detected: Please Include All Info") elif not Doctor.query.get(form.doc_id.data): return render_template( 'newreport.html', title='New Report', form=form, error="New Doctor Detected: Please Include All Info") #See if the hopsital exists if (not Doctor.query.get(form.doc_id.data) and not Hospital.query.get(form.doc_address.data) ) and form.hospital_name.data and form.doc_address.data: print("didn't see this hospital, adding") h = Hospital(hospital_name=form.hospital_name.data, address=form.doc_address.data) db.session.add(h) db.session.commit() print("added hospital: ", Hospital.query.get(form.doc_address.data)) elif not Hospital.query.get( form.doc_address.data) and not Doctor.query.get( form.doc_id.data): return render_template( 'newreport.html', title='New Report', form=form, error="New Hospital Detected: Please Include All Info") #See if the department exists if (not Doctor.query.get(form.doc_id.data) and not Department.query.get(form.doc_address.data) ) and form.doc_address.data and form.department_name.data: print("didn't see this department, adding") d = Department(address=form.doc_address.data, department_name=form.department_name.data) db.session.add(d) db.session.commit() print("added department: ", Department.query.get(form.doc_address.data)) elif (not Doctor.query.get(form.doc_id.data) and not Department.query.get(form.doc_address.data)): return render_template( 'newreport.html', title='New Report', form=form, error="New Department Detected: Please Include All Info") #Add report to the db if Report.query.get(form.report_id.data): return render_template('newreport.html', title='New Report', form=form, error="Duplicated Report ID") r = Report( report_id=form.report_id.data, ssn=form.ssn.data, doc_id=form.doc_id.data, med_id=form.med_id.data, purpose=form.purpose.data, patient_info=form.patient_info.data, ) db.session.add(r) db.session.commit() print( "Added: ", form.report_id.data, form.ssn.data, form.doc_id.data, form.med_id.data, form.purpose.data, form.patient_info.data, ) return render_template('index.html', create="Report", form=form) return render_template('newreport.html', title='NewReport', form=form)
def make_data(): clinic1 = Clinic(clinicSerialNum='123', company='test Clinic 1', nickname='Nickname 1', street='Main St', city='Example City', state='Example State', zip='00000', phone='100-800-9320', email='*****@*****.**', note='this is a note') clinic2 = Clinic(clinicSerialNum='456', company='test Clinic 2', nickname='Nickname 2', street='Main St 2', city='Example City 2', state='Example State 2', zip='22222', phone='200-800-9320', email='*****@*****.**', note='this is a note') db.session.add(clinic1) db.session.add(clinic2) doctor1 = Doctor(doctorSerialNum='789', first='Test', middle='M', last='Doctor1', cell='900-600-4000', phone='900-600-4000', email='*****@*****.**', note='this is a doc note', salutation='salutation', clinicName='Clinic 1', clinicSerialNum='123') doctor2 = Doctor(doctorSerialNum='1011', first='Test2', middle='M', last='Doctor2', cell='200-600-4000', phone='900-600-4000', email='*****@*****.**', note='this is a doc note 2', salutation='salutation 2', clinicName='Clinic 2', clinicSerialNum='456') db.session.add(doctor1) db.session.add(doctor2) service1 = MiscService(serviceID='1213', serviceType='Type 1', serviceAbbr='Abbr 1', reportType='reportType1', description='description 1', servicePrice=100) service2 = MiscService(serviceID='1415', serviceType='Type 2', serviceAbbr='Abbr 2', reportType='reportType2', description='description 2', servicePrice=200) db.session.add(service1) db.session.add(service2) db.session.commit()
def init_doctor_data(): client = MongoClient('mongodb://localhost:27017/') db = client['development_mongodb'] disease_list = ['糖尿病', '痛风/高尿酸血症', '甲状腺疾病', '骨代谢性疾病', '其他内分泌疾病'] age_group_list = [ '小于18岁', '18-30岁', '31-35岁', '41-45岁', '46-50岁', '51-55岁', '56-60岁', '60岁以上' ] doctor_office_list = ['糖尿病科', '内分泌科', '风湿科', '甲乳外科', '甲状腺外科', '综合内科', '全科'] doctor_title_list = ['住院医师', '主治医师', '副主任医师', '主任医师'] hospital_list = loadHospital() date_list = getEveryDay() doctor_index = 0 while (doctor_index < 1000): doctor = Doctor() doctor.name = getRandomName() doctor.age_group = random.choice(age_group_list) doctor.disease_list = random.sample( disease_list, random.choice(range(1, len(disease_list), 1))) doctor.doctor_office = random.choice(doctor_office_list) doctor.doctor_title = random.choice(doctor_title_list) doctor.phone = str(random.randrange(18800000001, 18899999999, 1)) # register_day now_date = datetime.datetime.strptime(random.choice(date_list), "%Y-%m-%d") doctor.register_year = now_date.year doctor.register_month = now_date.month doctor.register_day = now_date.day # hospital_info hospital = random.choice(hospital_list) #print(hospital)#test output doctor.hospital_name = hospital[0] doctor.hospital_level = hospital[1] doctor.province = hospital[2] doctor.city = hospital[3] doctor.longitude = float(hospital[4]) doctor.latitude = float(hospital[5]) doctor_json = { 'doctor_name': doctor.name, 'age_group': doctor.age_group, 'disease_list': doctor.disease_list, 'doctor_office': doctor.doctor_office, 'doctor_title': doctor.doctor_title, 'phone': doctor.phone, '': doctor.register_year, '': doctor.register_month, '': doctor.register_day, 'hospital_name': doctor.hospital_name, 'hospital_level': doctor.hospital_level, 'province': doctor.province, 'city': doctor.city, 'longitude': doctor.longitude, 'latitude': doctor.latitude } db.doctors.insert_one(doctor_json) doctor_index += 1
def verify_token(token): g.current_user = Doctor.check_token(token) if token else None return g.current_user is not None
def load_doctor(): docot_list = Doctor.objects().all() return docot_list
def api_add_user(): """Add new user Will receive data like this { "email": "*****@*****.**", "date_of_birth": "1999-06-18", "role": "patient" or "doctor" "super_admin" "password": "******", "full_name": "Farhad Hossain", "address": "Stadium para, Maijdee court", "contact_no": "01983495680", "age": 21, "profile_pic": "base64 encoded image string" } """ data = request.get_json() username = secrets.token_hex(8) email = data['email'].lower() password = bcrypt.generate_password_hash(data['password']).decode('utf-8') date_of_birth = data['date_of_birth'] if 'role' not in data: role = 'patient' else: role = data['role'] full_name = data['full_name'] address = data['address'] contact_no = data['contact_no'] age = data['age'] if 'profile_pic' in data: profile_pic = data['profile_pic'] imgdata = base64.b64decode(profile_pic.split(',')[1]) filename = save_picture(img=imgdata, folder="profile_pics") # check if email already exists user = User.query.filter_by(email=email).first() if user: return jsonify({"message": "user exists"}), 403 user = User(username=username, email=email, password=password, date_of_birth=date_of_birth, role=role) db.session.add(user) db.session.commit() if role == "patient": # now add the patient infos if 'profile_pic' in data: # now add the patient infos patient = Patient(full_name=full_name, address=address, contact_no=contact_no, age=age, profile_pic=filename, user_id=user.id) else: patient = Patient(full_name=full_name, address=address, contact_no=contact_no, age=age, user_id=user.id) db.session.add(patient) db.session.commit() elif role == "doctor": # now add the doctor infos if 'profile_pic' in data: # now add the patient infos doctor = Doctor(full_name=full_name, address=address, contact_no=contact_no, age=age, profile_pic=filename, user_id=user.id) else: doctor = Doctor(full_name=full_name, address=address, contact_no=contact_no, age=age, user_id=user.id) db.session.add(doctor) db.session.commit() elif role == "super_admin": # now add the super_admin infos if 'profile_pic' in data: # now add the patient infos super_admin = SuperAdmin(full_name=full_name, address=address, contact_no=contact_no, age=age, profile_pic=filename, user_id=user.id) else: super_admin = SuperAdmin(full_name=full_name, address=address, contact_no=contact_no, age=age, user_id=user.id) db.session.add(super_admin) db.session.commit() else: return jsonify({"message": "invalid role"}), 403 return jsonify({"message": "success"}), 201
def init_doctor_data(): hospital_list = loadHospital() date_list = getEveryDay() doctor_index = 0 while (doctor_index < 1000): doctor = Doctor() doctor.name = getRandomName() doctor.age_group = random.choice(age_group_list) doctor.disease_list = random.sample( disease_list, random.choice(range(1, len(disease_list), 1))) doctor.doctor_office = random.choice(doctor_office_list) doctor.doctor_title = random.choice(doctor_title_list) doctor.phone = str(random.randrange(18800000001, 18899999999, 1)) # register_day now_date = datetime.datetime.strptime(random.choice(date_list), "%Y-%m-%d") doctor.register_year = now_date.year doctor.register_month = now_date.month doctor.register_day = now_date.day # hospital_info hospital = random.choice(hospital_list) # print(hospital)#test output doctor.hospital_name = hospital[0] doctor.hospital_level = hospital[1] doctor.province = hospital[2] doctor.city = hospital[3] doctor.longitude = float(hospital[4]) doctor.latitude = float(hospital[5]) doctor.save() doctor_index += 1