Skip to content

Commit 360e0fd

Browse files
committed
New test scenario 6 file and added mark_appointment_as_attended method
1 parent cd518a5 commit 360e0fd

File tree

2 files changed

+376
-0
lines changed

2 files changed

+376
-0
lines changed
Lines changed: 331 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
import pytest
2+
import logging
3+
from datetime import datetime
4+
from playwright.sync_api import Page
5+
from utils.oracle.subject_creation_util import CreateSubjectSteps
6+
from utils.user_tools import UserTools
7+
from utils.subject_assertion import subject_assertion
8+
from utils.call_and_recall_utils import CallAndRecallUtils
9+
from utils import screening_subject_page_searcher
10+
from utils.batch_processing import batch_processing
11+
from utils.fit_kit import FitKitLogged, FitKitGeneration
12+
from pages.screening_subject_search.subject_screening_summary_page import (
13+
SubjectScreeningSummaryPage,
14+
)
15+
from utils.appointments import book_appointments
16+
from pages.logout.log_out_page import LogoutPage
17+
from pages.base_page import BasePage
18+
from pages.screening_subject_search.advance_fobt_screening_episode_page import (
19+
AdvanceFOBTScreeningEpisodePage,
20+
)
21+
from pages.screening_subject_search.record_diagnosis_date_page import (
22+
RecordDiagnosisDatePage,
23+
)
24+
from utils.appointments import mark_appointment_as_dna, mark_appointment_as_attended
25+
26+
27+
@pytest.mark.wip
28+
@pytest.mark.usefixtures("setup_org_and_appointments")
29+
@pytest.mark.vpn_required
30+
@pytest.mark.regression
31+
@pytest.mark.fobt_regression_tests
32+
def test_scenario_6(page: Page) -> None:
33+
"""
34+
Scenario: 6: Non-agreement to diagnostic tests
35+
36+
S1-S9-S10-S43-A8-A183-A25-J28-J30-A25-(A50)-J10-A100-(A167)-A38-A168-C203 [SSCL7a] J10-A99-A165-A168-C203 [SSCL8a]
37+
38+
This scenario tests where a subject is suitable but refuses to have a diagnostic test. This tests both routes to this discharge - one where the patient makes an immediate decision (A38 route) and one where the subject asks for time to consider but does not make a decision within the time limit (A165 route). It also tests both in-age and over-age closures, and the "further review" functionality of a colonoscopy assessment dataset, where the suitability chosen from the Advance Episode screen does not match with the suitability stored in the dataset.
39+
40+
Scenario summary:
41+
42+
> Create a new subject in the FOBT age range > Inactive
43+
> Run the FOBT failsafe trawl > Call
44+
> Run the database transition to invite them for FOBT screening > S1(1.1)
45+
> Process S1 letter batch > S9 (1.1)
46+
> Run timed events > creates S9 letter (1.1)
47+
> Process S9 letter batch > S10 (1.1)
48+
> Log kit > S43 (1.2)
49+
> Read kit with ABNORMAL result > A8 (1.3)
50+
> Invite for colonoscopy assessment > A183 (1.11)
51+
> Process A183 appointment letter > A25 (1.11)
52+
> SC DNA appointment > J28
53+
> Rebook colonoscopy assessment > J30 (1.11)
54+
> Process J30 letter > A25 (1.11)
55+
> Record diagnosis date (A50)
56+
> Attend assessment appointment > J10 (1.11)
57+
> Suitable for radiology > A100 (1.12)
58+
> Process A183 result letter (A167)
59+
> Decision not to proceed > A38 (1.12)
60+
> Process A38 letter batch > A168 (1.12) > C203 (1.13)
61+
> Check recall [SSCL7a]
62+
> Reopen following non-response > J10 (1.11)
63+
> SSPI update changes subject to over-age
64+
> Suitable for colonoscopy > A99 (1.12)
65+
> Awaiting decision to proceed > A165 (1.12)
66+
> Run timed events > creates A165 letter (1.12)
67+
> Process A165 letter batch > A168 (1.12) > C203 (1.13)
68+
> Check recall [SSCL8a]
69+
"""
70+
71+
summary_page = SubjectScreeningSummaryPage(page)
72+
logging.info(
73+
"[TEST START] Regression - Scenario: 6: Non-agreement to diagnostic tests"
74+
)
75+
76+
# Given I log in to BCSS "England" as user role "Hub Manager"
77+
user_role = UserTools.user_login(
78+
page, "Hub Manager at BCS01", return_role_type=True
79+
)
80+
if user_role is None:
81+
raise ValueError("User cannot be assigned to a UserRoleType")
82+
83+
# And I create a subject that meets the following criteria:
84+
requirements = {
85+
"age (y/d)": "68/301",
86+
"active gp practice in hub/sc": "BCS01/BCS001",
87+
}
88+
nhs_no = CreateSubjectSteps().create_custom_subject(requirements)
89+
if nhs_no is None:
90+
pytest.fail("Failed to create subject: NHS number not returned.")
91+
92+
# Then Comment: NHS number
93+
logging.info(f"[SUBJECT CREATED] NHS number: {nhs_no}")
94+
95+
# And my subject has been updated as follows:
96+
subject_assertion(
97+
nhs_no,
98+
{
99+
"subject age": "68",
100+
"subject has episodes": "No",
101+
"screening status": "Inactive",
102+
},
103+
)
104+
# Assert subject details in the UI
105+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
106+
summary_page.assert_subject_age(68)
107+
summary_page.assert_screening_status("Inactive")
108+
109+
# When I run the FOBT failsafe trawl for my subject
110+
CallAndRecallUtils().run_failsafe(nhs_no)
111+
112+
# Then my subject has been updated as follows:
113+
subject_assertion(
114+
nhs_no,
115+
{
116+
"subject has episodes": "No",
117+
"Screening Due Date": "Last Birthday",
118+
"Screening due date date of change": "Today",
119+
"Screening Due Date Reason": "Failsafe Trawl",
120+
"screening status": "Call",
121+
"Screening Status Date of Change": "Today",
122+
"Screening Status Reason": "Failsafe Trawl",
123+
},
124+
)
125+
126+
# When I invite my subject for FOBT screening
127+
CallAndRecallUtils().invite_subject_for_fobt_screening(nhs_no, user_role)
128+
129+
# Then my subject has been updated as follows:
130+
subject_assertion(
131+
nhs_no,
132+
{
133+
"latest event status": "S1 Selected for Screening",
134+
"latest episode kit class": "FIT",
135+
"latest episode type": "FOBT",
136+
},
137+
)
138+
139+
# Then there is a "S1" letter batch for my subject with the exact title "Pre-invitation (FIT)"
140+
# When I process the open "S1" letter batch for my subject
141+
# Then my subject has been updated as follows:
142+
batch_processing(
143+
page,
144+
"S1",
145+
"Pre-invitation (FIT)",
146+
"S9 - Pre-invitation Sent",
147+
True,
148+
)
149+
150+
# When I run Timed Events for my subject
151+
# Then there is a "S9" letter batch for my subject with the exact title "Invitation & Test Kit (FIT)"
152+
# When I process the open "S9" letter batch for my subject
153+
# # Then my subject has been updated as follows:
154+
batch_processing(
155+
page,
156+
"S9",
157+
"Invitation & Test Kit (FIT)",
158+
"S10 - Invitation & Test Kit Sent",
159+
True,
160+
)
161+
162+
# When I log my subject's latest unlogged FIT kit
163+
fit_kit = FitKitGeneration().get_fit_kit_for_subject_sql(nhs_no, False, False)
164+
sample_date = datetime.now()
165+
FitKitLogged().log_fit_kits(page, fit_kit, sample_date)
166+
167+
# Then my subject has been updated as follows:
168+
subject_assertion(
169+
nhs_no,
170+
{
171+
"latest event status": "S43 Kit Returned and Logged (Initial Test)",
172+
},
173+
)
174+
175+
# When I read my subject's latest logged FIT kit as "ABNORMAL"
176+
FitKitLogged().read_latest_logged_kit(user_role, 2, fit_kit, "ABNORMAL")
177+
178+
# Then my subject has been updated as follows:
179+
subject_assertion(
180+
nhs_no,
181+
{
182+
"latest event status": "A8 Abnormal",
183+
},
184+
)
185+
186+
# When I view the subject
187+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
188+
189+
# And I choose to book a practitioner clinic for my subject
190+
SubjectScreeningSummaryPage(page).click_book_practitioner_clinic_button()
191+
192+
# And I select "BCS001" as the screening centre where the practitioner appointment will be held
193+
# And I set the practitioner appointment date to "today"
194+
# And I book the "earliest" available practitioner appointment on this date
195+
book_appointments(
196+
page,
197+
"BCS001 - Wolverhampton Bowel Cancer Screening Centre",
198+
"The Royal Hospital (Wolverhampton)",
199+
)
200+
201+
# Then my subject has been updated as follows:
202+
subject_assertion(
203+
nhs_no,
204+
{
205+
"latest event status": "A183 1st Colonoscopy Assessment Appointment Requested",
206+
},
207+
)
208+
209+
# And there is a "A183" letter batch for my subject with the exact title "Practitioner Clinic 1st Appointment"
210+
# When I process the open "A183 - Practitioner Clinic 1st Appointment" letter batch for my subject
211+
# Then my subject has been updated as follows:
212+
batch_processing(
213+
page,
214+
"A183",
215+
"Practitioner Clinic 1st Appointment",
216+
"A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent",
217+
)
218+
219+
# And there is a "A183" letter batch for my subject with the exact title "GP Result (Abnormal)"
220+
batch_processing(
221+
page,
222+
"A183",
223+
"GP Result (Abnormal)",
224+
"A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent",
225+
)
226+
227+
# When I switch users to BCSS "England" as user role "Screening Centre Manager"
228+
LogoutPage(page).log_out(close_page=False)
229+
BasePage(page).go_to_log_in_page()
230+
UserTools.user_login(page, "Screening Centre Manager at BCS001")
231+
232+
# And I view the subject
233+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
234+
235+
# And I view the event history for the subject's latest episode
236+
# And I view the latest practitioner appointment in the subject's episode
237+
# And The Screening Centre DNAs the practitioner appointment
238+
mark_appointment_as_dna(page, "Screening Centre did not attend") # TODO: Line 1188
239+
240+
# Then my subject has been updated as follows:
241+
subject_assertion(
242+
nhs_no,
243+
{
244+
"latest event status": "J28 Appointment Non-attendance (Screening Centre)",
245+
},
246+
)
247+
248+
# And I view the subject
249+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
250+
251+
# And I choose to book a practitioner clinic for my subject
252+
SubjectScreeningSummaryPage(page).click_book_practitioner_clinic_button()
253+
254+
# And I select "BCS001" as the screening centre where the practitioner appointment will be held
255+
# And I set the practitioner appointment date to "today"
256+
# And I book the "earliest" available practitioner appointment on this date
257+
book_appointments(
258+
page,
259+
"BCS001 - Wolverhampton Bowel Cancer Screening Centre",
260+
"The Royal Hospital (Wolverhampton)",
261+
)
262+
263+
# Then my subject has been updated as follows:
264+
subject_assertion(
265+
nhs_no,
266+
{
267+
"latest event status": "J30 Appointment Requested (SC Non-attendance Letter)",
268+
},
269+
)
270+
271+
# And there is a "J30" letter batch for my subject with the exact title "Practitioner Clinic 1st Appointment Non Attendance (Screening Centre)"
272+
# When I process the open "J30" letter batch for my subject TODO: Line 1203
273+
# Then my subject has been updated as follows:
274+
batch_processing(
275+
page,
276+
"J30",
277+
"Practitioner Clinic 1st Appointment Non Attendance (Screening Centre)",
278+
"A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent",
279+
)
280+
281+
# When I switch users to BCSS "England" as user role "Hub Manager"
282+
LogoutPage(page).log_out(close_page=False)
283+
BasePage(page).go_to_log_in_page()
284+
UserTools.user_login(page, "Hub Manager State Registered at BCS01")
285+
286+
# When I view the subject
287+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
288+
289+
# And I view the advance episode options
290+
SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button()
291+
292+
# And I select the advance episode option for "Record Diagnosis Date"
293+
AdvanceFOBTScreeningEpisodePage(page).click_record_diagnosis_date_button()
294+
295+
# And I enter a Diagnosis Date of "today"
296+
RecordDiagnosisDatePage(page).enter_date_in_diagnosis_date_field(datetime.now())
297+
298+
# And I save Diagnosis Date Information
299+
RecordDiagnosisDatePage(page).click_save_button()
300+
301+
# Then my subject has been updated as follows: TODO: line 1215
302+
subject_assertion(
303+
nhs_no,
304+
{
305+
"latest episode diagnosis date reason": "Null",
306+
"latest episode has diagnosis date": "Yes",
307+
"latest episode includes event status": "A50 Diagnosis date recorded",
308+
"latest event status": "A25 1st Colonoscopy Assessment Appointment Booked",
309+
},
310+
)
311+
312+
# When I switch users to BCSS "England" as user role "Screening Centre Manager"
313+
LogoutPage(page).log_out(close_page=False)
314+
BasePage(page).go_to_log_in_page()
315+
UserTools.user_login(page, "Screening Centre Manager at BCS001")
316+
317+
# And I view the subject
318+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
319+
320+
# And I view the event history for the subject's latest episode
321+
# And I view the latest practitioner appointment in the subject's episode
322+
# And I attend the subject's practitioner appointment "today"
323+
mark_appointment_as_attended(page)
324+
325+
# Then my subject has been updated as follows:
326+
subject_assertion(
327+
"9006266558",
328+
{
329+
"latest event status": "J10 Attended Colonoscopy Assessment Appointment",
330+
},
331+
)

