Ejemplo n.º 1
0
 def setUpClass(cls):
     super().setUpClass()
     import_holidays(test=True)
     add_or_update_django_sites(sites=get_sites_by_country("tanzania"))
     site_list_data.autodiscover()
     GroupPermissionsUpdater(codenames_by_group=get_codenames_by_group(),
                             verbose=True)
     if cls.import_randomization_list:
         RandomizationListImporter(verbose=False, name="default")
Ejemplo n.º 2
0
    def test_country(self):
        for sites in self.default_all_sites.values():
            add_or_update_django_sites(sites=sites)
        self.assertEqual("mochudi", Site.objects.get_current().name)
        self.assertEqual("botswana",
                         Site.objects.get_current().siteprofile.country)
        self.assertEqual("botswana", get_current_country())
        self.assertEqual(self.default_all_sites.get("botswana"),
                         get_sites_by_country("botswana"))
        self.assertEqual(self.default_all_sites.get("botswana"),
                         get_sites_by_country())
        self.assertEqual(
            self.default_all_sites.get("botswana"),
            get_sites_by_country(all_sites=self.default_all_sites),
        )

        self.assertEqual(
            self.default_all_sites.get("botswana"),
            get_sites_by_country(country="botswana",
                                 all_sites=self.default_all_sites),
        )
Ejemplo n.º 3
0
class MapitioTestCaseMixin(SiteTestCaseMixin):
    fqdn = fqdn

    default_sites = get_sites_by_country("tanzania")

    site_names = [s.name for s in default_sites]

    import_randomization_list = True

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        import_holidays(test=True)
        add_or_update_django_sites(sites=get_sites_by_country("tanzania"))
        site_list_data.autodiscover()
        GroupPermissionsUpdater(codenames_by_group=get_codenames_by_group(),
                                verbose=True)
        if cls.import_randomization_list:
            RandomizationListImporter(verbose=False, name="default")

    @classmethod
    def tearDownClass(cls):
        super().tearDownClass()
        Holiday.objects.all().delete()

    def login(self, user=None, superuser=None, groups=None):
        user = self.user if user is None else user
        superuser = True if superuser is None else superuser
        if not superuser:
            user.is_superuser = False
            user.is_active = True
            user.save()
            for group_name in groups:
                group = Group.objects.get(name=group_name)
                user.groups.add(group)
        return self.client.force_login(user or self.user)

    def get_subject_visit(self, visit_code=None, enrollment=None):
        visit_code = visit_code or DAY1
        subject_identifier = enrollment.subject_identifier
        appointment = Appointment.objects.get(
            subject_identifier=subject_identifier, visit_code=visit_code)
        appointment.appt_status = IN_PROGRESS_APPT
        appointment.save()
        return SubjectVisit.objects.create(appointment=appointment,
                                           reason=SCHEDULED)
