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 }}
- ({{ presented_participant.age }}) - {% endset %} - - {% set ethnic_background = presented_participant.ethnic_background %} - {% set ethnic_background_category = presented_participant.ethnic_category %} {% set ethnicity_details_url = presented_participant.ethnicity_url(return_url) %} - {% set ethnicity_details_link %} - Enter ethnicity details - {% endset %} - {% set ethnicity_html %} - {% if ethnic_background == "Prefer not to say" %} - {{ ethnic_background }} - {% elif ethnic_background %} - {{ ethnic_background_category }} ({{ ethnic_background }}) - {% else %} - {{ ethnicity_details_link | safe }} - {% endif %} - {% endset %} - {% set ethnicity_change_link = { "items": [ { @@ -34,42 +15,7 @@ "visuallyHiddenText": "ethnicity" } ] - } if ethnic_background else undefined %} - - {% set address_html %} - {% if presented_participant.address %} - {% for line in presented_participant.address.lines %} - {{ line }}
- {% endfor %} - {{ address.postcode }} - {% endif %} - {% endset %} - {% set address_html = address_html | trim | default("Not provided") %} - - {% set mammograms_by_date_added = presented_mammograms.last_known_mammograms %} - {% set last_mammogram_html %} -
- {% if mammograms_by_date_added %} - {% for mammogram in mammograms_by_date_added %} -

- 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 %} -

- {% endfor %} - {% else %} - {{ "Not known" | as_hint }} - {% endif %} -
- {% endset %} + } if presented_participant.ethnic_background else undefined %} {{ summaryList({ "rows": [ @@ -102,7 +48,7 @@ "text": "Date of birth" }, "value": { - "html": dob + "html": date_of_birth_and_age_html(presented_participant) } }, { @@ -110,7 +56,7 @@ "text": "Ethnicity" }, "value": { - "html": ethnicity_html | safe + "html": ethnicity_html(presented_participant) | safe }, "actions": ethnicity_change_link }, @@ -119,7 +65,7 @@ "text": "Last known mammograms" }, "value": { - "html": last_mammogram_html + "html": last_mammogram_html(presented_mammograms) }, "actions": { "items": [ diff --git a/manage_breast_screening/participants/jinja2/components/participant-details/summary_list_rows.jinja b/manage_breast_screening/participants/jinja2/components/participant-details/summary_list_rows.jinja index 6c17ac04c..5deef592b 100644 --- a/manage_breast_screening/participants/jinja2/components/participant-details/summary_list_rows.jinja +++ b/manage_breast_screening/participants/jinja2/components/participant-details/summary_list_rows.jinja @@ -6,7 +6,9 @@ {% if presented_participant.address.postcode %}
{{ presented_participant.address.postcode }} {% endif %} - {% endif %} + {% else -%} + Not provided + {%- endif %} {% endmacro %} {% macro date_of_birth_and_age_html(presented_participant) %} @@ -30,3 +32,28 @@ {{ ethnicity_details_link | safe }} {% endif %} {% endmacro %} + +{% macro last_mammogram_html(presented_mammograms) %} + {% set mammograms_by_date_added = presented_mammograms.last_known_mammograms %} +
+ {% if mammograms_by_date_added %} + {% for mammogram in mammograms_by_date_added %} +

+ 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 %} +

+ {% endfor %} + {% else %} + {{ "Not known" | as_hint }} + {% endif %} +
+{% endmacro %} diff --git a/manage_breast_screening/tests/system/clinical/test_adding_previous_mammograms.py b/manage_breast_screening/tests/system/clinical/test_adding_previous_mammograms.py index 9b5145025..acf2b937a 100644 --- a/manage_breast_screening/tests/system/clinical/test_adding_previous_mammograms.py +++ b/manage_breast_screening/tests/system/clinical/test_adding_previous_mammograms.py @@ -60,6 +60,21 @@ def test_accessibility(self): self.and_i_am_on_the_add_previous_mammograms_page() self.then_the_accessibility_baseline_is_met() + def test_adding_a_mammogram_during_an_appointment(self): + self.given_i_am_logged_in_as_a_clinical_user() + self.and_there_is_an_appointment() + self.and_i_am_on_the_record_medical_information_page() + self.when_i_click_on_add_another_mammogram() + self.then_i_should_be_on_the_add_previous_mammogram_form() + + self.when_i_select_the_same_provider() + self.and_i_enter_an_exact_date() + self.and_i_select_yes_same_name() + self.and_i_enter_additional_information() + self.and_i_click_continue() + self.then_i_should_be_back_on_the_medical_information_page() + self.and_i_should_see_the_mammogram_with_the_same_provider() + def and_there_is_an_appointment(self): self.participant = ParticipantFactory(first_name="Janet", last_name="Williams") 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): expected_inner_text, use_inner_text=True, ) + + def and_i_am_on_the_record_medical_information_page(self): + self.page.goto( + self.live_server_url + + reverse( + "mammograms:record_medical_information", + kwargs={"pk": self.appointment.pk}, + ) + ) + + def when_i_click_on_add_another_mammogram(self): + self.page.get_by_text("Add another mammogram").click() + + def then_i_should_be_back_on_the_medical_information_page(self): + self.expect_url("mammograms:record_medical_information", pk=self.appointment.pk)