Beispiel #1
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)
        # Disc measurement
        self.ua_blood = factories.DiscreteMeasurementTypeFactory(
            long_name='Urine blood', short_name='blood', lab_type=self.ua)

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

        # Disc option 2
        self.disc_result_pos = factories.DiscreteResultTypeFactory(name='pos')
        self.disc_result_pos.measurement_type.set([self.ua_blood])

        self.pt = core_factories.PatientFactory()

        self.form_data = {
            'lab_time': now(),
            'patient': self.pt,
            'pH': 5,
            'glucose': 1,
            'blood': self.disc_result_neg
        }
Beispiel #2
0
    def test_create_action_item(self):

        assert models.ActionItem.objects.count() == 0

        submitted_ai = {
            "instruction": factories.ActionInstructionFactory(),
            "due_date": str(datetime.date.today() + datetime.timedelta(10)),
            "comments": "an arbitrary string comment"
        }

        pt = factories.PatientFactory()
        url = reverse('core:new-action-item', kwargs={'pt_id': pt.id})
        response = self.client.post(url, submitted_ai)

        assert response.status_code == 302
        assert reverse('core:patient-detail', args=(pt.id, )) in response.url
        assert models.ActionItem.objects.count() == 1

        new_ai = models.ActionItem.objects.first()

        submitted_ai['due_date'] = datetime.date(
            *([int(i) for i in submitted_ai['due_date'].split('-')]))

        for param in submitted_ai:
            assert str(submitted_ai[param]) == str(getattr(new_ai, param))

        assert new_ai.author.id == self.coordinator.id
        assert new_ai.author_type.id == self.coordinator.groups.first().id
        assert new_ai.patient.id == pt.id

        assert (now() - new_ai.written_datetime).total_seconds() <= 10
        assert (now() - new_ai.last_modified).total_seconds() <= 10
Beispiel #3
0
    def setUp(self):
        self.ua = factories.LabTypeFactory(name='Urinalysis')

        # Cont measurement without panic levels
        self.ua_glucose = factories.ContinuousMeasurementTypeFactory(
            long_name='Urine glucose',
            short_name='glucose',
            lab_type=self.ua,
            unit=None,
            panic_lower=None,
            panic_upper=None)
        # Disc measurement
        self.ua_blood = factories.DiscreteMeasurementTypeFactory(
            long_name='Urine blood', short_name='blood', lab_type=self.ua)

        # Disc option 1, normal
        self.disc_result_neg = factories.DiscreteResultTypeFactory(
            name='neg', is_panic='F')
        self.disc_result_neg.measurement_type.set([self.ua_blood])
        # Disc option 2, abnormal
        self.disc_result_pos = factories.DiscreteResultTypeFactory(
            name='pos', is_panic='T')
        self.disc_result_pos.measurement_type.set([self.ua_blood])

        self.pt = core_factories.PatientFactory()
        self.lab = factories.LabFactory(patient=self.pt, lab_type=self.ua)
Beispiel #4
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)
Beispiel #5
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
        }
Beispiel #6
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()
Beispiel #7
0
    def test_activate_urls(self):
        pt = factories.PatientFactory()

        response = self.client.get(reverse('core:patient-activate-detail', args=(pt.id,)))
        assert response.status_code == 302

        response = self.client.get(reverse('core:patient-activate-home', args=(pt.id,)))
        assert response.status_code == 302
Beispiel #8
0
    def setUp(self):
        self.coordinator = build_user([user_factories.CaseManagerGroupFactory])
        log_in_user(self.client, self.coordinator)

        self.pt1 = core_factories.PatientFactory()
        self.pt2 = core_factories.PatientFactory()
        self.pt3 = core_factories.PatientFactory()

        #pt1 has an active encounter today
        self.encounter1 = core_factories.EncounterFactory(patient=self.pt1)
        self.encounter1.order = 1
        #pt2 has an active encounter today
        self.encounter2 = core_factories.EncounterFactory(patient=self.pt2)
        self.encounter2.order = 2
        #pt3 has an inactive encounter today
        self.encounter3 = core_factories.EncounterFactory(
            patient=self.pt3,
            status=core_factories.EncounterStatusFactory(name="Nope",
                                                         is_active=False))
        self.encounter3.order = 3
