Example #1
0
    def test_form_casemanager_options(self):
        """PatientForm only offers valid case managers as options.
        """

        pvds = user_factories.UserFactory.create_batch(3)

        casemanager = user_factories.CaseManagerGroupFactory()
        not_casemanager = user_factories.VolunteerGroupFactory()

        assert Permission.objects.filter(
            codename='case_manage_Patient').count() == 1

        pvds[0].groups.add(not_casemanager)
        pvds[1].groups.add(casemanager)
        pvds[2].groups.add(not_casemanager, casemanager)
        [p.save() for p in pvds]

        cm_qs = User.objects.filter(
            groups__in=[casemanager]).values_list('id', flat=True)

        form = forms.PatientForm()

        # c[0] is the pk of each, [1:] indexing required because element 0
        # is the "blank" option.
        form_list = [c[0] for c in form['case_managers'].field.choices]

        # cast to set for 1) order-insensitivity and 2) b/c cm_qs is
        # a queryset and form_list is a list
        assert set(cm_qs) == set(form_list)

        # Make sure we reject non-case manager providers

        form = forms.PatientForm()
        form_data = self.valid_pt_dict.copy()
        form_data['case_managers'] = [pvds[0]]
        form = forms.PatientForm(data=form_data)
        assert len(form['case_managers'].errors) != 0

        form_data = self.valid_pt_dict.copy()
        form_data['case_managers'] = [pvds[1].pk]
        form = forms.PatientForm(data=form_data)
        assert len(form['case_managers'].errors) == 0

        # Make sure we accept case manager providers
        form_data = self.valid_pt_dict.copy()
        form_data['case_managers'] = [pvds[2].pk]
        form = forms.PatientForm(data=form_data)
        assert len(form['case_managers'].errors) == 0
Example #2
0
    def test_form_casemanager_options(self):
        """PatientForm only offers valid case managers as options.
        """

        pvds = user_factories.UserFactory.create_batch(3)

        casemanager = user_factories.CaseManagerGroupFactory()
        not_casemanager = user_factories.VolunteerGroupFactory()

        assert Permission.objects.filter(
            codename='case_manage_Patient').count() == 1

        pvds[0].groups.add(not_casemanager)
        pvds[1].groups.add(casemanager)
        pvds[2].groups.add(not_casemanager, casemanager)
        [p.save() for p in pvds]

        cm_qs = User.objects.filter(groups__in=[casemanager])

        form = forms.PatientForm()

        form_qs = form['case_managers'].field.queryset

        # avoid strange behavior with assertQuerysetEqual
        assert set(cm_qs) == set(form_qs)
        assert len(cm_qs) == len(form_qs)

        # Make sure we reject non-case manager providers

        form = forms.PatientForm()
        form_data = self.valid_pt_dict.copy()
        form_data['case_managers'] = [pvds[0]]
        form = forms.PatientForm(data=form_data)
        assert len(form['case_managers'].errors) != 0

        form_data = self.valid_pt_dict.copy()
        form_data['case_managers'] = [pvds[1].pk]
        form = forms.PatientForm(data=form_data)
        assert len(form['case_managers'].errors) == 0

        # Make sure we accept case manager providers
        form_data = self.valid_pt_dict.copy()
        form_data['case_managers'] = [pvds[2].pk]
        form = forms.PatientForm(data=form_data)
        assert len(form['case_managers'].errors) == 0
Example #3
0
    def test_missing_alt_phone_owner(self):
        '''Missing the alt phone owner w/o alt phone should fail.'''
        form_data = self.valid_pt_dict

        form_data['alternate_phone_1'] = "4258612322"
        # omit 'alternate_phone', should get an error

        form = forms.PatientForm(data=form_data)
        # we expect errors on the empty alternate_phone_1_owner field
        self.assertNotEqual(len(form['alternate_phone_1_owner'].errors), 0)
Example #4
0
    def test_missing_alt_phone(self):
        '''Missing the alternative phone w/o alt phone owner should fail.'''
        form_data = self.valid_pt_dict

        form_data['alternate_phone_1_owner'] = "Jamal"
        # omit 'alternate_phone', should get an error

        form = forms.PatientForm(data=form_data)

        # and expect an error to be on the empty altphone field
        self.assertNotEqual(len(form['alternate_phone_1'].errors), 0)
Example #5
0
    def test_form_casemanager_options(self):
        '''
        PatientForm only offers valid case managers as options.
        '''

        casemanager = ProviderType.objects.create(long_name='Case Manager',
                                                  short_name='CM',
                                                  signs_charts=False,
                                                  staff_view=True)

        not_casemanager = ProviderType.objects.create(
            long_name='Not Case Manager',
            short_name='NCM',
            signs_charts=False,
            staff_view=False)

        provider_skeleton = {
            'first_name': "Firstname",
            'last_name': "Lastname",
            'gender': Gender.objects.first(),
        }

        pvds = [
            Provider.objects.create(middle_name=str(i), **provider_skeleton)
            for i in range(4)
        ]
        pvds[1].clinical_roles.add(not_casemanager)
        pvds[2].clinical_roles.add(casemanager)
        pvds[3].clinical_roles.add(not_casemanager, casemanager)
        [p.save() for p in pvds]

        cm_qs = Provider.objects.filter(
            clinical_roles__in=[casemanager]).values_list('id', flat=True)

        form = forms.PatientForm()

        # c[0] is the pk of each, [1:] indexing required because element 0
        # is the "blank" option.
        form_list = [c[0] for c in form['case_managers'].field.choices]

        # cast to set for 1) order-insensitivity and 2) b/c cm_qs is
        # a queryset and form_list is a list
        self.assertEqual(set(cm_qs), set(form_list))

        # Make sure we reject non-case manager providers

        form_data = self.valid_pt_dict.copy()
        form_data['case_managers'] = [pvds[0]]
        form = forms.PatientForm(data=form_data)
        self.assertNotEqual(len(form['case_managers'].errors), 0)

        form_data = self.valid_pt_dict.copy()
        form_data['case_managers'] = [pvds[1].pk]
        form = forms.PatientForm(data=form_data)
        self.assertNotEqual(len(form['case_managers'].errors), 0)

        # Make sure we accept case manager providers

        form_data = self.valid_pt_dict.copy()
        form_data['case_managers'] = [pvds[2].pk]
        form = forms.PatientForm(data=form_data)
        self.assertEqual(len(form['case_managers'].errors), 0)

        form_data = self.valid_pt_dict.copy()
        form_data['case_managers'] = [pvds[3].pk]
        form = forms.PatientForm(data=form_data)
        self.assertEqual(len(form['case_managers'].errors), 0)