Skip to content

Commit e7d506a

Browse files
committed
PPHA-475: Ensure a response set is created on submission
Before all questionnaire pages unsure a response set exists for the user or redirect back to start if they have submitted responses in the last year. This replaces the /start page submission and creation of Participant and corresponding response set. Using NHS Login flow, no post can be made to create the response set so handle it on each POST request using the EnsureResponseSet mixin.
1 parent 8fc0f42 commit e7d506a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1880
-380
lines changed

lung_cancer_screening/questions/auth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def create_user(self, claims):
3939
raise ValueError("Missing 'nhs_number' claim in OIDC token")
4040
return User.objects.create_user(nhs_number=nhs_number)
4141

42+
4243
def update_user(self, user, _claims):
4344
return user
4445

lung_cancer_screening/questions/forms/asbestos_exposure_form.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
class AsbestosExposureForm(forms.ModelForm):
77
def __init__(self, *args, **kwargs):
8-
self.user = kwargs.pop('user')
98
super().__init__(*args, **kwargs)
10-
self.instance.user = self.user
119

1210
self.fields["asbestos_exposure"] = TypedChoiceField(
1311
choices=[(True, 'Yes'), (False, 'No')],

lung_cancer_screening/questions/forms/date_of_birth_form.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
from ..models.response_set import ResponseSet
55
from ...nhsuk_forms.split_date_field import SplitDateField
66

7+
78
class DateOfBirthForm(forms.ModelForm):
89
def __init__(self, *args, **kwargs):
9-
self.user = kwargs.pop('user')
1010
super().__init__(*args, **kwargs)
11-
self.instance.user = self.user
1211

1312
invalid_error_message = 'Date of birth must be a real date'
1413
self.fields["date_of_birth"] = SplitDateField(

lung_cancer_screening/questions/forms/ethnicity_form.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,30 @@
33
from ...nhsuk_forms.choice_field import ChoiceField
44
from ..models.response_set import ResponseSet, EthnicityValues
55

6+
67
class EthnicityForm(forms.ModelForm):
78

89
def __init__(self, *args, **kwargs):
9-
self.user = kwargs.pop('user')
1010
super().__init__(*args, **kwargs)
11-
self.instance.user = self.user
1211

1312
self.fields["ethnicity"] = ChoiceField(
1413
choices=EthnicityValues.choices,
1514
label="What is your ethnic background?",
1615
widget=forms.RadioSelect,
1716
label_classes="nhsuk-fieldset__legend--l",
1817
label_is_page_heading=True,
19-
hint="Your ethnicity may impact your chances of developing lung cancer.",
18+
hint=(
19+
"Your ethnicity may impact your chances of "
20+
"developing lung cancer."
21+
),
2022
error_messages={
2123
'required': 'Select your ethnic background'
2224
}
2325
)
2426

25-
self["ethnicity"].add_divider_after(EthnicityValues.OTHER.value, "or")
27+
self["ethnicity"].add_divider_after(
28+
EthnicityValues.OTHER.value, "or"
29+
)
2630

2731
class Meta:
2832
model = ResponseSet

lung_cancer_screening/questions/forms/gender_form.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
from ...nhsuk_forms.choice_field import ChoiceField
44
from ..models.response_set import ResponseSet, GenderValues
55

6+
67
class GenderForm(forms.ModelForm):
78

89
def __init__(self, *args, **kwargs):
9-
self.user = kwargs.pop('user')
1010
super().__init__(*args, **kwargs)
11-
self.instance.user = self.user
1211

1312
self.fields["gender"] = ChoiceField(
1413
choices=GenderValues.choices,
1514
widget=forms.RadioSelect,
1615
label="Which of these best describes you?",
1716
label_classes="nhsuk-fieldset__legend--l",
1817
label_is_page_heading=True,
19-
hint="This information is used to find your NHS number and match with your GP record.",
18+
hint=(
19+
"This information is used to find your NHS number and "
20+
"match with your GP record."
21+
),
2022
error_messages={
2123
'required': 'Select the option that best describes your gender'
2224
}

lung_cancer_screening/questions/forms/have_you_ever_smoked_form.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
class HaveYouEverSmokedForm(forms.ModelForm):
77

88
def __init__(self, *args, **kwargs):
9-
self.user = kwargs.pop('user')
109
super().__init__(*args, **kwargs)
11-
self.instance.user = self.user
1210

1311
self.fields["have_you_ever_smoked"] = TypedChoiceField(
1412
choices=HaveYouEverSmokedValues.choices,

lung_cancer_screening/questions/forms/imperial_height_form.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
from ...nhsuk_forms.imperial_height_field import ImperialHeightField
44
from ..models.response_set import ResponseSet
55

6+
67
class ImperialHeightForm(forms.ModelForm):
78

89
def __init__(self, *args, **kwargs):
9-
self.user = kwargs.pop('user')
1010
super().__init__(*args, **kwargs)
11-
self.instance.user = self.user
1211

1312
self.fields["height_imperial"] = ImperialHeightField(
1413
label="Height",

lung_cancer_screening/questions/forms/imperial_weight_form.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
from ...nhsuk_forms.imperial_weight_field import ImperialWeightField
44
from ..models.response_set import ResponseSet
55

6+
67
class ImperialWeightForm(forms.ModelForm):
78

89
def __init__(self, *args, **kwargs):
9-
self.user = kwargs.pop('user')
1010
super().__init__(*args, **kwargs)
11-
self.instance.user = self.user
1211

1312
self.fields["weight_imperial"] = ImperialWeightField(
1413
label="Weight",

lung_cancer_screening/questions/forms/metric_height_form.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
from ...nhsuk_forms.decimal_field import DecimalField
44
from ..models.response_set import ResponseSet
55

6+
67
class MetricHeightForm(forms.ModelForm):
78

89
def __init__(self, *args, **kwargs):
9-
self.user = kwargs.pop('user')
1010
super().__init__(*args, **kwargs)
11-
self.instance.user = self.user
1211

1312
self.fields["height"] = DecimalField(
1413
decimal_places=1,
1514
label="Centimetres",
1615
classes="nhsuk-input--width-4",
1716
error_messages={
1817
'required': 'Enter your height',
19-
"max_decimal_places": "Centimetres must be to 1 decimal place, for example 185.5cm",
18+
"max_decimal_places": (
19+
"Centimetres must be to 1 decimal place, "
20+
"for example 185.5cm"
21+
),
2022
},
2123
suffix="cm"
2224
)

lung_cancer_screening/questions/forms/metric_weight_form.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
from ...nhsuk_forms.decimal_field import DecimalField
44
from ..models.response_set import ResponseSet
55

6+
67
class MetricWeightForm(forms.ModelForm):
78

89
def __init__(self, *args, **kwargs):
9-
self.user = kwargs.pop('user')
1010
super().__init__(*args, **kwargs)
11-
self.instance.user = self.user
1211

1312
self.fields["weight_metric"] = DecimalField(
1413
decimal_places=1,
@@ -17,7 +16,10 @@ def __init__(self, *args, **kwargs):
1716
required=True,
1817
error_messages={
1918
'required': 'Enter your weight',
20-
'max_decimal_places': 'Kilograms must be to 1 decimal place, for example 90.2kgs',
19+
'max_decimal_places': (
20+
'Kilograms must be to 1 decimal place, '
21+
'for example 90.2kgs'
22+
),
2123
},
2224
suffix="kg"
2325
)

0 commit comments

Comments
 (0)