diff --git a/manage_breast_screening/mammograms/jinja2/mammograms/record_medical_information.jinja b/manage_breast_screening/mammograms/jinja2/mammograms/record_medical_information.jinja index 55b192a5c..abaa7cca3 100644 --- a/manage_breast_screening/mammograms/jinja2/mammograms/record_medical_information.jinja +++ b/manage_breast_screening/mammograms/jinja2/mammograms/record_medical_information.jinja @@ -3,9 +3,34 @@ {% from "nhsuk/components/card/macro.jinja" import card %} {% from "nhsuk/components/inset-text/macro.jinja" import insetText %} {% from "nhsuk/components/summary-list/macro.jinja" import summaryList %} +{% from "components/participant-details/summary_list_rows.jinja" import last_mammogram_html %} {% block step_content %} +{% call card({"heading": "Mammogram history"}) %} +
The last confirmed mammogram and any added manually since then
+ + {{ summaryList({ + "rows": [ + { + "key": { + "text": "Last known mammograms" + }, + "value": { + "html": last_mammogram_html(presented_mammograms) + } + }, + ] + }) }} + + {{ button({ + "text": presenter.add_mammogram_button.text, + "href": presenter.add_mammogram_button.href, + "classes": "nhsuk-button--secondary nhsuk-button--small" + }) }} + +{% endcall %} + {% call card({ "heading": "Symptoms", }) %} diff --git a/manage_breast_screening/mammograms/presenters/medical_information_presenter.py b/manage_breast_screening/mammograms/presenters/medical_information_presenter.py index 8ecf0d63f..672c801d9 100644 --- a/manage_breast_screening/mammograms/presenters/medical_information_presenter.py +++ b/manage_breast_screening/mammograms/presenters/medical_information_presenter.py @@ -1,3 +1,5 @@ +from urllib.parse import quote + from django.urls import reverse from manage_breast_screening.mammograms.presenters.benign_lump_history_item_presenter import ( @@ -225,6 +227,25 @@ def add_other_procedure_history_button(self): "text": "Other procedures", } + @property + def medical_information_url(self): + return reverse( + "mammograms:record_medical_information", kwargs={"pk": self.appointment.pk} + ) + + @property + def add_mammogram_button(self): + url = ( + reverse( + "participants:add_previous_mammogram", + kwargs={"pk": self.appointment.participant.pk}, + ) + + "?return_url=" + + quote(self.medical_information_url) + ) + + return {"href": url, "text": "Add another mammogram"} + def _present_items(self, items, presenter_class): items = list(items) if len(items) == 1: diff --git a/manage_breast_screening/mammograms/tests/presenters/test_medical_information_presenter.py b/manage_breast_screening/mammograms/tests/presenters/test_medical_information_presenter.py index 12f0729a7..52c2e04e4 100644 --- a/manage_breast_screening/mammograms/tests/presenters/test_medical_information_presenter.py +++ b/manage_breast_screening/mammograms/tests/presenters/test_medical_information_presenter.py @@ -261,3 +261,14 @@ def test_single_other_procedure_history_item_has_no_counter(self): ] assert counters == [None] + + def test_add_mammogram_button(self): + appointment = AppointmentFactory() + + assert MedicalInformationPresenter(appointment).add_mammogram_button == { + "href": ( + f"/participants/{appointment.participant.pk}/previous-mammograms/add" + + f"?return_url=/mammograms/{appointment.pk}/record-medical-information/" + ), + "text": "Add another mammogram", + } diff --git a/manage_breast_screening/mammograms/views/appointment_views.py b/manage_breast_screening/mammograms/views/appointment_views.py index 60a790240..0a638a3bb 100644 --- a/manage_breast_screening/mammograms/views/appointment_views.py +++ b/manage_breast_screening/mammograms/views/appointment_views.py @@ -14,7 +14,6 @@ from manage_breast_screening.participants.models import ( Appointment, AppointmentNote, - Participant, ParticipantReportedMammogram, ) from manage_breast_screening.participants.presenters import ParticipantPresenter @@ -222,14 +221,17 @@ class RecordMedicalInformation(InProgressAppointmentMixin, FormView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - pk = self.kwargs["pk"] - provider = self.request.user.current_provider - try: - participant = provider.participants.get( - screeningepisode__appointment__pk=pk, - ) - except Participant.DoesNotExist: - raise Http404("Participant not found") + participant = self.participant + last_known_mammograms = ParticipantReportedMammogram.objects.filter( + participant_id=participant.pk + ).order_by("-created_at") + + presented_mammograms = LastKnownMammogramPresenter( + last_known_mammograms, + participant_pk=participant.pk, + current_url=self.request.path, + ) + context.update( { "heading": "Record medical information", @@ -237,6 +239,7 @@ def get_context_data(self, **kwargs): "participant": participant, "caption": participant.full_name, "presenter": MedicalInformationPresenter(self.appointment), + "presented_mammograms": presented_mammograms, } ) diff --git a/manage_breast_screening/participants/jinja2/components/participant-details/participant_details.jinja b/manage_breast_screening/participants/jinja2/components/participant-details/participant_details.jinja index 54263e941..9e2b2dfc4 100644 --- a/manage_breast_screening/participants/jinja2/components/participant-details/participant_details.jinja +++ b/manage_breast_screening/participants/jinja2/components/participant-details/participant_details.jinja @@ -1,31 +1,12 @@ +{% from "summary-list/macro.jinja" import summaryList %} +{% from "components/participant-details/summary_list_rows.jinja" import date_of_birth_and_age_html, ethnicity_html, last_mammogram_html %} + {% macro participant_details(presented_participant, presented_mammograms, return_url=none, full_details=true, screening_protocol=none) %} {% if return_url is none %} {{ raise('return_url is required') }} {% endif %} - {% from "summary-list/macro.jinja" import summaryList %} - - {% set dob %} - {{ presented_participant.date_of_birth }}
- Added {{ mammogram.date_added }}
-
{% if mammogram.date.is_exact %}{{ mammogram.date.absolute }} ({{ mammogram.date.relative }}){% else %}{{ mammogram.date.value }}{% endif %}
-
{{ mammogram.location }}
-
- {% if mammogram.different_name %}
-
Previous name: {{ mammogram.different_name }}
- {% endif %}
-
- {% if mammogram.additional_information %}
-
Additional information: {{ mammogram.additional_information | nl2br }}
- {% endif %}
-
+ Added {{ mammogram.date_added }}
+
{% if mammogram.date.is_exact %}{{ mammogram.date.absolute }} ({{ mammogram.date.relative }}){% else %}{{ mammogram.date.value }}{% endif %}
+
{{ mammogram.location }}
+
+ {% if mammogram.different_name %}
+
Previous name: {{ mammogram.different_name }}
+ {% endif %}
+
+ {% if mammogram.additional_information %}
+
Additional information: {{ mammogram.additional_information | nl2br }}
+ {% endif %}
+