def select(id):
    sql = "SELECT * FROM patients WHERE id = %s"
    values = [id]
    results = run_sql(sql, values)
    if results is not None:
        result = results[0]
        vet = vet_repository.select(result['vet_id'])
        client = client_repository.select(result['client_id'])
        patient = Patient(result['name'], result['dob'], result['type'],
                          result['breed'], result['gender'], result['status'],
                          vet, client, result['check_in_date'],
                          result['check_out_date'], result['id'])
    return patient
def save(patient):
    results = None
    sql = "INSERT INTO patients (name, dob, type, breed, gender, status, check_in_date, check_out_date, client_id, vet_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING *"
    values = [
        patient.name, patient.dob, patient.type, patient.breed, patient.gender,
        patient.status, patient.check_in_date, patient.check_out_date,
        patient.client.id, patient.vet.id
    ]
    results = run_sql(sql, values)
    if results is not None:
        patient.id = results[0]['id']
        patient.client = client_repository.select(results[0]['client_id'])
        patient.vet = vet_repository.select(results[0]['vet_id'])
    return patient
Ejemplo n.º 3
0
def new_patient():
    selected_client = client_repository.select(request.form["client-name"])
    selected_vet = vet_repository.select(selected_client.vet.id)
    clients = client_repository.select_all()
    vets = vet_repository.select_all()
    pet_types.sort()
    date = date_today()
    return render_template('patients/new.html',
                           selected_client=selected_client,
                           selected_vet=selected_vet,
                           all_clients=clients,
                           all_vets=vets,
                           pet_types=pet_types,
                           date_today=date)
def select_all():
    patients = []
    sql = "SELECT * FROM patients"
    results = run_sql(sql)
    if results is not None:
        for row in results:
            vet = vet_repository.select(row['vet_id'])
            client = client_repository.select(row['client_id'])
            patient = Patient(row['name'], row['dob'], row['type'],
                              row['breed'], row['gender'], row['status'], vet,
                              client, row['check_in_date'],
                              row['check_out_date'], row['id'])
            patients.append(patient)
    return patients
Ejemplo n.º 5
0
def select_patients(vet_id):
    import repositories.client_repository as client_repository
    patients = []
    sql = "SELECT * FROM patients WHERE vet_id = %s"
    values = [vet_id]
    results = run_sql(sql, values)
    if results is not None:
        for row in results:
            vet = select(vet_id)
            client = client_repository.select(row['client_id'])
            patient = Patient(row['name'], row['dob'], row['type'],
                              row['breed'], row['gender'], row['status'], vet,
                              client, row['check_in_date'],
                              row['check_out_date'], row['id'])
            patients.append(patient)
    return patients
Ejemplo n.º 6
0
def update_patient(id):
    name = request.form['name']
    type = request.form['type']
    breed = request.form['breed']
    client_id = request.form['client-name']
    client = client_repository.select(client_id)
    vet_id = request.form['vet-name']
    vet = vet_repository.select(vet_id)
    dob = date_box_to_date(request.form['dob'])
    if request.form['gender'] == "Male":
        gender = "M"
    elif request.form['gender'] == "Female":
        gender = "F"
    status = request.form['status']
    check_in = date_box_to_date(request.form['check-in'])
    check_out = date_box_to_date(request.form['check-out'])
    patient = Patient(name, dob, type, breed, gender, status, vet, client,
                      check_in, check_out, id)
    patient_repository.update(patient)
    return redirect('/patients')
Ejemplo n.º 7
0
def edit_client(id):
    client = client_repository.select(id)
    vets = vet_repository.select_all()
    return render_template('/clients/edit.html', client=client, all_vets=vets)
Ejemplo n.º 8
0
def all_pets_clients(client_id):
    patients = client_repository.select_pets(client_id)
    patients.sort(key=lambda x: x.name)
    client = client_repository.select(client_id)
    patient_list = client.first_name + " " + client.last_name + " Pets"
    return render_template('/patients/index.html', all_patients = patients, patient_list=patient_list)
vet_list = vet_repository.select_all()
selected_vet = vet_repository.select(vet_list[0].id)
# vet_repository.delete(vet_list[1].id)
vet_1.first_name = "Mary"
vet_repository.update(vet_1)
vet_list = vet_repository.select_all()

# Client repo tests
client_1 = Client("James", "McBean", "07666666666",
                  "1 Baberton Mains Row, Edinburgh, EH12 1LS", True, vet_1)
client_2 = Client("Daniel", "Jackson", "07888888888",
                  "16 Duke Street, Glasgow, G5 2FH", False, vet_2)
client_1 = client_repository.save(client_1)
client_2 = client_repository.save(client_2)
client_list = client_repository.select_all()
selected_client = client_repository.select(vet_list[0].id)
# client_repository.delete(client_1.id)
client_1.first_name = "Jim"
client_repository.update(client_1)
client_list = client_repository.select_all()

# Patient repo tests
patient_1 = Patient("Rex", "12/09/2019", "Dog", "Bulldog", "M", "Alive", vet_1,
                    client_1, "03/10/2020", "10/10/2020")
patient_2 = Patient("Felix", "21/04/2016", "Cat", "British Shorthair", "F",
                    "Alive", vet_2, client_2, "04/10/2020", "09/10/2020")
patient_3 = Patient("Tiger", "01/08/2018", "Cat", "Bengal", "M", "Alive",
                    vet_2, client_2, "02/10/2020", "11/10/2020")
patient_1 = patient_repository.save(patient_1)
patient_2 = patient_repository.save(patient_2)
patient_3 = patient_repository.save(patient_3)