Skip to content

Commit 07ce75e

Browse files
authored
Merge pull request #814 from NHSDigital/DTOSS-11583-mammograms
Show reported mammograms card on record medical information page
2 parents 37a7cb1 + 6760f60 commit 07ce75e

File tree

7 files changed

+134
-71
lines changed

7 files changed

+134
-71
lines changed

manage_breast_screening/mammograms/jinja2/mammograms/record_medical_information.jinja

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,34 @@
33
{% from "nhsuk/components/card/macro.jinja" import card %}
44
{% from "nhsuk/components/inset-text/macro.jinja" import insetText %}
55
{% from "nhsuk/components/summary-list/macro.jinja" import summaryList %}
6+
{% from "components/participant-details/summary_list_rows.jinja" import last_mammogram_html %}
67

78
{% block step_content %}
89

10+
{% call card({"heading": "Mammogram history"}) %}
11+
<p>The last confirmed mammogram and any added manually since then</p>
12+
13+
{{ summaryList({
14+
"rows": [
15+
{
16+
"key": {
17+
"text": "Last known mammograms"
18+
},
19+
"value": {
20+
"html": last_mammogram_html(presented_mammograms)
21+
}
22+
},
23+
]
24+
}) }}
25+
26+
{{ button({
27+
"text": presenter.add_mammogram_button.text,
28+
"href": presenter.add_mammogram_button.href,
29+
"classes": "nhsuk-button--secondary nhsuk-button--small"
30+
}) }}
31+
32+
{% endcall %}
33+
934
{% call card({
1035
"heading": "Symptoms",
1136
}) %}

manage_breast_screening/mammograms/presenters/medical_information_presenter.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from urllib.parse import quote
2+
13
from django.urls import reverse
24

35
from manage_breast_screening.mammograms.presenters.benign_lump_history_item_presenter import (
@@ -225,6 +227,25 @@ def add_other_procedure_history_button(self):
225227
"text": "Other procedures",
226228
}
227229

230+
@property
231+
def medical_information_url(self):
232+
return reverse(
233+
"mammograms:record_medical_information", kwargs={"pk": self.appointment.pk}
234+
)
235+
236+
@property
237+
def add_mammogram_button(self):
238+
url = (
239+
reverse(
240+
"participants:add_previous_mammogram",
241+
kwargs={"pk": self.appointment.participant.pk},
242+
)
243+
+ "?return_url="
244+
+ quote(self.medical_information_url)
245+
)
246+
247+
return {"href": url, "text": "Add another mammogram"}
248+
228249
def _present_items(self, items, presenter_class):
229250
items = list(items)
230251
if len(items) == 1:

manage_breast_screening/mammograms/tests/presenters/test_medical_information_presenter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,14 @@ def test_single_other_procedure_history_item_has_no_counter(self):
261261
]
262262

263263
assert counters == [None]
264+
265+
def test_add_mammogram_button(self):
266+
appointment = AppointmentFactory()
267+
268+
assert MedicalInformationPresenter(appointment).add_mammogram_button == {
269+
"href": (
270+
f"/participants/{appointment.participant.pk}/previous-mammograms/add"
271+
+ f"?return_url=/mammograms/{appointment.pk}/record-medical-information/"
272+
),
273+
"text": "Add another mammogram",
274+
}

manage_breast_screening/mammograms/views/appointment_views.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from manage_breast_screening.participants.models import (
1616
Appointment,
1717
AppointmentNote,
18-
Participant,
1918
ParticipantReportedMammogram,
2019
)
2120
from manage_breast_screening.participants.presenters import ParticipantPresenter
@@ -229,21 +228,25 @@ class RecordMedicalInformation(InProgressAppointmentMixin, FormView):
229228

230229
def get_context_data(self, **kwargs):
231230
context = super().get_context_data(**kwargs)
232-
pk = self.kwargs["pk"]
233-
provider = self.request.user.current_provider
234-
try:
235-
participant = provider.participants.get(
236-
screeningepisode__appointment__pk=pk,
237-
)
238-
except Participant.DoesNotExist:
239-
raise Http404("Participant not found")
231+
participant = self.participant
232+
last_known_mammograms = ParticipantReportedMammogram.objects.filter(
233+
participant_id=participant.pk
234+
).order_by("-created_at")
235+
236+
presented_mammograms = LastKnownMammogramPresenter(
237+
last_known_mammograms,
238+
participant_pk=participant.pk,
239+
current_url=self.request.path,
240+
)
241+
240242
context.update(
241243
{
242244
"heading": "Record medical information",
243245
"page_title": "Record medical information",
244246
"participant": participant,
245247
"caption": participant.full_name,
246248
"presenter": MedicalInformationPresenter(self.appointment),
249+
"presented_mammograms": presented_mammograms,
247250
}
248251
)
249252

