Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 8
0
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)