diff --git a/edc_action_item/forms/action_item_form.py b/edc_action_item/forms/action_item_form.py index a5a5160..964268b 100644 --- a/edc_action_item/forms/action_item_form.py +++ b/edc_action_item/forms/action_item_form.py @@ -1,11 +1,13 @@ from django import forms from django.apps import apps as django_apps +from edc_consent.modelform_mixins import RequiresConsentModelFormMixin from edc_constants.constants import CANCELLED, NEW, OPEN +from edc_model_form.mixins import BaseModelFormMixin from ..models import ActionItem -class ActionItemForm(forms.ModelForm): +class ActionItemForm(RequiresConsentModelFormMixin, BaseModelFormMixin, forms.ModelForm): subject_identifier = forms.CharField( label="Subject Identifier", required=False, diff --git a/edc_action_item/tests/models.py b/edc_action_item/tests/models.py index 12e140a..1e67cc1 100644 --- a/edc_action_item/tests/models.py +++ b/edc_action_item/tests/models.py @@ -2,16 +2,37 @@ from django.db import models from django.db.models.deletion import CASCADE, PROTECT +from edc_consent.field_mixins import PersonalFieldsMixin +from edc_consent.model_mixins import ConsentModelMixin from edc_constants.choices import YES_NO from edc_constants.constants import YES from edc_crf.model_mixins import CrfWithActionModelMixin -from edc_identifier.model_mixins import NonUniqueSubjectIdentifierFieldMixin +from edc_identifier.model_mixins import ( + NonUniqueSubjectIdentifierFieldMixin, + NonUniqueSubjectIdentifierModelMixin, +) from edc_model.models import BaseUuidModel, HistoricalRecords from edc_sites.model_mixins import SiteModelMixin from ..models import ActionModelMixin +class SubjectConsent( + ConsentModelMixin, + SiteModelMixin, + NonUniqueSubjectIdentifierModelMixin, + PersonalFieldsMixin, + BaseUuidModel, +): + screening_identifier = models.CharField( + verbose_name="Screening identifier", max_length=50, unique=True + ) + history = HistoricalRecords() + + class Meta(ConsentModelMixin.Meta): + pass + + class SubjectIdentifierModelManager(models.Manager): def get_by_natural_key(self, subject_identifier): return self.get(subject_identifier=subject_identifier) diff --git a/edc_action_item/tests/test_case_mixin.py b/edc_action_item/tests/test_case_mixin.py index 269dec4..29ab77e 100644 --- a/edc_action_item/tests/test_case_mixin.py +++ b/edc_action_item/tests/test_case_mixin.py @@ -1,6 +1,7 @@ +from dateutil.relativedelta import relativedelta from django.test import TestCase +from edc_consent import site_consents from edc_facility.import_holidays import import_holidays -from edc_metadata.tests.models import SubjectConsent from edc_registration.models import RegisteredSubject from edc_utils import get_utcnow from edc_visit_schedule.site_visit_schedules import site_visit_schedules @@ -21,9 +22,14 @@ def enroll(subject_identifier=None): site_visit_schedules.loaded = False site_visit_schedules.register(visit_schedule) - subject_consent = SubjectConsent.objects.create( - subject_identifier=subject_identifier, consent_datetime=get_utcnow() + consent_datetime = get_utcnow() + cdef = site_consents.get_consent_definition(report_datetime=consent_datetime) + subject_consent = cdef.model_cls.objects.create( + subject_identifier=subject_identifier, + consent_datetime=consent_datetime, + dob=get_utcnow() - relativedelta(years=25), ) + RegisteredSubject.objects.create(subject_identifier=subject_identifier) _, schedule = site_visit_schedules.get_by_onschedule_model("edc_metadata.onschedule") schedule.put_on_schedule( subject_identifier=subject_consent.subject_identifier, diff --git a/edc_action_item/tests/tests/test_action_item.py b/edc_action_item/tests/tests/test_action_item.py index b281997..4879e20 100644 --- a/edc_action_item/tests/tests/test_action_item.py +++ b/edc_action_item/tests/tests/test_action_item.py @@ -1,7 +1,10 @@ +from dateutil.relativedelta import relativedelta from django.core.exceptions import ObjectDoesNotExist from django.db.models.deletion import ProtectedError -from django.test import TestCase +from django.test import TestCase, tag +from edc_consent.tests.consent_test_utils import consent_definition_factory from edc_constants.constants import CANCELLED, CLOSED, NEW, OPEN +from edc_utils import get_utcnow from edc_action_item.action import Action from edc_action_item.create_or_update_action_type import create_or_update_action_type @@ -17,8 +20,16 @@ class TestActionItem(TestCaseMixin, TestCase): + @classmethod + def setUpTestData(cls): + consent_definition_factory( + model="edc_action_item.subjectconsent", + start=get_utcnow() - relativedelta(years=1), + end=get_utcnow() + relativedelta(years=1), + ) + def setUp(self): - self.subject_identifier = self.fake_enroll() + self.subject_identifier = self.enroll() site_action_items.registry = {} site_action_items.register(FormZeroAction) get_action_type(FormZeroAction) @@ -74,6 +85,7 @@ def test_identifier_not_changed(self): except ObjectDoesNotExist: self.fail("ActionItem unexpectedly does not exist") + @tag("1") def test_changes_action_item_status_from_new_to_open_on_edit(self): action_type = ActionType.objects.get(name=FormZeroAction.name) diff --git a/edc_action_item/tests/visit_schedule.py b/edc_action_item/tests/visit_schedule.py index 2d83f56..2f48078 100644 --- a/edc_action_item/tests/visit_schedule.py +++ b/edc_action_item/tests/visit_schedule.py @@ -41,7 +41,7 @@ name="schedule", onschedule_model="edc_metadata.onschedule", offschedule_model="edc_metadata.offschedule", - consent_model="edc_metadata.subjectconsent", + consent_model="edc_action_item.subjectconsent", appointment_model="edc_appointment.appointment", )