Skip to content

Commit 20b68f7

Browse files
authored
Merge pull request #780 from NHSDigital/DTOSS-11531-update-mastectomy-and-lumpectomy
Add update form for mastectomy or lumpectomy history
2 parents b9dea7e + 6030339 commit 20b68f7

12 files changed

+436
-86
lines changed

manage_breast_screening/mammograms/forms/mastectomy_or_lumpectomy_history_form.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,21 @@ class MastectomyOrLumpectomyHistoryForm(FormWithConditionalFields):
9090
error_messages={"max_words": "Additional details must be 500 words or less"},
9191
)
9292

93-
def __init__(self, *args, participant, **kwargs):
93+
def __init__(self, *args, **kwargs):
94+
self.instance = kwargs.pop("instance", None)
95+
96+
if self.instance:
97+
kwargs["initial"] = {
98+
"left_breast_procedure": self.instance.left_breast_procedure,
99+
"right_breast_procedure": self.instance.right_breast_procedure,
100+
"left_breast_other_surgery": self.instance.left_breast_other_surgery,
101+
"right_breast_other_surgery": self.instance.right_breast_other_surgery,
102+
"year_of_surgery": self.instance.year_of_surgery,
103+
"surgery_reason": self.instance.surgery_reason,
104+
"surgery_other_reason_details": self.instance.surgery_other_reason_details,
105+
"additional_details": self.instance.additional_details,
106+
}
107+
94108
super().__init__(*args, **kwargs)
95109

96110
self.given_field_value(
@@ -132,3 +146,26 @@ def create(self, appointment, request):
132146
auditor.audit_create(mastectomy_or_lumpectomy_history)
133147

134148
return mastectomy_or_lumpectomy_history
149+
150+
def update(self, request):
151+
self.instance.left_breast_procedure = self.cleaned_data["left_breast_procedure"]
152+
self.instance.right_breast_procedure = self.cleaned_data[
153+
"right_breast_procedure"
154+
]
155+
self.instance.left_breast_other_surgery = self.cleaned_data[
156+
"left_breast_other_surgery"
157+
]
158+
self.instance.right_breast_other_surgery = self.cleaned_data[
159+
"right_breast_other_surgery"
160+
]
161+
self.instance.year_of_surgery = self.cleaned_data["year_of_surgery"]
162+
self.instance.surgery_reason = self.cleaned_data["surgery_reason"]
163+
self.instance.surgery_other_reason_details = self.cleaned_data[
164+
"surgery_other_reason_details"
165+
]
166+
self.instance.additional_details = self.cleaned_data["additional_details"]
167+
self.instance.save()
168+
169+
Auditor.from_request(request).audit_update(self.instance)
170+
171+
return self.instance

manage_breast_screening/mammograms/jinja2/mammograms/record_medical_information.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545

4646
{% set mastectomy_or_lumpectomy_history_html %}
4747
{% for presented_item in presenter.mastectomy_or_lumpectomy_history %}
48+
<a style="float: right" class="nhsuk-link nhsuk-link--no-visited-state" href="{{ presented_item.change_link.href}}">
49+
{{ presented_item.change_link.text }}<span class="nhsuk-u-visually-hidden">{{ presented_item.change_link.visually_hidden_text }}</span>
50+
</a><br>
4851
{{ summaryList(presented_item.summary_list_params) }}
4952
{% endfor %}
5053
<a href="{{ presenter.add_mastectomy_or_lumpectomy_history_link.href }}" class="nhsuk-link nhsuk-link--no-visited-state">{{ presenter.add_mastectomy_or_lumpectomy_history_link.text }}</a><br>

manage_breast_screening/mammograms/presenters/mastectomy_or_lumpectomy_history_item_presenter.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
from django.urls import reverse
2+
13
from manage_breast_screening.core.template_helpers import multiline_content, nl2br
24
from manage_breast_screening.participants.models.mastectomy_or_lumpectomy_history_item import (
35
MastectomyOrLumpectomyHistoryItem,
46
)
57

68

79
class MastectomyOrLumpectomyHistoryItemPresenter:
8-
def __init__(self, mastectomy_or_lumpectomy_history_item):
10+
def __init__(self, mastectomy_or_lumpectomy_history_item, counter=None):
911
self._item = mastectomy_or_lumpectomy_history_item
1012

13+
# If there are more than one of these items, we add a counter to the
14+
# visually hidden text
15+
self.counter = counter
16+
1117
self.right_breast_procedure = self._item.get_right_breast_procedure_display()
1218
self.left_breast_procedure = self._item.get_left_breast_procedure_display()
1319

@@ -75,3 +81,21 @@ def summary_list_params(self):
7581

7682
def _format_multiple_choices(self, choices, ChoiceClass):
7783
return ", ".join(ChoiceClass(choice).label for choice in choices)
84+
85+
@property
86+
def change_link(self):
87+
return {
88+
"href": reverse(
89+
"mammograms:change_mastectomy_or_lumpectomy_history_item",
90+
kwargs={
91+
"pk": self._item.appointment_id,
92+
"history_item_pk": self._item.pk,
93+
},
94+
),
95+
"text": "Change",
96+
"visually_hidden_text": (
97+
f" mastectomy or lumpectomy item {self.counter}"
98+
if self.counter
99+
else " mastectomy or lumpectomy item"
100+
),
101+
}

manage_breast_screening/mammograms/presenters/medical_information_presenter.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,15 @@ def __init__(self, appointment):
4141
BreastCancerHistoryItemPresenter,
4242
)
4343

44-
self.mastectomy_or_lumpectomy_history = [
45-
MastectomyOrLumpectomyHistoryItemPresenter(item)
46-
for item in appointment.mastectomy_or_lumpectomy_history_items.all()
47-
]
44+
self.mastectomy_or_lumpectomy_history = self._present_items(
45+
appointment.mastectomy_or_lumpectomy_history_items.all(),
46+
MastectomyOrLumpectomyHistoryItemPresenter,
47+
)
4848

49-
implanted_medical_device_history = list(
50-
appointment.implanted_medical_device_history_items.all()
49+
self.implanted_medical_device_history = self._present_items(
50+
appointment.implanted_medical_device_history_items.all(),
51+
ImplantedMedicalDeviceHistoryItemPresenter,
5152
)
52-
if len(implanted_medical_device_history) == 1:
53-
self.implanted_medical_device_history = [
54-
ImplantedMedicalDeviceHistoryItemPresenter(
55-
implanted_medical_device_history[0]
56-
)
57-
]
58-
else:
59-
self.implanted_medical_device_history = [
60-
ImplantedMedicalDeviceHistoryItemPresenter(item, counter=counter)
61-
for counter, item in enumerate(implanted_medical_device_history, 1)
62-
]
6353

6454
self.breast_augmentation_history = [
6555
BreastAugmentationHistoryItemPresenter(item)

0 commit comments

Comments
 (0)