예제 #1
0
class TestRapidTestForm(BaseTestCase):

    def setUp(self):
        super(TestRapidTestForm, self).setUp()
        self.maternal_eligibility = MaternalEligibilityFactory()
        self.assertTrue(self.maternal_eligibility.is_eligible)
        self.maternal_consent = MaternalConsentFactory(
            registered_subject=self.maternal_eligibility.registered_subject)
        self.registered_subject = self.maternal_consent.registered_subject
        self.data = {
            'report_datetime': timezone.now(),
            'maternal_visit': None,
            'rapid_test_done': YES,
            'result_date': timezone.now(),
            'result': None,
        }

    def test_validate_rapid_test_done_no_result(self):
        self.maternal_consent.dob = date(2015, 12, 7)
        self.maternal_consent.save()
        PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=YES,
            rapid_test_date=date.today(),
            rapid_test_result=NEG)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject, visit_definition__code='1000M')
        maternal_visit = MaternalVisitFactory(appointment=appointment, reason=SCHEDULED)
        self.data['maternal_visit'] = maternal_visit.id
        rapid_form = RapidTestResultForm(data=self.data)
        self.assertIn("If a rapid test was processed, what is the test result?",
                      rapid_form.errors.get("__all__"))

    def test_validate_rapid_test_done_result(self):
        self.maternal_consent.dob = date(2015, 12, 7)
        self.maternal_consent.save()
        PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=YES,
            rapid_test_date=date.today(),
            rapid_test_result=NEG)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='1000M')
        maternal_visit = MaternalVisitFactory(appointment=appointment, reason=SCHEDULED)
        self.data['maternal_visit'] = maternal_visit.id
        self.data['result'] = POS
        rapid_form = RapidTestResultForm(data=self.data)
        self.assertTrue(rapid_form.is_valid())

    def test_validate_rapid_test_done_no_result_date(self):
        self.maternal_consent.dob = date(2015, 12, 7)
        self.maternal_consent.save()
        PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=YES,
            rapid_test_result=NEG)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='1000M')
        maternal_visit = MaternalVisitFactory(appointment=appointment, reason=SCHEDULED)
        self.data['maternal_visit'] = maternal_visit.id
        self.data['result_date'] = None
        self.data['result'] = POS
        rapid_form = RapidTestResultForm(data=self.data)
        self.assertIn(
            "If a rapid test was processed, what is the date of the rapid test?",
            rapid_form.errors.get("__all__"))

    def test_validate_rapid_test_not_done(self):
        self.maternal_consent.dob = date(2015, 12, 7)
        self.maternal_consent.save()
        PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=YES,
            rapid_test_result=NEG)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='1000M')
        maternal_visit = MaternalVisitFactory(appointment=appointment, reason=SCHEDULED)
        self.data['maternal_visit'] = maternal_visit.id
        self.data['rapid_test_done'] = NO
        self.data['result_date'] = None
        self.data['result'] = None
        rapid_form = RapidTestResultForm(data=self.data)
        rapid_form.is_valid()
        self.assertTrue(rapid_form.is_valid())

    def test_validate_rapid_test_done_processed1(self):
        self.maternal_consent.dob = date(2015, 12, 7)
        self.maternal_consent.save()
        PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=YES,
            rapid_test_result=NEG)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject, visit_definition__code='1000M')
        maternal_visit = MaternalVisitFactory(appointment=appointment, reason=SCHEDULED)
        result_date = date.today()
        self.data['maternal_visit'] = maternal_visit.id
        self.data['rapid_test_done'] = NO
        self.data['result_date'] = result_date
        self.data['result'] = None
        rapid_form = RapidTestResultForm(data=self.data)
        self.assertIn(
            'If a rapid test was not processed, please do not '
            'provide the result date. Got {}.'.format(result_date.strftime('%Y-%m-%d')),
            rapid_form.errors.get("__all__"))
