Ejemplo n.º 1
0
 def setUp(self):
     super(TestEnrollmentMixin, self).setUp()
     self.maternal_eligibility = MaternalEligibilityFactory()
     self.maternal_consent = MaternalConsentFactory(
         registered_subject=self.maternal_eligibility.registered_subject)
     self.registered_subject = self.maternal_consent.registered_subject
     self.specimen_consent = SpecimenConsentFactory(
         registered_subject=self.registered_subject)
     self.data = {
         'registered_subject': self.registered_subject.id,
         'report_datetime': timezone.now(),
         'is_diabetic': NO,
         'on_tb_tx': NO,
         'will_breastfeed': NO,
         'will_remain_onstudy': NO,
         'week32_test': NO,
         'week32_result': '',
         'current_hiv_status': POS,
         'evidence_hiv_status': NO,
         'valid_regimen': NO,
         'valid_regimen_duration': NOT_APPLICABLE,
         'rapid_test_done': NO,
         'rapid_test_date': '',
         'rapid_test_result': '',
     }
Ejemplo n.º 2
0
    def test_serialize_deserialize(self):
        """Confirms all models have a get_by_natural_key manager method."""
        maternal_eligibility = MaternalEligibilityFactory()
        maternal_consent = MaternalConsentFactory(
            registered_subject=maternal_eligibility.registered_subject)
        specimen_consent = SpecimenConsentFactory(
            registered_subject=maternal_consent.registered_subject)
        antenatal_enrollment = AntenatalEnrollmentFactory(
            registered_subject=specimen_consent.registered_subject,
            current_hiv_status=POS,
            evidence_hiv_status=YES,
            rapid_test_done=NO)
        appointment = Appointment.objects.get(
            registered_subject=antenatal_enrollment.registered_subject,
            visit_definition__code='1000M')
        maternal_visit = MaternalVisitFactory(appointment=appointment)
        maternal_locator = MaternalLocatorFactory(
            maternal_visit=maternal_visit,
            registered_subject=antenatal_enrollment.registered_subject,
        )
        maternal_demographics = MaternalDemographics.objects.create(
            maternal_visit=maternal_visit,
            report_datetime=timezone.now(),
            marital_status='Single',
            ethnicity='Black African',
            highest_education='Tertiary',
            current_occupation='Student',
            provides_money='Mother',
            money_earned='P1001-5000 per month / P212 - 1157 per week',
            own_phone=YES,
            house_electrified=YES,
            house_fridge=YES,
            cooking_method='Gas or electric stove',
            toilet_facility='Indoor toilet',
            house_people_number=1,
            house_type='Formal: Tin-roofed, concrete walls')
        instances = []
        instances.append(maternal_eligibility)
        instances.append(maternal_consent)
        instances.append(specimen_consent)
        instances.append(antenatal_enrollment)
        instances.append(maternal_visit)
        instances.append(maternal_locator)
        instances.append(maternal_demographics)
        for obj in instances:
            natural_key = obj.natural_key()
            get_obj = obj.__class__.objects.get_by_natural_key(*natural_key)
            self.assertEqual(obj.pk, get_obj.pk)

        for obj in instances:
            outgoing_transaction = SerializeToTransaction().serialize(
                obj.__class__, obj, False, True, 'default')
            for transaction in serializers.deserialize(
                    "json",
                    FieldCryptor('aes',
                                 'local').decrypt(outgoing_transaction.tx)):
                self.assertEqual(transaction.object.pk, obj.pk)
 def setUp(self):
     super(TestEnrollmentMixin, self).setUp()
     self.maternal_eligibility = MaternalEligibilityFactory()
     self.maternal_consent = MaternalConsentFactory(
         registered_subject=self.maternal_eligibility.registered_subject)
     self.registered_subject = self.maternal_consent.registered_subject
     self.specimen_consent = SpecimenConsentFactory(registered_subject=self.registered_subject)
     self.data = {
         'registered_subject': self.registered_subject.id,
         'report_datetime': timezone.now(),
         'is_diabetic': NO,
         'on_tb_tx': NO,
         'will_breastfeed': NO,
         'will_remain_onstudy': NO,
         'week32_test': NO,
         'week32_result': '',
         'current_hiv_status': POS,
         'evidence_hiv_status': NO,
         'valid_regimen': NO,
         'valid_regimen_duration': NOT_APPLICABLE,
         'rapid_test_done': NO,
         'rapid_test_date': '',
         'rapid_test_result': '',
     }
