Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"}) %}
<p>The last confirmed mammogram and any added manually since then</p>

{{ 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",
}) %}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
21 changes: 12 additions & 9 deletions manage_breast_screening/mammograms/views/appointment_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from manage_breast_screening.participants.models import (
Appointment,
AppointmentNote,
Participant,
ParticipantReportedMammogram,
)
from manage_breast_screening.participants.presenters import ParticipantPresenter
Expand Down Expand Up @@ -222,21 +221,25 @@ 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",
"page_title": "Record medical information",
"participant": participant,
"caption": participant.full_name,
"presenter": MedicalInformationPresenter(self.appointment),
"presented_mammograms": presented_mammograms,
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -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 }}<br>
<span class="nhsuk-hint">({{ presented_participant.age }})</span>
{% 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 %}
<a href="{{ ethnicity_details_url }}" class="nhsuk-link">Enter ethnicity details</a>
{% 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": [
{
Expand All @@ -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 }}<br>
{% 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 %}
<div data-testid="mammograms">
{% if mammograms_by_date_added %}
{% for mammogram in mammograms_by_date_added %}
<p>
<span class="nhsuk-u-font-weight-bold">Added {{ mammogram.date_added }}</span>
<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 %}
<br>{{ mammogram.location }}

{% if mammogram.different_name %}
<br>Previous name: {{ mammogram.different_name }}
{% endif %}

{% if mammogram.additional_information %}
<br>Additional information: {{ mammogram.additional_information | nl2br }}
{% endif %}
</p>
{% endfor %}
{% else %}
{{ "Not known" | as_hint }}
{% endif %}
</div>
{% endset %}
} if presented_participant.ethnic_background else undefined %}

{{ summaryList({
"rows": [
Expand Down Expand Up @@ -102,15 +48,15 @@
"text": "Date of birth"
},
"value": {
"html": dob
"html": date_of_birth_and_age_html(presented_participant)
}
},
{
"key": {
"text": "Ethnicity"
},
"value": {
"html": ethnicity_html | safe
"html": ethnicity_html(presented_participant) | safe
},
"actions": ethnicity_change_link
},
Expand All @@ -119,7 +65,7 @@
"text": "Last known mammograms"
},
"value": {
"html": last_mammogram_html
"html": last_mammogram_html(presented_mammograms)
},
"actions": {
"items": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
{% if presented_participant.address.postcode %}
<br>{{ presented_participant.address.postcode }}
{% endif %}
{% endif %}
{% else -%}
Not provided
{%- endif %}
{% endmacro %}

{% macro date_of_birth_and_age_html(presented_participant) %}
Expand All @@ -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 %}
<div data-testid="mammograms">
{% if mammograms_by_date_added %}
{% for mammogram in mammograms_by_date_added %}
<p>
<span class="nhsuk-u-font-weight-bold">Added {{ mammogram.date_added }}</span>
<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 %}
<br>{{ mammogram.location }}

{% if mammogram.different_name %}
<br>Previous name: {{ mammogram.different_name }}
{% endif %}

{% if mammogram.additional_information %}
<br>Additional information: {{ mammogram.additional_information | nl2br }}
{% endif %}
</p>
{% endfor %}
{% else %}
{{ "Not known" | as_hint }}
{% endif %}
</div>
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)