def setUp(self): self.test_vet = Vet("Bob", "Wiseman", "Graduate") self.test_client = Client("Vic", "Simpson", "07777 777 777", "123 Sesame Street", True, self.test_vet) self.test_patient = Patient("Rex", "05/05/2019", "Dog", "Bulldog", "Male", "Alive", self.test_vet, self.test_client, "02/11/2020", "05/11/2020") self.test_date = "2019-05-07"
def setUp(self): self.test_vet = Vet("Bob", "Wiseman", "Graduate") self.test_client = Client("Vic", "Simpson", "07777 777 777", "123 Sesame Street", True, self.test_vet) self.test_patient = Patient("Rex", "05/05/2019", "Dog", "Bulldog", "Male", "Alive", self.test_vet, self.test_client, "02/11/2020", "05/11/2020") self.test_treatment = Treatment( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", "04/10/2020", self.test_patient, self.test_vet)
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 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
def select_pets(client_id): pets = [] sql = "SELECT * FROM patients WHERE client_id = %s" values = [client_id] results = run_sql(sql, values) if results is not None: for row in results: vet = vet_repository.select(row['vet_id']) client = select(row['client_id']) pet = 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']) pets.append(pet) return pets
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')
# 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) 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