Ejemplo n.º 4
0
class InteTestCaseMixin(AppointmentTestCaseMixin, FormValidatorTestCaseMixin,
                        SiteTestCaseMixin, TestCase):
    fqdn = fqdn

    default_sites = get_sites_by_country("uganda")

    site_names = [s.name for s in default_sites]

    import_randomization_list = True

    subject_visit_model_cls = SubjectVisit

    sid_count_for_tests = 1

    @classmethod
    def setUpTestData(cls):
        import_holidays(test=True)
        if cls.import_randomization_list:
            RandomizationListImporter(
                verbose=False,
                name="default",
                sid_count_for_tests=cls.sid_count_for_tests,
            )

    def setUp(self):
        self.user = User.objects.create_superuser("user_login",
                                                  "*****@*****.**", "pass")

    def login(self, user=None, superuser=None, groups=None):
        user = self.user if user is None else user
        superuser = True if superuser is None else superuser
        if not superuser:
            user.is_superuser = False
            user.is_active = True
            user.save()
            for group_name in groups:
                group = Group.objects.get(name=group_name)
                user.groups.add(group)
        return self.client.force_login(user or self.user)

    def get_subject_screening(self,
                              report_datetime=None,
                              eligibility_datetime=None,
                              **kwargs):
        data = {
            "screening_consent": YES,
            "age_in_years": 25,
            "clinic_type": HIV_CLINIC,
            "gender": MALE,
            "hospital_identifier": "13343322",
            "initials": "".join(choices(string.ascii_uppercase, k=2)),
            "lives_nearby": YES,
            "qualifying_condition": YES,
            "report_datetime": report_datetime or get_utcnow(),
            "requires_acute_care": NO,
            "selection_method": RANDOM_SAMPLING,
            "unsuitable_agreed": NOT_APPLICABLE,
            "unsuitable_for_study": NO,
        }
        data.update(**kwargs)
        form = SubjectScreeningForm(data=data, instance=None)
        form.save()

        subject_screening = SubjectScreening.objects.get(
            screening_identifier=form.instance.screening_identifier)

        self.assertTrue(subject_screening.eligible)

        if eligibility_datetime:
            subject_screening.eligibility_datetime = eligibility_datetime
            subject_screening.save()

        return subject_screening

    @staticmethod
    def get_subject_consent(subject_screening,
                            consent_datetime=None,
                            **kwargs):
        dob = (consent_datetime or get_utcnow()).date() - relativedelta(
            years=subject_screening.age_in_years)
        consent_datetime = consent_datetime or subject_screening.report_datetime

        options = dict(
            user_created="erikvw",
            user_modified="erikvw",
            screening_identifier=subject_screening.screening_identifier,
            initials=subject_screening.initials,
            dob=dob,
            site=Site.objects.get(id=settings.SITE_ID),
            clinic_type=HIV_CLINIC,
            consent_datetime=consent_datetime,
        )
        options.update(**kwargs)
        return baker.make_recipe("inte_consent.subjectconsent", **options)

    def get_subject_visit(
        self,
        visit_code=None,
        visit_code_sequence=None,
        subject_screening=None,
        subject_consent=None,
        reason=None,
        appointment=None,
        appt_datetime=None,
        report_datetime=None,
    ):
        reason = reason or SCHEDULED
        if not appointment:
            subject_screening = subject_screening or self.get_subject_screening(
            )
            subject_consent = subject_consent or self.get_subject_consent(
                subject_screening)
            options = dict(
                subject_identifier=subject_consent.subject_identifier,
                visit_code=visit_code or DAY1,
                visit_code_sequence=(visit_code_sequence if visit_code_sequence
                                     is not None else 0),
                reason=reason,
            )
            if appt_datetime:
                options.update(appt_datetime=appt_datetime)
            appointment = self.get_appointment(**options)
        try:
            return self.subject_visit_model_cls.objects.get(
                appointment=appointment)
        except ObjectDoesNotExist:
            return self.subject_visit_model_cls.objects.create(
                appointment=appointment,
                reason=reason,
                report_datetime=report_datetime or appt_datetime
                or appointment.appt_datetime,
            )

    def get_next_subject_visit(
        self,
        subject_visit=None,
        reason=None,
        appt_datetime=None,
        report_datetime=None,
    ):
        visit_code = (subject_visit.appointment.visit_code
                      if reason == UNSCHEDULED else
                      subject_visit.appointment.next.visit_code)
        # visit_code_sequence will increment in get_subject_visit
        visit_code_sequence = (subject_visit.appointment.visit_code_sequence
                               if reason == UNSCHEDULED else 0)
        return self.get_subject_visit(
            visit_code=visit_code,
            visit_code_sequence=visit_code_sequence,
            reason=reason,
            appt_datetime=appt_datetime,
            subject_screening=SubjectScreening.objects.get(
                subject_identifier=subject_visit.subject_identifier),
            subject_consent=SubjectConsent.objects.get(
                subject_identifier=subject_visit.subject_identifier),
            report_datetime=report_datetime,
        )

    @staticmethod
    def get_crf_metadata(subject_visit):
        return CrfMetadata.objects.filter(
            subject_identifier=subject_visit.subject_identifier,
            visit_code=subject_visit.visit_code,
            visit_code_sequence=subject_visit.visit_code_sequence,
            entry_status=REQUIRED,
        )
