def test_add_visits_duplicate_title(self): schedule = Schedule( name="schedule", onschedule_model="visit_schedule_app.onschedule", offschedule_model="visit_schedule_app.offschedule", consent_model="visit_schedule_app.subjectconsent", appointment_model="edc_appointment.appointment", ) visit = Visit( code=str(0), title="erik", timepoint=0, rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), ) schedule.add_visit(visit=visit) visit = Visit( code=str(1), title="erik", timepoint=1, rbase=relativedelta(days=1), rlower=relativedelta(days=0), rupper=relativedelta(days=6), ) self.assertRaises(AlreadyRegisteredVisit, schedule.add_visit, visit=visit)
def test_repr(self): visit = Visit( code="1000", rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), timepoint=1, ) self.assertIsNotNone(visit.__repr__())
def test_visit_datetime(self): visit = Visit( code="1000", rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), timepoint=1, ) visit.timepoint_datetime = datetime(2001, 12, 1) self.assertEqual( visit.timepoint_datetime, Arrow.fromdatetime(datetime(2001, 12, 1), tzinfo="utc"), )
def test_schedule_bad_crf_model(self): site_visit_schedules._registry = {} visit_schedule = VisitSchedule( name="visit_schedule", verbose_name="Visit Schedule", offstudy_model="visit_schedule_app.subjectoffstudy", death_report_model="visit_schedule_app.deathreport", ) schedule = Schedule( name="schedule", onschedule_model="visit_schedule_app.onschedule", offschedule_model="visit_schedule_app.offschedule", appointment_model="edc_appointment.appointment", consent_model="visit_schedule_app.subjectconsent", ) crfs = FormsCollection( Crf(show_order=10, model="blah.CrfOne"), Crf(show_order=20, model="blah.CrfTwo"), Crf(show_order=30, model="blah.CrfThree"), ) visit = Visit( code="1000", rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), facility_name="default", crfs=crfs, timepoint=1, ) schedule.add_visit(visit) visit_schedule.add_schedule(schedule) site_visit_schedules.register(visit_schedule) errors = visit_schedule_check(app_configs=django_apps.get_app_configs()) self.assertEqual(len(errors), 1) self.assertEqual("edc_visit_schedule.visits", errors[0].id)
def setUp(self): v1_consent = Consent( "visit_schedule_app.subjectconsent", version="1", start=Protocol().study_open_datetime, end=Protocol().study_close_datetime, age_min=18, age_is_adult=18, age_max=64, gender=[MALE, FEMALE], ) import_holidays() site_consents.registry = {} site_consents.register(v1_consent) self.visit_schedule = VisitSchedule( name="visit_schedule", verbose_name="Visit Schedule", offstudy_model="visit_schedule_app.subjectoffstudy", death_report_model="visit_schedule_app.deathreport", ) self.schedule = Schedule( name="schedule", onschedule_model="visit_schedule_app.onschedule", offschedule_model="visit_schedule_app.offschedule", appointment_model="edc_appointment.appointment", consent_model="visit_schedule_app.subjectconsent", ) visit = Visit( code="1000", rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), timepoint=1, ) self.schedule.add_visit(visit) self.visit_schedule.add_schedule(self.schedule) site_visit_schedules._registry = {} site_visit_schedules.register(self.visit_schedule) site_reference_configs.registry = {} site_reference_configs.register_from_visit_schedule(visit_models={ "edc_appointment.appointment": "visit_schedule_app.subjectvisit" }) self.subject_consent = SubjectConsent.objects.create( subject_identifier="12345", consent_datetime=get_utcnow() - relativedelta(seconds=1), dob=date(1995, 1, 1), identity="11111", confirm_identity="11111", ) self.subject_identifier = self.subject_consent.subject_identifier
def test_name(self): visit = Visit( code="1000", rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), timepoint=1, ) self.assertEqual(visit.name, "1000")
def test_visit_title(self): visit = Visit( code="1000", rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), timepoint=1, ) self.assertEqual(visit.title, "Visit 1000") self.assertEqual(str(visit), "Visit 1000")
def test_visit_lower_upper(self): visit = Visit( code="1000", rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), timepoint=1, ) visit.timepoint_datetime = Arrow.fromdatetime( datetime(2001, 12, 1), tzinfo="utc" ).datetime self.assertEqual( visit.dates.lower, Arrow.fromdatetime(datetime(2001, 12, 1), tzinfo="utc").datetime, ) self.assertEqual( visit.dates.upper, Arrow.fromdatetime(datetime(2001, 12, 7, 23, 59), tzinfo="utc").datetime, )
def test_last_visit(self): for i in range(0, 5): visit = Visit( code=str(i), timepoint=i, rbase=relativedelta(days=i), rlower=relativedelta(days=0), rupper=relativedelta(days=6), ) self.schedule.add_visit(visit=visit) visit = Visit( code=str(6), timepoint=6, rbase=relativedelta(days=6), rlower=relativedelta(days=0), rupper=relativedelta(days=6), ) self.schedule.add_visit(visit=visit) self.assertEqual(self.schedule.visits.last, visit)
def test_next_visit_none(self): for i in range(0, 5): visit = Visit( code=str(i), timepoint=i, rbase=relativedelta(days=i), rlower=relativedelta(days=0), rupper=relativedelta(days=6), ) self.schedule.add_visit(visit=visit) self.assertIsNone(self.schedule.visits.next("5"))
def test_next_visit(self): for i in range(0, 5): visit = Visit( code=str(i), timepoint=i, rbase=relativedelta(days=i), rlower=relativedelta(days=0), rupper=relativedelta(days=6), ) self.schedule.add_visit(visit=visit) visit = self.schedule.visits.next("3") self.assertEqual(visit.code, "4")
def test_good_codes(self): try: Visit( code="1000", rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), timepoint=1, ) except (VisitCodeError) as e: self.fail(f"VisitError unexpectedly raised. Got {e}") try: Visit( code="1000", rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), timepoint=1, ) except VisitCodeError as e: self.fail(f"VisitError unexpectedly raised. Got {e}")
def test_order(self): for i in [3, 5, 1, 0, 2, 4]: visit = Visit( code=str(i), timepoint=i, rbase=relativedelta(days=i), rlower=relativedelta(days=0), rupper=relativedelta(days=6), ) self.schedule.add_visit(visit=visit) self.assertEqual( [v.timepoint for v in self.schedule.visits.values()], [0, 1, 2, 3, 4, 5] )
def test_visit_dates(self): dt = get_utcnow() for index, seq in enumerate(range(0, 5)): visit = Visit( code=str(seq), timepoint=seq * (index + 1), rbase=relativedelta(days=seq * (index + 1)), rlower=relativedelta(days=0), rupper=relativedelta(days=6), ) self.schedule.add_visit(visit=visit) index = 0 for k, v in self.schedule.visits.timepoint_dates(dt=dt).items(): self.assertEqual(v - dt, timedelta(index * (index + 1)), msg=k) index += 1
def test_visit_lower_upper_no_datetime(self): visit = Visit( code="1000", rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), timepoint=1, ) try: visit.dates.lower except VisitDateError: pass try: visit.dates.upper except VisitDateError: pass
def test_add_visits(self): schedule = Schedule( name="schedule", onschedule_model="visit_schedule_app.onschedule", offschedule_model="visit_schedule_app.offschedule", consent_model="visit_schedule_app.subjectconsent", appointment_model="edc_appointment.appointment", ) for i in range(0, 5): visit = Visit( code=str(i), timepoint=i, rbase=relativedelta(days=i), rlower=relativedelta(days=0), rupper=relativedelta(days=6), ) try: schedule.add_visit(visit=visit) except AlreadyRegisteredVisit as e: self.fail(f"Exception unexpectedly raised. Got {e}")
from edc_visit_schedule.schedule import Schedule from edc_visit_schedule.visit import FormsCollection, Crf, Visit from edc_visit_schedule.visit_schedule import VisitSchedule from dateutil.relativedelta import relativedelta crfs = FormsCollection( Crf(show_order=1, model=f'edc_reference.crfone', required=True), ) visit0 = Visit(code='1000', title='Day 1', timepoint=0, rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), crfs=crfs, facility_name='default') schedule = Schedule(name='schedule', onschedule_model='edc_reference.onschedule', offschedule_model='edc_reference.offschedule', appointment_model='edc_appointment.appointment', consent_model='edc_reference.subjectconsent') schedule.add_visit(visit0) visit_schedule = VisitSchedule(name='visit_schedule', offstudy_model='edc_reference.subjectoffstudy', death_report_model='edc_reference.deathreport') visit_schedule.add_schedule(schedule)
from dateutil.relativedelta import relativedelta from edc_visit_schedule.schedule import Schedule from edc_visit_schedule.visit import Visit from ..constants import A0 from .crfs_ess import crfs_ess from .requisitions import requisitions app_label = 'bcpp_subject' ano_schedule = Schedule( name='ano_schedule', title='Anonymous', enrollment_model=f'{app_label}.enrollmentano', disenrollment_model=f'{app_label}.disenrollmentano') ano_visit = Visit( code=A0, title='Anonymous Survey', timepoint=0, rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=364), requisitions=requisitions.forms, crfs=crfs_ess.forms) ano_schedule.add_visit(visit=ano_visit)
from dateutil.relativedelta import relativedelta from edc_visit_schedule.schedule import Schedule from edc_visit_schedule.site_visit_schedules import site_visit_schedules from edc_visit_schedule.visit import Crf, FormsCollection, Visit from edc_visit_schedule.visit_schedule import VisitSchedule crfs = FormsCollection( Crf(show_order=1, model=f"reference_app.crfone", required=True)) visit0 = Visit( code="1000", title="Day 1", timepoint=0, rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), crfs=crfs, facility_name="default", ) visit1 = Visit( code="2000", title="Day 2", timepoint=1, rbase=relativedelta(days=7), rlower=relativedelta(days=6), rupper=relativedelta(days=6), crfs=crfs, facility_name="default", )
from dateutil.relativedelta import relativedelta from edc_visit_schedule.schedule import Schedule from edc_visit_schedule.visit import Crf, FormsCollection, Visit from edc_visit_schedule.visit_schedule import VisitSchedule crfs = FormsCollection(Crf(show_order=1, model=f"visit_schedule_app.crfone", required=True)) visit0 = Visit( code="1000", title="Day 1", timepoint=0, rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=6), crfs=crfs, ) visit1 = Visit( code="2000", title="Day 2", timepoint=1, rbase=relativedelta(days=1), rlower=relativedelta(days=0), rupper=relativedelta(days=6), crfs=crfs, ) visit2 = Visit( code="3000", title="Day 3",
from .requisitions import requisitions app_label = 'bcpp_subject' ahs_schedule = Schedule( name='ahs_schedule', title='AHS', enrollment_model=f'{app_label}.enrollmentahs', disenrollment_model=f'{app_label}.disenrollmentahs', ) ahs_visit1 = Visit(code=T1, title='1st Annual Survey', timepoint=1, rbase=relativedelta(years=1), rlower=relativedelta(years=1), rupper=relativedelta(years=2), base_interval_unit=YEARS, requisitions=requisitions.forms, crfs=crfs_ahs.forms) ahs_visit2 = Visit(code=T2, title='2nd Annual Survey', timepoint=2, rbase=relativedelta(years=2), rlower=relativedelta(years=2), rupper=relativedelta(years=3), base_interval_unit=YEARS, requisitions=requisitions.forms, crfs=crfs_ahs.forms)
from dateutil.relativedelta import relativedelta from edc_visit_schedule.schedule import Schedule from edc_visit_schedule.visit import Visit from ..constants import E0 from .crfs_ess import crfs_ess from .requisitions import requisitions app_label = 'bcpp_subject' # schedule for new participants ess_schedule = Schedule(name='ess_schedule', title='ESS', enrollment_model=f'{app_label}.enrollmentess', disenrollment_model=f'{app_label}.disenrollmentess') ess_visit = Visit(code=E0, title='End-of-study Household Survey', timepoint=0, rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=364), requisitions=requisitions.forms, crfs=crfs_ess.forms) ess_schedule.add_visit(visit=ess_visit)
from dateutil.relativedelta import relativedelta from edc_visit_schedule.schedule import Schedule from edc_visit_schedule.visit import Visit from ..constants import T0 from .crfs_bhs import crfs_bhs from .requisitions import requisitions app_label = 'bcpp_subject' bhs_schedule = Schedule( name='bhs_schedule', title='BHS', enrollment_model=f'{app_label}.enrollmentbhs', disenrollment_model=f'{app_label}.disenrollmentbhs', ) bhs_visit = Visit(code=T0, title='Baseline Survey', timepoint=0, base_interval=0, rbase=relativedelta(days=0), rlower=relativedelta(days=0), rupper=relativedelta(days=364), requisitions=requisitions.forms, crfs=crfs_bhs.forms) bhs_schedule.add_visit(visit=bhs_visit)