Exemplo n.º 1
0
def create_appointment():
    if not request.form:
        abort(400)
    try:
        params = request.form
        professional = Professional.find_by_id(params['professional_id'])
        appointments = Appointment.find_by_professional(professional)
        start_date = dateparser.parse(params['start_date'])
        end_date = dateparser.parse(params['end_date'])
        for appointment in appointments:
            schedule_start_date = dateparser.parse(appointment.start_date)
            schedule_end_date = dateparser.parse(appointment.end_date)
            if not (start_date <= schedule_start_date
                    and end_date <= schedule_start_date
                    or start_date >= schedule_end_date
                    and end_date >= schedule_end_date):
                abort(404)

        appointment = Appointment(
            professional=professional,
            patient=Patient.find_by_id(params['patient_id']),
            start_date=params['start_date'],
            end_date=params['end_date'],
        )

        appointment.save()
    except:
        abort(500)
    return jsonify(appointment.to_dict())
    def get_appointments_for_staff_and_status_filter_by_date_time(
            staff_id, status, start_time, end_time):
        try:
            client = MongoClient(Constant.DB_CONNECTION_URL)
            document = client[Constant.DB_NAME][AppointmentDB.COLLECTION_NAME]

            appointments = document.find({
                'staffId': staff_id,
                'status': status,
                'dateTime': {
                    '$gte': start_time,
                    '$lte': end_time
                }
            })

            appointments_for_staff = []

            for appointment in appointments:
                a = Appointment(str(appointment['_id']), staff_id,
                                appointment['visitorId'],
                                appointment['subject'],
                                appointment['dateTime'], appointment['status'])

                visitor = VisitorDB.get_visitor_by_id(appointment['visitorId'])
                a.set_visitor(visitor)

                appointments_for_staff.append(a)

            client.close()
            return appointments_for_staff

        except Exception as e:
            print('unable to get appointments for staff')
            raise Exception('Could not get appointments for staff')
    def search_all_appointments_visitors_name(visitor_name_keyword):
        try:
            client = MongoClient(Constant.DB_CONNECTION_URL)
            document = client[Constant.DB_NAME][AppointmentDB.COLLECTION_NAME]

            appointments = document.find({})

            appointments_for_staff = []

            for appointment in appointments:
                a = Appointment(str(appointment['_id']),
                                appointment['staffId'],
                                appointment['visitorId'],
                                appointment['subject'],
                                appointment['dateTime'], appointment['status'])

                visitor = VisitorDB.get_visitor_by_id(appointment['visitorId'])
                if visitor_name_keyword.lower() not in visitor.name.lower():
                    continue

                a.set_visitor(visitor)

                staff = StaffDB.get_staff_by_id(appointment['staffId'])
                a.set_staff(staff.serialize)

                appointments_for_staff.append(a)

            client.close()
            return appointments_for_staff

        except Exception as e:
            print('unable to get appointments')
            raise Exception('Could not get appointments')
    def get_appointments_for_staff_in(staff_id, appointment_ids):
        try:
            client = MongoClient(Constant.DB_CONNECTION_URL)
            document = client[Constant.DB_NAME][AppointmentDB.COLLECTION_NAME]

            appointment_ids_obj = [ObjectId(item) for item in appointment_ids]

            appointments = document.find({
                '_id': {
                    '$in': appointment_ids_obj
                },
                'staffId': staff_id
            })

            appointments_for_staff = []

            for appointment in appointments:
                a = Appointment(str(appointment['_id']), staff_id,
                                appointment['visitorId'],
                                appointment['subject'],
                                appointment['dateTime'], appointment['status'])

                visitor = VisitorDB.get_visitor_by_id(appointment['visitorId'])
                a.set_visitor(visitor)

                appointments_for_staff.append(a)

            client.close()
            return appointments_for_staff

        except Exception as e:
            print('unable to get appointments for staff - ' + str(e))
            raise Exception('Could not get appointments for staff')
    def get_appointments_for_status(status):
        try:
            client = MongoClient(Constant.DB_CONNECTION_URL)
            document = client[Constant.DB_NAME][AppointmentDB.COLLECTION_NAME]

            appointments = document.find({'status': status})

            appointments_for_status = []

            for appointment in appointments:
                a = Appointment(str(appointment['_id']),
                                appointment['staffId'],
                                appointment['visitorId'],
                                appointment['subject'],
                                appointment['dateTime'], status)

                visitor = VisitorDB.get_visitor_by_id(appointment['visitorId'])
                a.set_visitor(visitor)

                staff = StaffDB.get_staff_by_id(appointment['staffId'])
                a.set_staff(staff.serialize)

                appointments_for_status.append(a)

            client.close()
            return appointments_for_status

        except Exception as e:
            print('unable to get appointments for staff')
            raise Exception('Could not get appointments for staff')