Ejemplo n.º 4
0
 def maternal_instances(self):
     instances = []
     maternal_eligibility = MaternalEligibilityFactory()
     instances.append(maternal_eligibility)
     maternal_consent = MaternalConsentFactory(
         registered_subject=maternal_eligibility.registered_subject)
     instances.append(maternal_consent)
     specimen_consent = SpecimenConsentFactory(
         registered_subject=maternal_consent.registered_subject)
     instances.append(specimen_consent)
     antenatal_enrollment = AntenatalEnrollmentFactory(
         registered_subject=specimen_consent.registered_subject,
         current_hiv_status=POS,
         evidence_hiv_status=YES,
         rapid_test_done=NO)
     instances.append(antenatal_enrollment)
     post_natal_enrollment = PostnatalEnrollmentFactory(
         registered_subject=specimen_consent.registered_subject, )
     instances.append(post_natal_enrollment)
     appointment_1000 = Appointment.objects.get(
         registered_subject=antenatal_enrollment.registered_subject,
         visit_definition__code='1000M')
     instances.append(appointment_1000)
     maternal_visit_1000 = MaternalVisitFactory(
         appointment=appointment_1000)
     instances.append(maternal_visit_1000)
     maternal_locator = MaternalLocatorFactory(
         maternal_visit=maternal_visit_1000,
         registered_subject=antenatal_enrollment.registered_subject,
     )
     instances.append(maternal_locator)
     maternal_demographics = MaternalDemographicsFactory(
         maternal_visit=maternal_visit_1000, )
     instances.append(maternal_demographics)
     appointment_2000 = Appointment.objects.get(
         registered_subject=antenatal_enrollment.registered_subject,
         visit_definition__code='2000M')
     instances.append(appointment_2000)
     maternal_visit_2000 = MaternalVisitFactory(
         appointment=appointment_2000)
     instances.append(maternal_visit_2000)
     appointment_2010 = Appointment.objects.get(
         registered_subject=antenatal_enrollment.registered_subject,
         visit_definition__code='2010M')
     maternal_visit_2010 = MaternalVisitFactory(
         appointment=appointment_2010)
     instances.append(maternal_visit_2010)
     reproductive_health = ReproductiveHealthFactory(
         maternal_visit=maternal_visit_2010)
     instances.append(reproductive_health)
     maternal_arv_post = MaternalArvPostFactory(
         maternal_visit=maternal_visit_2010)
     instances.append(maternal_arv_post)
     maternal_arv_post_mod = MaternalArvPostModFactory(
         maternal_arv_post=maternal_arv_post)
     instances.append(maternal_arv_post_mod)
     maternal_arv_preg = MaternalArvPregFactory(
         maternal_visit=maternal_visit_2000)
     instances.append(maternal_arv_preg)
     maternal_arv = MaternalArvFactory(maternal_arv_preg=maternal_arv_preg)
     instances.append(maternal_arv)
     maternal_post_fu_med = MaternalPostFuMedFactory(
         maternal_visit=maternal_visit_2010)
     instances.append(maternal_post_fu_med)
     maternal_post_fu_items = MaternalPostFuMedItemsFactory(
         maternal_post_fu_med=maternal_post_fu_med)
     instances.append(maternal_post_fu_items)
     maternal_post_fu_dx = MaternalPostFuDxFactory(
         maternal_visit=maternal_visit_2010)
     instances.append(maternal_post_fu_dx)
     #         maternal_post_fu_dxt = MaternalPostFuDxTFactory(maternal_post_fu_dx=maternal_post_fu_dx)
     #         instances.append(maternal_post_fu_dxt)
     return instances
