82 lines
4.5 KiB
Python
82 lines
4.5 KiB
Python
from datetime import datetime, date
|
|
from flask import render_template, request, url_for, session, flash
|
|
from werkzeug.utils import redirect
|
|
|
|
from flask_app.decorators import permission_required
|
|
from . import appointment
|
|
from .. import db
|
|
from .forms import PatientForm
|
|
from flask_login import current_user
|
|
from ..models import User, DocComment, Workday, Appointment, Permission
|
|
|
|
|
|
@appointment.route('/doctor_info/<int:docid>',methods=['GET','POST']) #咨询医生页
|
|
def doctor_info(docid):
|
|
session['next'] = request.url # 将当前URL保存到session中
|
|
doctor = User.query.filter_by(id=docid).first()
|
|
comments=DocComment.query.filter_by(doc_id=docid).all()
|
|
authors = [User.query.get(comment.author_id) for comment in comments]
|
|
comment_pairs = zip(comments, authors)
|
|
empty_comments = (len(comments) == 0)
|
|
return render_template('appointment/doctor_info.html', doctor=doctor,empty_comments=empty_comments,comment_pairs=comment_pairs)
|
|
@appointment.route('/search_res')
|
|
def search_res():
|
|
stars = [4.50, 3.9, 4.30, 4, 3.5]
|
|
counts = [155, 56, 100, 80, 56]
|
|
session['next'] = request.url # 将当前URL保存到session中
|
|
active_page = "date"
|
|
q = request.args.get('q', '')
|
|
doctors = User.query.filter_by(role_id=1).filter(User.name.ilike('%' + q + '%')).all()
|
|
return render_template('main/date.html', active_page=active_page, doctors=doctors,stars=stars,counts=counts)
|
|
|
|
@appointment.route('/book_date/<int:chosen_docid>') #预约挂号
|
|
def book_date(chosen_docid):
|
|
session['next'] = request.url # 将当前URL保存到session中
|
|
doctor=User.query.filter_by(id=chosen_docid).first()
|
|
today = date.today()
|
|
workdays = Workday.query.filter(Workday.doc_id == chosen_docid, Workday.date >= today).order_by(Workday.date).limit(6).all()
|
|
return render_template('appointment/book_date.html',doctor=doctor,active_date="0",workdays=workdays,actworkdays=workdays)
|
|
|
|
@appointment.route('/<int:chosen_docid>/<formatted_date>') #预约挂号/具体日期
|
|
def book_appointment(chosen_docid,formatted_date):
|
|
session['next'] = request.url # 将当前URL保存到session中
|
|
doctor=User.query.filter_by(id=chosen_docid).first()
|
|
today = date.today()
|
|
workdays = Workday.query.filter(Workday.doc_id == chosen_docid, Workday.date >= today).order_by(Workday.date).limit(6).all()
|
|
date_obj = datetime.strptime(formatted_date, '%Y-%m-%d').date()
|
|
workday=Workday.query.filter_by(doc_id=chosen_docid,date=date_obj).all()
|
|
return render_template('appointment/book_date.html', doctor=doctor,active_date=formatted_date,workdays=workdays,actworkdays=workday)
|
|
|
|
|
|
@appointment.route('/<int:chosen_docid>/<formatted_date>/<time>',methods=['GET','POST']) #申请挂号
|
|
@permission_required(Permission.COMMENT)
|
|
def submit_date(chosen_docid,formatted_date,time):
|
|
session['next'] = request.url # 将当前URL保存到session中
|
|
doctor = User.query.filter_by(id=chosen_docid).first()
|
|
date_obj = datetime.strptime(formatted_date, '%Y-%m-%d').date()
|
|
dateday=Workday.query.filter_by(doc_id=chosen_docid,date=date_obj).first()
|
|
form = PatientForm()
|
|
appointment = Appointment.query.filter_by(patient_id=current_user.id, doc_id=chosen_docid, date=formatted_date,
|
|
time=time).first()
|
|
if(appointment):
|
|
flash("您已经预约过了")
|
|
return render_template('appointment/submit_date.html',form=form,doctor=doctor,dateday=dateday,time=time)
|
|
else:
|
|
if request.method == 'POST' and form.validate_on_submit():
|
|
if(time=="0"):
|
|
num=dateday.afternoon_num-dateday.temp_afternoon+1
|
|
dateday.temp_afternoon-=1
|
|
else:
|
|
num = dateday.morning_num - dateday.temp_morning + 1
|
|
dateday.temp_morning -= 1
|
|
appointment = Appointment(cost=dateday.cost,patient_id=current_user.id, doc_id=chosen_docid, date=date_obj,time=int(time),email=form.email.data,
|
|
name=form.name.data, id_number=form.id_number.data, location=form.location.data, gender=form.gender.data,
|
|
phone=form.phone.data, age=form.age.data,num=num)
|
|
db.session.add(dateday)
|
|
db.session.add(appointment)
|
|
db.session.commit()
|
|
flash("你已成功预约!")
|
|
return redirect(url_for('appointment.book_date',chosen_docid=doctor.id))
|
|
return render_template('appointment/submit_date.html',form=form,doctor=doctor,dateday=dateday,time=time)
|
|
|