def create_appointment():
    start_time = request.form["start_time"]
    end_time = request.form["end_time"]
    appointment_date = request.form["appointment_date"]
    animal = animal_repository.select(request.form["animal_id"])
    new_appointment = Appointment(start_time, end_time, appointment_date,
                                  animal)
    appointment_repository.save(new_appointment)
    return redirect("/appointments")
def add_new_appointment():
    date = request.form["date"]
    time = request.form["time"]
    notes = request.form["notes"]
    vet = vet_repository.select_vet(request.form["vet_id"])
    animal = animal_repository.select_animal(request.form["animal_id"])
    appointment = Appointment(date, time, vet, animal, notes)
    appointment_repository.save_new_appointment(appointment)
    return redirect('/appointments')
def update_appointment(id):
    start_time = request.form["start_time"]
    end_time = request.form["end_time"]
    appointment_date = request.form["appointment_date"]
    animal = request.form["animal_id"]
    appointment = Appointment(start_time, end_time, appointment_date, animal,
                              id)
    appointment_repository.update(appointment)
    return redirect("/appointments")
Exemplo n.º 9
0
def select_appointment(id):
    sql = "SELECT * FROM appointments WHERE id=%s"
    value = [id]
    result = run_sql(sql, value)[0]
    if result is not None:
        vet = vet_repository.select_vet(result["vet_id"])
        animal = animal_repository.select_animal(result["animal_id"])
        appointment = Appointment(result["date"], result["time"], vet, animal,
                                  result["additional_notes"], result["id"])
        return appointment
Exemplo n.º 10
0
 def test_instance(self):
     params = {
         'name': 'Mr Praline',
         'phone_number': '+12025550170',
         'delta': '15',
         'time': datetime.datetime(2015, 7, 28, 12, 24),
         'timezone': 'US/Pacific'
     }
     appt = Appointment(**params)
     self.assertEqual(repr(appt), "<Appointment 'Mr Praline'>")
Exemplo n.º 11
0
def select_all_appointments():
    sql = "SELECT * FROM appointments"
    results = run_sql(sql)
    appointments = []
    for result in results:
        animal = animal_repository.select_animal(result["animal_id"])
        vet = vet_repository.select_vet(result["vet_id"])
        appointment = Appointment(result["date"], result["time"], vet, animal,
                                  result["additional_notes"], result["id"])
        appointments.append(appointment)
    return appointments
Exemplo n.º 12
0
    def _set_new_appointment(self):
        subject = input("Enter subject:")
        duration = input("Enter duration:")
        start_time = input("Enter start time:")
        client_name = input("Enter client name:")
        counselor_id = self.counselor.id

        appointment = Appointment(subject, duration, start_time, client_name,
                                  counselor_id)
        appointment.save_to_db()

        print("Appointment has been set successfully!")
Exemplo n.º 13
0
def select(id):
    sql = "SELECT * FROM appointments WHERE id = %s"
    vaules = [id]
    result = run_sql(sql, vaules)[0]
    animal = animal_repository.select(result["animal_id"])
        
    if result is not None:
        appointment = Appointment(
        result["start_time"], 
        result["end_time"],
        result["appointment_date"], 
        animal, 
        result["id"]) 
    return appointment
Exemplo n.º 14
0
def save_from_pet(id):
    # Grab request data
    date = request.form['appointment_date']
    note = request.form['appointment_note']
    vet_id = request.form['appointment_vet']

    # Grab needed objects
    vet = VR.select(vet_id)
    pet = PR.select(id)

    # Create object for saving
    appointment = Appointment(date, note, vet, pet, pet)
    AR.save(appointment)

    # Redirect
    return redirect('/pets/' + id)
