diff --git a/manage_breast_screening/mammograms/jinja2/mammograms/appointment_notes/appointment_note_banner.jinja b/manage_breast_screening/mammograms/jinja2/mammograms/appointment_notes/appointment_note_banner.jinja new file mode 100644 index 000000000..0d35a596a --- /dev/null +++ b/manage_breast_screening/mammograms/jinja2/mammograms/appointment_notes/appointment_note_banner.jinja @@ -0,0 +1,21 @@ +{% from 'nhsuk/components/warning-callout/macro.jinja' import warningCallout %} +{% macro appointment_note_banner(appointment_note, change_url=None, show_change_link=True) %} + {% if appointment_note %} + {% set appointment_note_html %} +
+ {{ appointment_note.content | nl2br }} +
+ {% if show_change_link and change_url %} +

+ + Change appointment note + +

+ {% endif %} + {% endset %} + {{ warningCallout({ + "heading": "Appointment note", + "html": appointment_note_html + }) }} + {% endif %} +{% endmacro %} diff --git a/manage_breast_screening/mammograms/jinja2/mammograms/show/appointment_details.jinja b/manage_breast_screening/mammograms/jinja2/mammograms/show/appointment_details.jinja index 3a87b89cd..2e9cc4d7e 100644 --- a/manage_breast_screening/mammograms/jinja2/mammograms/show/appointment_details.jinja +++ b/manage_breast_screening/mammograms/jinja2/mammograms/show/appointment_details.jinja @@ -1,6 +1,5 @@ {% extends 'layout-app.jinja' %} {% from 'nhsuk/components/card/macro.jinja' import card %} -{% from 'nhsuk/components/warning-callout/macro.jinja' import warningCallout %} {% from 'nhsuk/components/back-link/macro.jinja' import backLink %} {% from 'nhsuk/components/summary-list/macro.jinja' import summaryList %} {% from 'components/appointment-status/macro.jinja' import appointment_status %} @@ -8,6 +7,7 @@ {% from 'components/check-in/macro.jinja' import check_in %} {% from 'components/secondary-navigation/macro.jinja' import app_secondary_navigation %} {% from 'mammograms/special_appointments/special_appointment_banner.jinja' import special_appointment_banner %} +{% from 'mammograms/appointment_notes/appointment_note_banner.jinja' import appointment_note_banner %} {% block beforeContent %} {{ backLink({ @@ -55,6 +55,11 @@ "items": secondary_nav_items }) }} + {{ appointment_note_banner( + appointment_note, + change_url=url('mammograms:appointment_note', kwargs={'pk': presented_appointment.pk}) + ) }} + {% set appointment_details_html %} {{ summaryList({ "rows": [ diff --git a/manage_breast_screening/mammograms/presenters/appointment_presenters.py b/manage_breast_screening/mammograms/presenters/appointment_presenters.py index ca12a985b..d8e857768 100644 --- a/manage_breast_screening/mammograms/presenters/appointment_presenters.py +++ b/manage_breast_screening/mammograms/presenters/appointment_presenters.py @@ -8,7 +8,7 @@ ) from ...core.utils.date_formatting import format_date, format_relative_date, format_time -from ...participants.models import AppointmentStatus, SupportReasons +from ...participants.models import AppointmentNote, AppointmentStatus, SupportReasons from ...participants.presenters import ParticipantPresenter, status_colour @@ -113,6 +113,13 @@ def status_attribution(self): else: return None + @cached_property + def note(self): + try: + return self._appointment.note + except AppointmentNote.DoesNotExist: + return None + class ClinicSlotPresenter: def __init__(self, clinic_slot): diff --git a/manage_breast_screening/mammograms/views/appointment_views.py b/manage_breast_screening/mammograms/views/appointment_views.py index 60a790240..d5dd79617 100644 --- a/manage_breast_screening/mammograms/views/appointment_views.py +++ b/manage_breast_screening/mammograms/views/appointment_views.py @@ -1,5 +1,6 @@ import logging +from django.contrib import messages from django.http import Http404 from django.shortcuts import redirect, render from django.urls import reverse, reverse_lazy @@ -68,6 +69,7 @@ def get(self, request, *args, **kwargs): "presented_appointment": appointment_presenter, "presented_participant": appointment_presenter.participant, "presented_mammograms": last_known_mammogram_presenter, + "appointment_note": appointment_presenter.note, "secondary_nav_items": present_secondary_nav( appointment.pk, current_tab="appointment" ), @@ -155,6 +157,11 @@ def form_valid(self, form): auditor.audit_create(note) else: auditor.audit_update(note) + messages.add_message( + self.request, + messages.SUCCESS, + "Appointment note saved", + ) return redirect("mammograms:appointment_note", pk=self.appointment.pk) diff --git a/manage_breast_screening/tests/system/clinical/test_appointment_note.py b/manage_breast_screening/tests/system/clinical/test_appointment_note.py index feb3d3314..11f8e8a22 100644 --- a/manage_breast_screening/tests/system/clinical/test_appointment_note.py +++ b/manage_breast_screening/tests/system/clinical/test_appointment_note.py @@ -20,11 +20,15 @@ def test_clinical_user_adds_and_updates_an_appointment_note(self): self.when_i_enter_a_note() self.and_i_save_the_note() + self.then_i_see_a_message_confirming_the_save() self.then_the_note_field_contains(self.initial_note_text) + self.and_the_appointment_details_tab_shows_the_note(self.initial_note_text) self.when_i_update_the_note() self.and_i_save_the_note() + self.then_i_see_a_message_confirming_the_save() self.then_the_note_field_contains(self.updated_note_text) + self.and_the_appointment_details_tab_shows_the_note(self.updated_note_text) def and_there_is_an_appointment_for_my_provider(self): self.appointment = AppointmentFactory( @@ -48,6 +52,10 @@ def when_i_enter_a_note(self): self.page.get_by_label("Note").fill(self.initial_note_text) def when_i_update_the_note(self): + secondary_nav = self.page.locator(".app-secondary-navigation") + expect(secondary_nav).to_be_visible() + note_tab = secondary_nav.get_by_text("Note") + note_tab.click() field = self.page.get_by_label("Note") expect(field).to_have_value(self.initial_note_text) field.fill(self.updated_note_text) @@ -61,3 +69,20 @@ def when_i_save_the_note(self): def then_the_note_field_contains(self, text): expect(self.page.get_by_label("Note")).to_have_value(text) + + def then_i_see_a_message_confirming_the_save(self): + banner = self.page.locator(".nhsuk-notification-banner--success") + expect(banner).to_be_visible() + expect(banner).to_contain_text("Appointment note saved") + + def and_the_appointment_details_tab_shows_the_note(self, text): + secondary_nav = self.page.locator(".app-secondary-navigation") + expect(secondary_nav).to_be_visible() + appointment_details_tab = secondary_nav.get_by_text("Appointment details") + appointment_details_tab.click() + + note_container = self.page.locator( + ".nhsuk-warning-callout", has_text="Appointment note" + ) + expect(note_container).to_be_visible() + expect(note_container).to_contain_text(text)