Beispiel #1
0
def main(
    country=None,
    site_name=None,
    assignment=None,
    slots=None,
    write_header=None,
    filename=None,
    assignment_map=None,
):
    """
    Adds slots to  a dummy `randomisation` list file where all assignments are the same
    for each slot.
    """
    assignment_map = assignment_map or ["intervention", "control"]
    if assignment not in assignment_map:
        raise ValueError(f"Invalid assignment. Got {assignment}")

    # get site ID and write the file
    site_id = get_site_id(site_name, sites=all_sites[country])
    with open(filename, "a+", newline="") as f:
        writer = csv.DictWriter(
            f, fieldnames=["sid", "assignment", "site_name", "country"])
        if write_header:
            writer.writeheader()
        for j in range(1, int(slots)):
            sid = str(j).zfill(len(slots))
            writer.writerow(
                dict(
                    sid=f"{site_id}{sid}",
                    assignment=assignment,
                    site_name=site_name,
                    country=country,
                ))

    print(f"(*) Added {slots} slots for {site_name}.")
Beispiel #2
0
             additional=False),
 Requisition(show_order=100,
             panel=plasma_buffycoat_panel,
             required=True,
             additional=False),
 Requisition(show_order=120,
             panel=qpcr_blood_panel,
             required=True,
             additional=False),
 Requisition(
     show_order=125,
     panel=qpcr24_blood_panel,
     required=True,
     additional=False,
     site_ids=[
         get_site_id("blantyre", sites=ambition_sites),
         get_site_id("gaborone", sites=ambition_sites),
         get_site_id("harare", sites=ambition_sites),
         get_site_id("kampala", sites=ambition_sites),
         get_site_id("lilongwe", sites=ambition_sites),
         get_site_id("mbarara", sites=ambition_sites),
     ],
 ),
 Requisition(
     show_order=200,
     panel=wb_paxgene_panel,
     required=True,
     additional=False,
     site_ids=[
         get_site_id("blantyre", sites=ambition_sites),
         get_site_id("gaborone", sites=ambition_sites),
Beispiel #3
0
 def test_all(self):
     self.assertEqual(get_site_id("reviewer", sites=meta_sites), 1)
     self.assertEqual(get_site_id("hindu_mandal", sites=meta_sites), 10)
     self.assertEqual(get_site_id("amana", sites=meta_sites), 20)
Beispiel #4
0
class TestPredicates(AmbitionTestCaseMixin, TestCase):

    app_label = "ambition_subject"
    import_randomization_list = True
    reference_helper_cls = ReferenceTestHelper
    reference_model = "edc_reference.reference"
    visit_model = "ambition_subject.subjectvisit"

    @classmethod
    def setUpClass(cls):
        add_or_update_django_sites(apps=django_apps,
                                   sites=ambition_sites,
                                   fqdn=fqdn)
        return super().setUpClass()

    def update_randomization_list(self, arm):
        site = Site.objects.get_current()
        RandomizationList.objects.update(site_name=site.name,
                                         subject_identifier=None)
        rando = (RandomizationList.objects.filter(
            site_name=site.name, assignment=arm).order_by("sid").first())
        rando.subject_identifier = self.subject_identifier
        rando.save()

    def setUp(self):
        self.subject_identifier = "111111111"
        self.reference_helper = self.reference_helper_cls(
            visit_model=self.visit_model,
            subject_identifier=self.subject_identifier)

        report_datetime = Arrow.fromdatetime(datetime(2017, 7, 7)).datetime
        self.reference_helper.create_visit(
            report_datetime=report_datetime,
            visit_schedule_name="visit_schedule",
            schedule_name="schedule",
            visit_code=DAY1,
            timepoint=Decimal("1.0"),
        )
        self.reference_helper.create_visit(
            report_datetime=report_datetime + relativedelta(days=3),
            visit_schedule_name="visit_schedule",
            schedule_name="schedule",
            visit_code=DAY3,
            timepoint=Decimal("1.0"),
        )
        self.reference_helper.create_visit(
            report_datetime=report_datetime + relativedelta(days=5),
            visit_schedule_name="visit_schedule",
            schedule_name="schedule",
            visit_code=DAY5,
            timepoint=Decimal("1.0"),
        )

    @property
    def subject_visits(self):
        return LongitudinalRefsets(
            subject_identifier=self.subject_identifier,
            visit_model=self.visit_model,
            name=self.visit_model,
            reference_model_cls=self.reference_model,
        ).order_by("report_datetime")

    def test_cd4_requisition_required(self):
        pc = Predicates()
        self.reference_helper.create_for_model(
            report_datetime=self.subject_visits[0].report_datetime,
            reference_name=f"{self.app_label}.patienthistory",
            visit_schedule_name=self.subject_visits[0].visit_schedule_name,
            schedule_name=self.subject_visits[0].schedule_name,
            visit_code=self.subject_visits[0].visit_code,
            timepoint=self.subject_visits[0].timepoint,
            cd4_date=(self.subject_visits[0].report_datetime -
                      relativedelta(months=4)).date(),
        )
        self.assertTrue(pc.func_require_cd4(self.subject_visits[0]))

    def test_cd4_requisition_not_required(self):
        pc = Predicates()
        self.reference_helper.create_for_model(
            report_datetime=self.subject_visits[0].report_datetime,
            reference_name=f"{self.app_label}.patienthistory",
            visit_schedule_name=self.subject_visits[0].visit_schedule_name,
            schedule_name=self.subject_visits[0].schedule_name,
            visit_code=self.subject_visits[0].visit_code,
            timepoint=self.subject_visits[0].timepoint,
            cd4_date=(self.subject_visits[0].report_datetime).date(),
        )
        self.assertFalse(pc.func_require_cd4(self.subject_visits[0]))

    def test_vl_requisition_required(self):
        pc = Predicates()
        self.reference_helper.create_for_model(
            report_datetime=self.subject_visits[0].report_datetime,
            reference_name=f"{self.app_label}.patienthistory",
            visit_schedule_name=self.subject_visits[0].visit_schedule_name,
            schedule_name=self.subject_visits[0].schedule_name,
            visit_code=self.subject_visits[0].visit_code,
            timepoint=self.subject_visits[0].timepoint,
            viral_load_date=(self.subject_visits[0].report_datetime -
                             relativedelta(months=4)).date(),
        )
        self.assertTrue(pc.func_require_vl(self.subject_visits[0]))

    def test_vl_requisition_not_required(self):
        pc = Predicates()
        self.reference_helper.create_for_model(
            report_datetime=self.subject_visits[0].report_datetime,
            reference_name=f"{self.app_label}.patienthistory",
            visit_schedule_name=self.subject_visits[0].visit_schedule_name,
            schedule_name=self.subject_visits[0].schedule_name,
            visit_code=self.subject_visits[0].visit_code,
            timepoint=self.subject_visits[0].timepoint,
            viral_load_date=(self.subject_visits[0].report_datetime).date(),
        )
        self.assertFalse(pc.func_require_vl(self.subject_visits[0]))

    @override_settings(SITE_ID=get_site_id("blantyre", sites=ambition_sites))
    def test_pkpd_site_eq_blantyre(self):
        pc = Predicates()
        self.update_randomization_list(CONTROL)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))
        self.update_randomization_list(SINGLE_DOSE)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))

    @override_settings(SITE_ID=get_site_id("harare", sites=ambition_sites))
    def test_pkpd_site_eq_harare(self):
        pc = Predicates()
        self.update_randomization_list(CONTROL)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))
        self.update_randomization_list(SINGLE_DOSE)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))

    @override_settings(SITE_ID=get_site_id("gaborone", sites=ambition_sites))
    def test_pkpd_site_eq_gaborone(self):
        pc = Predicates()
        self.update_randomization_list(CONTROL)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))
        self.update_randomization_list(SINGLE_DOSE)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))

    @override_settings(SITE_ID=get_site_id("capetown", sites=ambition_sites))
    def test_pkpd_site_eq_capetown(self):
        pc = Predicates()
        self.update_randomization_list(CONTROL)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))
        self.update_randomization_list(SINGLE_DOSE)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))

    @override_settings(SITE_ID=get_site_id("lilongwe", sites=ambition_sites))
    def test_pkpd_site_eq_lilongwe(self):
        pc = Predicates()
        self.update_randomization_list(CONTROL)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))
        self.update_randomization_list(SINGLE_DOSE)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))

    @override_settings(SITE_ID=get_site_id("kampala", sites=ambition_sites))
    def test_pkpd_site_eq_kampala(self):
        pc = Predicates()
        self.update_randomization_list(CONTROL)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))
        self.update_randomization_list(SINGLE_DOSE)
        self.assertFalse(pc.func_require_pkpd_stopcm(self.subject_visits[0]))

    @override_settings(SITE_ID=get_site_id("gaborone", sites=ambition_sites))
    def test_qpcr_requisition_site_eq_gaborone(self):
        pc = Predicates()
        self.update_randomization_list(CONTROL)
        self.assertTrue(
            pc.func_require_qpcr_requisition(self.subject_visits[0]))
        self.update_randomization_list(SINGLE_DOSE)
        self.assertTrue(
            pc.func_require_qpcr_requisition(self.subject_visits[0]))

    @override_settings(SITE_ID=get_site_id("harare", sites=ambition_sites))
    def test_qpcr_requisition_site_eq_harare(self):
        pc = Predicates()
        self.update_randomization_list(CONTROL)
        self.assertFalse(
            pc.func_require_qpcr_requisition(self.subject_visits[0]))
        self.update_randomization_list(SINGLE_DOSE)
        self.assertFalse(
            pc.func_require_qpcr_requisition(self.subject_visits[0]))

    @override_settings(SITE_ID=get_site_id("capetown", sites=ambition_sites))
    def test_qpcr_24_requisition_site_eq_cape_town(self):
        pc = Predicates()
        self.update_randomization_list(CONTROL)
        self.assertTrue(
            pc.func_require_qpcr_requisition(self.subject_visits[0]))
        self.update_randomization_list(SINGLE_DOSE)
        self.assertTrue(
            pc.func_require_qpcr_requisition(self.subject_visits[0]))
