Skip to content

Commit 12c720d

Browse files
committed
PPHA-483: Add Education forms
1 parent c344f49 commit 12c720d

15 files changed

Lines changed: 354 additions & 18 deletions

File tree

features/education.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@wip
2+
Feature: Education page
3+
Scenario: The page is accessible
4+
Given I am logged in
5+
When I go to "/education"
6+
Then there are no accessibility violations
7+
8+
Scenario: Form errors
9+
Given I am logged in
10+
When I go to "/education"
11+
And I click "Continue"
12+
Then I am on "/education"
13+
And I see a form error "Select your level of education"
14+
And there are no accessibility violations
15+
16+
Scenario: Navigating backwards and forwards
17+
Given I am logged in
18+
When I go to "/education"
19+
Then I see a back link to "/ethnicity"
20+
When I fill in and submit my education with "A-levels"
21+
Then I am on "/respiratory-conditions"
22+

features/questionnaire.feature

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Feature: Questionnaire
3535
When I fill in and submit my ethnicity with "White"
3636

3737
Then I am on "/education"
38-
When I click "Continue"
38+
When I fill in and submit my education with "A-levels"
39+
3940

4041
Then I am on "/respiratory-conditions"
4142
When I fill in and submit my respiratory conditions with "Pneumonia" and "Emphysema"
@@ -61,6 +62,7 @@ Feature: Questionnaire
6162
And I see responses "What was your sex at birth? Male"
6263
And I see responses "Which of these best describes you? Female"
6364
And I see responses "What is your ethnic background? White"
65+
And I see responses "What level of education have you completed? A-levels"
6466
And I see responses "Have you ever worked in a job where you might have been exposed to asbestos? No"
6567
And I see responses "Have you ever been diagnosed with any of the following respiratory conditions? Pneumonia and Emphysema"
6668
And I see responses "Have you ever been diagnosed with cancer? No"

features/steps/form_steps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def when_i_fill_in_and_submit_my_ethnicity(context, ethnicity):
6363
context.page.get_by_label(ethnicity, exact=True).check()
6464
when_i_submit_the_form(context)
6565

66+
@when(u'I fill in and submit my education with "{education}"')
67+
def when_i_fill_in_and_submit_my_education(context, education):
68+
context.page.get_by_label(education, exact=True).check()
69+
when_i_submit_the_form(context)
70+
6671
@when(u'I fill in and submit my respiratory conditions with "{condition_a}" and "{condition_b}"')
6772
def when_i_fill_in_and_submit_my_respiratory_conditions(context, condition_a, condition_b):
6873
context.page.get_by_label(condition_a).check()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from django import forms
2+
3+
from ...nhsuk_forms.choice_field import ChoiceField
4+
from ..models.education_response import EducationResponse, EducationValues
5+
6+
7+
class EducationForm(forms.ModelForm):
8+
9+
def __init__(self, *args, **kwargs):
10+
super().__init__(*args, **kwargs)
11+
12+
self.fields["value"] = ChoiceField(
13+
choices=EducationValues.choices,
14+
label="What level of education have you completed?",
15+
widget=forms.RadioSelect,
16+
label_classes="nhsuk-fieldset__legend--l",
17+
label_is_page_heading=True,
18+
hint=(
19+
"Select all that apply"
20+
),
21+
error_messages={
22+
'required': 'Select your level of education'
23+
}
24+
)
25+
26+
self["value"].add_divider_after(
27+
EducationValues.POSTGRADUATE_DEGREE.value, "or"
28+
)
29+
30+
class Meta:
31+
model = EducationResponse
32+
fields = ['value']
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends 'question_form.jinja' %}
2+
3+
{% block prelude %}
4+
5+
<h1 class="nhsuk-heading-l">Help us give you an accurate result by telling us about your education</h1>
6+
7+
<p>Education is linked to other factors that may impact your chances of developing lung cancer.</p>
8+
9+
<p>You do not have to tell us about your education but this may affect the accuracy of your result.</p>
10+
11+
<p>If you did not study in England choose the closest equivalent.</p>
12+
13+
{% endblock prelude %}

