From e913f473b5d164dfb05750af38fe99c2f3984383 Mon Sep 17 00:00:00 2001 From: erikvw Date: Thu, 18 Jan 2024 12:23:30 -0600 Subject: [PATCH] fix tests --- edc_pharmacy/tests/consents.py | 16 +++++++++++ edc_pharmacy/tests/models.py | 28 +++++++++++++------ .../tests/tests/test_study_medication_crf.py | 12 -------- edc_pharmacy/tests/visit_schedule.py | 9 +++--- 4 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 edc_pharmacy/tests/consents.py diff --git a/edc_pharmacy/tests/consents.py b/edc_pharmacy/tests/consents.py new file mode 100644 index 0000000..b8ed0eb --- /dev/null +++ b/edc_pharmacy/tests/consents.py @@ -0,0 +1,16 @@ +from edc_consent.consent_definition import ConsentDefinition +from edc_consent.site_consents import site_consents +from edc_constants.constants import FEMALE, MALE +from edc_protocol import Protocol + +v1_consent = ConsentDefinition( + "edc_pharmacy.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], +) +site_consents.register(v1_consent) diff --git a/edc_pharmacy/tests/models.py b/edc_pharmacy/tests/models.py index 407beb4..1c9c817 100644 --- a/edc_pharmacy/tests/models.py +++ b/edc_pharmacy/tests/models.py @@ -1,7 +1,11 @@ +from datetime import date + from django.db import models from edc_crf.model_mixins import CrfModelMixin from edc_identifier.managers import SubjectIdentifierManager +from edc_identifier.model_mixins import NonUniqueSubjectIdentifierFieldMixin from edc_model.models import BaseUuidModel +from edc_registration.model_mixins import UpdatesOrCreatesRegistrationModelMixin from edc_screening.model_mixins import ScreeningModelMixin from edc_sites.model_mixins import SiteModelMixin from edc_utils import get_utcnow @@ -11,19 +15,27 @@ from edc_pharmacy.model_mixins import StudyMedicationCrfModelMixin -class SubjectScreening(ScreeningModelMixin, BaseUuidModel): - objects = SubjectIdentifierManager() +class SubjectConsent( + SiteModelMixin, + NonUniqueSubjectIdentifierFieldMixin, + UpdatesOrCreatesRegistrationModelMixin, + BaseUuidModel, +): + report_datetime = models.DateTimeField(default=get_utcnow) + consent_datetime = models.DateTimeField(default=get_utcnow) -class SubjectConsent(SiteModelMixin, BaseUuidModel): - subject_identifier = models.CharField(max_length=25) + version = models.CharField(max_length=25, default="1") - consent_datetime = models.DateTimeField() + identity = models.CharField(max_length=25) - dob = models.DateTimeField(null=True) + confirm_identity = models.CharField(max_length=25) - class Meta: - pass + dob = models.DateField(default=date(1995, 1, 1)) + + +class SubjectScreening(ScreeningModelMixin, BaseUuidModel): + objects = SubjectIdentifierManager() class SubjectVisit(SiteModelMixin, VisitModelMixin, BaseUuidModel): diff --git a/edc_pharmacy/tests/tests/test_study_medication_crf.py b/edc_pharmacy/tests/tests/test_study_medication_crf.py index 98a0640..4dd0785 100644 --- a/edc_pharmacy/tests/tests/test_study_medication_crf.py +++ b/edc_pharmacy/tests/tests/test_study_medication_crf.py @@ -9,10 +9,6 @@ from edc_appointment.models import Appointment from edc_appointment.tests.helper import Helper from edc_appointment.utils import get_next_appointment -from edc_consent.site_consents import ( - AlreadyRegistered as ConsentDefinitionAlreadyRegistered, -) -from edc_consent.tests.consent_test_utils import consent_definition_factory from edc_constants.constants import YES from edc_facility import import_holidays from edc_protocol import Protocol @@ -51,14 +47,7 @@ def setUpTestData(cls): def setUp(self) -> None: site_visit_schedules._registry = {} site_visit_schedules.loaded = False - site_visit_schedules.register(visit_schedule) - for schedule in visit_schedule.schedules.values(): - try: - consent_definition_factory(model=schedule.consent_model) - except ConsentDefinitionAlreadyRegistered: - pass - self.subject_identifier = "12345" self.registration_datetime = get_utcnow() - relativedelta(years=5) RegisteredSubject.objects.create( @@ -71,7 +60,6 @@ def setUp(self) -> None: now=get_utcnow() - relativedelta(years=5), ) self.helper.consent_and_put_on_schedule( - subject_identifier=self.subject_identifier, visit_schedule_name="visit_schedule", schedule_name="schedule", ) diff --git a/edc_pharmacy/tests/visit_schedule.py b/edc_pharmacy/tests/visit_schedule.py index 6d725d2..d328531 100644 --- a/edc_pharmacy/tests/visit_schedule.py +++ b/edc_pharmacy/tests/visit_schedule.py @@ -1,12 +1,13 @@ from dateutil.relativedelta import relativedelta -from edc_consent.utils import get_consent_model_name from edc_visit_schedule.schedule import Schedule -from edc_visit_schedule.visit import Crf, FormsCollection, Visit +from edc_visit_schedule.visit import Crf, CrfCollection, Visit from edc_visit_schedule.visit_schedule import VisitSchedule +from edc_pharmacy.tests.consents import v1_consent + app_label = "edc_pharmacy" -crfs = FormsCollection( +crfs = CrfCollection( Crf(show_order=1, model=f"{app_label}.studymedication", required=True), ) @@ -49,7 +50,7 @@ name="schedule", onschedule_model="edc_pharmacy.onschedule", offschedule_model="edc_pharmacy.offschedule", - consent_model=get_consent_model_name(), + consent_definitions=[v1_consent], appointment_model="edc_appointment.appointment", )