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 @@ -4,7 +4,7 @@
{% from 'nhsuk/components/back-link/macro.jinja' import backLink %}
{% from 'components/appointment-status/macro.jinja' import appointment_status %}
{% from 'components/appointment-header/macro.jinja' import appointment_header %}
{% from 'components/participant-details/template.jinja' import participant_details %}
{% from 'components/participant-details/participant_details.jinja' import participant_details %}
{% from 'components/participant-details/contact_details.jinja' import contact_details %}
{% from 'components/secondary-navigation/macro.jinja' import app_secondary_navigation %}
{% from 'mammograms/special_appointments/special_appointment_banner.jinja' import special_appointment_banner %}
Expand Down

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions manage_breast_screening/participants/models/appointment.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def checked_in(self):
def in_progress(self):
return self.in_status(AppointmentStatus.IN_PROGRESS)

def for_participant(self, participant_id):
return self.filter(screening_episode__participant_id=participant_id)

def complete(self):
return self.in_status(
AppointmentStatus.CANCELLED,
Expand Down

This file was deleted.

15 changes: 15 additions & 0 deletions manage_breast_screening/participants/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,21 @@ def test_order_by_starts_at(self):
[late, middle, early],
)

def test_for_participant(self):
a = AppointmentFactory.create()
b = AppointmentFactory.create(
screening_episode__participant=a.screening_episode.participant
)
AppointmentFactory.create()

assertQuerySetEqual(
models.Appointment.objects.for_participant(
a.screening_episode.participant_id
),
[a, b],
ordered=False,
)

@pytest.mark.django_db
class TestEagerLoadCurrentStatus:
def test_eager_loads_most_recent_status_with_created_by(
Expand Down
26 changes: 23 additions & 3 deletions manage_breast_screening/participants/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from django.urls import reverse
from pytest_django.asserts import assertRedirects

from manage_breast_screening.participants.tests.factories import (
AppointmentFactory,
Expand All @@ -9,14 +10,33 @@

@pytest.mark.django_db
class TestShowParticipant:
def test_renders_response(self, clinical_user_client):
def test_redirects_to_appointment_participant_details(self, clinical_user_client):
# Create an appointment with the current provider so the participant is accessible
participant = ParticipantFactory.create()
AppointmentFactory.create(
appointment = AppointmentFactory.create(
screening_episode__participant=participant,
clinic_slot__clinic__setting__provider=clinical_user_client.current_provider,
)
response = clinical_user_client.http.get(
reverse("participants:show", kwargs={"pk": participant.pk}),
)
assert response.status_code == 200

assertRedirects(
response,
reverse(
"mammograms:participant_details",
kwargs={"pk": appointment.pk},
),
)

def test_redirects_to_home_if_no_appointment(self, clinical_user_client):
participant = ParticipantFactory.create()

response = clinical_user_client.http.get(
reverse("participants:show", kwargs={"pk": participant.pk}),
)

assertRedirects(
response,
reverse("clinics:index"),
)
50 changes: 13 additions & 37 deletions manage_breast_screening/participants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
from django.shortcuts import redirect, render
from django.urls import reverse

from manage_breast_screening.mammograms.presenters import LastKnownMammogramPresenter
from manage_breast_screening.participants.models.appointment import Appointment
from manage_breast_screening.participants.services import fetch_most_recent_provider

from .forms import EthnicityForm, ParticipantReportedMammogramForm
from .models import Participant, ParticipantReportedMammogram
from .presenters import ParticipantAppointmentsPresenter, ParticipantPresenter
from .models import Participant

logger = getLogger(__name__)

Expand All @@ -35,41 +34,18 @@ def parse_return_url(request, default: str) -> str:
def show(request, pk):
provider = request.user.current_provider
try:
participant = provider.participants.get(pk=pk)
except Participant.DoesNotExist:
raise Http404("Participant not found")
presented_participant = ParticipantPresenter(participant)

appointments = participant.appointments.order_by_starts_at(
desc=True
).select_related("clinic_slot__clinic__setting")

presented_appointments = ParticipantAppointmentsPresenter(
past_appointments=list(appointments.past()),
upcoming_appointments=list(appointments.upcoming()),
)

last_known_mammograms = ParticipantReportedMammogram.objects.filter(
participant_id=pk
).order_by("-created_at")

presented_mammograms = LastKnownMammogramPresenter(
last_known_mammograms,
participant_pk=pk,
current_url=request.path,
)
appointment_id = (
provider.appointments.select_related("clinic_slot")
.for_participant(pk)
.order_by_starts_at(desc=True)[0:1]
.values_list("id", flat=True)
.get()
)
except Appointment.DoesNotExist:
logger.exception(f"Appointment not found for participant {pk}")
return redirect(reverse("clinics:index"))

return render(
request,
"participants/show.jinja",
context={
"presented_participant": presented_participant,
"presented_appointments": presented_appointments,
"presented_mammograms": presented_mammograms,
"heading": participant.full_name,
"page_title": "Participant",
},
)
return redirect("mammograms:participant_details", pk=appointment_id)


def edit_ethnicity(request, pk):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_viewing_participant_record_from_an_appointment(self):
self.given_i_am_logged_in_as_an_administrative_user()
self.and_the_participant_has_an_upcoming_appointment()
self.and_i_am_viewing_the_upcoming_appointment()
self.when_i_click_on_view_participant_record()
self.when_i_click_on_participant_details()
self.then_i_should_be_on_the_participant_record_page()
self.and_i_should_see_the_participant_record()
self.when_i_click_on_the_back_link()
Expand All @@ -36,25 +36,9 @@ def test_viewing_participant_record_from_an_appointment(self):
def test_accessibility(self):
self.given_i_am_logged_in_as_an_administrative_user()
self.and_the_participant_has_an_upcoming_appointment()
self.and_i_am_on_the_participant_record_page()
self.and_i_am_on_the_participant_details_tab()
self.then_the_accessibility_baseline_is_met()

def test_viewing_upcoming_appointments(self):
self.given_i_am_logged_in_as_an_administrative_user()
self.and_the_participant_has_an_upcoming_appointment()
self.and_i_am_on_the_participant_record_page()
self.then_i_should_see_the_upcoming_appointment()
self.when_i_click_on_the_upcoming_appointment()
self.then_i_should_be_on_the_upcoming_appointment_page()

def test_viewing_past_appointments(self):
self.given_i_am_logged_in_as_an_administrative_user()
self.and_the_participant_has_past_appointments()
self.and_i_am_on_the_participant_record_page()
self.then_i_should_see_the_past_appointments()
self.when_i_click_on_a_past_appointment()
self.then_i_should_be_on_the_past_appointment_page()

def and_the_participant_has_an_upcoming_appointment(self):
clinic_slot = ClinicSlotFactory(
starts_at=datetime(2025, 1, 2, 11, tzinfo=tz.utc),
Expand Down Expand Up @@ -95,18 +79,16 @@ def and_i_am_viewing_the_upcoming_appointment(self):
)
)

def and_i_am_on_the_participant_record_page(self):
def and_i_am_on_the_participant_details_tab(self):
self.page.goto(
self.live_server_url
+ reverse(
"participants:show",
kwargs={"pk": self.participant.pk},
"mammograms:participant_details",
kwargs={"pk": self.upcoming_appointment.pk},
)
)

and_i_am_on_the_participant_record_page = and_i_am_on_the_participant_record_page

def when_i_click_on_view_participant_record(self):
def when_i_click_on_participant_details(self):
self.page.get_by_role("link", name="Participant details").click()

def then_i_should_be_on_the_participant_record_page(self):
Expand Down