Ejemplo n.º 5
0
    def test_to_subject_dashboard(self):
        add_or_update_django_sites(apps=django_apps,
                                   sites=get_sites_by_country("uganda"))
        self.login(superuser=False, groups=[EVERYONE, CLINIC, PII])
        subject_screening = self.get_subject_screening()
        home_page = self.client.get(reverse("home_url"))
        screening_listboard_page = home_page.click(description="Screening",
                                                   index=1)
        add_subjectconsent_page = screening_listboard_page.click(
            description="Consent", index=1)
        # submit blank form
        response = add_subjectconsent_page.form.submit()
        self.assertIn("Please correct the errors below", response)

        subject_consent = baker.make_recipe(
            "mocca_subject.subjectconsent",
            screening_identifier=subject_screening.screening_identifier,
            dob=(get_utcnow() -
                 relativedelta(years=subject_screening.age_in_years)).date(),
            first_name="Melissa",
            last_name="Rodriguez",
            initials="MR",
            consent_datetime=get_utcnow(),
        )

        home_page = self.client.get(reverse("home_url"),
                                    user=self.user,
                                    status=200)
        screening_listboard_page = home_page.click(description="Screening",
                                                   index=1)

        self.assertIn("Dashboard", screening_listboard_page)
        self.assertIn(
            f"subjectscreening_change_{subject_screening.screening_identifier}",
            screening_listboard_page,
        )

        home_page = self.client.get(reverse("home_url"),
                                    user=self.user,
                                    status=200)
        subject_listboard_page = home_page.click(description="Subjects",
                                                 index=1)

        self.assertIn(subject_consent.subject_identifier,
                      subject_listboard_page)

        href = reverse(
            "mocca_dashboard:subject_dashboard_url",
            kwargs={"subject_identifier": subject_consent.subject_identifier},
        )
        subject_dashboard_page = subject_listboard_page.click(href=href)

        self.assertEqual(subject_dashboard_page.status_code, 200)

        # on subject_dashboard
        # assert all appointment are showing
        subject_identifier = subject_consent.subject_identifier
        appointments = Appointment.objects.filter(
            subject_identifier=subject_identifier).order_by("appt_datetime")
        for appointment in appointments:
            self.assertIn(appointment.visit_code, subject_dashboard_page)

        # start appointment 1000
        page = subject_dashboard_page.click(linkid="start_btn_1000")
        page.form["appt_status"] = IN_PROGRESS_APPT
        page.form["appt_reason"] = SCHEDULED_APPT
        subject_dashboard_page = page.form.submit()
        self.assertEqual(subject_dashboard_page.status_code, 302)
        self.assertEqual(
            subject_dashboard_page.url,
            f"/subject/subject_dashboard/{subject_identifier}/",
        )

        subject_dashboard_page = self.client.get(subject_dashboard_page.url,
                                                 user=self.user,
                                                 status=200)

        # start visit 1000
        self.assertIn(" Start ", subject_dashboard_page)
        subject_visit_page = subject_dashboard_page.click(
            linkid=(f"start_btn_{appointments[0].visit_code}_"
                    f"{appointments[0].visit_code_sequence}"))
        subject_visit_page.form["info_source"] = "patient"
        subject_dashboard_page = subject_visit_page.form.submit()

        url = f"/subject/subject_dashboard/{subject_identifier}/" f"{str(appointments[0].pk)}/"
        self.assertEqual(subject_dashboard_page.status_code, 302)
        self.assertEqual(subject_dashboard_page.url, url)

        subject_dashboard_page = self.client.get(
            reverse(
                "mocca_dashboard:subject_dashboard_url",
                kwargs=dict(
                    subject_identifier=subject_identifier,
                    appointment=str(appointments[0].id),
                ),
            ),
            user=self.user,
            status=200,
        )

        self.assertIn("CRFs", subject_dashboard_page)
        self.assertIn("Requisitions", subject_dashboard_page)