Exemplo n.º 15
0
def create_appointment():
    """Creates an appointment
    :return: a success message
    """
    details = json.loads(request.data)

    appointment = Appointment(consultation_type=details["consultation_type"],
                              resolution=details["resolution"],
                              status=details["status"],
                              slot_id=details["slot_id"],
                              venue=details["venue"],
                              patient_id=details["patient_id"],
                              doctor_id=details["doctor_id"])

    appointment.save()
    return make_response(
        jsonify({"message": "appointment created_successfully"}), 201)
Exemplo n.º 16
0
    def post(self):
        form = NewAppointmentForm(request.form)

        if form.validate():
            from tasks import send_sms_reminder

            appt = Appointment(**form.data)
            appt.time = arrow.get(appt.time, appt.timezone).to('utc').naive

            reminders.db.session.add(appt)
            reminders.db.session.commit()
            send_sms_reminder.apply_async(args=[appt.id],
                                          eta=appt.get_notification_time())

            return redirect(url_for('appointment.index'), code=303)
        else:
            return render_template('appointments/new.html', form=form), 400
Exemplo n.º 17
0
def select_all():
    appointments = []
    
    sql = "SELECT * FROM appointments"
    results = run_sql(sql)
    
    for result in results:
        animal = animal_repository.select(result["animal_id"])
        
        appointment = Appointment(
            result["start_time"], 
            result["end_time"],
            result["appointment_date"], 
            animal, 
            result["id"])
        appointments.append(appointment)
    return appointments
Exemplo n.º 18
0
def select(id):
    # Create SQL query, insert data and run
    sql = "SELECT * FROM appointment WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)

    # Check result has returned something
    if len(result) > 0:
        # Grab secondary data
        vet = VR.select(result[0]['vet_id'])
        pet = PR.select(result[0]['pet_id'])

        # Create new object
        appointment = Appointment(result[0]['date'], result[0]['note'], vet,
                                  pet, result[0]['id'])

    return appointment
Exemplo n.º 19
0
    def get(self, appointment_id):

        appointment = None
        if connection is None:
            return {'message': 'No Connection'}, HTTPStatus.SERVICE_UNAVAILABLE

        with connection.cursor() as cur:
            cur.execute('select * from appointment where appointment_id = :id',
                        {'id': appointment_id})
            record = cur.fetchone()

            if record is None:
                connection.close()
                return {'message': "Not Found"}, HTTPStatus.NOT_FOUND
            else:
                appointment = Appointment(*record)

        connection.close()
        return {'data': appointment.data}, HTTPStatus.OK
Exemplo n.º 20
0
def create():
    online_user = get_jwt_identity()
    user = User.get_or_none(User.id == online_user['id'])

    if "admin" not in user.role:
        return jsonify({
            "message": "401 Unauthorized (Only admin is allowed)",
            "status": "fail"
        })

    params = request.json
    doctor_ic = params.get("doctor_ic")
    patient_ic = params.get("patient_ic")
    start_datetime = params.get("start_datetime")
    end_datetime = params.get("end_datetime")

    doctor = User.get_or_none(User.ic_number == doctor_ic)
    patient = User.get_or_none(User.ic_number == patient_ic)
    if doctor and patient:
        new_appointment = Appointment(doctor_id=doctor.id,
                                      patient_id=patient.id,
                                      start_datetime=start_datetime,
                                      end_datetime=end_datetime)
        if new_appointment.save():
            response = {
                "message": "Successfully created an appointment",
                "status ": "success",
                "doctor_name": new_appointment.doctor.name,
                "doctor_ic": new_appointment.doctor.ic_number,
                "patient_name": new_appointment.patient.name,
                "patient_ic": new_appointment.patient.ic_number,
                "start_datetime": new_appointment.start_datetime,
                "end_datetime": new_appointment.end_datetime
            }
        else:
            response = new_appointment.error()
        return jsonify(response)
    else:
        return jsonify({
            "message": "Can't find doctor or patient",
            "status ": "fail",
        })
Exemplo n.º 21
0
def select_all(id):
    # Create list of appointments == empty list
    appointments = []

    # Create SQL query, pass in data && run
    sql = "SELECT * FROM appointment"
    results = run_sql(sql)

    # Loop through results
    for row in results:
        # Grab secondary data
        vet = VR.select(row['vet_id'])
        pet = PR.select(row['pet_id'])

        # Create new object
        appointment = Appointment(row['date'], row['note'], vet, pet,
                                  row['id'])
        appointments.append(appointment)

    return appointments
