Ejemplo n.º 1
0
    def test_workup_update(self):
        '''
        Updating should be possible always for attendings, only without
        attestation for non-attendings.
        '''

        # if the wu is unsigned, all can access update.
        for role in user_factories.all_roles:
            log_in_user(self.client, build_user([role]))
            response = self.client.get(
                reverse('workup-update', args=(self.wu.id, )))
            assert response.status_code == 200

        signer = build_user([user_factories.AttendingGroupFactory])
        self.wu.sign(signer, signer.groups.first())
        self.wu.save()

        # nonattesting cannot access while attesting can
        for role in user_factories.all_roles:
            log_in_user(self.client, build_user([role]))
            response = self.client.get(
                reverse('workup-update', args=(self.wu.id, )))
            if role in user_factories.attesting_roles:
                assert response.status_code == 200
            else:
                self.assertRedirects(response,
                                     reverse('workup', args=(self.wu.id, )))
Ejemplo n.º 2
0
    def test_form_other_volunteer_options(self):
        """WorkupForm offers only non-attendings for 'other volunteers'"""

        form = WorkupForm()
        user_pks = [u.pk for u in self.users]
        other_vol_options = [c[0] for c in form['other_volunteer'].field.choices]

        # check that any user can be the other volunteer
        assert set(user_pks) == set(other_vol_options)
        assert len(user_pks) == len(other_vol_options)

        # check that error is thrown if one of the other volunteers
        # is the attending
        attending = build_user([user_factories.AttendingGroupFactory])
        non_attending = build_user()

        form_data = wu_dict()
        form_data['attending'] = attending
        form_data['other_volunteer'] = [non_attending, attending]
        form = WorkupForm(data=form_data)
        assert form['other_volunteer'].errors

        # and that no error is thrown if they are different
        form_data['other_volunteer'] = [non_attending]
        form = WorkupForm(data=form_data)
        assert not form['other_volunteer'].errors
Ejemplo n.º 3
0
    def setUp(self):

        # build an attending and a clinical student
        self.attending = build_user([user_factories.AttendingGroupFactory])
        self.clinical_student = build_user()
        log_in_user(self.client, self.attending)

        self.wu_info = dict(chief_complaint="SOB",
                            diagnosis="MI",
                            hpi="A",
                            pmh="B",
                            psh="W",
                            meds="C",
                            allergies="D",
                            fam_hx="E",
                            soc_hx="F",
                            ros="",
                            pe="",
                            a_and_p="")

        # prepare a patient with an unsigned wu today, in addition to
        # what comes in in the fixture

        self.pt2 = Patient.objects.create(
            first_name="Arthur",
            last_name="Miller",
            middle_name="",
            phone='+49 178 236 5288',
            gender=Gender.objects.first(),
            address='Schulstrasse 9',
            city='Munich',
            state='BA',
            zip_code='63108',
            pcp_preferred_zip='63018',
            date_of_birth=datetime.date(1994, 1, 22),
            patient_comfortable_with_english=False,
            preferred_contact_method=ContactMethod.objects.first(),
        )

        EncounterStatus.objects.create(name="Active", is_active=True)

        self.encounter_info = dict(clinic_day=now().date(),
                                   status=EncounterStatus.objects.first())

        Encounter.objects.create(patient=Patient.objects.first(),
                                 **self.encounter_info)

        self.wu2 = Workup.objects.create(
            encounter=Encounter.objects.create(patient=self.pt2,
                                               **self.encounter_info),
            author=self.clinical_student,
            author_type=self.clinical_student.groups.first(),
            patient=self.pt2,
            **self.wu_info)
Ejemplo n.º 4
0
 def test_dispense_history_creation(self):
     assert DispenseHistory.objects.count() == 0
     user = build_user()
     dispense_history = factories.DispenseHistoryFactory(
         author=user, author_type=user.groups.first())
     assert isinstance(dispense_history, DispenseHistory)
     assert DispenseHistory.objects.count() == 1
Ejemplo n.º 5
0
    def attestable_note_signing_one_group_test(self, note):
        """test signing permissions for attestable note
        when user has one group."""

        for role in user_factories.all_roles:
            user = build_user([role])
            group = user.groups.first()

            # attending can sign
            if role in user_factories.attesting_roles:
                note.sign(user, group)
                assert note.signed()

            else:
                # non-attending can't sign
                with self.assertRaises(ValueError):
                    note.sign(user, group)
                assert not note.signed()

                # non-attending can't use another group to sign
                with self.assertRaises(ValueError):
                    note.sign(user, user_factories.AttendingGroupFactory())
                assert not note.signed()

            # reset chart's signed status
            note.signer = None