lung_cancer_screening/questions/jinja2/responses.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
<li>What was your sex at birth? {{ response_set.sex_at_birth }}</li>
1515
<li>Which of these best describes you? {{ response_set.gender }}</li>
1616
<li>What is your ethnic background? {{ response_set.ethnicity }}</li>
17-
<li>Have you ever worked in a job where you might have been exposed to asbestos? {{ response_set.asbestos_exposure }}</li>
17+
<li>What level of education have you completed? {{ response_set.education }}</li>
1818
<li>Have you ever been diagnosed with any of the following respiratory conditions? {{ response_set.respiratory_conditions }}</li>
19+
<li>Have you ever worked in a job where you might have been exposed to asbestos? {{ response_set.asbestos_exposure }}</li>
1920
<li>Have you ever been diagnosed with cancer? {{ response_set.cancer_diagnosis }}</li>
2021
<li>Have any of your parents, siblings or children ever been diagnosed with lung cancer {{ response_set.family_history_lung_cancer }}</li>
2122
<li>Were any of your relatives younger than 60 years old when they were diagnosed with lung cancer? {{ response_set.relatives_age_when_diagnosed }}</li>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 5.2.9 on 2026-01-09 13:33
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('questions', '0038_relativesagewhendiagnosedresponse_and_more'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='EducationResponse',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('created_at', models.DateTimeField(auto_now_add=True)),
19+
('updated_at', models.DateTimeField(auto_now=True)),
20+
('value', models.CharField(choices=[('X', 'I finished school before the age of 15'), ('G', 'GCSEs'), ('A', 'A-levels'), ('B', "Bachelor's degree"), ('P', 'Postgraduate degree'), ('N', "I'd prefer not to say")], max_length=1)),
21+
('response_set', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='education_response', to='questions.responseset')),
22+
],
23+
options={
24+
'abstract': False,
25+
},
26+
),
27+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.db import models
2+
3+
from .base import BaseModel
4+
from .response_set import ResponseSet
5+
6+
7+
class EducationValues(models.TextChoices):
8+
FINISHED_SCHOOL_BEFORE_15 = "X", "I finished school before the age of 15"
9+
GCSES = "G", "GCSEs"
10+
A_LEVELS = "A", "A-levels"
11+
BACHELORS_DEGREE = "B", "Bachelor's degree"
12+
POSTGRADUATE_DEGREE = "P", "Postgraduate degree"
13+
PREFER_NOT_TO_SAY = "N", "I'd prefer not to say"
14+
15+
16+
class EducationResponse(BaseModel):
17+
response_set = models.OneToOneField(ResponseSet, on_delete=models.CASCADE, related_name='education_response')
18+
value = models.CharField(max_length=1, choices=EducationValues.choices)

lung_cancer_screening/questions/presenters/response_set_presenter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def ethnicity(self):
6969

7070
return self.response_set.ethnicity_response.get_value_display()
7171

72+
@property
73+
def education(self):
74+
if not hasattr(self.response_set, 'education_response'):
75+
return None
76+
77+
return self.response_set.education_response.get_value_display()
78+
7279
@property
7380
def asbestos_exposure(self):
7481
if not hasattr(self.response_set, 'asbestos_exposure_response'):
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import factory
2+
3+
from .response_set_factory import ResponseSetFactory
4+
from ...models.education_response import EducationResponse, EducationValues
5+
6+
7+
class EducationResponseFactory(factory.django.DjangoModelFactory):
8+
class Meta:
9+
model = EducationResponse
10+
11+
response_set = factory.SubFactory(ResponseSetFactory)
12+
value = factory.Iterator(EducationValues)

0 commit comments

Comments
 (0)