Beispiel #9
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)))
        self.pt = core_factories.PatientFactory()
Beispiel #10
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
Beispiel #11
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
Beispiel #12
0
    def test_action_item_urls(self):
        ai = models.ActionItem.objects.create(
            instruction=factories.ActionInstructionFactory(),
            due_date=now().today(),
            author=self.coordinator,
            author_type=self.coordinator.groups.first(),
            patient=factories.PatientFactory())

        response = self.client.get(
            reverse('core:patient-detail', args=(ai.patient.id, )))
        self.assertTemplateUsed(response, 'core/patient_detail.html')
        self.assertContains(response,
                            reverse('core:done-action-item', args=(ai.id, )))

        # new action items should not be done
        assert not ai.done()

        # submit a request to mark the new ai as done. should redirect to
        # choose a followup type.
        response = self.client.get(
            reverse('core:done-action-item', args=(ai.id, )))
        assert response.status_code == 302
        assert reverse("new-actionitem-followup",
                       kwargs={
                           'pt_id': ai.patient.pk,
                           'ai_id': ai.pk
                       }) in response.url
        assert models.ActionItem.objects.first().done()
        assert \
            models.ActionItem.objects.first().written_datetime != \
            models.ActionItem.objects.first().last_modified

        # submit a request to reset the ai. should redirect to pt
        prev_mod_datetime = models.ActionItem.objects.first().last_modified
        response = self.client.get(
            reverse('core:reset-action-item', args=(ai.id, )))
        assert response.status_code == 302
        assert reverse('core:patient-detail',
                       args=(ai.patient.id, )) in response.url
        assert not models.ActionItem.objects.first().done()

        assert (models.ActionItem.objects.first().written_datetime !=
                models.ActionItem.objects.first().last_modified)
        assert prev_mod_datetime != \
            models.ActionItem.objects.first().last_modified

        # make sure updating the action items url works
        response = self.client.get(
            reverse('core:update-action-item', args=(ai.pk, )))
        assert response.status_code == 200
Beispiel #13
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)
Beispiel #14
0
    def test_activate_perms(self):
        pt = factories.PatientFactory()
        assert not pt.get_status().is_active

        pt.toggle_active_status(self.coordinator, self.coordinator.groups.first())
        assert pt.get_status().is_active

        attending = build_user([user_factories.AttendingGroupFactory])
        with self.assertRaises(ValueError):
            pt.toggle_active_status(attending, attending.groups.first())
        assert pt.get_status().is_active

        volunteer = build_user([user_factories.VolunteerGroupFactory])
        with self.assertRaises(ValueError):
            pt.toggle_active_status(volunteer, volunteer.groups.first())
        assert pt.get_status().is_active
Beispiel #15
0
    def setUp(self):
        self.users = user_factories.UserFactory.create_batch(
            4,
            groups=[user_factories.CaseManagerGroupFactory()],
            provider=factories.ProviderFactory())

        pt = factories.PatientFactory(
            case_managers=[self.users[0], self.users[2]]
        )

        tomorrow = now().date() + datetime.timedelta(days=1)
        yesterday = now().date() - datetime.timedelta(days=1)

        # action item due today
        factories.ActionItemFactory(
            due_date=now().today(),
            author=self.users[0],
            author_type=self.users[0].groups.first(),
            patient=pt
        )

        # action item due yesterday
        factories.ActionItemFactory(
            due_date=yesterday,
            author=self.users[0],
            author_type=self.users[0].groups.first(),
            patient=pt
        )

        # action item due tomorrow
        factories.ActionItemFactory(
            due_date=tomorrow,
            author=self.users[1],
            author_type=self.users[1].groups.first(),
            patient=pt
        )

        # complete action item from yesterday
        factories.ActionItemFactory(
            due_date=yesterday,
            author=self.users[1],
            author_type=self.users[1].groups.first(),
            patient=pt,
            completion_date=now(),
            completion_author=self.users[1],
        )