Ejemplo n.º 6
0
    def setUp(self):
        self.ua = factories.LabTypeFactory(name='Urinalysis')
        self.ua_pH = factories.ContinuousMeasurementTypeFactory(
            long_name='Urine pH', short_name='pH', lab_type=self.ua)
        self.ua_glucose = factories.ContinuousMeasurementTypeFactory(
            long_name='Urine glucose', short_name='glucose', lab_type=self.ua)
        self.ua_blood = factories.DiscreteMeasurementTypeFactory(
            long_name='Urine blood', short_name='blood', lab_type=self.ua)

        self.disc_result_neg = factories.DiscreteResultTypeFactory(name='neg')
        self.disc_result_neg.measurement_type.set([self.ua_blood])

        self.pt = core_factories.PatientFactory()
        self.lab = factories.LabFactory(patient=self.pt, lab_type=self.ua)

        lab_ua_pH = factories.ContinuousMeasurementFactory(
            measurement_type=self.ua_pH, lab=self.lab)
        lab_ua_glucose = factories.ContinuousMeasurementFactory(
            measurement_type=self.ua_glucose, lab=self.lab)
        lab_ua_blood = factories.DiscreteMeasurementFactory(
            measurement_type=self.ua_blood, lab=self.lab)

        log_in_user(self.client, build_user())

        self.submitted_form_step1 = {"lab_type": self.ua.id}

        self.submitted_form_step2 = {
            'lab_time': now().strftime("%Y-%m-%d %H:%M:%S"),
            'pH': '5',
            'glucose': '1',
            'blood': self.disc_result_neg.name
        }
Ejemplo n.º 7
0
    def test_lab_add_view_with_perm(self):
        """User with lab permissions is able to add lab"""
        log_in_user(self.client,
                    build_user([user_factories.CaseManagerGroupFactory]))

        assert ContinuousMeasurement.objects.count() == 2
        assert DiscreteMeasurement.objects.count() == 1
        assert Lab.objects.count() == 1

        url = reverse('labs:new-lab', kwargs={'pt_id': self.pt.id})
        response = self.client.get(url)

        response = self.client.post(url, self.submitted_form_step1)
        assert response.status_code == 302

        # Successfully redirect to step 2 view
        url = reverse('labs:new-full-lab',
                      kwargs={
                          'pt_id': self.pt.id,
                          'lab_type_id': self.ua.id
                      })
        assert response.url == url

        response = self.client.post(url, self.submitted_form_step2)
        assert response.status_code == 302

        # Successfully added lab and measurement objects
        assert ContinuousMeasurement.objects.count() == 4
        assert DiscreteMeasurement.objects.count() == 2
        assert Lab.objects.count() == 2

        # Successfully redirect back to table view
        url = reverse("labs:all-labs-table", kwargs={'pt_id': self.pt.id})
        assert response.url == url
Ejemplo n.º 8
0
    def setUp(self):

        self.user = build_user()

        log_in_user(self.client, self.user)

        self.unit = factories.MeasuringUnitFactory(name='different_unit')
        self.category = factories.DrugCategoryFactory(name='different_category')
        self.manufacturer = factories.ManufacturerFactory(name='different_manufacturer')

        self.diff_drug = {
                            'name': 'Differentdrug',
                            'unit': self.unit.pk,
                            'dose': 500.0,
                            'stock': 5,
                            'expiration_date': '2100-01-01',
                            'lot_number': 'HGFEDCBA',
                            'category': self.category.pk,
                            'manufacturer': self.manufacturer.pk
                        }
        self.drug = factories.DrugFactory()

        self.pt = core_factories.PatientFactory()

        self.encounter = core_factories.EncounterFactory(patient=self.pt)
Ejemplo n.º 9
0
    def test_workup_submit(self):
        """verify we can submit a valid workup as a signer and nonsigner"""

        for role in user_factories.all_roles:
            user = build_user([role])
            log_in_user(self.client, user)

            wu_count = models.Workup.objects.all().count()
            wu_data = wu_dict(units=True, dx_category=True)
            pt = wu_data['patient']
            wu_data['patient'] = pt.id
            wu_data['author'] = user.id
            wu_data['author_type'] = user.groups.first().id
            e = wu_data['encounter']
            wu_data['encounter'] = e.id

            response = self.client.post(reverse('new-workup', args=(pt.id, )),
                                        data=wu_data)
            self.assertRedirects(
                response, reverse("core:patient-detail", args=(pt.id, )))

            can_attest = role in user_factories.attesting_roles
            assert models.Workup.objects.all().count() == wu_count + 1
            new = models.Workup.objects.get(patient=pt)
            assert new.signed() == can_attest