Beispiel #5
0
APP_NAME = env.str("DJANGO_APP_NAME")

LIVE_SYSTEM = env.str("DJANGO_LIVE_SYSTEM")

ETC_DIR = env.str("DJANGO_ETC_FOLDER")

TEST_DIR = os.path.join(BASE_DIR, APP_NAME, "tests")

ALLOWED_HOSTS = ["*"]  # env.list('DJANGO_ALLOWED_HOSTS')

ENFORCE_RELATED_ACTION_ITEM_EXISTS = False

# get site ID from more familiar town name
TOWN = env.str("DJANGO_TOWN")
if TOWN:
    SITE_ID = get_site_id(TOWN, sites=inte_sites)
else:
    SITE_ID = env.int("DJANGO_SITE_ID")

DEFAULT_APPOINTMENT_TYPE = "hospital"

REVIEWER_SITE_ID = env.int("DJANGO_REVIEWER_SITE_ID")

LOGIN_REDIRECT_URL = env.str("DJANGO_LOGIN_REDIRECT_URL")

SENTRY_ENABLED = env("SENTRY_ENABLED")

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
 def test_all(self):
     self.assertEqual(get_site_id("reviewer", sites=inte_sites), 1)
     self.assertEqual(get_site_id("kinoni", sites=inte_sites), 100)
     self.assertEqual(get_site_id("bugamba", sites=inte_sites), 110)
     self.assertEqual(get_site_id("bwizibwera", sites=inte_sites), 120)
     self.assertEqual(get_site_id("ruhoko", sites=inte_sites), 140)
     self.assertEqual(get_site_id("kyazanga", sites=inte_sites), 150)
     self.assertEqual(get_site_id("bukulula", sites=inte_sites), 160)
     self.assertEqual(get_site_id("kojja", sites=inte_sites), 170)
     self.assertEqual(get_site_id("mpigi", sites=inte_sites), 180)
     self.assertEqual(get_site_id("namayumba", sites=inte_sites), 190)
     self.assertEqual(get_site_id("buwambo", sites=inte_sites), 200)
     self.assertEqual(get_site_id("kajjansi", sites=inte_sites), 210)
     self.assertEqual(get_site_id("tikalu", sites=inte_sites), 220)
     self.assertEqual(get_site_id("namulonge", sites=inte_sites), 230)
     self.assertEqual(get_site_id("kasanje", sites=inte_sites), 240)
     self.assertEqual(get_site_id("kasangati", sites=inte_sites), 250)