Beispiel #16
0
    def test_unsigned_email(self):

        pt = core_factories.PatientFactory()

        wu_data = wu_dict(user=self.user)
        wu_data['attending'] = self.user

        wu_signed = models.Workup.objects.create(**wu_data)
        wu_signed.sign(self.user, self.user.groups.first())
        wu_signed.save()

        wu_unsigned = models.Workup.objects.create(**wu_data)

        call_command('unsigned_wu_notify')

        assert len(mail.outbox) == 1
        assert mail.outbox[0].subject == '[OSLER] 1 Unattested Notes'
        assert str(pt) in mail.outbox[0].body
        assert self.user.last_name in mail.outbox[0].body
Beispiel #17
0
    def test_action_item_completeable_functions(self):

        ai = models.ActionItem.objects.create(
            author=self.coordinator,
            author_type=self.coordinator.groups.first(),
            due_date=(now() + datetime.timedelta(days=3)).date(),
            instruction=factories.ActionInstructionFactory(),
            patient=factories.PatientFactory())

        self.assertEqual(
            ai.attribution(),
            "Added by %s on %s" % (self.coordinator.name, now().date()))

        coordinator2 = build_user([user_factories.CaseManagerGroupFactory])
        ai.mark_done(coordinator2)
        ai.save()

        assert ai.attribution() == ("Marked done by %s on %s" %
                                    (coordinator2.name, now().date()))
Beispiel #18
0
    def test_activate_encounter_logic(self):
        pt = factories.PatientFactory()
        #new patient should have no encounters
        assert not models.Encounter.objects.filter(patient=pt).exists()

        pt.toggle_active_status(self.coordinator, self.coordinator.groups.first())
        #now one encounter today that is active
        assert len(models.Encounter.objects.filter(patient=pt)) == 1
        encounter = models.Encounter.objects.get(patient=pt)
        assert encounter.clinic_day == now().date()
        assert encounter.status.is_active
        
        pt.toggle_active_status(self.coordinator, self.coordinator.groups.first())
        #inactivates that encounter
        assert not models.Encounter.objects.get(patient=pt).status.is_active

        pt.toggle_active_status(self.coordinator, self.coordinator.groups.first())
        #reactivates that encounter but doesn't make a new one
        assert models.Encounter.objects.get(patient=pt).status.is_active
        assert len(models.Encounter.objects.filter(patient=pt)) == 1
Beispiel #19
0
    def test_invalid_workup_submit_preserves_units(self):

        # first, craft a workup that has units, but fail to set the
        # diagnosis categories, so that it will fail to be accepted.
        wu_data = wu_dict(units=True)
        del wu_data['chief_complaint']
        pt = core_factories.PatientFactory()

        response = self.client.post(reverse('new-workup', args=(pt.id, )),
                                    data=wu_data)

        # verify we're bounced back to workup_create
        assert response.status_code == 200
        self.assertTemplateUsed(response, 'workup/workup_create.html')
        self.assertFormError(response, 'form', 'chief_complaint',
                             'This field is required.')

        for unit in ['height_units', 'weight_units', 'temperature_units']:
            self.assertContains(response, '<input name="%s"' % (unit))

            assert response.context['form'][unit].value() == wu_data[unit]
Beispiel #20
0
def note_dict(user=None, encounter_pk=True):

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

    if not user:
        user = build_user()

    pn = {
        'title': 'Good',
        'text': 'boy',
        'author': user,
        'author_type': user.groups.first(),
        'patient': pt
    }

    if encounter_pk:
        pn['encounter'] = Encounter.objects.create(patient=pt,
                                                   clinic_day=now().date(),
                                                   status=status)

    return pn
Beispiel #21
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)

        self.vai = models.VaccineActionItem.objects.create(
            instruction=ActionInstruction.objects.create(
                instruction="Please call"),
            due_date=datetime.date.today(),
            comments="",
            author=self.user,
            author_type=self.user.groups.first(),
            patient=self.pt,
            vaccine=self.series)
Beispiel #22
0
    def setUp(self):
        self.user = build_user()
        log_in_user(self.client, self.user)

        self.patient = factories.PatientFactory()
Beispiel #23
0
    def setUp(self):
        self.user = build_user()

        log_in_user(self.client, self.user)

        self.pt = core_factories.PatientFactory(case_managers=[self.user])
Beispiel #24
0
    def test_new_workup_view(self):
        """Test that user can successfully access new workup page."""

        pt = core_factories.PatientFactory()
        response = self.client.get(reverse('new-workup', args=(pt.id, )))
        assert response.status_code == 200