def treatments(patient_id):
    treatments = treatment_repository.select_all(patient_id)
    treatments.sort(key=lambda x: date_to_date_box(x.date), reverse=True)
    patient = patient_repository.select(patient_id)
    return render_template('/treatments/index.html',
                           all_treatments=treatments,
                           selected_patient=patient)
def new_treatment(patient_id):
    patient = patient_repository.select(patient_id)
    vets = vet_repository.select_all()
    date = date_today()
    return render_template('/treatments/new.html',
                           selected_patient=patient,
                           all_vets=vets,
                           date_today=date)
def update_treatment(patient_id, treatment_id):
    patient = patient_repository.select(patient_id)
    vet_id = request.form['vet-name']
    vet = vet_repository.select(vet_id)
    date = date_box_to_date(request.form['date'])
    notes = request.form['notes']
    treatment = Treatment(notes, date, patient, vet, treatment_id)
    treatment_repository.update(treatment)
    return redirect(url_for('.treatments', patient_id=patient_id))
def new_patient():
    selected_patient = patient_repository.select(request.form["patient-name"])
    patients = patient_repository.select_all()
    vets = vet_repository.select_all()
    date = date_today()
    print(date)
    return render_template('treatments/new.html',
                           selected_patient=selected_patient,
                           all_patients=patients,
                           all_vets=vets,
                           date_today=date)
Ejemplo n.º 5
0
def select(id):
    sql = "SELECT * FROM treatments WHERE id = %s"
    values = [id]
    results = run_sql(sql, values)
    if results is not None:
        result = results[0]
        patient = patient_repository.select(result['patient_id'])
        vet = vet_repository.select(result['vet_id'])
        treatment = Treatment(result['notes'], result['date'], patient, vet,
                              result['id'])
    return treatment
Ejemplo n.º 6
0
def save(treatment):
    sql = "INSERT INTO treatments (notes, date, patient_id, vet_id) VALUES (%s, %s, %s, %s) RETURNING *"
    values = [
        treatment.notes, treatment.date, treatment.patient.id, treatment.vet.id
    ]
    results = run_sql(sql, values)
    if results is not None:
        result = results[0]
        treatment.patient = patient_repository.select(result['patient_id'])
        treatment.vet = vet_repository.select(result['vet_id'])
        treatment.id = result['id']
    return treatment
Ejemplo n.º 7
0
def select_all(patient_id):
    treatments = []
    sql = "SELECT * FROM treatments WHERE patient_id = %s"
    values = [patient_id]
    results = run_sql(sql, values)
    if results is not None:
        for row in results:
            patient = patient_repository.select(row['patient_id'])
            vet = vet_repository.select(row['vet_id'])
            treatment = Treatment(row['notes'], row['date'], patient, vet,
                                  row['id'])
            treatments.append(treatment)
    return treatments
Ejemplo n.º 8
0
def edit_patient(id):
    patient = patient_repository.select(id)
    clients = client_repository.select_all()
    vets = vet_repository.select_all()
    dob = date_to_date_box(patient.dob)
    check_in = date_to_date_box(patient.check_in_date)
    check_out = date_to_date_box(patient.check_out_date)
    pet_types.sort()
    return render_template('/patients/edit.html',
                           patient=patient,
                           all_clients=clients,
                           all_vets=vets,
                           dob=dob,
                           check_in=check_in,
                           check_out=check_out,
                           pet_types=pet_types)
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)
patient_list = patient_repository.select_all()
selected_patient = patient_repository.select(patient_list[0].id)
# patient_repository.delete(patient_list[1].id)
patient_2.name = "Black Panther"
patient_repository.update(patient_2)
patient_list = patient_repository.select_all()

# Treatment repo tests
treatment_1 = Treatment(
    "X-ray done on front left leg following car collision. Results sent to specialists at vet hospital. Awaiting results from specialist.",
    "02/10/2020", patient_1, vet_1)
treatment_2 = Treatment(
    "Patient arrived with severe dehydration and heatstroke due to heatwave. Put in ice bath and on fluids and keeping overnight to monitor progress.",
    "03/10/2020", patient_2, vet_2)
treatment_3 = Treatment(
    "Prepared patient for abdominable surgery following foreign object injestion.",
    "01/10/2020", patient_3, vet_1)