def appointment1(d='', d_id='', t=''): c = db.connection.cursor() data = c.execute("select * from doctor;") data = c.fetchall() dataa = c.execute( "select doc_id,time_slot,pat_id from appointment where date={}".format( int(d))) dataa = c.fetchall() form = AppointmentForm() if form.validate_on_submit() or (request.method == 'POST'): c.execute("select * from patient where id={};".format(form.p_id.data)) pdata = c.fetchall() if d_id == '' or t == '': flash('Please click the appropriate column') c.close() return redirect(url_for('appointment1', d=d)) elif form.p_id.data == '' or len(pdata) <= 0: flash('Please enter a valid patient id') c.close() return redirect(url_for('appointment1', d=d, d_id=d_id, t=t)) else: data = c.execute( "INSERT INTO appointment(doc_id, pat_id, date, time_slot) values({}, {}, {}, {})" .format(int(d_id), int(form.p_id.data), int(d), int(t))) db.connection.commit() c.close() flash('Appointment booked for {}'.format(form.p_id.data)) return redirect(url_for('home')) return render_template('appointment1.html', title='Appointments1', data=data, dataa=dataa, form=form, d=d)
def main(): form = AppointmentForm() params = { 'name': form.name.data, 'start_datetime': datetime.combine(form.start_date.data, form.start_time.data), 'end_datetime': datetime.combine(form.end_date.data, form.end_time.data), 'description': form.description.data, 'private': form.private.data } if form.validate(): print('am i in') with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as cursor: cursor.execute(''' INSERT INTO appointments(name, start_datetime, end_datetime, description, private) VALUES (%(name)s, %(start_datetime)s, %(end_datetime)s, %(description)s, %(private)s); ''', params # {'name': params.name,'start_datetime': params.start_datetime, 'end_datetime': params.end_datetime, 'description': params.description, 'private': params.private}, ) return redirect('/') with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as cursor: cursor.execute(''' SELECT id, name, start_datetime, end_datetime FROM appointments ORDER BY start_datetime ''' ) rows = cursor.fetchall() return render_template('main.html', rows=rows, form=form)
def daily(year, month, day): form = AppointmentForm() print(form.validate_on_submit()) if form.validate_on_submit(): print("submitted") with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as curs: params = { 'name': form.name.data, 'start_datetime': datetime.combine(form.start_date.data, form.start_time.data), 'end_datetime': datetime.combine(form.end_date.data, form.end_time.data), 'description': form.description.data, 'private': form.private.data } print(params) curs.execute(f''' INSERT INTO appointments (name, start_datetime, end_datetime, description, private) VALUES ('{params["name"]}', '{params["start_datetime"]}', '{params["end_datetime"]}', '{params["description"]}', {params["private"]}); ''') d = datetime.now() return redirect("/") with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as curs: curs.execute( "SELECT id, name, start_datetime, end_datetime FROM appointments ORDER BY start_datetime;" ) rows = curs.fetchall() return render_template('main.html', rows=rows, form=form)
def book(Did): app = Appointment(doctor_id=Did, patient_id=current_user.id) form = AppointmentForm(obj=app) if form.validate_on_submit(): appoint = Appointment(requested_date=form.date.data, doctor_id=form.doctor_id.data, patient_id=form.patient_id.data, status=0) db.session.add(appoint) db.session.commit() flash('Congratulations, your appointment is successfully booked!') return redirect(url_for('home')) return render_template('bookdoctor.html', form=form)
def appointment_edit(appointment_id): """Provide HTML form to edit a given appointment.""" appt = db.session.query(Appointment).get(appointment_id) if appt is None: abort(404) form = AppointmentForm(request.form, appt) if request.method == 'POST' and form.validate(): form.populate_obj(appt) db.session.commit() # Success. Send the user back to the detail view. return redirect(url_for('appointment_detail', appointment_id=appt.id)) return render_template('appointment/edit.html', form=form)
def appointment_create(): """Provide HTML form to create a new appointment.""" form = AppointmentForm(request.form) if request.method == 'POST' and form.validate(): appt = Appointment() form.populate_obj(appt) db.session.add(appt) db.session.commit() # Success. Send user back to full appointment list. return redirect(url_for('appointment_list')) # Either first load or validation error at this point. return render_template('appointment/edit.html', form=form)
def main(): form = AppointmentForm() if form.validate_on_submit(): with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as insert: sql = ''' INSERT INTO appointments (name, start_datetime, end_datetime, description, private) VALUES (%(name)s, %(start_datetime)s, %(end_datetime)s, %(description)s, %(private)s) ''' params = { 'name': form.name.data, 'start_datetime': datetime.combine(form.start_date.data, form.start_time.data), 'end_datetime': datetime.combine(form.end_date.data, form.end_time.data), 'description': form.description.data, 'private': form.private.data } insert.execute(sql, params) return redirect('/') with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as curs: curs.execute(''' SELECT id, name, start_datetime, end_datetime FROM appointments ORDER BY start_datetime; ''') rows = curs.fetchall() appointments = [] for row in rows: appointments.append({ 'id': row[0], 'name': row[1], 'start': row[2], 'end': row[3] }) return render_template('main.html', appointments=appointments, form=form)
def AddAppointment(request): if request.method == 'POST': form = AppointmentForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('payment') else: form = AppointmentForm() return render(request, 'app.html', {'form': form})
def index(): if current_user.is_administrator: return redirect( url_for('administrator', username=current_user.username)) form = AppointmentForm(datetime.now().date(), current_user.id) if form.validate_on_submit(): appointment = Appointment( address=current_user.address, date=datetime.strptime(form.date.data, "%Y-%m-%d").date(), time=timeslot[int(form.time.data)], comment=form.comment.data, applicant=current_user, fordog=Dog.query.filter_by(id=form.dog.data, user_id=current_user.id).first(), type=Service.query.filter_by(id=form.service.data).first()) db.session.add(appointment) db.session.commit() flash('Your appointment is already submitted!') return redirect(url_for('user', username=current_user.username)) return render_template('index.html', title='Home', form=form)
def main(): form = AppointmentForm() if form.validate_on_submit(): with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as curs: curs.execute( 'insert into appointments values (default, %(name)s, %(start_datetime)s, %(end_datetime)s, %(description)s, %(private)s)', { 'name': form.name.data, 'start_datetime': datetime.combine(form.start_date.data, form.start_time.data), 'end_datetime': datetime.combine(form.end_date.data, form.end_time.data), 'description': form.description.data, 'private': form.private.data }) return redirect("/") with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as curs: curs.execute( 'SELECT id, name, start_datetime, end_datetime FROM appointments ORDER BY start_datetime;' ) rows = curs.fetchall() # Create a psycopg2 connection with the connection parameters # Create a cursor from the connection # Execute "SELECT id, name, start_datetime, end_datetime # FROM appointments # ORDER BY start_datetime;" # Fetch all of the records return render_template("main.html", rows=rows, form=form)
def main(): form = AppointmentForm() if form.validate_on_submit(): req = dict(request.form) req['start_datetime'] = req['start_date'] + " " + req['start_time'] req['end_datetime'] = req['end_date'] + " " + req['end_time'] if not "private" in req: req["private"] = False with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as curs: curs.execute( '''INSERT INTO appointments (name, start_datetime, end_datetime, description, private) values (%(name)s, %(start_datetime)s, %(end_datetime)s, %(description)s, %(private)s);''', req) return redirect("/") with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as curs: curs.execute('''SELECT id, name, start_datetime, end_datetime FROM appointments ORDER BY start_datetime;''') result = curs.fetchall() return render_template('main.html', rows=result, form=form)
def post(self, request, *args, **kwargs): form = AppointmentForm(request.POST) if form.is_valid(): appointment_list = list( Appointment.objects.filter( datetime__gte=form.cleaned_data['datetime'] - datetime.timedelta(hours=1)).filter( datetime__lte=form.cleaned_data['datetime'] + datetime.timedelta(hours=1)).filter( doctor=form.cleaned_data['doctor'])) if appointment_list: messages.error(request, "Doctor is busy during this time.") return render(request, 'app/appointment/appointment.haml', {'form': form}) else: appointment = form.save(commit=False) patient = Patient.objects.get(user__id=request.user.id) appointment.patient = patient appointment.save() return HttpResponseRedirect( reverse('app:patient', args=(request.user.id, ))) else: return render(request, 'app/appointment/appointment.haml', {'form': form})
def post_appointment(id): form = AppointmentForm() data = request.get_json() # print("********************************* ", data["notes"]) new_appointment = Appointment(user_id=data["user_id"], chef_id=data["chef_id"], notes=form.data['notes'], date=datetime.datetime.strptime( data["date"], "%a, %d %b %Y %H:%M:%S %Z")) db.session.add(new_appointment) db.session.commit() return new_appointment.to_dict()
def Appointment(request): if request.method == "POST": form = AppointmentForm(request.POST, request.FILES) if form.is_valid(): form.save() messages.success( request, ' your Appointment book successfully!!! please wait for confirmations' ) return redirect("Appointment") else: form = AppointmentForm(request.FILES) return render(request, "bookappoitment.html", {"form": form})
def daily(year, month, day): form = AppointmentForm() if form.validate_on_submit(): with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as insert: sql = """ INSERT INTO appointments ( name, start_datetime, end_datetime, description, private ) VALUES ( %(name)s, %(start_datetime)s, %(end_datetime)s, %(description)s, %(private)s ) """ params = { 'name': form.name.data, 'start_datetime': round_time( datetime.combine( form.start_date.data, form.start_time.data, )), 'end_datetime': round_time( datetime.combine( form.end_date.data, form.end_time.data, )), 'description': form.description.data, 'private': form.private.data } insert.execute(sql, params) return redirect("/") with psycopg2.connect(**CONNECTION_PARAMETERS) as conn: with conn.cursor() as select: day = datetime(year, month, day) next_day = day + timedelta(days=1) sql = """ SELECT id, name, start_datetime, end_datetime FROM appointments WHERE start_datetime BETWEEN %(day)s AND %(next_day)s ORDER BY start_datetime """ select.execute(sql, {'day': day, 'next_day': next_day}) rows = select.fetchall() timeslots = [{ 'time': slot(day, slot_index, 8), 'open': True } for slot_index in range(12 * 4)] overriden = 0 for timeslot in timeslots: for id, name, start, end in rows: if start == timeslot['time']: timeslot['appointment'] = { 'units': int((end - start).seconds / 60 // 15), 'name': name, } overriden = timeslot['appointment']['units'] if overriden > 0: overriden -= 1 timeslot['open'] = False from pprint import pprint pprint(rows) return render_template("main.html", day=day, timeslots=timeslots, form=form)
def get(self, request, *args, **kwargs): form = AppointmentForm() return render(request, 'app/appointment/appointment.haml', {'form': form})