def update(id): description = request.form["description"] days = request.form["duration_days"] hours = request.form["duration_hours"] minutes = request.form["duration_minutes"] duration = dh.time_delta(f"{days}:{hours}:{minutes}:00") days = request.form["recovery_days"] hours = request.form["recovery_hours"] minutes = request.form["recovery_minutes"] recovery = dh.time_delta(f"{days}:{hours}:{minutes}:00") cost = int(float(request.form["cost"]) * 100) animal = animal_repository.select(request.form["animal_id"]) old_treatment = treatment_repository.select(animal) animal.owner.decrease_bill(old_treatment.cost) treatment = Treatment(description, duration, recovery, cost, animal, id) if "start" in request.form: treatment.start_treatment() else: start = treatment_repository.select(animal).start treatment.start_treatment(start) animal.owner.increase_bill(treatment.cost) owner_repository.update(animal.owner) treatment_repository.update(treatment) return redirect(f"/animals/{animal.id}")
def index(): global search results = [] search_term = False animals = animal_repository.select_all() if search: results = [ animal for animal in animals if search.lower() in animal.name.lower() ] for result in results: treatment = treatment_repository.select(result) result.where(treatment) search_term = search search = False for animal in animals: treatment = treatment_repository.select(animal) animal.where(treatment) return render_template( "animals/index.html", title="Animals", animals=animals, results=results, search=search_term, )
def edit_treatment(patient_id, treatment_id): treatment = treatment_repository.select(treatment_id) vets = vet_repository.select_all() date = date_to_date_box(treatment.date) return render_template('/treatments/edit.html', treatment=treatment, all_vets=vets, date=date)
def delete_from_source(id, source): treatment = treatment_repository.select(id) if source == "vet": source_id = vet_repository.select(treatment.vet.id).id elif source == "animal": source_id = animal_repository.select(treatment.animal.id).id treatment_repository.delete(id) return redirect(f'/{source}s/{source_id}')
def admitted(): animals = animal_repository.select_all() for animal in animals: treatment = treatment_repository.select(animal) animal.where(treatment) checked_in_animals = [animal for animal in animals if animal.checked_in] return render_template("animals/index.html", title="Animals", animals=checked_in_animals, admitted=True)
def edit(animal_id): animal = animal_repository.select(animal_id) treatment = treatment_repository.select(animal) duration = dh.list_delta(treatment.duration) recovery = dh.list_delta(treatment.recovery) return render_template( "treatments/edit.html", title="Edit Treatment", treatment=treatment, duration=duration, recovery=recovery, )
def save_treatment(id): # Pull in POST data treatment_id = request.form['treatment_id'] # Pull in database data pet = PR.select(id) treatment = TR.select(treatment_id) # Save to perscribed treatments perscribed_treatment = PerscribedTreatment(pet, treatment) perscribed.save(perscribed_treatment) return redirect('/pets/' + id)
def show(id): animal = animal_repository.select(id) treatment = treatment_repository.select(animal) animal.where(treatment) if not animal.checked_in and treatment is not None: treatment_repository.delete(treatment.id) treatment = None records = record_repository.records_by_animal(animal) return render_template( "animals/show.html", title="Animal", animal=animal, records=records, treatment=treatment, )
def show(id): treatment = treatment_repository.select(id) return render_template("treatments/show.html", title="Treatment", treatment=treatment)
def delete(animal_id): animal = animal_repository.select(animal_id) treatment = treatment_repository.select(animal) treatment_repository.delete(treatment.id) return redirect(f"/animals/{treatment.animal.id}")
def get_info_for_update(id, source): treatment = treatment_repository.select(id) vet = vet_repository.select(treatment.vet.id) animal = animal_repository.select(treatment.animal.id) return render_template('treatments/edit.html', treatment=treatment, source=source, vet=vet, animal=animal, title='Update Treatment')
def delete_no_source(id): treatment = treatment_repository.select(id) source_id = animal_repository.select(treatment.animal.id).id treatment_repository.delete(id) return redirect(f'/animals/{source_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) treatment_4 = Treatment( "Patient underwent abdominal surgery and foreign object causing distress was successfully removed. Patient moved to intensive care for overnight observation", "02/10/2020", patient_3, vet_1) treatment_1 = treatment_repository.save(treatment_1) treatment_2 = treatment_repository.save(treatment_2) treatment_3 = treatment_repository.save(treatment_3) treatment_4 = treatment_repository.save(treatment_4) treatment_list_patient_3 = treatment_repository.select_all(patient_3.id) selected_treatment = treatment_repository.select(treatment_4.id) # treatment_repository.delete(treatment_3.id) treatment_list_patient_3 = treatment_repository.select_all(patient_3.id) treatment_1.date = "30/09/2020" treatment_repository.update(treatment_1) selected_treatment = treatment_repository.select(treatment_1.id) pdb.set_trace()