utils/appointments.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,48 @@ def mark_appointment_as_dna(page: Page, non_attendance_reason: str) -> None:
166166
appointment_detail_page.click_save_button(accept_dialog=True)
167167

168168
logging.info("[APPOINTMENT DNA] DNA flow completed successfully")
169+
170+
171+
def mark_appointment_as_attended(page: Page) -> None:
172+
"""
173+
Marks an appointment as attended and logs the auto-filled attendance details.
174+
This process starts from the subject screening summary page.
175+
176+
This method navigates through the subject's episode and appointment pages,
177+
selects the 'Attendance' radio option, checks the 'Attended' checkbox,
178+
and logs the resulting date and time values.
179+
180+
Args:
181+
page (Page): Playwright page object.
182+
183+
Raises:
184+
AssertionError: If expected elements are not found or interaction fails.
185+
"""
186+
appointment_detail_page = AppointmentDetailPage(page)
187+
subject_screening_summary_page = SubjectScreeningSummaryPage(page)
188+
episode_events_and_notes_page = EpisodeEventsAndNotesPage(page)
189+
190+
logging.info("[APPOINTMENT ATTENDED] Starting attended flow")
191+
192+
subject_screening_summary_page.click_list_episodes()
193+
subject_screening_summary_page.click_view_events_link()
194+
episode_events_and_notes_page.click_most_recent_view_appointment_link()
195+
appointment_detail_page.check_attendance_radio()
196+
197+
# Check the 'Attended' checkbox
198+
attended_checkbox = page.locator("#UI_ATTENDED")
199+
attended_checkbox.check()
200+
201+
# Log the auto-filled attendance details
202+
attended_date = page.locator("#UI_ATTENDED_DATE").input_value()
203+
time_from = page.locator("#UI_ATTENDED_TIME_FROM").input_value()
204+
time_to = page.locator("#UI_ATTENDED_TIME_TO").input_value()
205+
meeting_mode = page.locator("#UI_NEW_MEETING_MODE").input_value()
206+
207+
logging.info(
208+
f"[APPOINTMENT ATTENDED] How Attended: {meeting_mode}, Date: {attended_date}, Time From: {time_from}, Time To: {time_to}"
209+
)
210+
211+
appointment_detail_page.click_save_button(accept_dialog=True)
212+
213+
logging.info("[APPOINTMENT ATTENDED] Attended flow completed successfully")

0 commit comments

Comments
 (0)