Ejemplo n.º 10
0
    def setUp(self):
        self.user = build_user()

        log_in_user(self.client, self.user)

        self.contact_method = ContactMethod.objects.create(
            name="Carrier Pidgeon")

        self.contact_result = ContactResult.objects.create(
            name="Reached on phone", patient_reached=True)

        self.pt = Patient.objects.create(
            first_name="Juggie",
            last_name="Brodeltein",
            middle_name="Bayer",
            phone='+49 178 236 5288',
            gender=Gender.objects.first(),
            address='Schulstrasse 9',
            city='Munich',
            state='BA',
            zip_code='63108',
            pcp_preferred_zip='63018',
            date_of_birth=datetime.date(1990, 1, 1),
            patient_comfortable_with_english=False,
            preferred_contact_method=self.contact_method,
        )

        self.reftype = ReferralType.objects.create(
            name="Specialty", is_fqhc=False)
        self.refloc = ReferralLocation.objects.create(
            name='COH', address='Euclid Ave.')
        self.refloc.care_availiable.add(self.reftype)

        self.no_show_reason = NoShowReason.objects.create(name="Hella busy.")
Ejemplo n.º 11
0
    def setUp(self):
        self.user = build_user()

        log_in_user(self.client, self.user)

        self.pt = core_factories.PatientFactory(case_managers=[self.user])

        self.series_type = factories.VaccineSeriesTypeFactory()
Ejemplo n.º 12
0
    def test_lab_add_view_no_perm(self):
        """User without lab permissions can't add lab"""
        log_in_user(self.client,
                    build_user([user_factories.NoPermGroupFactory]))

        url = reverse('labs:new-lab', kwargs={'pt_id': self.pt.id})
        response = self.client.get(url, follow=True)
        assert response.status_code == 403
Ejemplo n.º 13
0
    def test_login(self):
        '''
        Test the login sequence for one clinical role and mulitiple clinical
        roles.
        '''

        build_user(username='******',
                   password='******',
                   group_factories=[
                       user_factories.CaseManagerGroupFactory,
                       user_factories.VolunteerGroupFactory
                   ])

        # any valid URL should redirect to login at this point.
        self.get_homepage()
        self.submit_login('jrporter', 'password')

        # now we should have to choose a clinical role
        assert self.selenium.current_url == '%s%s%s' % (
            self.live_server_url, reverse('core:choose-role'),
            '?next=%s' % reverse('dashboard-dispatch'))

        self.selenium.find_element_by_xpath(
            '//input[@name="radio-roles"]').click()
        self.selenium.find_element_by_xpath('//button[@type="submit"]').click()

        WebDriverWait(self.selenium, self.DEFAULT_WAIT_TIME).until(
            EC.presence_of_element_located((By.ID, "all-patients-table")))

        assert self.selenium.current_url == '%s%s' % (
            self.live_server_url, reverse('dashboard-active'))

        self.logout()

        # make a provider with only one role.
        build_user(username='******',
                   password='******',
                   group_factories=[user_factories.AttendingGroupFactory])

        self.get_homepage()
        self.submit_login('timmy', 'password')

        # now we should be redirected directly to home.
        assert self.selenium.current_url == '%s%s' % (
            self.live_server_url, reverse('dashboard-active'))
Ejemplo n.º 14
0
    def setUp(self):
        self.user = build_user()

        self.apt = models.Appointment.objects.create(
            comment='test this stuff',
            clindate=now().date(),
            author=self.user,
            author_type=self.user.groups.first(),
            patient=Patient.objects.first())
Ejemplo n.º 15
0
    def setUp(self):

        self.user = build_user()
        log_in_user(self.client, self.user)

        self.note_data = note_dict(user=self.user)

        self.wu = models.Workup.objects.create(**wu_dict(user=self.user))
        self.form_data = note_dict(user=self.user, encounter_pk=False)
Ejemplo n.º 16
0
    def test_lab_edit_view_no_perm(self):
        """User without lab permissions can't edit lab"""
        log_in_user(self.client,
                    build_user([user_factories.NoPermGroupFactory]))

        lab = self.lab
        url = reverse('labs:lab-edit', kwargs={'pk': lab.id})
        response = self.client.get(url, follow=True)
        assert response.status_code == 403