class TestEnrollmentMixin(BaseTestCase):
    """Test eligibility of a mother for antenatal enrollment."""

    def setUp(self):
        super(TestEnrollmentMixin, self).setUp()
        self.maternal_eligibility = MaternalEligibilityFactory()
        self.maternal_consent = MaternalConsentFactory(
            registered_subject=self.maternal_eligibility.registered_subject)
        self.registered_subject = self.maternal_consent.registered_subject
        self.specimen_consent = SpecimenConsentFactory(registered_subject=self.registered_subject)
        self.data = {
            'registered_subject': self.registered_subject.id,
            'report_datetime': timezone.now(),
            'is_diabetic': NO,
            'on_tb_tx': NO,
            'will_breastfeed': NO,
            'will_remain_onstudy': NO,
            'week32_test': NO,
            'week32_result': '',
            'current_hiv_status': POS,
            'evidence_hiv_status': NO,
            'valid_regimen': NO,
            'valid_regimen_duration': NOT_APPLICABLE,
            'rapid_test_done': NO,
            'rapid_test_date': '',
            'rapid_test_result': '',
        }

    def test_process_rapid_yes_date_req(self):
        """If rapid test was processed, test date was processed is required"""
        self.data['rapid_test_done'] = YES
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You indicated that a rapid test was processed. Please provide the date.',
                      form.errors.get('__all__'))

    def test_process_rapid_no_date_req(self):
        """If rapid test was NOT processed, test date was processed is  NOT required"""
        self.data['rapid_test_done'] = NO
        self.data['rapid_test_date'] = date.today()
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You indicated that a rapid test was NOT processed, yet rapid test date was provided. '
                      'Please correct.', form.errors.get('__all__'))

    def test_process_rapid_na_date_req(self):
        """If rapid test was NOT processed, test date was processed is  NOT required"""
        self.data['rapid_test_done'] = NOT_APPLICABLE
        self.data['rapid_test_date'] = date.today()
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You indicated that a rapid test was NOT processed, yet rapid test date was provided. '
                      'Please correct.', form.errors.get('__all__'))

    def test_process_rapid_yes_result_req(self):
        """If rapid test was processed, test result was processed is required"""
        self.data['rapid_test_done'] = YES
        self.data['rapid_test_date'] = date.today()
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You indicated that a rapid test was processed. Please provide a result.',
                      form.errors.get('__all__'))

    def test_process_rapid_no_result_not_req(self):
        """If rapid test was NOT processed, test result was processed is NOT required"""
        self.data['rapid_test_done'] = NO
        self.data['rapid_test_result'] = POS
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You indicated that a rapid test was NOT processed, yet rapid test result was provided. '
                      'Please correct.', form.errors.get('__all__'))

    def test_process_rapid_na_result_not_req(self):
        """If rapid test was NOT processed, test result was processed is NOT required"""
        self.data['rapid_test_done'] = NOT_APPLICABLE
        self.data['rapid_test_result'] = NEG
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You indicated that a rapid test was NOT processed, yet rapid test result was provided. '
                      'Please correct.', form.errors.get('__all__'))

    def test_regimen_duration_na(self):
        self.data['valid_regimen'] = YES
        self.data['valid_regimen_duration'] = NOT_APPLICABLE
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You have indicated that the participant is on ARV. Regimen validity period'
                      ' CANNOT be \'Not Applicable\'. Please correct.', form.errors.get('__all__'))

    def test_regimen_duration_yes(self):
        self.data['valid_regimen'] = NO
        self.data['valid_regimen_duration'] = YES
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You have indicated that there are no records of Participant taking ARVs. '
                      'Regimen validity period should be \'Not Applicable\'. '
                      'Please correct.', form.errors.get('__all__'))

    def test_regimen_duration_no(self):
        self.data['valid_regimen'] = NO
        self.data['valid_regimen_duration'] = NO
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You have indicated that there are no records of Participant taking ARVs. '
                      'Regimen validity period should be \'Not Applicable\'. '
                      'Please correct.', form.errors.get('__all__'))

    def test_hiv_evidence_pos(self):
        self.data['evidence_hiv_status'] = NOT_APPLICABLE
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You have indicated that the participant is Positive, Evidence of HIV '
                      'result CANNOT be \'Not Applicable\'. Please correct.', form.errors.get('__all__'))

    def test_hiv_evidence_pos_reg_na(self):
        self.data['valid_regimen'] = NOT_APPLICABLE
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You have indicated that the participant is Positive, \'do records show that'
                      ' participant takes ARVs\' cannot be \'Not Applicable\'.', form.errors.get('__all__'))

    def test_hiv_evidence_neg(self):
        self.data['current_hiv_status'] = NEG
        self.data['evidence_hiv_status'] = NOT_APPLICABLE
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('You have indicated that the participant is Negative, Evidence of HIV '
                      'result CANNOT be \'Not Applicable\'. Please correct.', form.errors.get('__all__'))

    def test_sample_filled_before_enrollment(self):
        self.specimen_consent.delete()
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('Please ensure to save the Specimen Consent before completing Enrollment',
                      form.errors.get('__all__'))

    def test_pos_with_evidence_and_do_rapid_test(self):
        self.data['evidence_hiv_status'] = YES
        self.data['rapid_test_done'] = YES
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('There is no need for a rapid test. Subject is positive and has evidence.',
                      form.errors.get('__all__'))

    def test_participant_never_tested(self):
        self.data['current_hiv_status'] = NEVER
        self.data['evidence_hiv_status'] = NOT_APPLICABLE
        self.data['valid_regimen'] = NOT_APPLICABLE
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('Participant current HIV status is {}. You must conduct HIV rapid testing '
                      'today to continue with the eligibility screen'.format(
                          self.data['current_hiv_status']), form.errors.get('__all__'))

    def test_results_comparison(self):
        self.data['week32_test'] = YES
        self.data['week32_result'] = NEG
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'The current hiv status and result at 32weeks should be the same!',
            form.errors.get('__all__'))

    def test_tested_at_32weeks_no_result(self):
        self.data['week32_test'] = YES
        self.data['week32_result'] = None
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('Please provide test result at week 32.', form.errors.get('__all__'))

    def test_not_tested_at_32weeks_results_given(self):
        self.data['week32_result'] = POS
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You mentioned testing was not done at 32weeks yet provided a '
            'test result.', form.errors.get('__all__'))

    def test_date_at_32wks(self):
        """Asserts the test date is correctly calculated to be on or after 32 wks."""
        obj = AntenatalEnrollment(
            week32_test_date=date.today() - relativedelta(weeks=7),
            gestation_wks=38,
            report_datetime=timezone.now())
        enrollment_helper = EnrollmentHelper(obj)
        self.assertFalse(enrollment_helper.test_date_is_on_or_after_32wks())

        obj = AntenatalEnrollment(
            week32_test_date=date.today() - relativedelta(weeks=6),
            gestation_wks=38,
            report_datetime=timezone.now())
        enrollment_helper = EnrollmentHelper(obj)
        self.assertTrue(enrollment_helper.test_date_is_on_or_after_32wks())

        obj = AntenatalEnrollment(
            week32_test_date=date.today() - relativedelta(weeks=5),
            gestation_wks=38,
            report_datetime=timezone.now())
        enrollment_helper = EnrollmentHelper(obj)
        self.assertTrue(enrollment_helper.test_date_is_on_or_after_32wks())

        obj = AntenatalEnrollment(
            week32_test_date=date.today(),
            gestation_wks=38,
            report_datetime=timezone.now())
        enrollment_helper = EnrollmentHelper(obj)
        self.assertTrue(enrollment_helper.test_date_is_on_or_after_32wks())

    def test_neg_rapid_not_required(self):
        """Assert rapid not required if last test was within 32 weeks."""
        obj = AntenatalEnrollment(
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            week32_test=YES,
            week32_test_date=date(2015, 11, 13),
            week32_result=NEG,
            rapid_test_done=NOT_APPLICABLE,
            report_datetime=timezone.datetime(2015, 12, 11, 0, 0, 0),
            gestation_wks=36,
            is_diabetic=NO,
            on_tb_tx=NO,
            on_hypertension_tx=NO,
            will_breastfeed=YES,
            will_remain_onstudy=YES)
        enrollment_helper = EnrollmentHelper(obj)
        self.assertTrue(enrollment_helper.is_eligible)

    def test_neg_rapid_required_raises_on_invalid_week32_date(self):
        obj = AntenatalEnrollment(
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            week32_test=YES,
            week32_test_date=date(2015, 11, 1),
            week32_result=NEG,
            rapid_test_done=NOT_APPLICABLE,
            report_datetime=timezone.datetime(2015, 12, 11, 0, 0, 0),
            gestation_wks=36,
            is_diabetic=NO,
            on_tb_tx=NO,
            on_hypertension_tx=NO,
            will_breastfeed=YES,
            will_remain_onstudy=YES)
        self.assertRaises(EnrollmentError, EnrollmentHelper, obj)

    def test_neg_rapid_required(self):
        obj = AntenatalEnrollment(
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            week32_test=NO,
            rapid_test_done=NOT_APPLICABLE,
            report_datetime=timezone.datetime(2015, 12, 11, 0, 0, 0),
            gestation_wks=36,
            is_diabetic=NO,
            on_tb_tx=NO,
            on_hypertension_tx=NO,
            will_breastfeed=YES,
            will_remain_onstudy=YES)
        enrollment_helper = EnrollmentHelper(obj)
        self.assertFalse(enrollment_helper.is_eligible)

    def test_neg_rapid_required2(self):
        obj = AntenatalEnrollment(
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            week32_test=YES,
            week32_test_date=date(2015, 11, 13),
            week32_result=NEG,
            rapid_test_done=YES,
            rapid_test_date=date(2015, 12, 11),
            rapid_test_result=NEG,
            report_datetime=timezone.datetime(2015, 12, 11, 0, 0, 0),
            gestation_wks=36,
            is_diabetic=NO,
            on_tb_tx=NO,
            on_hypertension_tx=NO,
            will_breastfeed=YES,
            will_remain_onstudy=YES)
        enrollment_helper = EnrollmentHelper(obj)
        self.assertTrue(enrollment_helper.is_eligible)

    def test_neg_rapid_required_invalid_rapid_test_date(self):
        obj = AntenatalEnrollment(
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            week32_test=YES,
            week32_test_date=date(2015, 11, 13),
            week32_result=NEG,
            rapid_test_done=YES,
            rapid_test_date=date(2015, 11, 12),
            rapid_test_result=NEG,
            report_datetime=timezone.datetime(2015, 12, 11, 0, 0, 0),
            gestation_wks=36,
            is_diabetic=NO,
            on_tb_tx=NO,
            on_hypertension_tx=NO,
            will_breastfeed=YES,
            will_remain_onstudy=YES)
        self.assertRaises(EnrollmentError, EnrollmentHelper, obj)
