В настоящее время я планирую встречу.Я хочу выполнить заявление «если», если врач доступен в выбранное время и дату.В настоящее время у меня есть следующий код:
def book():
form = BookAppointment(request.form)
if request.method == 'POST' and form.validate():
appointment_date = form.appointment_date.data
appointment_time = form.appointment_time.data
appointment_patient_id = form.appointment_patient_id.data
appointment_doctor_id = form.appointment_doctor_id.data
appointment_centre_id = form.appointment_centre_id.data
username = session.get('username', None)
# Create cursor
cur = mysql.connection.cursor()
find_doctor = cur.execute("SELECT * FROM doctors WHERE doctor_id =%s", [appointment_doctor_id])
find_date = cur.execute("SELECT * FROM appointments WHERE appointment_date =%s", [appointment_date])
find_time = cur.execute("SELECT * FROM appointments WHERE appointment_time =%s", [appointment_time])
msg = cur.fetchone()
# Execute query
cur.execute("INSERT INTO appointments(appointment_date, appointment_time, patient_id, doctor_id, centre_id, patient_username) VALUES(%s, %s, %s, %s, %s, %s)", (appointment_date, appointment_time, appointment_patient_id, appointment_doctor_id, appointment_centre_id, username))
if find_doctor == 0 and find_date == 0 and find_time == 0:
if appointment_date.weekday() == 0 or appointment_date.weekday() == 1 or appointment_date.weekday() == 2 or appointment_date.weekday() == 3 or appointment_date.weekday() == 4:
# Commit to DB
mysql.connection.commit()
# Close connection
cur.close()
flash('Appointment made successfully!', 'success')
return redirect(url_for('book'))
else:
error = 'Sorry, appointments cannot be made for a Saturday/Sunday'
return render_template('/patient/bookappointment.html', error=error, form=form)
else:
flash('Appointment unavailable, please select another date or time', 'danger')
return redirect(url_for('book'))
return render_template('/patient/bookappointment.html', form=form)
Поэтому я хочу назначить встречу, если в настоящее время не назначена встреча с тем же врачом на ту же дату и время.Спасибо