Ejemplo n.º 17
0
    def setUp(self):

        self.user = build_user([user_factories.AttendingGroupFactory])
        log_in_user(self.client, self.user)

        models.ClinicType.objects.create(name="Basic Care Clinic")
        models.ClinicDate.objects.create(
            clinic_type=models.ClinicType.objects.first(),
            clinic_date=now().date())
Ejemplo n.º 18
0
    def test_core_patient_detail_collapseable(self):
        """Ensure that collapsable AI lists open and close with AIs inside
        """

        user = build_user(password='******',
                       group_factories=[user_factories.AttendingGroupFactory])
        self.get_homepage()
        self.submit_login(user.username, 'password')

        ai_prototype = {
            'instruction': models.ActionInstruction.objects.first(),
            'comments': "",
            'author_type': user.groups.first(),
            'patient': models.Patient.objects.first(),
            'author': user
        }

        models.ActionItem.objects.create(
            due_date=now().today(),
            **ai_prototype
        )

        yesterday = now().date() - datetime.timedelta(days=1)
        models.ActionItem.objects.create(
            due_date=yesterday,
            **ai_prototype
        )

        self.selenium.get('%s%s' % (self.live_server_url,
            reverse('core:patient-detail', args=(1,))))

        active_action_item_id = 'collapse8'

        WebDriverWait(self.selenium, 2).until(
            EC.presence_of_element_located(
                (By.ID, 'toggle-' + active_action_item_id)))

        assert not (self.selenium.find_element_by_id(active_action_item_id)
            .find_element_by_xpath('./ul/li')
            .is_displayed())

        assert len(self.selenium.find_element_by_id(active_action_item_id)
            .find_elements_by_xpath('./ul/li')) == 2

        self.selenium.find_element_by_id('toggle-' + active_action_item_id).click()

        WebDriverWait(self.selenium, 2).until(
            EC.presence_of_element_located(
                (By.XPATH, '//div[@class="panel-collapse collapse in"]')))

        assert len(self.selenium.find_element_by_id(active_action_item_id)
            .find_elements_by_xpath('./ul/li')) == 2

        assert (self.selenium.find_element_by_id(active_action_item_id)
            .find_element_by_xpath('./ul/li')
            .is_displayed())
Ejemplo n.º 19
0
    def setUp(self):

        # build large list of users with different combinations of roles
        self.users = []
        role_list = list(user_factories.all_roles)
        role_powerset = chain.from_iterable(
            combinations(role_list, r) for r in range(1, len(role_list)+1))
        for role_tuple in role_powerset:
            for _ in range(3):
                self.users.append(build_user(list(role_tuple)))
Ejemplo n.º 20
0
    def test_no_create_on_view_if_USER_IP_is_in_BLACKLIST(self):

        expected_user = log_in_user(self.client, build_user())

        # format is: {X-Forwarded-For: client, proxy1, proxy2}
        USER_IP = '0.0.0.1'
        self.client.get(reverse('home'), HTTP_X_FORWARDED_FOR=USER_IP + ',,')

        n_records = PageviewRecord.objects.count()
        self.assertEqual(n_records, 0)
Ejemplo n.º 21
0
    def setUp(self):

        self.user = build_user()
        log_in_user(self.client, self.user)

        self.note_data = note_dict(user=self.user)

        models.ClinicDate.objects.create(
            clinic_type=models.ClinicType.objects.first(),
            clinic_date=now().date())
Ejemplo n.º 22
0
    def setUp(self):

        models.ClinicDate.objects.create(
            clinic_type=models.ClinicType.objects.first(),
            clinic_date=now().date())

        self.user = build_user()
        log_in_user(self.client, self.user)

        self.wu = models.Workup.objects.create(**wu_dict(user=self.user))
Ejemplo n.º 23
0
    def setUp(self):

        log_in_user(self.client, build_user())

        models.IncomeRange.objects.create(name="Default")
        models.EducationLevel.objects.create(name="Default")
        models.WorkStatus.objects.create(name="Default")
        models.ResourceAccess.objects.create(name="Default")
        models.ChronicCondition.objects.create(name="Default")
        models.TransportationOption.objects.create(name="Default")
Ejemplo n.º 24
0
    def setUp(self):

        self.user = build_user()

        for i in range(settings.OSLER_MAX_APPOINTMENTS):
            models.Appointment.objects.create(
                comment=str(i),
                clindate=now().date(),
                author=self.user,
                author_type=self.user.groups.first(),
                patient=Patient.objects.first())
