Ejemplo n.º 1
0
    def doctor_selected_appointment(title, start):

        if title == 'Walk_in':
            walk_in = True
        else:
            walk_in = False

        selected_datetime = Tools.convert_to_python_datetime(start)
        selected_date = Tools.get_date_iso_format(selected_datetime)
        selected_time = Tools.get_time_iso_format(selected_datetime)

        user_type = 'doctor'
        doctor = mediator.get_doctor_by_id(session['id'])
        selected_appointment = doctor.appointment_dict[selected_datetime]
        clinic = selected_appointment.clinic
        room = selected_appointment.room.name
        patient = selected_appointment.patient

        return render_template('doctor_appointment_details.html',
                               clinic=clinic,
                               room=room,
                               walk_in=walk_in,
                               date=selected_date,
                               time=selected_time,
                               datetime=str(selected_datetime),
                               user_type=user_type,
                               patient=patient)
Ejemplo n.º 2
0
    def selected_appointment(start):
        clinic = mediator.get_clinic_by_id(session['selected_clinic'])
        if not session['has_selected_walk_in']:
            appointment_type = "Annual"
        else:
            appointment_type = "Walk-in"

        selected_datetime = Tools.convert_to_python_datetime(start)
        selected_date = Tools.get_date_iso_format(selected_datetime)
        selected_time = Tools.get_time_iso_format(selected_datetime)

        user_type = session['user_type']

        patient_id = session[
            'selected_patient'] if user_type == 'nurse' else session['id']

        selected_patient = mediator.get_patient_by_id(patient_id)
        return render_template('appointment.html',
                               clinic=clinic,
                               walk_in=session['has_selected_walk_in'],
                               date=selected_date,
                               time=selected_time,
                               datetime=str(selected_datetime),
                               user_type=user_type,
                               selected_patient=selected_patient)
Ejemplo n.º 3
0
 def return_weekly_availabilities():
     date_time = Tools.convert_to_python_datetime(
         str(request.args.get('start')))
     result = mediator.find_availability(int(session['selected_clinic']),
                                         date_time,
                                         session['has_selected_walk_in'])
     return result if result is not None else Tools.get_unavailable_times_message(
         date_time)
Ejemplo n.º 4
0
    def view_scheduled_appointment_details(appointment_id):
        selected_appointment = mediator.get_appointment_by_id(appointment_id)

        clinic = selected_appointment.clinic
        walk_in = selected_appointment.walk_in
        date = Tools.get_date_iso_format(selected_appointment.date_time)
        time = Tools.get_time_iso_format(selected_appointment.date_time)
        datetime = str(selected_appointment.date_time)
        user_type = session['user_type']
        selected_patient = selected_appointment.patient

        return render_template('appointment.html',
                               clinic=clinic,
                               walk_in=walk_in,
                               date=date,
                               time=time,
                               datetime=datetime,
                               user_type=user_type,
                               selected_patient=selected_patient)
Ejemplo n.º 5
0
 def book_for_patient():
     walk_in = (request.json['walk_in'] == 'True')
     selected_date_time = Tools.convert_to_python_datetime(
         request.json['start'])
     mediator.add_appointment(session['selected_patient'],
                              request.json['clinic_id'], selected_date_time,
                              walk_in)
     result = {
         'url':
         url_for('view_selected_patient_appointments',
                 id=str(session['selected_patient']))
     }
     return jsonify(result)
Ejemplo n.º 6
0
    def cart():
        if request.method == 'GET':  # view cart
            cart = mediator.get_patient_cart(session['id'])
            return render_template('cart.html', items=cart.get_item_dict())
        elif request.method == 'POST':  # add item to cart
            clinic = mediator.get_clinic_by_id(request.json['clinic_id'])
            start_time = request.json['start']
            walk_in = (request.json['walk_in'] == 'True')

            selected_datetime = Tools.convert_to_python_datetime(start_time)

            cart = mediator.get_patient_cart(session['id'])
            add_item_status = cart.add(clinic, selected_datetime, walk_in)
            result = {'url': url_for('cart'), 'status': str(add_item_status)}
            return jsonify(result)
Ejemplo n.º 7
0
    def before_request():
        if session and 'user_type' in session:
            user = None
            if session['user_type'] == 'patient':
                user = mediator.get_patient_by_id(session['id'])
            elif session['user_type'] == 'doctor':
                user = mediator.get_doctor_by_id(session['id'])

            if user is None:
                return

            if user.has_new_appointment_notification():
                flash('New appointment(s) scheduled!', 'dark')
                inserted_appointments = user.modified_appointment_dict[
                    'inserted']

                for appointment in inserted_appointments:
                    clinic_name = appointment.clinic.name
                    date = Tools.get_date_iso_format(appointment.date_time)
                    time = Tools.get_time_iso_format(appointment.date_time)
                    flash(clinic_name + ' at ' + time + ' on ' + date, 'dark')

                mediator.reset_appointment_operation_states(
                    inserted_appointments)
                user.modified_appointment_dict['inserted'] = []

            if user.has_deleted_appointment_notification():
                flash('Cancelled appointment(s)!', 'dark')
                deleted_appointments = user.modified_appointment_dict[
                    'deleted']

                for appointment in deleted_appointments:
                    clinic_name = appointment.clinic.name
                    date = Tools.get_date_iso_format(appointment.date_time)
                    time = Tools.get_time_iso_format(appointment.date_time)
                    flash(clinic_name + ' at ' + time + ' on ' + date, 'dark')

                mediator.reset_appointment_operation_states(
                    deleted_appointments)
                user.modified_appointment_dict['deleted'] = []

            if user.has_updated_appointment_notification():
                flash('Updated appoinment(s)!', 'dark')
                updated_appointments = user.modified_appointment_dict[
                    'updated']

                for appointment in updated_appointments:
                    clinic_name = appointment.clinic.name
                    date = Tools.get_date_iso_format(appointment.date_time)
                    time = Tools.get_time_iso_format(appointment.date_time)
                    flash(clinic_name + ' at ' + time + ' on ' + date, 'dark')

                mediator.reset_appointment_operation_states(
                    updated_appointments)
                user.modified_appointment_dict['updated'] = []
