Skip to content

Commit 3858144

Browse files
cameronhargreaves1-nhsgpeng
authored andcommitted
Show current user appointment attribution
* Add (you) to the appointment user attribution in the clinic list if the appointment is attributed to the current logged in user
1 parent 61bdf2c commit 3858144

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

manage_breast_screening/auth/tests/factories.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from django.contrib.auth import get_user_model
2+
from factory import Trait
23
from factory.declarations import Sequence
34
from factory.django import DjangoModelFactory
45

6+
from manage_breast_screening.auth.models import Role
7+
58

69
class UserFactory(DjangoModelFactory):
710
class Meta:
@@ -12,3 +15,7 @@ class Meta:
1215
nhs_uid = Sequence(lambda n: "alice%d" % n)
1316
first_name = Sequence(lambda n: "Alice%d" % n)
1417
last_name = "Lastname"
18+
19+
class Params:
20+
clinical = Trait(roles=[Role.CLINICAL])
21+
administrative = Trait(roles=[Role.ADMINISTRATIVE])

manage_breast_screening/clinics/jinja2/clinics/show.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
app_appointment_status(presented_appointment)
7171
}}
7272
{% if presented_appointment.status_attribution %}
73-
<span class="app-text-grey app-nowrap nhsuk-body-s nhsuk-u-margin-bottom-0">{{ presented_appointment.status_attribution }}</span>
73+
<span class="app-text-grey app-nowrap nhsuk-body-s nhsuk-u-margin-bottom-0">{{ presented_appointment.status_attribution }} {{presented_appointment.attribution_user_check(request.user)}}</span>
7474
{% endif %}
7575
<p class="nhsuk-u-margin-top-2 nhsuk-u-margin-bottom-0 app-u-nowrap">
7676
<a href="{{ url('mammograms:show_appointment', kwargs={"pk": presented_appointment.pk}) }}" class="nhsuk-link">

manage_breast_screening/mammograms/presenters/appointment_presenters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ def status_attribution(self):
117117
else:
118118
return None
119119

120+
def attribution_user_check(self, user):
121+
if user.pk == self._appointment.current_status.created_by.pk:
122+
return " (you)"
123+
else:
124+
return ""
125+
120126
@cached_property
121127
def note(self):
122128
try:

manage_breast_screening/tests/system/clinical/test_clinic_show_page.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.urls import reverse
77
from playwright.sync_api import expect
88

9+
from manage_breast_screening.auth.models import Role
910
from manage_breast_screening.auth.tests.factories import UserFactory
1011
from manage_breast_screening.clinics.models import Clinic
1112
from manage_breast_screening.clinics.tests.factories import ClinicFactory
@@ -64,12 +65,13 @@ def test_accessibility(self):
6465
self.then_the_accessibility_baseline_is_met()
6566

6667
def test_status_attribution_display(self):
67-
self.given_i_am_logged_in_as_a_clinical_user()
68+
self.given_i_am_logged_in_as_a_user_with_appointment_in_progress()
6869
self.and_a_clinic_exists_that_is_run_by_my_provider()
6970
self.and_there_are_appointments_in_various_statuses_with_attributed_users()
7071
self.and_i_am_on_the_clinic_show_page()
7172
self.when_i_click_on_all()
7273
self.then_i_can_see_status_attribution_for_relevant_appointments()
74+
self.then_i_can_see_you_in_status_attribution()
7375

7476
def and_a_clinic_exists_that_is_run_by_my_provider(self):
7577
user_assignment = self.current_user.assignments.first()
@@ -266,7 +268,6 @@ def then_i_can_see_the_special_appointment_banner(self):
266268

267269
def and_there_are_appointments_in_various_statuses_with_attributed_users(self):
268270
# Create users for attribution
269-
user_in_progress = UserFactory(first_name="Alice", last_name="User")
270271
user_screened = UserFactory(first_name="Bob", last_name="User")
271272
user_cancelled = UserFactory(first_name="Charlie", last_name="User")
272273

@@ -285,8 +286,8 @@ def and_there_are_appointments_in_various_statuses_with_attributed_users(self):
285286
last_name="InProgress",
286287
)
287288
self.in_progress_appointment.statuses.create(
288-
name=AppointmentStatus.STARTED,
289-
created_by=user_in_progress,
289+
state=AppointmentStatus.IN_PROGRESS,
290+
created_by=self.user_in_progress,
290291
)
291292

292293
# SCREENED status
@@ -320,10 +321,24 @@ def then_i_can_see_status_attribution_for_relevant_appointments(self):
320321
in_progress_row = self.page.locator("tr").filter(
321322
has_text="Participant InProgress"
322323
)
323-
expect(in_progress_row).to_contain_text("with A. User")
324+
expect(in_progress_row).to_contain_text("with A. InProgress (you)")
324325

325326
screened_row = self.page.locator("tr").filter(has_text="Participant Screened")
326327
expect(screened_row).to_contain_text("by B. User")
327328

328329
cancelled_row = self.page.locator("tr").filter(has_text="Participant Cancelled")
329330
expect(cancelled_row).to_contain_text("by C. User")
331+
332+
def given_i_am_logged_in_as_a_user_with_appointment_in_progress(self):
333+
# Create and log in the user who will be attributed with the IN_PROGRESS status
334+
self.user_in_progress = self.create_user_with_role(
335+
first_name="Alice", last_name="InProgress", role=Role.CLINICAL
336+
)
337+
self.login_as_user(self.user_in_progress)
338+
339+
def then_i_can_see_you_in_status_attribution(self):
340+
# Check that the "(you)" indicator is present for the in-progress attribution
341+
in_progress_row = self.page.locator("tr").filter(
342+
has_text="Participant InProgress"
343+
)
344+
expect(in_progress_row).to_contain_text("(you)")

manage_breast_screening/tests/system/system_test_setup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def login_as_user(self, user: User):
4646
Emulate logging in as a particular user, without needing
4747
to visit a login page.
4848
"""
49+
50+
self.current_user = user
51+
4952
# Fake a login
5053
client = Client()
5154
client.force_login(user)
@@ -75,12 +78,19 @@ def login_as_role(self, role: Role):
7578
without needing to visit a login page.
7679
"""
7780
user = UserFactory.create()
81+
7882
UserAssignmentFactory.create(user=user, roles=[role.value])
7983

80-
self.current_user = user
8184
self.current_provider = user.assignments.first().provider
8285
self.login_as_user(user)
8386

87+
def create_user_with_role(
88+
self, first_name: str, last_name: str, role: Role
89+
) -> User:
90+
user = UserFactory.create(first_name=first_name, last_name=last_name)
91+
UserAssignmentFactory.create(user=user, roles=[role.value])
92+
return user
93+
8494
def expect_validation_error(
8595
self,
8696
error_text: str,

0 commit comments

Comments
 (0)