예제 #1
0
def add_patient():
    form = AddPatientForm()
    if form.validate_on_submit():
        try:
            patient = Patient(first_name=form.first_name.data,
                              last_name=form.last_name.data,
                              age=form.age.data,
                              sex=form.sex.data,
                              email=form.email.data)
            db.session.add(patient)
            patient.add_doctor(current_user)
            db.session.commit()
            flash('Patient succesfully added.')
        except Exception as e:
            flash('Failed to add patient. ' + str(e))
        return redirect(url_for('auth.add_patient'))
    return render_template('auth/add_patient.html',
                           title='Add Patient',
                           form=form)
예제 #2
0
    def test_patient_has_doctor(self):
        d1 = Doctor(name = 'Stefan')
        d2 = Doctor(name = 'Dan')
        p1 = Patient(first_name = 'Kelsey')
        p2 = Patient(first_name = 'Josh')

        db.session.add_all([d1, d2, p1, p2])
        db.session.commit()

        self.assertEqual(p1.doctors.all(), [])
        self.assertEqual(p2.doctors.all(), [])

        p1.add_doctor(d1)
        db.session.commit()
        self.assertTrue(p1.has_doctor(d1))
        self.assertEqual(p1.doctors.count(), 1)
        self.assertEqual(p1.doctors.first().name, 'Stefan')

        self.assertFalse(p2.has_doctor(d1))
        self.assertEqual(p2.doctors.count(), 0)

        p1.add_doctor(d2)
        db.session.commit()
        doctors = p1.get_all_doctors().all()
        self.assertEqual(doctors, [d1, d2])

        p1.remove_doctor(d1)
        db.session.commit()
        self.assertFalse(p1.has_doctor(d1))
        self.assertTrue(p1.has_doctor(d2))
        self.assertEqual(p1.doctors.count(), 1)

        p1.remove_doctor(d2)
        db.session.commit()
        self.assertFalse(p1.has_doctor(d2))
        self.assertEqual(p1.doctors.count(), 0)