manage_breast_screening/participants/jinja2/components/participant-details/participant_details.jinja

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
1+
{% from "summary-list/macro.jinja" import summaryList %}
2+
{% from "components/participant-details/summary_list_rows.jinja" import date_of_birth_and_age_html, ethnicity_html, last_mammogram_html %}
3+
14
{% macro participant_details(presented_participant, presented_mammograms, return_url=none, full_details=true, screening_protocol=none) %}
25
{% if return_url is none %}
36
{{ raise('return_url is required') }}
47
{% endif %}
58

6-
{% from "summary-list/macro.jinja" import summaryList %}
7-
8-
{% set dob %}
9-
{{ presented_participant.date_of_birth }}<br>
10-
<span class="nhsuk-hint">({{ presented_participant.age }})</span>
11-
{% endset %}
12-
13-
{% set ethnic_background = presented_participant.ethnic_background %}
14-
{% set ethnic_background_category = presented_participant.ethnic_category %}
159
{% set ethnicity_details_url = presented_participant.ethnicity_url(return_url) %}
16-
{% set ethnicity_details_link %}
17-
<a href="{{ ethnicity_details_url }}" class="nhsuk-link">Enter ethnicity details</a>
18-
{% endset %}
19-
{% set ethnicity_html %}
20-
{% if ethnic_background == "Prefer not to say" %}
21-
{{ ethnic_background }}
22-
{% elif ethnic_background %}
23-
{{ ethnic_background_category }} ({{ ethnic_background }})
24-
{% else %}
25-
{{ ethnicity_details_link | safe }}
26-
{% endif %}
27-
{% endset %}
28-
2910
{% set ethnicity_change_link = {
3011
"items": [
3112
{
@@ -34,42 +15,7 @@
3415
"visuallyHiddenText": "ethnicity"
3516
}
3617
]
37-
} if ethnic_background else undefined %}
38-
39-
{% set address_html %}
40-
{% if presented_participant.address %}
41-
{% for line in presented_participant.address.lines %}
42-
{{ line }}<br>
43-
{% endfor %}
44-
{{ address.postcode }}
45-
{% endif %}
46-
{% endset %}
47-
{% set address_html = address_html | trim | default("Not provided") %}
48-
49-
{% set mammograms_by_date_added = presented_mammograms.last_known_mammograms %}
50-
{% set last_mammogram_html %}
51-
<div data-testid="mammograms">
52-
{% if mammograms_by_date_added %}
53-
{% for mammogram in mammograms_by_date_added %}
54-
<p>
55-
<span class="nhsuk-u-font-weight-bold">Added {{ mammogram.date_added }}</span>
56-
<br>{% if mammogram.date.is_exact %}{{ mammogram.date.absolute }} <span class="nhsuk-u-secondary-text-color">({{ mammogram.date.relative }})</span>{% else %}{{ mammogram.date.value }}{% endif %}
57-
<br>{{ mammogram.location }}
58-
59-
{% if mammogram.different_name %}
60-
<br>Previous name: {{ mammogram.different_name }}
61-
{% endif %}
62-
63-
{% if mammogram.additional_information %}
64-
<br>Additional information: {{ mammogram.additional_information | nl2br }}
65-
{% endif %}
66-
</p>
67-
{% endfor %}
68-
{% else %}
69-
{{ "Not known" | as_hint }}
70-
{% endif %}
71-
</div>
72-
{% endset %}
18+
} if presented_participant.ethnic_background else undefined %}
7319

