Skip to content

Commit 96492fe

Browse files
Change 'all' filtering to only include clinics from the last 7 days
This has been changed as if we collect all clinics, this list will grow very large and will get out of control very quick. This has been changed to the last 7 days and can be more digestable
1 parent 129f037 commit 96492fe

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

manage_breast_screening/clinics/jinja2/clinics/index.jinja

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66

77
{% block page_content %}
88
<h1>
9-
<span class="nhsuk-caption-l">
10-
{{ provider_name }}
11-
</span>
12-
{{
13-
presenter.heading
14-
}}
9+
<span class="nhsuk-caption-l"> {{ provider_name }} </span>
10+
{{ presenter.heading }}
1511
</h1>
1612

1713
{% set ns = namespace() %}

manage_breast_screening/clinics/models.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uuid
2-
from datetime import date
2+
from datetime import date, timedelta
33
from enum import StrEnum
44

55
from django.conf import settings
@@ -60,7 +60,7 @@ def by_filter(self, filter: str):
6060
case ClinicFilter.COMPLETED:
6161
return self.completed()
6262
case ClinicFilter.ALL:
63-
return self
63+
return self.last_seven_days()
6464
case _:
6565
raise ValueError(filter)
6666

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

79+
def last_seven_days(self):
80+
return self.filter(starts_at__date__gte=(date.today() - timedelta(days=7)))
81+
7982
def completed(self):
8083
"""
8184
Completed clinics that started in the past
@@ -89,7 +92,8 @@ def completed(self):
8992
)
9093

9194
return (
92-
self.filter(starts_at__date__lt=date.today())
95+
self.last_seven_days()
96+
.filter(starts_at__date__lt=date.today())
9397
.annotate(latest_status=Subquery(latest_status))
9498
.filter(latest_status__in=["CLOSED", "CANCELLED"])
9599
.order_by("-ends_at")
@@ -161,7 +165,7 @@ def filter_counts(cls, provider_id):
161165
queryset = cls.objects.filter(setting__provider_id=provider_id)
162166

163167
return {
164-
ClinicFilter.ALL: queryset.count(),
168+
ClinicFilter.ALL: queryset.last_seven_days().count(),
165169
ClinicFilter.TODAY: queryset.today().count(),
166170
ClinicFilter.UPCOMING: queryset.upcoming().count(),
167171
ClinicFilter.COMPLETED: queryset.completed().count(),

manage_breast_screening/clinics/tests/test_models.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ def test_clean_clinic_slots():
101101
clinic_slot.clean()
102102

103103

104+
@time_machine.travel(datetime(2025, 1, 1, 10, tzinfo=tz.utc))
105+
@pytest.mark.django_db
106+
def test_last_seven_days_all_filtering():
107+
_clinic1 = ClinicFactory.create(
108+
starts_at=datetime(2024, 12, 1, 9, tzinfo=tz.utc),
109+
ends_at=datetime(2024, 12, 1, 17, tzinfo=tz.utc),
110+
current_status=models.ClinicStatus.CLOSED,
111+
)
112+
_clinic2 = ClinicFactory.create(
113+
starts_at=datetime(2024, 12, 2, 9, tzinfo=tz.utc),
114+
ends_at=datetime(2024, 12, 2, 17, tzinfo=tz.utc),
115+
current_status=models.ClinicStatus.CLOSED,
116+
)
117+
clinic3 = ClinicFactory.create(
118+
starts_at=datetime(2024, 12, 29, 9, tzinfo=tz.utc),
119+
ends_at=datetime(2024, 12, 29, 17, tzinfo=tz.utc),
120+
current_status=models.ClinicStatus.CLOSED,
121+
)
122+
123+
last_seven_days_clinics = models.Clinic.objects.last_seven_days()
124+
assertQuerySetEqual(last_seven_days_clinics, [clinic3])
125+
126+
104127
class TestUserAssignment:
105128
def test_str(self):
106129
user = UserFactory.build(first_name="John", last_name="Doe")

0 commit comments

Comments
 (0)