Beispiel #7
0
if SENTRY_ENABLED:
    import sentry_sdk
    from sentry_sdk.integrations.django import DjangoIntegration

    sentry_sdk.init(dsn=SENTRY_DSN,
                    integrations=[DjangoIntegration()],
                    send_default_pii=True)
else:
    if env("DJANGO_LOGGING_ENABLED"):
        from .logging.standard import LOGGING  # noqa

# read SITE specific variables from separate .env file
env.read_env(os.path.join(BASE_DIR, ".env-site"))
COUNTRY = env.str("DJANGO_COUNTRY")
# get site ID from more familiar town name
DJANGO_SITE_NAME = env.str("DJANGO_SITE_NAME")
if DJANGO_SITE_NAME:
    SITE_ID = get_site_id(DJANGO_SITE_NAME, sites=inte_sites)
else:
    SITE_ID = env.int("DJANGO_SITE_ID")

# if running tests ...
if "test" in sys.argv or "runtests" in sys.argv:
    ETC_DIR = os.path.join(BASE_DIR, "inte_edc", "tests", "etc")
    KEY_PATH = os.path.join(BASE_DIR, "inte_edc", "tests", "etc")
    DJANGO_CRYPTO_FIELDS_TEMP_PATH = env("DJANGO_CRYPTO_FIELDS_TEMP_PATH")
    MIGRATION_MODULES = DisableMigrations()
    PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher", )
    DEFAULT_FILE_STORAGE = "inmemorystorage.InMemoryStorage"
Beispiel #8
0
if env.str("DJANGO_ETC_FOLDER"):
    ETC_DIR = env.str("DJANGO_ETC_FOLDER")
else:
    ETC_DIR = BASE_DIR

TEST_DIR = os.path.join(BASE_DIR, APP_NAME, "tests")

ALLOWED_HOSTS = ["*"]  # env.list('DJANGO_ALLOWED_HOSTS')

ENFORCE_RELATED_ACTION_ITEM_EXISTS = False

# get site ID from more familiar town name
TOWN = env.str("DJANGO_TOWN")
if TOWN:
    SITE_ID = get_site_id(TOWN, sites=ambition_sites)
else:
    SITE_ID = env.int("DJANGO_SITE_ID")

DEFAULT_APPOINTMENT_TYPE = "hospital"

REVIEWER_SITE_ID = env.int("DJANGO_REVIEWER_SITE_ID")

LOGIN_REDIRECT_URL = env.str("DJANGO_LOGIN_REDIRECT_URL")

SENTRY_ENABLED = env("SENTRY_ENABLED")

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",