예제 #2
0
class TestOffStudy(BaseTestCase):

    def setUp(self):
        super(TestOffStudy, 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.data = {
            'registered_subject': self.registered_subject.id,
            'reason': 'not_{}'.format(MIN_AGE_OF_CONSENT),
            'has_scheduled_data': YES,
            'maternal_visit': None,
            'offstudy_date': timezone.now().date()}

    def test_1000M_metadata_set_to_offstudy_if_not_ante(self):
        """Asserts ineligible at postnatal creates 1000M off study visit and makes off study form required."""
        postnatal_enrollment = PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=NO)
        self.assertFalse(postnatal_enrollment.is_eligible)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='1000M')
        MaternalVisit.objects.get(appointment=appointment, reason=FAILED_ELIGIBILITY)
        self.assertEqual(CrfMetaData.objects.filter(
            entry_status=REQUIRED,
            crf_entry__app_label='mb_maternal',
            crf_entry__model_name='maternaloffstudy',
            appointment=appointment).count(), 1)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='2000M')
        self.assertRaises(MaternalVisit.DoesNotExist, MaternalVisit.objects.get, appointment=appointment)

    def test_2000M_metadata_set_to_offstudy(self):
        """Asserts eligible at antenatal but ineligible at postnatal creates 2000M
        off study visit and makes off study form required."""
        antenatal_enrollment = AntenatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=YES,
            rapid_test_date=date.today(),
            rapid_test_result=NEG)
        self.assertTrue(antenatal_enrollment.is_eligible)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='1000M')
        MaternalVisitFactory(
            appointment=appointment, reason=SCHEDULED)
        postnatal_enrollment = PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=NO)
        self.assertFalse(postnatal_enrollment.is_eligible)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='2000M')
        with self.assertRaises(MaternalVisit.DoesNotExist):
            try:
                MaternalVisit.objects.get(appointment=appointment, reason=FAILED_ELIGIBILITY)
            except:
                pass
            else:
                raise MaternalVisit.DoesNotExist
        self.assertEqual(CrfMetaData.objects.filter(
            entry_status=REQUIRED,
            crf_entry__app_label='mb_maternal',
            crf_entry__model_name='maternaloffstudy',
            appointment=appointment).count(), 1)

    def test_offstudy2(self):
        PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=POS,
            evidence_hiv_status=YES,
            rapid_test_done=NOT_APPLICABLE)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='1000M')
        maternal_visit = MaternalVisitFactory(
            appointment=appointment,
            report_datetime=timezone.now(),
            study_status=OFF_STUDY,
            reason=COMPLETED_PROTOCOL_VISIT)
        MaternalOffStudyFactory(
            registered_subject=appointment.registered_subject,
            report_datetime=timezone.now(),
            offstudy_date=date.today(),
            maternal_visit=maternal_visit)
        self.assertEqual(
            Appointment.objects.filter(
                registered_subject=self.registered_subject).count(), 1)

    def test_offstudy3(self):
        PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=YES,
            rapid_test_result=NEG)
        post_natal_visit_schedule = site_visit_schedules.get_visit_schedule('postnatal visit schedule')
        self.assertEqual(Appointment.objects.filter(
            registered_subject=self.registered_subject).count(),
            len(post_natal_visit_schedule.visit_definitions))
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='1000M',
            visit_instance='0')
        maternal_visit = MaternalVisitFactory(
            appointment=appointment,
            report_datetime=timezone.now(),
            study_status=OFF_STUDY,
            survival_status=ALIVE,
            reason=COMPLETED_PROTOCOL_VISIT)
        MaternalOffStudyFactory(
            registered_subject=appointment.registered_subject,
            maternal_visit=maternal_visit,
            report_datetime=timezone.now(),
            offstudy_date=date.today())
        self.assertEqual(Appointment.objects.filter(
            registered_subject=self.registered_subject).count(), 1)

    def test_validate_offstudy_date(self):
        PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=YES,
            rapid_test_result=NEG)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='1000M')
        maternal_visit = MaternalVisitFactory(
            appointment=appointment,
            reason=COMPLETED_PROTOCOL_VISIT,
            study_status=OFF_STUDY,
            survival_status=ALIVE)
        self.data['maternal_visit'] = maternal_visit.id
        self.data['offstudy_date'] = date(2015, 10, 6)
        offstudy_form = MaternalOffStudyForm(data=self.data)
        self.assertIn(
            "Off study date cannot be before consent date",
            offstudy_form.errors.get("__all__"))

    def test_validate_offstudy_date_consent_datetime(self):
        self.maternal_consent.consent_datetime = timezone.now() - relativedelta(hours=1)
        self.maternal_consent.save()
        PostnatalEnrollmentFactory(
            registered_subject=self.registered_subject,
            current_hiv_status=NEG,
            evidence_hiv_status=YES,
            rapid_test_done=YES,
            rapid_test_result=NEG)
        appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='1000M',
            visit_instance='0')
        maternal_visit = MaternalVisitFactory(
            appointment=appointment,
            reason=COMPLETED_PROTOCOL_VISIT,
            study_status=OFF_STUDY,
            survival_status=ALIVE)
        self.data['maternal_visit'] = maternal_visit.id
        self.data['offstudy_date'] = timezone.now() - relativedelta(weeks=2)
        offstudy_form = MaternalOffStudyForm(data=self.data)
        self.assertIn(
            "Off study date cannot be before consent date",
            offstudy_form.errors.get("__all__"))