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/',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/') #预约挂号 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('//') #预约挂号/具体日期 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('///