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
12 changes: 4 additions & 8 deletions manage_breast_screening/clinics/jinja2/clinics/index.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
{% from 'components/secondary-navigation/macro.jinja' import app_secondary_navigation %}

{% block page_content %}
<h1>{{ presenter.heading }}</h1>
<h1>
<span class="nhsuk-caption-l"> {{ provider_name }} </span>
{{ presenter.heading }}
</h1>

{% set ns = namespace() %}
{% set ns.secondaryNavItems = [] %}
Expand Down Expand Up @@ -37,7 +40,6 @@
<tr>
<th scope="col">Location</th>
<th scope="col">Date and time</th>
<th scope="col">Clinic type</th>
<th scope="col" class="nhsuk-table__cell--numeric">Participants</th>
<th scope="col">Status</th>
</tr>
Expand All @@ -56,12 +58,6 @@
<td>{{ presented_clinic.starts_at | no_wrap }}<br>
{{presented_clinic.time_range | as_hint }}
</td>
<td>
{{ presented_clinic.type }}
<br>
<span class="nhsuk-u-secondary-text-color">{{ presented_clinic.risk_type }}</span>
</td>

<td class="nhsuk-table__cell--numeric">
{{ presented_clinic.number_of_slots }}
</td>
Expand Down
12 changes: 8 additions & 4 deletions manage_breast_screening/clinics/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
from datetime import date
from datetime import date, timedelta
from enum import StrEnum

from django.conf import settings
Expand Down Expand Up @@ -60,7 +60,7 @@ def by_filter(self, filter: str):
case ClinicFilter.COMPLETED:
return self.completed()
case ClinicFilter.ALL:
return self
return self.last_seven_days()
case _:
raise ValueError(filter)

Expand All @@ -76,6 +76,9 @@ def upcoming(self):
"""
return self.filter(starts_at__date__gt=date.today())

def last_seven_days(self):
return self.filter(starts_at__date__gte=(date.today() - timedelta(days=7)))

def completed(self):
"""
Completed clinics that started in the past
Expand All @@ -89,7 +92,8 @@ def completed(self):
)

return (
self.filter(starts_at__date__lt=date.today())
self.last_seven_days()
.filter(starts_at__date__lt=date.today())
.annotate(latest_status=Subquery(latest_status))
.filter(latest_status__in=["CLOSED", "CANCELLED"])
.order_by("-ends_at")
Expand Down Expand Up @@ -161,7 +165,7 @@ def filter_counts(cls, provider_id):
queryset = cls.objects.filter(setting__provider_id=provider_id)

return {
ClinicFilter.ALL: queryset.count(),
ClinicFilter.ALL: queryset.last_seven_days().count(),
ClinicFilter.TODAY: queryset.today().count(),
ClinicFilter.UPCOMING: queryset.upcoming().count(),
ClinicFilter.COMPLETED: queryset.completed().count(),
Expand Down
23 changes: 23 additions & 0 deletions manage_breast_screening/clinics/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ def test_clean_clinic_slots():
clinic_slot.clean()


@time_machine.travel(datetime(2025, 1, 1, 10, tzinfo=tz.utc))
@pytest.mark.django_db
def test_last_seven_days_all_filtering():
_clinic1 = ClinicFactory.create(
starts_at=datetime(2024, 12, 1, 9, tzinfo=tz.utc),
ends_at=datetime(2024, 12, 1, 17, tzinfo=tz.utc),
current_status=models.ClinicStatus.CLOSED,
)
_clinic2 = ClinicFactory.create(
starts_at=datetime(2024, 12, 2, 9, tzinfo=tz.utc),
ends_at=datetime(2024, 12, 2, 17, tzinfo=tz.utc),
current_status=models.ClinicStatus.CLOSED,
)
clinic3 = ClinicFactory.create(
starts_at=datetime(2024, 12, 29, 9, tzinfo=tz.utc),
ends_at=datetime(2024, 12, 29, 17, tzinfo=tz.utc),
current_status=models.ClinicStatus.CLOSED,
)

last_seven_days_clinics = models.Clinic.objects.last_seven_days()
assertQuerySetEqual(last_seven_days_clinics, [clinic3])


class TestUserAssignment:
def test_str(self):
user = UserFactory.build(first_name="John", last_name="Doe")
Expand Down
6 changes: 5 additions & 1 deletion manage_breast_screening/clinics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def clinic_list(request, filter="today"):
return render(
request,
"clinics/index.jinja",
context={"presenter": presenter, "page_title": presenter.heading},
context={
"presenter": presenter,
"page_title": presenter.heading,
"provider_name": provider.name,
},
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def and_there_are_appointments(self):
def and_i_am_on_the_clinic_list(self):
self.page.goto(self.live_server_url + reverse("clinics:index"))
self.assert_page_title_contains("Today’s clinics")
heading = self.page.get_by_role("heading", level=1)
expect(heading).to_contain_text(self.current_provider.name)

def and_i_am_on_the_clinic_show_page(self):
self.page.goto(
Expand Down