Skip to content

Commit da87561

Browse files
committed
wip
1 parent fb33aec commit da87561

File tree

12 files changed

+511
-378
lines changed

12 files changed

+511
-378
lines changed

manage_breast_screening/core/views/generic.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@ def form_valid(self, form):
8686
auditor = Auditor.from_request(self.request)
8787
auditor.audit_create(created_object)
8888

89-
messages.add_message(
90-
self.request,
91-
messages.SUCCESS,
92-
self.get_success_message_content(created_object),
93-
)
89+
if self.should_add_message(form):
90+
messages.add_message(
91+
self.request,
92+
messages.SUCCESS,
93+
self.get_success_message_content(created_object),
94+
)
9495

9596
return super().form_valid(form)
9697

98+
def should_add_message(self, form) -> bool:
99+
return True
100+
97101

98102
class UpdateWithAuditView(NamedThingMixin, SingleObjectMixin, FormView):
99103
"""
@@ -159,14 +163,18 @@ def form_valid(self, form):
159163
auditor = Auditor.from_request(self.request)
160164
auditor.audit_update(created_object)
161165

162-
messages.add_message(
163-
self.request,
164-
messages.SUCCESS,
165-
self.get_success_message_content(created_object),
166-
)
166+
if self.should_add_message(form):
167+
messages.add_message(
168+
self.request,
169+
messages.SUCCESS,
170+
self.get_success_message_content(created_object),
171+
)
167172

168173
return super().form_valid(form)
169174

175+
def should_add_message(self, form) -> bool:
176+
return True
177+
170178

171179
class DeleteWithAuditView(NamedThingMixin, DeleteView):
172180
"""
Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,22 @@
11
{% extends "layout-form.jinja" %}
22
{% from "nhsuk/components/button/macro.jinja" import button %}
3-
{% from "nhsuk/components/back-link/macro.jinja" import backLink %}
3+
{% from "nhsuk/components/fieldset/macro.jinja" import fieldset %}
44

5-
{% from "django_form_helpers.jinja" import form_error_summary, app_date_input %}
5+
{% block form %}
6+
<input type="hidden" name="return_url" value="{{ return_url }}"/>
67

7-
{% block beforeContent %}
8-
{{ backLink(back_link_params) }}
9-
{% endblock beforeContent %}
8+
{% do form.location_type.add_divider_after("OUTSIDE_UK", "or") %}
9+
{{ form.location_type.as_field_group() }}
1010

11-
{% block messages %}
12-
{{ form_error_summary(form) }}
13-
{% endblock messages %}
11+
{{ form.when_taken.as_field_group() }}
1412

15-
{% block page_content %}
16-
<div class="nhsuk-grid-row">
17-
<div class="nhsuk-grid-column-two-thirds">
13+
{{ form.name_is_the_same.as_field_group() }}
1814

19-
<h1 class="nhsuk-heading-l">
20-
{% if caption %}
21-
<span class="nhsuk-caption-l">{{ caption }}</span>
22-
{% endif %}
23-
{{ title }}
24-
</h1>
15+
{{ form.additional_information.as_field_group() }}
2516

26-
<form action="{{ request.path }}" method="post">
27-
{# Radios with conditionals #}
28-
{% do form.where_taken.add_conditional_html(form.WhereTaken.UK, form.somewhere_in_the_uk_details.as_field_group()) %}
29-
{% do form.where_taken.add_conditional_html(form.WhereTaken.OUTSIDE_UK, form.outside_the_uk_details.as_field_group()) %}
30-
{% do form.where_taken.add_divider_after(form.WhereTaken.OUTSIDE_UK, "or") %}
31-
{{ form.where_taken.as_field_group() }}
32-
33-
{% do form.when_taken.add_conditional_html(form.WhenTaken.EXACT, form.exact_date.as_field_group()) %}
34-
{% do form.when_taken.add_conditional_html(form.WhenTaken.APPROX, form.approx_date.as_field_group()) %}
35-
{{ form.when_taken.as_field_group() }}
36-
37-
{% do form.name_is_the_same.add_conditional_html(form.NameIsTheSame.NO, form.different_name.as_field_group()) %}
38-
{{ form.name_is_the_same.as_field_group() }}
39-
40-
{# Textarea for any other relevant details #}
41-
{{ form.additional_information.as_field_group() }}
42-
43-
{{ button({
44-
"text": "Continue"
45-
}) }}
46-
47-
{{ csrf_input }}
48-
49-
<input type="hidden" name="return_url" value="{{ return_url }}"/>
50-
</form>
17+
<div class="nhsuk-button-group">
18+
{{ button({
19+
"text": "Save"
20+
}) }}
5121
</div>
52-
</div>
53-
{% endblock page_content %}
22+
{% endblock %}

manage_breast_screening/mammograms/jinja2/mammograms/appointment_should_not_proceed.jinja

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
{% block page_content %}
1313
<div class="nhsuk-grid-row">
1414
<div class="nhsuk-grid-column-two-thirds">
15-
{{ form_error_summary(form) }}
16-
1715
<h1 class="nhsuk-heading-l">
1816
{% if caption %}
1917
<span class="nhsuk-caption-l">
@@ -35,6 +33,10 @@
3533
}) }}
3634
</div>
3735
</form>
36+
37+
<p>
38+
<a href="{{ change_previous_mammogram_url }}">Edit previous mammogram details</a>
39+
</p>
3840
</div>
3941
</div>
4042
{% endblock %}

