Skip to content

Commit fb33aec

Browse files
committed
Move add_previous_mammogram from participants to mammograms
1 parent 1678005 commit fb33aec

File tree

12 files changed

+384
-139
lines changed

12 files changed

+384
-139
lines changed

manage_breast_screening/participants/jinja2/participants/add_previous_mammogram.jinja renamed to manage_breast_screening/mammograms/jinja2/mammograms/add_previous_mammogram.jinja

File renamed without changes.

manage_breast_screening/participants/jinja2/participants/appointment_should_not_proceed.jinja renamed to manage_breast_screening/mammograms/jinja2/mammograms/appointment_should_not_proceed.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
{{ heading }}
2424
</h1>
2525

26-
<p>The mammogram added took place 4 days ago. It is not recommended to take breast x-rays within 6 months of each other.</p>
26+
<p>The mammogram added took place {{ time_since_previous_mammogram }}. It is not recommended to take breast x-rays within 6 months of each other.</p>
2727

2828
<p>Advise the participant that they will be invited for their next scheduled mammogram based on the information provided.</p>
2929

30-
<form action="{{ url('participants:attended_not_screened', kwargs={'appointment_pk': appointment.pk}) }}" method="post">
30+
<form action="{{ url('mammograms:attended_not_screened', kwargs={'appointment_pk': appointment.pk}) }}" method="post">
3131
<div class="nhsuk-button-group">
3232
{{ csrf_input }}
3333
{{ button({

manage_breast_screening/mammograms/presenters/last_known_mammogram_presenter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _present_mammogram(self, mammogram):
6666
def add_link(self):
6767
href = (
6868
reverse(
69-
"participants:add_previous_mammogram",
69+
"mammograms:add_previous_mammogram",
7070
kwargs={"appointment_pk": self.appointment_pk},
7171
)
7272
+ f"?return_url={self.current_url}"

manage_breast_screening/mammograms/presenters/medical_information_presenter.py

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

manage_breast_screening/mammograms/tests/presenters/test_last_known_mammogram_presenter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_add_link(self, reported_today):
105105
)
106106

107107
assert result.add_link == {
108-
"href": f"/participants/{appointment_pk}/previous-mammograms/add?return_url={current_url}",
108+
"href": f"/mammograms/{appointment_pk}/previous-mammograms/add?return_url={current_url}",
109109
"text": "Add another",
110110
"visually_hidden_text": "mammogram",
111111
}

manage_breast_screening/mammograms/tests/presenters/test_medical_information_presenter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def test_add_mammogram_button(self):
267267

268268
assert MedicalInformationPresenter(appointment).add_mammogram_button == {
269269
"href": (
270-
f"/participants/{appointment.pk}/previous-mammograms/add"
270+
f"/mammograms/{appointment.pk}/previous-mammograms/add"
271271
+ f"?return_url=/mammograms/{appointment.pk}/record-medical-information/"
272272
),
273273
"text": "Add another mammogram",
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
from datetime import date
2+
3+
import pytest
4+
from dateutil.relativedelta import relativedelta
5+
from django.urls import reverse
6+
from pytest_django.asserts import assertInHTML, assertRedirects
7+
8+
from manage_breast_screening.participants.forms import ParticipantReportedMammogramForm
9+
from manage_breast_screening.participants.models.appointment import AppointmentStatus
10+
from manage_breast_screening.participants.tests.factories import AppointmentFactory
11+
12+
13+
@pytest.mark.django_db
14+
class TestShowAppointment:
15+
def test_get(self, clinical_user_client):
16+
appointment = AppointmentFactory.create(
17+
clinic_slot__clinic__setting__provider=clinical_user_client.current_provider
18+
)
19+
response = clinical_user_client.http.get(
20+
reverse(
21+
"mammograms:add_previous_mammogram",
22+
kwargs={"appointment_pk": appointment.pk},
23+
)
24+
)
25+
assert response.status_code == 200
26+
27+
def test_post_with_missing_parameters(self, clinical_user_client):
28+
appointment = AppointmentFactory.create(
29+
clinic_slot__clinic__setting__provider=clinical_user_client.current_provider
30+
)
31+
response = clinical_user_client.http.post(
32+
reverse(
33+
"mammograms:add_previous_mammogram",
34+
kwargs={"appointment_pk": appointment.pk},
35+
)
36+
)
37+
assert response.status_code == 200
38+
assertInHTML(
39+
"""
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>
59+
""",
60+
response.text,
61+
)
62+
63+
def test_post_date_unsure(self, clinical_user_client):
64+
appointment = AppointmentFactory.create(
65+
clinic_slot__clinic__setting__provider=clinical_user_client.current_provider
66+
)
67+
return_url = reverse(
68+
"mammograms:record_medical_information",
69+
kwargs={"pk": appointment.pk},
70+
)
71+
72+
response = clinical_user_client.http.post(
73+
reverse(
74+
"mammograms:add_previous_mammogram",
75+
kwargs={"appointment_pk": appointment.pk},
76+
),
77+
{
78+
"return_url": return_url,
79+
"where_taken": ParticipantReportedMammogramForm.WhereTaken.SAME_UNIT,
80+
"when_taken": ParticipantReportedMammogramForm.WhenTaken.NOT_SURE,
81+
"name_is_the_same": ParticipantReportedMammogramForm.NameIsTheSame.YES,
82+
},
83+
)
84+
85+
assertRedirects(response, return_url)
86+
87+
def test_post_approx_date(self, clinical_user_client):
88+
appointment = AppointmentFactory.create(
89+
clinic_slot__clinic__setting__provider=clinical_user_client.current_provider
90+
)
91+
return_url = reverse(
92+
"mammograms:record_medical_information",
93+
kwargs={"pk": appointment.pk},
94+
)
95+
96+
response = clinical_user_client.http.post(
97+
reverse(
98+
"mammograms:add_previous_mammogram",
99+
kwargs={"appointment_pk": appointment.pk},
100+
),
101+
{
102+
"return_url": return_url,
103+
"where_taken": ParticipantReportedMammogramForm.WhereTaken.SAME_UNIT,
104+
"when_taken": ParticipantReportedMammogramForm.WhenTaken.APPROX,
105+
"approx_date": "last month",
106+
"name_is_the_same": ParticipantReportedMammogramForm.NameIsTheSame.YES,
107+
},
108+
)
109+
110+
assertRedirects(response, return_url)
111+
112+
@pytest.mark.parametrize(
113+
"exact_date",
114+
[
115+
date.today() - relativedelta(months=6),
116+
date.today() - relativedelta(months=6) - relativedelta(days=1),
117+
date.today() - relativedelta(years=50),
118+
],
119+
)
120+
def test_post_exact_date_six_months_ago_or_later(
121+
self, clinical_user_client, exact_date
122+
):
123+
appointment = AppointmentFactory.create(
124+
clinic_slot__clinic__setting__provider=clinical_user_client.current_provider
125+
)
126+
return_url = reverse(
127+
"mammograms:record_medical_information",
128+
kwargs={"pk": appointment.pk},
129+
)
130+
131+
response = clinical_user_client.http.post(
132+
reverse(
133+
"mammograms:add_previous_mammogram",
134+
kwargs={"appointment_pk": appointment.pk},
135+
),
136+
{
137+
"return_url": return_url,
138+
"where_taken": ParticipantReportedMammogramForm.WhereTaken.SAME_UNIT,
139+
"when_taken": ParticipantReportedMammogramForm.WhenTaken.EXACT,
140+
"exact_date_0": exact_date.day,
141+
"exact_date_1": exact_date.month,
142+
"exact_date_2": exact_date.year,
143+
"name_is_the_same": ParticipantReportedMammogramForm.NameIsTheSame.YES,
144+
},
145+
)
146+
147+
assertRedirects(response, return_url)
148+
149+
@pytest.mark.parametrize(
150+
"exact_date",
151+
[
152+
date.today(),
153+
date.today() - relativedelta(months=6) + relativedelta(days=1),
154+
date.today() - relativedelta(months=6) + relativedelta(days=2),
155+
],
156+
)
157+
def test_post_exact_date_within_last_six_months(
158+
self, clinical_user_client, exact_date
159+
):
160+
appointment = AppointmentFactory.create(
161+
clinic_slot__clinic__setting__provider=clinical_user_client.current_provider
162+
)
163+
return_url = reverse(
164+
"mammograms:record_medical_information",
165+
kwargs={"pk": appointment.pk},
166+
)
167+
168+
response = clinical_user_client.http.post(
169+
reverse(
170+
"mammograms:add_previous_mammogram",
171+
kwargs={"appointment_pk": appointment.pk},
172+
),
173+
{
174+
"return_url": return_url,
175+
"where_taken": ParticipantReportedMammogramForm.WhereTaken.SAME_UNIT,
176+
"when_taken": ParticipantReportedMammogramForm.WhenTaken.EXACT,
177+
"exact_date_0": exact_date.day,
178+
"exact_date_1": exact_date.month,
179+
"exact_date_2": exact_date.year,
180+
"name_is_the_same": ParticipantReportedMammogramForm.NameIsTheSame.YES,
181+
},
182+
)
183+
assertRedirects(
184+
response,
185+
reverse(
186+
"mammograms:appointment_should_not_proceed",
187+
kwargs={"appointment_pk": appointment.pk},
188+
)
189+
+ f"?exact_date={exact_date.isoformat()}",
190+
)
191+
assert appointment.current_status.state == AppointmentStatus.CONFIRMED
192+
193+
response = clinical_user_client.http.post(
194+
reverse(
195+
"mammograms:attended_not_screened",
196+
kwargs={"appointment_pk": appointment.pk},
197+
),
198+
)
199+
assertRedirects(
200+
response,
201+
reverse(
202+
"clinics:show",
203+
kwargs={"pk": appointment.clinic_slot.clinic.pk},
204+
),
205+
)
206+
assert (
207+
appointment.current_status.state == AppointmentStatus.ATTENDED_NOT_SCREENED
208+
)

manage_breast_screening/mammograms/urls.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from django.urls import path
22

3+
from manage_breast_screening.mammograms.views import mammogram_views
4+
35
from .views import (
46
appointment_note_views,
57
appointment_views,
@@ -219,4 +221,19 @@
219221
other_procedure_history_item_views.DeleteOtherProcedureHistoryView.as_view(),
220222
name="delete_other_procedure_history_item",
221223
),
224+
path(
225+
"<uuid:appointment_pk>/previous-mammograms/add",
226+
mammogram_views.add_previous_mammogram,
227+
name="add_previous_mammogram",
228+
),
229+
path(
230+
"<uuid:appointment_pk>/appointment-should-not-proceed/",
231+
mammogram_views.appointment_should_not_proceed,
232+
name="appointment_should_not_proceed",
233+
),
234+
path(
235+
"<uuid:appointment_pk>/attended-not-screened/",
236+
mammogram_views.attended_not_screened,
237+
name="attended_not_screened",
238+
),
222239
]

0 commit comments

Comments
 (0)