Ejemplo n.º 8
0
    def modify_appointment():
        is_walk_in = (request.json['walk_in'] == 'True')
        selected_date_time = Tools.convert_to_python_datetime(
            request.json['start'])
        mediator.update_appointment(request.json['old_appointment_id'],
                                    request.json['clinic_id'],
                                    selected_date_time, is_walk_in)

        result = None

        if session['user_type'] == 'nurse':
            result = {
                'url':
                url_for('view_selected_patient_appointments',
                        id=str(session['selected_patient']))
            }
        elif session['user_type'] == 'patient':
            result = {
                'url':
                url_for('view_selected_patient_appointments',
                        id=str(session['id']))
            }
        return jsonify(result)
Ejemplo n.º 9
0
    def get_schedule_by_week(self, doctor_id, fullcalendar_datetime):
        date_time = Tools.convert_to_python_datetime(fullcalendar_datetime)

        week_start_time = self.week_start_from_date_time(date_time)
        week_end_time = self.week_end_from_week_start(week_start_time)
        doctor = self.get_by_id(doctor_id)

        requested_week_availabilities_dict = {}
        for day in range(week_start_time.weekday(),
                         len(doctor.generic_week_availability)):
            daily_availability = doctor.generic_week_availability[day]
            for time, walk_in in daily_availability.items():
                availability_date_time = week_start_time + timedelta(
                    days=day - week_start_time.weekday())
                availability_date_time = datetime(availability_date_time.year,
                                                  availability_date_time.month,
                                                  availability_date_time.day,
                                                  time.hour, time.minute)
                requested_week_availabilities_dict[
                    availability_date_time] = walk_in

        for adjustment in doctor.adjustment_list:
            if week_start_time < adjustment.date_time < week_end_time:
                if adjustment.operation_type_add is True:
                    requested_week_availabilities_dict[
                        adjustment.date_time] = adjustment.walk_in
                else:
                    if adjustment.date_time in requested_week_availabilities_dict:
                        del requested_week_availabilities_dict[
                            adjustment.date_time]

        requested_week_appointments_dict = {}
        for appointment in doctor.appointment_dict.values():
            if week_start_time < appointment.date_time < week_end_time:
                requested_week_appointments_dict[
                    appointment.date_time] = appointment.walk_in

        # remove any availabilities that have become appointments
        no_longer_available_list = []
        for date_time in requested_week_availabilities_dict.keys():
            date_time_to_check = date_time - timedelta(minutes=20)
            date_time_to_check2 = date_time - timedelta(minutes=40)
            for appointment_date_time in requested_week_appointments_dict.keys(
            ):
                if date_time == appointment_date_time:
                    no_longer_available_list.append(date_time)
                elif date_time_to_check == appointment_date_time and requested_week_appointments_dict[
                        appointment_date_time].walk_in == False:
                    no_longer_available_list.append(date_time)
                elif date_time_to_check2 == appointment_date_time and requested_week_appointments_dict[
                        appointment_date_time].walk_in == False:
                    no_longer_available_list.append(date_time)
            if requested_week_availabilities_dict[date_time] is False:
                date_time_to_check = date_time + timedelta(minutes=20)
                date_time_to_check2 = date_time + timedelta(minutes=40)
                for appointment_date_time in requested_week_appointments_dict.keys(
                ):
                    if date_time_to_check == appointment_date_time:
                        no_longer_available_list.append(date_time)
                    elif date_time_to_check2 == appointment_date_time:
                        no_longer_available_list.append(date_time)

        for date_time in no_longer_available_list:
            requested_week_availabilities_dict.pop(date_time)

        event_source = Tools.json_from_doctor_week_availabilities(
            requested_week_availabilities_dict)
        event_source2 = Tools.json_from_doctor_week_appointments(
            requested_week_appointments_dict)
        for item in event_source2:
            event_source.append(item)
        return json.dumps(event_source)
Ejemplo n.º 10
0
 def __init__(self, fullcalendar_event):
     WrapDoctorEvent.__init__(self, fullcalendar_event)
     self.date_time = Tools.convert_to_python_datetime(fullcalendar_event['time'])
     self.operation_type_add = self.convert_id_to_operation_type(fullcalendar_event['id'])