Skip to content

Commit 0aa198e

Browse files
authored
Merge pull request #803 from NHSDigital/DTOSS-11572-delete-other-procedure
Allow deletion of other procedures
2 parents 4feaeaa + a63717c commit 0aa198e

File tree

5 files changed

+91
-1
lines changed

5 files changed

+91
-1
lines changed

manage_breast_screening/mammograms/jinja2/mammograms/medical_information/medical_history/forms/other_procedure_history.jinja

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,13 @@
1414
"text": "Save"
1515
}) }}
1616
</div>
17+
18+
{% if delete_link %}
19+
<p class="nhsuk-u-margin-top-4">
20+
<a href="{{ delete_link.href }}" class="{{ delete_link.class }}">
21+
{{ delete_link.text }}
22+
</a>
23+
</p>
24+
{% endif %}
1725
{% endblock %}
1826

manage_breast_screening/mammograms/tests/views/test_other_procedure_history_view.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
)
1313

1414

15+
@pytest.fixture
16+
def history_item(appointment):
17+
return OtherProcedureHistoryItemFactory.create(appointment=appointment)
18+
19+
1520
@pytest.mark.django_db
1621
class TestAddOtherProcedureView:
1722
def test_renders_response(self, clinical_user_client):
@@ -107,7 +112,7 @@ def test_renders_response(self, clinical_user_client, history_item):
107112
)
108113
assert response.status_code == 200
109114

110-
def test_valid_post_redirects_to_appointment(
115+
def test_valid_post_redirects_to_record_medical_information(
111116
self, clinical_user_client, appointment, history_item
112117
):
113118
response = clinical_user_client.http.post(
@@ -136,3 +141,18 @@ def test_valid_post_redirects_to_appointment(
136141
)
137142
],
138143
)
144+
145+
def test_the_other_procedure_is_deleted(self, clinical_user_client, history_item):
146+
assert OtherProcedureHistoryItem.objects.filter(pk=history_item.pk).exists()
147+
148+
clinical_user_client.http.post(
149+
reverse(
150+
"mammograms:delete_other_procedure_history_item",
151+
kwargs={
152+
"pk": history_item.appointment.pk,
153+
"history_item_pk": history_item.pk,
154+
},
155+
)
156+
)
157+
158+
assert not OtherProcedureHistoryItem.objects.filter(pk=history_item.pk).exists()

manage_breast_screening/mammograms/urls.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,9 @@
201201
other_procedure_history_view.ChangeOtherProcedureHistoryView.as_view(),
202202
name="change_other_procedure_history_item",
203203
),
204+
path(
205+
"<uuid:pk>/record-medical-information/other-procedure-history/<uuid:history_item_pk>/delete",
206+
other_procedure_history_view.DeleteOtherProcedureHistoryView.as_view(),
207+
name="delete_other_procedure_history_item",
208+
),
204209
]

manage_breast_screening/mammograms/views/other_procedure_history_view.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.urls import reverse
77
from django.views.generic import FormView
88

9+
from manage_breast_screening.core.views.generic import DeleteWithAuditView
910
from manage_breast_screening.participants.models.other_procedure_history_item import (
1011
OtherProcedureHistoryItem,
1112
)
@@ -133,7 +134,39 @@ def get_context_data(self, **kwargs):
133134
{
134135
"heading": "Edit details of other procedure",
135136
"page_title": "Details of the other procedure",
137+
"delete_link": {
138+
"text": "Delete this item",
139+
"class": "nhsuk-link app-link--warning",
140+
"href": reverse(
141+
"mammograms:delete_other_procedure_history_item",
142+
kwargs={
143+
"pk": self.kwargs["pk"],
144+
"history_item_pk": self.kwargs["history_item_pk"],
145+
},
146+
),
147+
},
136148
},
137149
)
138150

139151
return context
152+
153+
154+
class DeleteOtherProcedureHistoryView(DeleteWithAuditView):
155+
def get_thing_name(self, object):
156+
return "item"
157+
158+
def get_success_message_content(self, object):
159+
return "Deleted other procedure"
160+
161+
def get_object(self):
162+
provider = self.request.user.current_provider
163+
appointment = provider.appointments.get(pk=self.kwargs["pk"])
164+
return appointment.other_procedure_history_items.get(
165+
pk=self.kwargs["history_item_pk"]
166+
)
167+
168+
def get_success_url(self) -> str:
169+
return reverse(
170+
"mammograms:record_medical_information",
171+
kwargs={"pk": self.kwargs["pk"]},
172+
)

manage_breast_screening/tests/system/clinical/test_other_procedure_history.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def test_adding_and_changing_other_procedure(self):
3737
self.and_the_other_procedure_is_updated()
3838
self.and_the_message_says_other_procedure_updated()
3939

40+
self.when_i_click_change()
41+
self.and_i_click_delete_this_item()
42+
self.and_i_click_delete_item()
43+
self.then_i_am_back_on_the_medical_information_page()
44+
self.and_the_history_item_is_gone()
45+
4046
def test_accessibility(self):
4147
self.given_i_am_logged_in_as_a_clinical_user()
4248
self.and_there_is_an_appointment()
@@ -103,6 +109,7 @@ def and_the_other_procedure_is_listed(self):
103109
has=self.page.get_by_text("Other procedure history", exact=True),
104110
)
105111
row = self.page.locator(".nhsuk-summary-list__row").filter(has=key)
112+
expect(row).to_contain_text("Procedure details")
106113
expect(row).to_contain_text("Breast reduction")
107114
expect(row).to_contain_text("Reason for breast reduction surgery")
108115
expect(row).to_contain_text("2000")
@@ -133,6 +140,7 @@ def and_the_other_procedure_is_updated(self):
133140
has=self.page.get_by_text("Other procedure history", exact=True),
134141
)
135142
row = self.page.locator(".nhsuk-summary-list__row").filter(has=key)
143+
expect(row).to_contain_text("Procedure details")
136144
expect(row).to_contain_text("Nipple correction")
137145
expect(row).to_contain_text("Reason for nipple correction surgery")
138146
expect(row).to_contain_text("2000")
@@ -143,3 +151,19 @@ def and_the_message_says_other_procedure_updated(self):
143151

144152
expect(alert).to_contain_text("Success")
145153
expect(alert).to_contain_text("Details of other procedure updated")
154+
155+
def and_i_click_delete_this_item(self):
156+
self.page.get_by_text("Delete this item").click()
157+
158+
def and_i_click_delete_item(self):
159+
self.page.get_by_text("Delete item").click()
160+
161+
def and_the_history_item_is_gone(self):
162+
key = self.page.locator(
163+
".nhsuk-summary-list__key",
164+
has=self.page.get_by_text("Other procedure history", exact=True),
165+
)
166+
row = self.page.locator(".nhsuk-summary-list__row").filter(has=key)
167+
expect(row).not_to_contain_text("Procedure details")
168+
expect(row.get_by_text("Change")).not_to_be_attached()
169+
expect(row.get_by_text("Add other procedure history")).to_be_attached()

0 commit comments

Comments
 (0)