Ejemplo n.º 6
0
class TestEnrollmentMixin(BaseTestCase):
    """Test eligibility of a mother for antenatal enrollment."""
    def setUp(self):
        super(TestEnrollmentMixin, self).setUp()
        self.maternal_eligibility = MaternalEligibilityFactory()
        self.maternal_consent = MaternalConsentFactory(
            registered_subject=self.maternal_eligibility.registered_subject)
        self.registered_subject = self.maternal_consent.registered_subject
        self.specimen_consent = SpecimenConsentFactory(
            registered_subject=self.registered_subject)
        self.data = {
            'registered_subject': self.registered_subject.id,
            'report_datetime': timezone.now(),
            'is_diabetic': NO,
            'on_tb_tx': NO,
            'will_breastfeed': NO,
            'will_remain_onstudy': NO,
            'week32_test': NO,
            'week32_result': '',
            'current_hiv_status': POS,
            'evidence_hiv_status': NO,
            'valid_regimen': NO,
            'valid_regimen_duration': NOT_APPLICABLE,
            'rapid_test_done': NO,
            'rapid_test_date': '',
            'rapid_test_result': '',
        }

    def test_process_rapid_yes_date_req(self):
        """If rapid test was processed, test date was processed is required"""
        self.data['rapid_test_done'] = YES
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You indicated that a rapid test was processed. Please provide the date.',
            form.errors.get('__all__'))

    def test_process_rapid_no_date_req(self):
        """If rapid test was NOT processed, test date was processed is  NOT required"""
        self.data['rapid_test_done'] = NO
        self.data['rapid_test_date'] = date.today()
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You indicated that a rapid test was NOT processed, yet rapid test date was provided. '
            'Please correct.', form.errors.get('__all__'))

    def test_process_rapid_na_date_req(self):
        """If rapid test was NOT processed, test date was processed is  NOT required"""
        self.data['rapid_test_done'] = NOT_APPLICABLE
        self.data['rapid_test_date'] = date.today()
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You indicated that a rapid test was NOT processed, yet rapid test date was provided. '
            'Please correct.', form.errors.get('__all__'))

    def test_process_rapid_yes_result_req(self):
        """If rapid test was processed, test result was processed is required"""
        self.data['rapid_test_done'] = YES
        self.data['rapid_test_date'] = date.today()
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You indicated that a rapid test was processed. Please provide a result.',
            form.errors.get('__all__'))

    def test_process_rapid_no_result_not_req(self):
        """If rapid test was NOT processed, test result was processed is NOT required"""
        self.data['rapid_test_done'] = NO
        self.data['rapid_test_result'] = POS
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You indicated that a rapid test was NOT processed, yet rapid test result was provided. '
            'Please correct.', form.errors.get('__all__'))

    def test_process_rapid_na_result_not_req(self):
        """If rapid test was NOT processed, test result was processed is NOT required"""
        self.data['rapid_test_done'] = NOT_APPLICABLE
        self.data['rapid_test_result'] = NEG
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You indicated that a rapid test was NOT processed, yet rapid test result was provided. '
            'Please correct.', form.errors.get('__all__'))

    def test_regimen_duration_na(self):
        self.data['valid_regimen'] = YES
        self.data['valid_regimen_duration'] = NOT_APPLICABLE
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You have indicated that the participant is on ARV. Regimen validity period'
            ' CANNOT be \'Not Applicable\'. Please correct.',
            form.errors.get('__all__'))

    def test_regimen_duration_yes(self):
        self.data['valid_regimen'] = NO
        self.data['valid_regimen_duration'] = YES
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You have indicated that there are no records of Participant taking ARVs. '
            'Regimen validity period should be \'Not Applicable\'. '
            'Please correct.', form.errors.get('__all__'))

    def test_regimen_duration_no(self):
        self.data['valid_regimen'] = NO
        self.data['valid_regimen_duration'] = NO
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You have indicated that there are no records of Participant taking ARVs. '
            'Regimen validity period should be \'Not Applicable\'. '
            'Please correct.', form.errors.get('__all__'))

    def test_hiv_evidence_pos(self):
        self.data['evidence_hiv_status'] = NOT_APPLICABLE
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You have indicated that the participant is Positive, Evidence of HIV '
            'result CANNOT be \'Not Applicable\'. Please correct.',
            form.errors.get('__all__'))

    def test_hiv_evidence_pos_reg_na(self):
        self.data['valid_regimen'] = NOT_APPLICABLE
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You have indicated that the participant is Positive, \'do records show that'
            ' participant takes ARVs\' cannot be \'Not Applicable\'.',
            form.errors.get('__all__'))

    def test_hiv_evidence_neg(self):
        self.data['current_hiv_status'] = NEG
        self.data['evidence_hiv_status'] = NOT_APPLICABLE
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You have indicated that the participant is Negative, Evidence of HIV '
            'result CANNOT be \'Not Applicable\'. Please correct.',
            form.errors.get('__all__'))

    def test_sample_filled_before_enrollment(self):
        self.specimen_consent.delete()
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'Please ensure to save the Specimen Consent before completing Enrollment',
            form.errors.get('__all__'))

    def test_pos_with_evidence_and_do_rapid_test(self):
        self.data['evidence_hiv_status'] = YES
        self.data['rapid_test_done'] = YES
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'There is no need for a rapid test. Subject is positive and has evidence.',
            form.errors.get('__all__'))

    def test_participant_never_tested(self):
        self.data['current_hiv_status'] = NEVER
        self.data['evidence_hiv_status'] = NOT_APPLICABLE
        self.data['valid_regimen'] = NOT_APPLICABLE
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'Participant current HIV status is {}. You must conduct HIV rapid testing '
            'today to continue with the eligibility screen'.format(
                self.data['current_hiv_status']), form.errors.get('__all__'))

    def test_results_comparison(self):
        self.data['week32_test'] = YES
        self.data['week32_result'] = NEG
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'The current hiv status and result at 32weeks should be the same!',
            form.errors.get('__all__'))

    def test_tested_at_32weeks_no_result(self):
        self.data['week32_test'] = YES
        self.data['week32_result'] = None
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn('Please provide test result at week 32.',
                      form.errors.get('__all__'))

    def test_not_tested_at_32weeks_results_given(self):
        self.data['week32_result'] = POS
        form = BaseEnrollTestForm(data=self.data)
        self.assertIn(
            'You mentioned testing was not done at 32weeks yet provided a '
            'test result.', form.errors.get('__all__'))

    def test_date_at_32wks(self):
        """Asserts the test date is correctly calculated to be on or after 32 wks."""
        obj = AntenatalEnrollment(week32_test_date=date.today() -
                                  relativedelta(weeks=7),
                                  gestation_wks=38,
                                  report_datetime=timezone.now())
        enrollment_helper = EnrollmentHelper(obj)
        self.assertFalse(enrollment_helper.test_date_is_on_or_after_32wks())

        obj = AntenatalEnrollment(week32_test_date=date.today() -
                                  relativedelta(weeks=6),
                                  gestation_wks=38,
                                  report_datetime=timezone.now())
        enrollment_helper = EnrollmentHelper(obj)
        self.assertTrue(enrollment_helper.test_date_is_on_or_after_32wks())

        obj = AntenatalEnrollment(week32_test_date=date.today() -
                                  relativedelta(weeks=5),
                                  gestation_wks=38,
                                  report_datetime=timezone.now())
        enrollment_helper = EnrollmentHelper(obj)
        self.assertTrue(enrollment_helper.test_date_is_on_or_after_32wks())

        obj = AntenatalEnrollment(week32_test_date=date.today(),
                                  gestation_wks=38,
                                  report_datetime=timezone.now())
        enrollment_helper = EnrollmentHelper(obj)
        self.assertTrue(enrollment_helper.test_date_is_on_or_after_32wks())

    def test_neg_rapid_not_required(self):
        """Assert rapid not required if last test was within 32 weeks."""
        obj = AntenatalEnrollment(current_hiv_status=NEG,
                                  evidence_hiv_status=YES,
                                  week32_test=YES,
                                  week32_test_date=date(2015, 11, 13),
                                  week32_result=NEG,
                                  rapid_test_done=NOT_APPLICABLE,
                                  report_datetime=timezone.datetime(
                                      2015, 12, 11, 0, 0, 0),
                                  gestation_wks=36,
                                  is_diabetic=NO,
                                  on_tb_tx=NO,
                                  on_hypertension_tx=NO,
                                  will_breastfeed=YES,
                                  will_remain_onstudy=YES)
        enrollment_helper = EnrollmentHelper(obj)
        self.assertTrue(enrollment_helper.is_eligible)

    def test_neg_rapid_required_raises_on_invalid_week32_date(self):
        obj = AntenatalEnrollment(current_hiv_status=NEG,
                                  evidence_hiv_status=YES,
                                  week32_test=YES,
                                  week32_test_date=date(2015, 11, 1),
                                  week32_result=NEG,
                                  rapid_test_done=NOT_APPLICABLE,
                                  report_datetime=timezone.datetime(
                                      2015, 12, 11, 0, 0, 0),
                                  gestation_wks=36,
                                  is_diabetic=NO,
                                  on_tb_tx=NO,
                                  on_hypertension_tx=NO,
                                  will_breastfeed=YES,
                                  will_remain_onstudy=YES)
        self.assertRaises(EnrollmentError, EnrollmentHelper, obj)

    def test_neg_rapid_required(self):
        obj = AntenatalEnrollment(current_hiv_status=NEG,
                                  evidence_hiv_status=YES,
                                  week32_test=NO,
                                  rapid_test_done=NOT_APPLICABLE,
                                  report_datetime=timezone.datetime(
                                      2015, 12, 11, 0, 0, 0),
                                  gestation_wks=36,
                                  is_diabetic=NO,
                                  on_tb_tx=NO,
                                  on_hypertension_tx=NO,
                                  will_breastfeed=YES,
                                  will_remain_onstudy=YES)
        enrollment_helper = EnrollmentHelper(obj)
        self.assertFalse(enrollment_helper.is_eligible)

    def test_neg_rapid_required2(self):
        obj = AntenatalEnrollment(current_hiv_status=NEG,
                                  evidence_hiv_status=YES,
                                  week32_test=YES,
                                  week32_test_date=date(2015, 11, 13),
                                  week32_result=NEG,
                                  rapid_test_done=YES,
                                  rapid_test_date=date(2015, 12, 11),
                                  rapid_test_result=NEG,
                                  report_datetime=timezone.datetime(
                                      2015, 12, 11, 0, 0, 0),
                                  gestation_wks=36,
                                  is_diabetic=NO,
                                  on_tb_tx=NO,
                                  on_hypertension_tx=NO,
                                  will_breastfeed=YES,
                                  will_remain_onstudy=YES)
        enrollment_helper = EnrollmentHelper(obj)
        self.assertTrue(enrollment_helper.is_eligible)

    def test_neg_rapid_required_invalid_rapid_test_date(self):
        obj = AntenatalEnrollment(current_hiv_status=NEG,
                                  evidence_hiv_status=YES,
                                  week32_test=YES,
                                  week32_test_date=date(2015, 11, 13),
                                  week32_result=NEG,
                                  rapid_test_done=YES,
                                  rapid_test_date=date(2015, 11, 12),
                                  rapid_test_result=NEG,
                                  report_datetime=timezone.datetime(
                                      2015, 12, 11, 0, 0, 0),
                                  gestation_wks=36,
                                  is_diabetic=NO,
                                  on_tb_tx=NO,
                                  on_hypertension_tx=NO,
                                  will_breastfeed=YES,
                                  will_remain_onstudy=YES)
        self.assertRaises(EnrollmentError, EnrollmentHelper, obj)