Skip to content

Commit

Permalink
move review questions to mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 16, 2025
1 parent 4377a85 commit 4b8b0e7
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 58 deletions.
2 changes: 1 addition & 1 deletion edc_consent/field_mixins/review_fields_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ReviewFieldsMixin(models.Model):

consent_copy = models.CharField(
verbose_name=(
"I have provided the participant with a copy of their " "signed informed consent"
"I have provided the participant with a copy of their signed informed consent"
),
max_length=20,
choices=YES_NO_DECLINED,
Expand Down
7 changes: 4 additions & 3 deletions edc_consent/model_mixins/consent_extension_model_mixin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django.utils.translation import gettext as _
from django_crypto_fields.fields import EncryptedTextField
from edc_constants.choices import YES_NO
from edc_constants.choices import YES_NO_NA
from edc_identifier.model_mixins import UniqueSubjectIdentifierModelMixin
from edc_utils import get_utcnow

Expand All @@ -21,10 +21,11 @@ class ConsentExtensionModelMixin(UniqueSubjectIdentifierModelMixin, models.Model

agrees_to_extension = models.CharField(
verbose_name=_(
"Does the participant agree to extend followup as per the protocol amendment?"
"Does the participant give consent to extend clinic "
"followup as per the protocol amendment?"
),
max_length=15,
choices=YES_NO,
choices=YES_NO_NA,
help_text=_("See above for the definition of extended followup."),
)

Expand Down
8 changes: 6 additions & 2 deletions edc_consent/modelform_mixins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from .consent_modelform_mixin import ConsentModelFormMixin
from .consent_modelform_mixin import ConsentModelFormMixin, ReviewFieldsModelFormMixin
from .requires_consent_modelform_mixin import RequiresConsentModelFormMixin

__all__ = ["ConsentModelFormMixin", "RequiresConsentModelFormMixin"]
__all__ = [
"ConsentModelFormMixin",
"RequiresConsentModelFormMixin",
"ReviewFieldsModelFormMixin",
]
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .consent_modelform_mixin import ConsentModelFormMixin
from .review_fields_modelform_mixin import ReviewFieldsModelFormMixin

__all__ = ["ConsentModelFormMixin"]
__all__ = ["ConsentModelFormMixin", "ReviewFieldsModelFormMixin"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
from typing import TYPE_CHECKING

from django import forms
from edc_constants.constants import NO, YES
from edc_screening.utils import (
get_subject_screening_model_cls,
get_subject_screening_or_raise,
)

from .review_fields_modelform_mixin import ReviewFieldsModelFormMixin

if TYPE_CHECKING:
from edc_screening.model_mixins import ScreeningModelMixin


class ConsentModelFormMixinError(Exception):
pass
___all__ = ["CleanFieldsModelFormValidationMixin"]


class CleanFieldsModelFormValidationMixin:
class CleanFieldsModelFormValidationMixin(ReviewFieldsModelFormMixin):
"""A model form mixin calling the default `clean_xxxxx` django
methods.
Expand All @@ -42,51 +41,6 @@ def subject_screening(self):
)
return get_subject_screening_or_raise(screening_identifier, is_modelform=True)

def clean_consent_reviewed(self) -> str:
consent_reviewed = self.cleaned_data.get("consent_reviewed")
if consent_reviewed != YES:
raise forms.ValidationError(
"Complete this part of the informed consent process before continuing.",
code="invalid",
)
return consent_reviewed

def clean_study_questions(self) -> str:
study_questions = self.cleaned_data.get("study_questions")
if study_questions != YES:
raise forms.ValidationError(
"Complete this part of the informed consent process before continuing.",
code="invalid",
)
return study_questions

def clean_assessment_score(self) -> str:
assessment_score = self.cleaned_data.get("assessment_score")
if assessment_score != YES:
raise forms.ValidationError(
"Complete this part of the informed consent process before continuing.",
code="invalid",
)
return assessment_score

def clean_consent_copy(self) -> str:
consent_copy = self.cleaned_data.get("consent_copy")
if consent_copy == NO:
raise forms.ValidationError(
"Complete this part of the informed consent process before continuing.",
code="invalid",
)
return consent_copy

def clean_consent_signature(self) -> str:
consent_signature = self.cleaned_data.get("consent_signature")
if consent_signature != YES:
raise forms.ValidationError(
"Complete this part of the informed consent process before continuing.",
code="invalid",
)
return consent_signature

def clean_initials(self) -> str:
initials = self.cleaned_data.get("initials")
if initials and initials != self.subject_screening.initials:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .clean_fields_modelform_validation_mixin import CleanFieldsModelFormValidationMixin
from .consent_modelform_validation_mixin import ConsentModelFormValidationMixin

__all__ = ["ConsentModelFormMixin"]


class ConsentModelFormMixin(
CleanFieldsModelFormValidationMixin, ConsentModelFormValidationMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
from edc_model_form.utils import get_field_or_raise
from edc_utils import AgeValueError, age, formatted_age

from ... import site_consents
from ...exceptions import ConsentDefinitionValidityPeriodError
from ...site_consents import site_consents
from ...utils import InvalidInitials, verify_initials_against_full_name

if TYPE_CHECKING:
from ...consent_definition import ConsentDefinition

___all__ = ["ConsentModelFormValidationMixin"]


class ConsentModelFormValidationMixin:
"""A mixin for the consent ModelForm consisting of validation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from django import forms
from edc_constants.constants import NO, YES

___all__ = ["ReviewFieldsModelFormMixin"]


class ReviewFieldsModelFormMixin:
def clean_consent_reviewed(self) -> str:
consent_reviewed = self.cleaned_data.get("consent_reviewed")
if consent_reviewed != YES:
raise forms.ValidationError(
"Complete this part of the informed consent process before continuing.",
code="invalid",
)
return consent_reviewed

def clean_study_questions(self) -> str:
study_questions = self.cleaned_data.get("study_questions")
if study_questions != YES:
raise forms.ValidationError(
"Complete this part of the informed consent process before continuing.",
code="invalid",
)
return study_questions

def clean_assessment_score(self) -> str:
assessment_score = self.cleaned_data.get("assessment_score")
if assessment_score != YES:
raise forms.ValidationError(
"Complete this part of the informed consent process before continuing.",
code="invalid",
)
return assessment_score

def clean_consent_copy(self) -> str:
consent_copy = self.cleaned_data.get("consent_copy")
if consent_copy == NO:
raise forms.ValidationError(
"Complete this part of the informed consent process before continuing.",
code="invalid",
)
return consent_copy

def clean_consent_signature(self) -> str:
consent_signature = self.cleaned_data.get("consent_signature")
if consent_signature != YES:
raise forms.ValidationError(
"Complete this part of the informed consent process before continuing.",
code="invalid",
)
return consent_signature

0 comments on commit 4b8b0e7

Please sign in to comment.