manage_breast_screening/mammograms/presenters/last_known_mammogram_presenter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def add_link(self):
6767
href = (
6868
reverse(
6969
"mammograms:add_previous_mammogram",
70-
kwargs={"appointment_pk": self.appointment_pk},
70+
kwargs={"pk": self.appointment_pk},
7171
)
7272
+ f"?return_url={self.current_url}"
7373
)

manage_breast_screening/mammograms/presenters/medical_information_presenter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def add_mammogram_button(self):
238238
url = (
239239
reverse(
240240
"mammograms:add_previous_mammogram",
241-
kwargs={"appointment_pk": self.appointment.pk},
241+
kwargs={"pk": self.appointment.pk},
242242
)
243243
+ "?return_url="
244244
+ quote(self.medical_information_url)

manage_breast_screening/mammograms/tests/views/test_mammogram_views.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pytest_django.asserts import assertInHTML, assertRedirects
77

88
from manage_breast_screening.participants.forms import ParticipantReportedMammogramForm
9+
from manage_breast_screening.participants.models import ParticipantReportedMammogram
910
from manage_breast_screening.participants.models.appointment import AppointmentStatus
1011
from manage_breast_screening.participants.tests.factories import AppointmentFactory
1112

@@ -19,7 +20,7 @@ def test_get(self, clinical_user_client):
1920
response = clinical_user_client.http.get(
2021
reverse(
2122
"mammograms:add_previous_mammogram",
22-
kwargs={"appointment_pk": appointment.pk},
23+
kwargs={"pk": appointment.pk},
2324
)
2425
)
2526
assert response.status_code == 200
@@ -31,31 +32,17 @@ def test_post_with_missing_parameters(self, clinical_user_client):
3132
response = clinical_user_client.http.post(
3233
reverse(
3334
"mammograms:add_previous_mammogram",
34-
kwargs={"appointment_pk": appointment.pk},
35+
kwargs={"pk": appointment.pk},
3536
)
3637
)
3738
assert response.status_code == 200
3839
assertInHTML(
3940
"""
40-
<span id="id_where_taken-error" class="nhsuk-error-message">
41-
<span class="nhsuk-u-visually-hidden">Error:</span> This field is required.
42-
</span>
43-
""",
44-
response.text,
45-
)
46-
assertInHTML(
47-
"""
48-
<span id="id_when_taken-error" class="nhsuk-error-message">
49-
<span class="nhsuk-u-visually-hidden">Error:</span> This field is required.
50-
</span>
51-
""",
52-
response.text,
53-
)
54-
assertInHTML(
55-
"""
56-
<span id="id_name_is_the_same-error" class="nhsuk-error-message">
57-
<span class="nhsuk-u-visually-hidden">Error:</span> This field is required.
58-
</span>
41+
<ul class="nhsuk-list nhsuk-error-summary__list">
42+
<li><a href="#id_location_type">Select where the breast x-rays were taken</a></li>
43+
<li><a href="#id_when_taken">Select when the x-rays were taken</a></li>
44+
<li><a href="#id_name_is_the_same">Select if the x-rays were taken with the same name</a></li>
45+
</ul>
5946
""",
6047
response.text,
6148
)
@@ -72,11 +59,11 @@ def test_post_date_unsure(self, clinical_user_client):
7259
response = clinical_user_client.http.post(
7360
reverse(
7461
"mammograms:add_previous_mammogram",
75-
kwargs={"appointment_pk": appointment.pk},
62+
kwargs={"pk": appointment.pk},
7663
),
7764
{
7865
"return_url": return_url,
79-
"where_taken": ParticipantReportedMammogramForm.WhereTaken.SAME_UNIT,
66+
"location_type": ParticipantReportedMammogram.LocationType.NHS_BREAST_SCREENING_UNIT,
8067
"when_taken": ParticipantReportedMammogramForm.WhenTaken.NOT_SURE,
8168
"name_is_the_same": ParticipantReportedMammogramForm.NameIsTheSame.YES,
8269
},
@@ -96,11 +83,11 @@ def test_post_approx_date(self, clinical_user_client):
9683
response = clinical_user_client.http.post(
9784
reverse(
9885
"mammograms:add_previous_mammogram",
99-
kwargs={"appointment_pk": appointment.pk},
86+
kwargs={"pk": appointment.pk},
10087
),
10188
{
10289
"return_url": return_url,
103-
"where_taken": ParticipantReportedMammogramForm.WhereTaken.SAME_UNIT,
90+
"location_type": ParticipantReportedMammogram.LocationType.NHS_BREAST_SCREENING_UNIT,
10491
"when_taken": ParticipantReportedMammogramForm.WhenTaken.APPROX,
10592
"approx_date": "last month",
10693
"name_is_the_same": ParticipantReportedMammogramForm.NameIsTheSame.YES,
@@ -131,11 +118,11 @@ def test_post_exact_date_six_months_ago_or_later(
131118
response = clinical_user_client.http.post(
132119
reverse(
133120
"mammograms:add_previous_mammogram",
134-
kwargs={"appointment_pk": appointment.pk},
121+
kwargs={"pk": appointment.pk},
135122
),
136123
{
137124
"return_url": return_url,
138-
"where_taken": ParticipantReportedMammogramForm.WhereTaken.SAME_UNIT,
125+
"location_type": ParticipantReportedMammogram.LocationType.NHS_BREAST_SCREENING_UNIT,
139126
"when_taken": ParticipantReportedMammogramForm.WhenTaken.EXACT,
140127
"exact_date_0": exact_date.day,
141128
"exact_date_1": exact_date.month,
@@ -165,28 +152,43 @@ def test_post_exact_date_within_last_six_months(
165152
kwargs={"pk": appointment.pk},
166153
)
167154

155+
assert (
156+
ParticipantReportedMammogram.objects.filter(
157+
participant=appointment.participant
158+
).count()
159+
== 0
160+
)
161+
168162
response = clinical_user_client.http.post(
169163
reverse(
170164
"mammograms:add_previous_mammogram",
171-
kwargs={"appointment_pk": appointment.pk},
165+
kwargs={"pk": appointment.pk},
172166
),
173167
{
174168
"return_url": return_url,
175-
"where_taken": ParticipantReportedMammogramForm.WhereTaken.SAME_UNIT,
169+
"location_type": ParticipantReportedMammogram.LocationType.NHS_BREAST_SCREENING_UNIT,
176170
"when_taken": ParticipantReportedMammogramForm.WhenTaken.EXACT,
177171
"exact_date_0": exact_date.day,
178172
"exact_date_1": exact_date.month,
179173
"exact_date_2": exact_date.year,
180174
"name_is_the_same": ParticipantReportedMammogramForm.NameIsTheSame.YES,
181175
},
182176
)
177+
178+
mammogram = ParticipantReportedMammogram.objects.filter(
179+
participant=appointment.participant
180+
).first()
181+
183182
assertRedirects(
184183
response,
185184
reverse(
186185
"mammograms:appointment_should_not_proceed",
187-
kwargs={"appointment_pk": appointment.pk},
186+
kwargs={
187+
"appointment_pk": appointment.pk,
188+
"participant_reported_mammogram_pk": mammogram.pk,
189+
},
188190
)
189-
+ f"?exact_date={exact_date.isoformat()}",
191+
+ f"?exact_date={exact_date.isoformat()}&return_url={return_url}",
190192
)
191193
assert appointment.current_status.state == AppointmentStatus.CONFIRMED
192194

manage_breast_screening/mammograms/urls.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from manage_breast_screening.mammograms.views import mammogram_views
44

55
from .views import (
6+
add_mammogram_views,
67
appointment_note_views,
78
appointment_views,
89
special_appointment_views,
@@ -222,12 +223,17 @@
222223
name="delete_other_procedure_history_item",
223224
),
224225
path(
225-
"<uuid:appointment_pk>/previous-mammograms/add",
226-
mammogram_views.add_previous_mammogram,
226+
"<uuid:pk>/previous-mammograms/add",
227+
add_mammogram_views.AddParticipantReportedMammogramView.as_view(),
227228
name="add_previous_mammogram",
228229
),
229230
path(
230-
"<uuid:appointment_pk>/appointment-should-not-proceed/",
231+
"<uuid:pk>/previous-mammograms/<uuid:participant_reported_mammogram_pk>",
232+
add_mammogram_views.UpdateParticipantReportedMammogramView.as_view(),
233+
name="change_previous_mammogram",
234+
),
235+
path(
236+
"<uuid:appointment_pk>/appointment-should-not-proceed/<uuid:participant_reported_mammogram_pk>",
231237
mammogram_views.appointment_should_not_proceed,
232238
name="appointment_should_not_proceed",
233239
),

0 commit comments

Comments
 (0)