diff --git a/edc_consent/consent_definition.py b/edc_consent/consent_definition.py index 7854d4c..3f9d7f1 100644 --- a/edc_consent/consent_definition.py +++ b/edc_consent/consent_definition.py @@ -174,16 +174,21 @@ def check_date_within_study_period(self) -> None: protocol = ResearchProtocolConfig() study_open_datetime = protocol.study_open_datetime study_close_datetime = protocol.study_close_datetime - for index, attr in enumerate(["start", "end"]): + for attr in ["start", "end"]: if not ( floor_secs(study_open_datetime) <= getattr(self, attr) <= ceil_secs(study_close_datetime) ): - date_string = formatted_datetime(getattr(self, attr)) + open_date_string = formatted_datetime(study_open_datetime) + close_date_string = formatted_datetime(study_close_datetime) + attr_date_string = formatted_datetime(getattr(self, attr)) raise ConsentDefinitionError( - f"Invalid {attr} date. Cannot be before study start date. " - f"See {self}. Got {date_string}." + f"Invalid {attr} date. " + f"Must be within the opening and closing dates of the protocol. " + f"See {self}. " + f"Got {open_date_string=}, {close_date_string=}, " + f"{attr=}, {attr_date_string=}." ) def get_previous_consent(