Ejemplo n.º 25
0
    def test_pending_wu_signing(self):
        """Pending workups should not be able to be signed."""

        self.wu.is_pending = True
        self.wu.save()

        user = build_user([user_factories.AttendingGroupFactory])
        group = user.groups.first()

        with self.assertRaises(ValueError):
            self.wu.sign(user, group)
Ejemplo n.º 26
0
def apt_dict():
    apt = {
        'clindate': now().date(),
        'clintime': time(9, 0),
        'appointment_type': 'PSYCH_NIGHT',
        'comment': 'stuff',
        'author': build_user(),
        'patient': core_factories.PatientFactory().id
    }
    apt['author_type'] = apt['author'].groups.first()

    return apt
Ejemplo n.º 27
0
    def setUp(self):
        self.user = build_user()

        log_in_user(self.client, self.user)

        self.ai = ActionItem.objects.create(
            due_date=datetime.date(2020, 1, 1),
            author=self.user,
            instruction=ActionInstruction.objects.create(
                instruction="Follow up on labs"),
            comments="I hate tests",
            author_type=self.user.groups.first(),
            patient=Patient.objects.all()[0])
Ejemplo n.º 28
0
def wu_dict(user=None, units=False, dx_category=False):

    if not user:
        user = build_user()

    fake_text = 'abc'

    pt = core_factories.PatientFactory()
    status = core_factories.EncounterStatusFactory()

    e = Encounter.objects.create(patient=pt,
                                 clinic_day=now().date(),
                                 status=status)

    wu = {
        'encounter': e,
        'chief_complaint': "SOB",
        'diagnosis': "MI",
        'hpi': fake_text,
        'pmh': fake_text,
        'psh': fake_text,
        'meds': fake_text,
        'allergies': fake_text,
        'fam_hx': fake_text,
        'soc_hx': fake_text,
        'ros': "f",
        'pe': "f",
        'a_and_p': "f",
        'hr': '89',
        'bp_sys': '120',
        'bp_dia': '80',
        'rr': '16',
        't': '98',
        'labs_ordered_internal': 'f',
        'labs_ordered_external': 'f',
        'got_voucher': False,
        'got_imaging_voucher': False,
        'author': user,
        'author_type': user.groups.first(),
        'patient': pt
    }

    if units:
        wu['temperature_units'] = 'F'
        wu['weight_units'] = 'lbs'
        wu['height_units'] = 'in'

    if dx_category:
        wu['diagnosis_categories'] = [models.DiagnosisType.objects.first().pk]

    return wu
Ejemplo n.º 29
0
    def test_core_view_rendering(self):
        '''
        Test that core urls render correctly, as determined by the
        existence of a jumbotron at the top.
        '''
        from django.urls import NoReverseMatch

        # build a provider and log in.
        user = build_user(
            password='******',
            group_factories=[user_factories.CaseManagerGroupFactory])
        self.get_homepage()
        self.submit_login(user.username, 'password')

        for url in urls.urlpatterns:
            # except 'core:choose-role' and action item modifiers from test
            # since they're redirects.

            if url.name in [
                    'choose-role', 'done-action-item', 'reset-action-item',
                    'document-detail', 'document-update', 'update-action-item'
            ]:
                # TODO: add test data for documents so document-detail and
                # document-update can be tested as well.
                continue

            # all the URLs have either one parameter or none. Try one
            # parameter first; if that fails, try with none.
            try:
                self.selenium.get(
                    '%s%s' % (self.live_server_url,
                              reverse("%s%s" %
                                      ("core:", url.name), args=(1, ))))
            except NoReverseMatch:
                self.selenium.get(
                    '%s%s' %
                    (self.live_server_url, reverse("%s%s" %
                                                   ("core:", url.name))))

            WebDriverWait(self.selenium, self.DEFAULT_WAIT_TIME).until(
                EC.presence_of_element_located(
                    (By.XPATH, '//div[@class="jumbotron"]')))

            jumbotron_elements = self.selenium.find_elements_by_xpath(
                '//div[@class="jumbotron"]')
            self.assertNotEqual(len(jumbotron_elements),
                                0,
                                msg=" ".join([
                                    "Expected the URL ", url.name,
                                    " to have a jumbotron element."
                                ]))
Ejemplo n.º 30
0
    def setUp(self):
        self.user = build_user()

        log_in_user(self.client, self.user)

        self.pt = core_factories.PatientFactory(case_managers=[self.user])

        self.series_type = factories.VaccineSeriesTypeFactory()

        self.series = factories.VaccineSeriesFactory(
            author=self.user,
            author_type=self.user.groups.first(),
            patient=self.pt,
            kind=self.series_type)