Exemplo n.º 22
0
    def get(self, doctor_id):
        appointment = None
        if connection is None:
            return {'message': 'No Connection'}, HTTPStatus.SERVICE_UNAVAILABLE

        data = []
        with connection.cursor() as cur:
            cur.execute('select * from appointment where doctor_id = :id',
                        {'id': doctor_id})
            record = cur.fetchall()

            if len(record) == 0:
                connection.close()
                return {'message': "Not Found"}, HTTPStatus.NOT_FOUND
            else:
                for row in record:
                    appointment = Appointment(*row)
                    data.append(appointment)
        connection.close()
        return {'data': data}, HTTPStatus.OK
Exemplo n.º 23
0
    def get(self):

        if connection is None:
            return {'message': 'No Connection'}, HTTPStatus.SERVICE_UNAVAILABLE

        data = []

        with connection.cursor() as cur:
            cur.execute('select * from appointment')
            records = cur.fetchall()

            if len(records) == 0:
                return {'message': "Not Found"}, HTTPStatus.NOT_FOUND

            for row in records:
                appointment = Appointment(*list(row))
                data.append(appointment.data)

        connection.close()

        return {'data': data}, HTTPStatus.OK
Exemplo n.º 24
0
def filter_appointments(date, vet_id, animal_id):
    filter_values_to_match = f"{bool(date)} {bool(vet_id)} {bool(animal_id)}"

    filter_dictionary = {
        "False False False":
        "",
        "True False False":
        f"WHERE date = '{date}'",
        "False False True":
        f"WHERE animal_id = {animal_id}",
        "False True False":
        f"WHERE vet_id = {vet_id}",
        "True False True":
        f"WHERE date = '{date}' AND animal_id =  {animal_id}",
        "True True False":
        f"WHERE date = '{date}' AND vet_id = {vet_id}",
        "False True True":
        f"WHERE vet_id = {vet_id} AND animal_id = {animal_id}",
        "True True True":
        f"WHERE date = '{date}' AND vet_id = {vet_id} AND animal_id = {animal_id}"
    }

    sql = f"SELECT * FROM appointments {filter_dictionary[filter_values_to_match]}"

    results = run_sql(sql)
    appointments = []
    for result in results:

        # if (vet_id != "" and int(vet_id) != result["vet_id"]) or (animal_id != "" and int(animal_id) != result["animal_id"]) or (date != "" and date != result["date"]):
        #     continue
        vet = vet_repository.select_vet(result["vet_id"])
        animal = animal_repository.select_animal(result["animal_id"])
        appointment = Appointment(result["date"], result["time"], vet, animal,
                                  result["additional_notes"], result["id"])
        appointments.append(appointment)
    return appointments
Exemplo n.º 25
0
 def Appointment(self,owner_id, start_time, end_time, amanuensis):
     return Appointment(owner_id, start_time, end_time, amanuensis)
 def setUp(self):
     super(TasksTest, self).setUp()
     self.celery.conf.CELERY_ALWAYS_EAGER = True
     self.newAppt = Appointment(**self.params)
Exemplo n.º 27
0
# Pets
pet_1 = Pet('Hudini', '1/1/2012', owner_1, pet_type_3, vet_1)
PR.save(pet_1)

pet_2 = Pet('KitKat', '1/1/2010', owner_1, pet_type_3, vet_1)
PR.save(pet_2)

pet_3 = Pet('Steven', '03/10/2004', owner_3, pet_type_5, vet_2)
PR.save(pet_3)

# Notes

note_1 = Note('09/08/2020', 'Hudini is a stinky boy', pet_1, vet_1)
NR.save(note_1)

# Treatments
treatment_1 = Treatment('Worming tablets', 10, 2, 'dewormitroxin',
                        'Liquid Spray')
TR.save(treatment_1)

treatment_2 = Treatment('Antibiotics - Stinkyitus', 50, 7, 'stinkicillin',
                        'Tablet')
TR.save(treatment_2)

# Test appointment

appointment1 = Appointment('2020-09-12', 'Note text', vet_1, pet_3)
AR.save(appointment1)

pdb.set_trace()