7420
{{ summaryList({
7521
"rows": [
@@ -102,15 +48,15 @@
10248
"text": "Date of birth"
10349
},
10450
"value": {
105-
"html": dob
51+
"html": date_of_birth_and_age_html(presented_participant)
10652
}
10753
},
10854
{
10955
"key": {
11056
"text": "Ethnicity"
11157
},
11258
"value": {
113-
"html": ethnicity_html | safe
59+
"html": ethnicity_html(presented_participant) | safe
11460
},
11561
"actions": ethnicity_change_link
11662
},
@@ -119,7 +65,7 @@
11965
"text": "Last known mammograms"
12066
},
12167
"value": {
122-
"html": last_mammogram_html
68+
"html": last_mammogram_html(presented_mammograms)
12369
},
12470
"actions": {
12571
"items": [

manage_breast_screening/participants/jinja2/components/participant-details/summary_list_rows.jinja

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
{% if presented_participant.address.postcode %}
77
<br>{{ presented_participant.address.postcode }}
88
{% endif %}
9-
{% endif %}
9+
{% else -%}
10+
Not provided
11+
{%- endif %}
1012
{% endmacro %}
1113

1214
{% macro date_of_birth_and_age_html(presented_participant) %}
@@ -30,3 +32,28 @@
3032
{{ ethnicity_details_link | safe }}
3133
{% endif %}
3234
{% endmacro %}
35+
36+
{% macro last_mammogram_html(presented_mammograms) %}
37+
{% set mammograms_by_date_added = presented_mammograms.last_known_mammograms %}
38+
<div data-testid="mammograms">
39+
{% if mammograms_by_date_added %}
40+
{% for mammogram in mammograms_by_date_added %}
41+
<p>
42+
<span class="nhsuk-u-font-weight-bold">Added {{ mammogram.date_added }}</span>
43+
<br>{% if mammogram.date.is_exact %}{{ mammogram.date.absolute }} <span class="nhsuk-u-secondary-text-color">({{ mammogram.date.relative }})</span>{% else %}{{ mammogram.date.value }}{% endif %}
44+
<br>{{ mammogram.location }}
45+
46+
{% if mammogram.different_name %}
47+
<br>Previous name: {{ mammogram.different_name }}
48+
{% endif %}
49+
50+
{% if mammogram.additional_information %}
51+
<br>Additional information: {{ mammogram.additional_information | nl2br }}
52+
{% endif %}
53+
</p>
54+
{% endfor %}
55+
{% else %}
56+
{{ "Not known" | as_hint }}
57+
{% endif %}
58+
</div>
59+
{% endmacro %}

manage_breast_screening/tests/system/clinical/test_adding_previous_mammograms.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ def test_accessibility(self):
6060
self.and_i_am_on_the_add_previous_mammograms_page()
6161
self.then_the_accessibility_baseline_is_met()
6262

63+
def test_adding_a_mammogram_during_an_appointment(self):
64+
self.given_i_am_logged_in_as_a_clinical_user()
65+
self.and_there_is_an_appointment()
66+
self.and_i_am_on_the_record_medical_information_page()
67+
self.when_i_click_on_add_another_mammogram()
68+
self.then_i_should_be_on_the_add_previous_mammogram_form()
69+
70+
self.when_i_select_the_same_provider()
71+
self.and_i_enter_an_exact_date()
72+
self.and_i_select_yes_same_name()
73+
self.and_i_enter_additional_information()
74+
self.and_i_click_continue()
75+
self.then_i_should_be_back_on_the_medical_information_page()
76+
self.and_i_should_see_the_mammogram_with_the_same_provider()
77+
6378
def and_there_is_an_appointment(self):
6479
self.participant = ParticipantFactory(first_name="Janet", last_name="Williams")
6580
self.screening_episode = ScreeningEpisodeFactory(participant=self.participant)
@@ -159,3 +174,18 @@ def and_i_should_see_the_mammogram_with_the_other_provider_and_name(self):
159174
expected_inner_text,
160175
use_inner_text=True,
161176
)
177+
178+
def and_i_am_on_the_record_medical_information_page(self):
179+
self.page.goto(
180+
self.live_server_url
181+
+ reverse(
182+
"mammograms:record_medical_information",
183+
kwargs={"pk": self.appointment.pk},
184+
)
185+
)
186+
187+
def when_i_click_on_add_another_mammogram(self):
188+
self.page.get_by_text("Add another mammogram").click()
189+
190+
def then_i_should_be_back_on_the_medical_information_page(self):
191+
self.expect_url("mammograms:record_medical_information", pk=self.appointment.pk)

0 commit comments

Comments
 (0)