Ejemplo n.º 6
0
class MetaTestCaseMixin(SiteTestCaseMixin):

    fqdn = fqdn

    default_sites = get_sites_by_country("tanzania")

    site_names = [s.name for s in default_sites]

    import_randomization_list = True

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        add_or_update_django_sites(sites=get_sites_by_country("tanzania"))
        if cls.import_randomization_list:
            RandomizationListImporter(name="default", verbose=False)
        import_holidays(test=True)
        site_list_data.autodiscover()
        GroupPermissionsUpdater(
            codenames_by_group=get_codenames_by_group(), verbose=True
        )

    @classmethod
    def tearDownClass(cls):
        super().tearDownClass()
        RandomizationList.objects.all().delete()
        Holiday.objects.all().delete()

    def get_subject_screening(self, report_datetime=None, eligibility_datetime=None):
        if report_datetime:
            part_one_eligible_options.update(report_datetime=report_datetime)

        part_one = ScreeningPartOne.objects.create(
            user_created="erikvw", user_modified="erikvw", **part_one_eligible_options
        )
        screening_identifier = part_one.screening_identifier
        self.assertEqual(part_one.eligible_part_one, YES)

        screening_part_two = ScreeningPartTwo.objects.get(
            screening_identifier=screening_identifier
        )
        for k, v in part_two_eligible_options.items():
            setattr(screening_part_two, k, v)
        screening_part_two.save()
        print(screening_part_two.reasons_ineligible_part_two)
        self.assertEqual(screening_part_two.eligible_part_two, YES)

        screening_part_three = ScreeningPartThree.objects.get(
            screening_identifier=screening_identifier
        )
        for k, v in part_three_eligible_options.items():
            setattr(screening_part_three, k, v)
        screening_part_three.save()
        self.assertEqual(screening_part_three.eligible_part_three, YES)

        subject_screening = SubjectScreening.objects.get(
            screening_identifier=screening_identifier
        )

        self.assertTrue(subject_screening.eligible)

        if eligibility_datetime:
            screening_part_three.eligibility_datetime = eligibility_datetime
            screening_part_three.save()
            subject_screening = SubjectScreening.objects.get(
                screening_identifier=screening_identifier
            )
        return subject_screening

    def get_subject_consent(self, subject_screening):
        return baker.make_recipe(
            "meta_consent.subjectconsent",
            user_created="erikvw",
            user_modified="erikvw",
            screening_identifier=subject_screening.screening_identifier,
            initials=subject_screening.initials,
            dob=(
                get_utcnow().date()
                - relativedelta(years=subject_screening.age_in_years)
            ),
            site=Site.objects.get(name="hindu_mandal"),
        )

    def get_subject_visit(self):
        subject_screening = self.get_subject_screening()
        subject_consent = self.get_subject_consent(subject_screening)
        subject_identifier = subject_consent.subject_identifier

        appointment = Appointment.objects.get(
            subject_identifier=subject_identifier, visit_code=DAY1
        )
        appointment.appt_status = IN_PROGRESS_APPT
        appointment.save()
        return SubjectVisit.objects.create(appointment=appointment, reason=SCHEDULED)

    @staticmethod
    def get_next_subject_visit(subject_visit):
        appointment = subject_visit.appointment
        appointment.appt_status = INCOMPLETE_APPT
        appointment.save()
        appointment.refresh_from_db()
        next_appointment = appointment.next_by_timepoint
        next_appointment.appt_status = IN_PROGRESS_APPT
        next_appointment.save()
        return SubjectVisit.objects.create(
            appointment=next_appointment, reason=SCHEDULED
        )