def test_add_doctor(self): hospital = Hospital(name='hospital') user1 = User(first_name='one', last_name='one', username='******', email='*****@*****.**', password='******') user2 = User(first_name='two', last_name='two', username='******', email='*****@*****.**', password='******') patient1 = Patient(first_name='patient1', last_name='patient1', email='*****@*****.**') patient2 = Patient(first_name='patient2', last_name='patient2', email='*****@*****.**') user1.hospital = hospital user2.hospital = hospital patient1.users.append(user1) patient2.users.append(user2) db.session.add_all([user1, user2, patient1, patient2, hospital]) db.session.commit() with self.client: self.client.post(url_for('auth.login'), data={ 'email': '*****@*****.**', 'username': '******', 'password': '******' }) # patient does not exist response = self.client.get( url_for('patients.add_doctor', patient_id=100)) self.assertEqual(response.status_code, 404) # invalid patient response = self.client.get( url_for('patients.add_doctor', patient_id=2)) self.assertEqual(response.status_code, 403) # patient already connected to doctor response = self.client.post(url_for('patients.add_doctor', patient_id=1), data={'doctor': '1'}, follow_redirects=True) data = response.get_data(as_text=True) self.assertTrue('Patient Already Connected to User' in data) # successful connection to doctor self.assertFalse(patient1 in user2.patients.all()) response = self.client.post(url_for('patients.add_doctor', patient_id=1), data={'doctor': '2'}, follow_redirects=True) data = response.get_data(as_text=True) self.assertTrue('Doctor Successfully Added To Patient' in data) self.assertTrue(patient1 in user2.patients.all())
def test_patient_treatment_table_relationship(self): patient1 = Patient(first_name='Patient', last_name='1', email='*****@*****.**') patient2 = Patient(first_name='Patient', last_name='2', email='*****@*****.**') table1 = TreatmentTable(name='Table 1') table2 = TreatmentTable(name='Table 2') # before connecting self.assertEqual(len(patient1.treatment_tables.all()), 0) self.assertEqual(len(patient2.treatment_tables.all()), 0) # after connecting table1.patient = patient1 table2.patient = patient1 self.assertEqual(len(patient1.treatment_tables.all()), 2) self.assertEqual(patient1, table1.patient) self.assertEqual(patient1, table2.patient) self.assertTrue(table1 in patient1.treatment_tables.all()) self.assertTrue(table2 in patient1.treatment_tables.all()) self.assertEqual(len(patient2.treatment_tables.all()), 0) self.assertNotEqual(patient2, table1.patient) self.assertNotEqual(patient2, table2.patient) self.assertFalse(table1 in patient2.treatment_tables.all())
def test_patients_edit(self): user1 = User(first_name='one', last_name='one', username='******', email='*****@*****.**', password='******') user2 = User(first_name='two', last_name='two', username='******', email='*****@*****.**', password='******') patient1 = Patient(first_name='patient1', last_name='patient1', email='*****@*****.**') patient2 = Patient(first_name='patient2', last_name='patient2', email='*****@*****.**') patient1.users.append(user1) patient2.users.append(user2) db.session.add_all([user1, user2, patient1, patient2]) db.session.commit() with self.client: self.client.post(url_for('auth.login'), data={ 'email': '*****@*****.**', 'username': '******', 'password': '******' }) # patient that does not exist response = self.client.get(url_for('patients.edit', id=100)) self.assertEqual(response.status_code, 404) # patient that does not belong to current user response = self.client.get(url_for('patients.edit', id=2)) self.assertEqual(response.status_code, 403) # patient that does belong to current user (GET) response = self.client.get(url_for('patients.edit', id=1)) data = response.get_data(as_text=True) self.assertTrue('patient1' in data) self.assertTrue('*****@*****.**' in data) # patient that does belong to current user (POST) response = self.client.post(url_for('patients.edit', id=1), data={ 'first_name': 'new first_name', 'last_name': 'new last_name', 'email': 'new email' }, follow_redirects=True) data = response.get_data(as_text=True) self.assertEqual(response.status_code, 200) self.assertTrue('new first_name' in data) self.assertTrue('new last_name' in data) self.assertTrue('new email' in data)
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() self.client = self.app.test_client(use_cookies=True) @self.app.context_processor def utility_processor(): def get_curr_date(): return datetime.utcnow() def get_next_month(year, month): curr = datetime(year=year, month=month, day=1) next_month = curr + relativedelta(months=1) return next_month def get_prev_month(year, month): curr = datetime(year=year, month=month, day=1) prev_month = curr - relativedelta(months=1) return prev_month return dict(get_curr_date=get_curr_date, get_next_month=get_next_month, get_prev_month=get_prev_month) # model instances used in unit tests user1 = User(first_name='one', last_name='one', username='******', email='*****@*****.**', password='******') user2 = User(first_name='two', last_name='two', username='******', email='*****@*****.**', password='******') patient1 = Patient(first_name='patient1', last_name='patient1', email='*****@*****.**') patient2 = Patient(first_name='patient2', last_name='patient2', email='*****@*****.**') patient_note_1 = PatientNote(title='title1', notes='notes1') patient_note_2 = PatientNote(title='title2', notes='notes2') patient_note_1.user = user1 patient_note_2.user = user2 patient_note_1.patient = patient1 patient_note_2.patient = patient2 patient1.users.append(user1) patient2.users.append(user2) db.session.add_all( [user1, user2, patient1, patient2, patient_note_1, patient_note_2]) db.session.commit()
def test_email_is_unique(self): patient1 = Patient(first_name='John', last_name='Doe', email='*****@*****.**') patient2 = Patient(first_name='Jane', last_name='Doe', email='*****@*****.**') db.session.add(patient1) db.session.commit() with self.assertRaises(IntegrityError): db.session.add(patient2) db.session.commit()
def test_patients_delete(self): user1 = User(first_name='one', last_name='one', username='******', email='*****@*****.**', password='******') user2 = User(first_name='two', last_name='two', username='******', email='*****@*****.**', password='******') patient1 = Patient(first_name='patient1', last_name='patient1', email='*****@*****.**') patient2 = Patient(first_name='patient2', last_name='patient2', email='*****@*****.**') patient1.users.append(user1) patient2.users.append(user2) db.session.add_all([user1, user2, patient1, patient2]) db.session.commit() with self.client: self.client.post(url_for('auth.login'), data={ 'email': '*****@*****.**', 'username': '******', 'password': '******' }) # patient that does not exist response = self.client.get(url_for('patients.delete', id=100)) self.assertEqual(response.status_code, 404) # patient that does not belong to current user response = self.client.get(url_for('patients.delete', id=2)) self.assertEqual(response.status_code, 403) # patient that does belong to current user patient1 = Patient.query.get(1) self.assertEqual(len(current_user.patients.all()), 1) self.assertTrue(patient1 in current_user.patients.all()) response = self.client.get(url_for('patients.delete', id=1), follow_redirects=True) data = response.get_data(as_text=True) self.assertEqual(response.status_code, 200) self.assertTrue('Patient Successfully Deleted' in data) self.assertEqual(len(current_user.patients.all()), 0) self.assertFalse(patient1 in current_user.patients.all())
def test_patient_notes_relationship(self): patient = Patient(first_name='John', last_name='Elliot', email="*****@*****.**") user = User(first_name='John', last_name='Elliot', username='******', email="*****@*****.**", password='******') patient_note1 = PatientNote(title='title1', notes='note1') patient_note2 = PatientNote(title='title2', notes='note2') # before connecting self.assertEqual(len(patient.patient_notes.all()), 0) self.assertEqual(len(user.patient_notes.all()), 0) # after connecting patient_note1 patient_note1.patient = patient patient_note1.user = user db.session.add_all([patient, user, patient_note1, patient_note2]) db.session.commit() self.assertEqual(len(patient.patient_notes.all()), 1) self.assertTrue(patient_note1 in patient.patient_notes.all()) self.assertEqual(patient_note1.patient_id, patient.id) self.assertFalse(patient_note2 in patient.patient_notes.all()) self.assertNotEqual(patient_note2.patient_id, patient.id) self.assertEqual(len(user.patient_notes.all()), 1) self.assertTrue(patient_note1 in user.patient_notes.all()) self.assertEqual(patient_note1.user_id, user.id) self.assertFalse(patient_note2 in user.patient_notes.all()) self.assertNotEqual(patient_note2.user_id, user.id)
def test_name_assignment(self): patient = Patient(first_name='John', last_name='Doe', email='*****@*****.**') self.assertEqual(patient.first_name, 'John') self.assertEqual(patient.last_name, 'Doe') self.assertEqual(patient.fullname, 'John Doe')
def test_id(self): patient = Patient(first_name='John', last_name='Doe', email='*****@*****.**') db.session.add(patient) db.session.commit() self.assertEqual(patient.id, 1)
def create_patient(): data = request.json patient = Patient(firstName=data['firstName'], lastName=data['lastName'], address_line_one=data['addressLineOne'], address_line_two=data['addressLineTwo'], address_line_three=data['addressLineThree'], address_city=data['addressCity'], address_state=data['addressState'], address_zip=data['addressZip'], bmi=data['bmi'], weight=data['weight'], height=data["height"], home_phone=data['homePhone'], mobile_phone=data['mobilePhone'], work_phone=data['workPhone'], occupation=data['occupation'], dob=data['birthday'], sex=data['sex'], smoker=data['smoker'], beats_per_minute=data["heartRate"]) db.session.add(patient) db.session.commit() format_patient = patient.to_dict() return {"patient": format_patient}
def new_patient(): """Display the form for a new patient, and create a new patient after submission.""" form = PatientForm() if form.validate_on_submit(): patient = Patient() update_patient(patient, form, request.files) # If the patient was created by a patient user, link the new patient to the # user account if current_user.is_patient_user(): current_user.patient = patient db.session.add(patient) db.session.commit() return redirect(url_for('screener.patient_details', id=patient.id)) else: index_search = {} if 'first_name' in session and session['first_name']: index_search['first_name'] = session['first_name'] if 'last_name' in session and session['last_name']: index_search['last_name'] = session['last_name'] if 'dob' in session and session['dob']: index_search['dob'] = 'test' if 'ssn' in session and session['ssn']: index_search['ssn'] = session['ssn'] # Delete empty rows at end of many-to-one tables remove_blank_rows(form) return render_template('patient_details.html', patient={}, form=form, index_search=index_search)
def create_patient(): ''' Creates a new patient ''' form = CreatePatientForm() if request.method == 'POST': if form.validate_on_submit: patient = Patient.query.filter_by(email = form.email.data).first() if patient is None: patient = Patient( firstname = form.firstname.data, lastname = form.lastname.data, dob = form.dob.data, email = form.email.data, phone_no = form.phone_no.data, id_no = form.id_no.data, nhif_no = form.nhif_no.data, ward_id = form.ward_id.data.id ) patient.save() flash('Successfully created a new patient') return redirect(url_for('admin.patients')) else: flash('Patient exists') return render_template('admin/create-patient.html', title='Patients', form=form)
def create_patient(): form = NewPatientForm(request.form) if request.method == 'GET': today = datetime.date.today().strftime("%m/%d/%Y") form.visit_date.data = today if form.validate() and request.method == 'POST': notes = {} if form.visit_notes.data is not None and form.visit_notes.data != "": notes_info = [] notes_info.append(form.visit_doctor.data) notes_info.append(form.visit_notes.data) notes[form.visit_date.data] = notes_info new_patient = Patient(name=form.name.data, DOB=clean_date(form.DOB.data), hx=form.hx.data, phone_number=form.phone_number.data, past_visit_notes=notes, address=form.address.data, patient_note=form.patient_note.data) database.session.add(new_patient) database.session.commit() if form.phone_number.data is not None: send_update_to_sms_server(new_patient, new=True) flash("Successfully added patient {}".format(form.name.data)) return redirect('/index') elif request.method == 'POST': flash_errors(form) return render_template('new_patient.html', title="CreatePatient", form=form, is_admin=is_admin)
def employee(employee_id): employee = User.query.filter_by(employee_id=employee_id).first_or_404() patientform = NewPatientForm() clients = db.session.query(appointments).filter( appointments.c.employee_id == employee_id).all() patient_list = [] for item in clients: patient_id = item[1] query = Patient.query.filter_by(patient_id=patient_id).all() patient_list.append(query) if patientform.validate_on_submit(): patient = Patient(patient_id=patientform.patient_id.data, name=patientform.name.data, age=patientform.age.data, gender=patientform.gender.data, height=patientform.height.data, weight=patientform.weight.data, prescription=patientform.prescription.data, medications=patientform.medications.data, tests=patientform.tests.data) db.session.add(patient) db.session.commit() patient.appointments.append(employee) db.session.commit() flash('Successfully Added New Patient') return redirect(url_for('employee', employee_id=employee_id)) else: flash("Registration Unsuccessful. Kindly input correct form values") return render_template('employee_dashboard.html', user=employee, patientform=patientform, patientlist=patient_list)
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() self.client = self.app.test_client(use_cookies=True) hospital = Hospital(name='Hospital') user = User(first_name='userone', last_name='userone', username='******', email='*****@*****.**', password='******') user.hospital = hospital patient = Patient('Patient', '100', '*****@*****.**') user.patients.append(patient) treatment = Treatment(name='Treatment 1') treatment.hospital = hospital table1 = TreatmentTable(patient=patient, name='Table 1') entry1 = TreatmentTableEntry(amount='Entry1Amount', note='Entry1Note', treatment=treatment, treatment_table=table1) db.session.add_all( [hospital, user, patient, treatment, table1, entry1]) db.session.commit()
def register(): req_data = request.get_json() account_type = req_data.get('account_type') username = req_data.get('username') password = req_data.get('password') hashed_pass = bcrypt.generate_password_hash(password).decode('utf-8') status = 'registration error' if account_type == "caregiver": if Caregiver.query.filter_by(username=username).first() == None: user = Caregiver(username=username, password=hashed_pass) else: status = 'username taken' elif account_type == "patient": caregiver_name = req_data.get('caregiver') caregiver = Caregiver.query.filter_by(username=caregiver_name).first() if Patient.query.filter_by(username=username).first() == None: user = Patient(username=username, password=hashed_pass, caregiver_id=caregiver.id) else: status = 'username taken' else: user = None if user: db.session.add(user) db.session.commit() access_token = create_access_token(identity=username, expires_delta=False) status = f'{access_token}' return (status)
def post(self): args = self.reqparse.parse_args() patient = Patient() patient.first_name = args['first_name'] patient.last_name = args['last_name'] patient.date_of_birth = datetime.datetime.strptime( args['date_of_birth'], '%Y-%m-%d') user = User() user.username = patient.first_name[0].lower( ) + patient.last_name.lower() user.email = args['email'] password = "******" % (random.randrange(1, 9999999999), ) msg = Message( subject="Password", recipients=[user.email], body= "Your credentials to log into the HospitalWaiter application is as follows:\n\n" "Username: %s\n" "Password: %s\n\n" "Keep these credentials secure!" % (user.username, password)) with app.app_context(): mail.send(msg) user.password = bcrypt.hashpw(password.encode('utf8'), bcrypt.gensalt(10)) db.session.add(patient) db.session.commit() user.patient_id = patient.id db.session.add(user) db.session.commit() return {'patient': marshal(patient, patient_fields)}, 201
def list(category=None): page = request.args.get('page', 1, type=int) # retrieve patients of user or hospital if category == "hospital": query = current_user.hospital.get_patients() elif category == "user": query = current_user.patients.order_by(Patient.last_name.asc()) else: abort(404) pagination = query.paginate(page, per_page=10) patients = pagination.items # form processing form = PatientAddForm() if form.validate_on_submit(): # create new patient patient = Patient(first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data) current_user.patients.append(patient) db.session.add(patient) db.session.commit() flash('New Patient Added') return redirect(url_for('patients.list', category='user')) return render_template('patients/list.html', patients=patients, pagination=pagination, form=form, category=category)
def add(username): form = PatientForm() if form.validate_on_submit(): patient = Patient( name=form.name.data, age=form.age.data, hospital=form.hospital.data, mrn=form.mrn.data, height=form.height.data, weight=form.weight.data, user_id=User.query.filter_by(username=username).first().id) patient.set_bmi() patient.set_bsa() patient.set_ecoli() patient.set_vincristine() patient.set_daunorubicin() patient.set_methotrexate() patient.set_pegaspargase() patient.set_prednisolone() patient.set_cotrimoxazole() db.session.add(patient) db.session.commit() flash('Patient added!') return redirect(url_for('edit', username=username, name=patient.name)) return render_template('patient.html', title='Patient', form=form)
def addNewPatient(): if request.method == 'POST': patient = Patient( firstName = str(request.form["firstname"]), lastName = str(request.form["lastname"]), phoneNumber = str(request.form["phonenumber"]), email = str(request.form["email"]), operation = str(request.form["operation"]), operationDate = datetime.strptime(request.form['operationdate'], '%Y-%m-%d'), prescriptionMed = str(request.form["presciptionmedication"]), prescriptionDosage = float(request.form["prescriptiondosage"]), notes = str(request.form["notes"]), priorOpioid = int(request.form["prioropioduse"]), onAntidepressants = int(request.form["onantidepressants"]), password = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(6)), isDoctor = False ) phonenumber='+15715986645' # patient.password = "******" sendsms(patient.email,patient.password,phonenumber) patient.set_password(patient.password) db.session.add(patient) db.session.commit() return redirect(url_for('doctorDashBoard')) return render_template("addnewpatient.html")
def register(choice): if current_user.is_authenticated: return redirect(url_for('home')) idd = token_hex(16) if(choice=='doctor'): idd = 'D'+idd form = DoctorRegister() if form.validate_on_submit(): user = Doctor(id = idd, full_name=form.name.data, email=form.email.data, city=form.city.data, phone=form.phone.data, address=form.address.data, qual=form.qual.data, fees=form.fees.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) else: idd = 'P'+idd form = PatientRegister() if form.validate_on_submit(): user = Patient(id=idd, full_name=form.name.data, email=form.email.data, city=form.city.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) return render_template('register.html', choice=choice, form=form)
def test_create_appointment(): """ Test creating an appointment with a patient and a provider """ # Arrange patient = Patient(first_name="Aly", last_name="Sivji") provider = Provider(first_name="Doctor", last_name="Acula") now = datetime.now() a = Appointment(start=now, end=now, department='foo', patient=patient, provider=provider) # Act db.session.add(a) db.session.commit() # Assert assert len(Appointment.query.all()) == 1 queried_appointment = Appointment.query.one() assert queried_appointment.department == 'foo' assert queried_appointment.patient_id == patient.id assert queried_appointment.provider_id == provider.id db.session.delete(a) db.session.delete(patient) db.session.delete(provider) db.session.commit()
def test_user_patient_relationship(self): patient1 = Patient(first_name='one', last_name='one', email='one') patient2 = Patient(first_name='two', last_name='two', email='two') user1 = User(first_name='three', last_name='three', username='******', email='three', password='******') user2 = User(first_name='four', last_name='four', username='******', email='four', password='******') # before connecting self.assertEqual(len(patient1.users.all()), 0) self.assertEqual(len(patient2.users.all()), 0) self.assertEqual(len(user1.patients.all()), 0) self.assertEqual(len(user2.patients.all()), 0) # connect patients to user1 user1.patients.append(patient1) user1.patients.append(patient2) self.assertEqual(len(user1.patients.all()), 2) self.assertTrue(patient1 in user1.patients.all()) self.assertTrue(patient2 in user1.patients.all()) self.assertFalse(patient1 in user2.patients.all()) self.assertFalse(patient2 in user2.patients.all()) self.assertTrue(user1 in patient1.users.all()) self.assertTrue(user1 in patient2.users.all()) #undo user1.patients.remove(patient1) user1.patients.remove(patient2) # connect users to patient1 patient1.users.append(user1) patient1.users.append(user2) self.assertEqual(len(patient1.users.all()), 2) self.assertTrue(user1 in patient1.users.all()) self.assertTrue(user2 in patient1.users.all()) self.assertFalse(user1 in patient2.users.all()) self.assertFalse(user2 in patient2.users.all()) self.assertTrue(patient1 in user1.patients.all()) self.assertTrue(patient1 in user2.patients.all()) self.assertFalse(patient2 in user1.patients.all()) self.assertFalse(patient2 in user2.patients.all())
def add(order_id=0): order = None if order_id != 0: order = Order.query.get(order_id) form = PatientForm() form.order.choices = [(c.id, c.serial) for c in Order.query.all()] for entry in form.samples.entries: entry.sample_type.choices = [(c.id, c.name) for c in SampleType.query.all()] entry.mesure.choices = [(c.id, c.name) for c in Mesure.query.all()] entry.support.choices = [(c.id, c.name) for c in Support.query.all()] entry.sample_nature.choices = [(c.id, c.name) for c in SampleNature.query.all()] entry.jonc_type.choices = [(c.id, c.name) for c in JoncType.query.all()] if form.validate_on_submit(): patient = Patient(bio_code=get_bio_code('HU'), order_id=order_id, origin_id=1, code=form.code.data, sexe=form.sexe.data, birthday=form.birthday.data, age=form.age.data, city=form.city.data, job=form.job.data, clinical_data=form.clinical_data.data) db.session.add(patient) db.session.commit() for s in form.samples.entries: print(int(s.number.data)) for r in range(int(s.number.data)): sample = Sample() sample.origin_id = s.patient.origin_id sample.code = s.code.data sample.technique = s.technique.data sample.results = s.results.data sample.sample_nature_id = s.sample_nature.data sample.sample_type_id = s.sample_type.data sample.date = s.date.data sample.site = s.site.data sample.support_id = s.support.data sample.jonc_type_id = s.jonc_type.data sample.number = s.number.data sample.mesure_id = s.mesure.data sample.volume = s.volume.data sample.patient_id = patient.id sample.status = 0 db.session.add(sample) db.session.commit() generateCode(sample, r + 1) flash(_('Nouveau patient ajouté avec succèss!')) return redirect(url_for('patient.add', order_id=order_id)) form.order.data = order_id return render_template('patient/form.html', form=form, order=order)
def create_patient(request): instance = Patient() form = PatientForm(request.POST or None, instance=instance) if request.POST and form.is_valid(): patient = form.save(commit=False) patient.author = UserProfile.objects.by_user(request.user) patient.save() return HttpResponseRedirect(reverse('patients')) return render(request, 'create_form.html', {'form': form})
def add_patient(self): p = Patient( id="40f680c8-238b-426b-b1c0-1649c780ce69", age=5, name="Winford Altenwerth", gender="male", ) db.session.add(p) db.session.commit()
def test_attributes_assignment(self): self.assertEqual(TreatmentTable.__tablename__, 'treatment_tables') patient = Patient(first_name='John', last_name='Doe', email='*****@*****.**') table = TreatmentTable(name='Table 1', patient=patient) self.assertEqual(table.name, 'Table 1') self.assertEqual(table.patient, patient)
def add_patient(self): p = Patient( id="3123f5a6-e224-4255-b5ba-f7238fb7d0f5", age=26, name="Mimi Altenwerth", gender="female", ) db.session.add(p) db.session.commit()
def newpatient(): """Form to add a new patient to the database.""" form = NewPatientForm() if form.validate_on_submit(): p = Patient(name=form.name.data, age=int(form.age.data), qr_code=form.qr_code.data) db.session.add(p) db.session.commit() flash('New Patient Registered :' + form.name.data) return redirect(url_for('index')) return render_template('addpatient.html', title='Add Patient', form=form)
def insert_patient(): patient = Patient( first_name='John', last_name='Richmond', dob='1950-01-01', ssn='111-11-1111' ) db.session.add(patient) db.session.commit() return patient