11import pytest
22import logging
33from playwright .sync_api import Page
4+ from classes .user .user_role_type import UserRoleType
45from pages .datasets .cancer_audit_datasets_page import (
56 CancerRadiologyYesNoOptions ,
67)
@@ -169,34 +170,11 @@ def test_scenario_8(page: Page) -> None:
169170
170171 # Then there is a "S9" letter batch for my subject with the exact title "Invitation & Test Kit (FIT)"
171172 # When I process the open "S9" letter batch for my subject
172- # Then my subject has been updated as follows:
173- batch_processing (
174- page ,
175- "S9" ,
176- "Invitation & Test Kit (FIT)" ,
177- "S10 - Invitation & Test Kit Sent" ,
178- True ,
179- )
180-
181173 # When I log my subject's latest unlogged FIT kit
182- fit_kit = FitKitGeneration ().get_fit_kit_for_subject_sql (nhs_no , False , False )
183- sample_date = datetime .now ()
184- FitKitLogged ().log_fit_kits (page , fit_kit , sample_date )
185-
186- # Then my subject has been updated as follows:
187- criteria = {
188- "latest event status" : "S43 Kit Returned and Logged (Initial Test)" ,
189- }
190- subject_assertion (nhs_no , criteria )
191-
192174 # When I read my subject's latest logged FIT kit as "ABNORMAL"
193- FitKitLogged ().read_latest_logged_kit (user_role , 2 , fit_kit , "ABNORMAL" )
194-
195175 # Then my subject has been updated as follows:
196- criteria = {
197- "latest event status" : "A8 Abnormal" ,
198- }
199- subject_assertion (nhs_no , criteria )
176+ process_initial_invitation_and_fit_kit (page , nhs_no , user_role )
177+
200178 # When I view the subject
201179 screening_subject_page_searcher .navigate_to_subject_summary_page (page , nhs_no )
202180
@@ -206,40 +184,10 @@ def test_scenario_8(page: Page) -> None:
206184 # And I select "BCS001" as the screening centre where the practitioner appointment will be held
207185 # And I set the practitioner appointment date to "today"
208186 # And I book the "earliest" available practitioner appointment on this date
209- book_appointments (
210- page ,
211- "BCS001 - Wolverhampton Bowel Cancer Screening Centre" ,
212- "The Royal Hospital (Wolverhampton)" ,
213- )
214-
215- # Then my subject has been updated as follows:
216- criteria = {
217- "latest event status" : "A183 1st Colonoscopy Assessment Appointment Requested" ,
218- }
219- subject_assertion (nhs_no , criteria )
220-
221- # And there is a "A183" letter batch for my subject with the exact title "Practitioner Clinic 1st Appointment"
222- # When I process the open "A183 - Practitioner Clinic 1st Appointment" letter batch for my subject
223- # Then my subject has been updated as follows:
224- batch_processing (
225- page ,
226- "A183" ,
227- "Practitioner Clinic 1st Appointment" ,
228- "A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent" ,
229- )
230-
231- # And there is a "A183" letter batch for my subject with the exact title "GP Result (Abnormal)"
232- batch_processing (
233- page ,
234- "A183" ,
235- "GP Result (Abnormal)" ,
236- "A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent" ,
237- )
187+ book_practitioner_clinic_and_process_letters (page , nhs_no )
238188
239189 # When I switch users to BCSS "England" as user role "Screening Centre Manager"
240- LogoutPage (page ).log_out (close_page = False )
241- BasePage (page ).go_to_log_in_page ()
242- UserTools .user_login (page , "Screening Centre Manager at BCS001" )
190+ switch_to_screening_centre_manager (page )
243191
244192 # When I view the subject
245193 screening_subject_page_searcher .navigate_to_subject_summary_page (page , nhs_no )
@@ -315,20 +263,20 @@ def test_scenario_8(page: Page) -> None:
315263 BasePage (page ).go_to_log_in_page ()
316264 UserTools .user_login (page , "Hub Manager at BCS01" )
317265
318- # And I process the open "A183 - GP Result (Abnormal)" letter batch for my subject
319- # NOTE LEAVE COMMENTED - Subject is already at A172 DNA Diagnostic Test (line 313)
320- # Then my subject has been updated as follows:
321- # batch_processing(
322- # page,
323- # "A183",
324- # "GP Result (Abnormal)",
325- # "A172 - DNA Diagnostic Test",
326- # )
327- # criteria = {
328- # "latest episode includes event status": "A167 GP Abnormal FOBT Result Sent",
329- # "latest episode accumulated result": "No Result",
330- # }
331- # subject_assertion(nhs_no, criteria)
266+ # # And I process the open "A183 - GP Result (Abnormal)" letter batch for my subject
267+ # # NOTE LEAVE COMMENTED - Subject is already at A172 DNA Diagnostic Test (line 313)
268+ # # Then my subject has been updated as follows:
269+ # # batch_processing(
270+ # # page,
271+ # # "A183",
272+ # # "GP Result (Abnormal)",
273+ # # "A172 - DNA Diagnostic Test",
274+ # # )
275+ # # criteria = {
276+ # # "latest episode includes event status": "A167 GP Abnormal FOBT Result Sent",
277+ # # "latest episode accumulated result": "No Result",
278+ # # }
279+ # # subject_assertion(nhs_no, criteria)
332280
333281 # When I switch users to BCSS "England" as user role "Screening Centre Manager"
334282 LogoutPage (page ).log_out (close_page = False )
@@ -424,7 +372,7 @@ def test_scenario_8(page: Page) -> None:
424372 screening_subject_page_searcher .navigate_to_subject_summary_page (page , nhs_no )
425373
426374 # And I reopen the subject's episode for "Reopen to Reschedule Diagnostic Test"
427- # SubjectScreeningSummaryPage(page).click_reopen_fobt_screening_episode_button()
375+ SubjectScreeningSummaryPage (page ).click_reopen_fobt_screening_episode_button ()
428376 ReopenFOBTScreeningEpisodePage (
429377 page
430378 ).click_reopen_to_reschedule_diagnostic_test_button ()
@@ -1004,3 +952,87 @@ def test_scenario_8(page: Page) -> None:
1004952 "surveillance due date reason" : "Unchanged" ,
1005953 }
1006954 subject_assertion (nhs_no , criteria , user_role )
955+
956+
957+ # Helper functions
958+ def process_initial_invitation_and_fit_kit (
959+ page : Page , nhs_no : str , user_role : UserRoleType
960+ ) -> None :
961+ """
962+ Processes the initial invitation and FIT kit flow:
963+ - Processes S9 batch
964+ - Logs FIT kit
965+ - Reads kit as ABNORMAL
966+ - Asserts subject status updates
967+ """
968+ batch_processing (
969+ page ,
970+ "S9" ,
971+ "Invitation & Test Kit (FIT)" ,
972+ "S10 - Invitation & Test Kit Sent" ,
973+ True ,
974+ )
975+
976+ fit_kit = FitKitGeneration ().get_fit_kit_for_subject_sql (nhs_no , False , False )
977+ sample_date = datetime .now ()
978+ FitKitLogged ().log_fit_kits (page , fit_kit , sample_date )
979+
980+ subject_assertion (
981+ nhs_no , {"latest event status" : "S43 Kit Returned and Logged (Initial Test)" }
982+ )
983+
984+ FitKitLogged ().read_latest_logged_kit (user_role , 2 , fit_kit , "ABNORMAL" )
985+ subject_assertion (nhs_no , {"latest event status" : "A8 Abnormal" })
986+
987+ criteria = {
988+ "latest event status" : "A8 Abnormal" ,
989+ }
990+ subject_assertion (nhs_no , criteria )
991+
992+
993+ def book_practitioner_clinic_and_process_letters (page : Page , nhs_no : str ) -> None :
994+ """
995+ Books practitioner clinic and processes A183 letters:
996+ - Navigates to subject
997+ - Books appointment
998+ - Processes both A183 letter batches
999+ - Asserts subject status
1000+ """
1001+ screening_subject_page_searcher .navigate_to_subject_summary_page (page , nhs_no )
1002+ SubjectScreeningSummaryPage (page ).click_book_practitioner_clinic_button ()
1003+
1004+ book_appointments (
1005+ page ,
1006+ "BCS001 - Wolverhampton Bowel Cancer Screening Centre" ,
1007+ "The Royal Hospital (Wolverhampton)" ,
1008+ )
1009+
1010+ subject_assertion (
1011+ nhs_no ,
1012+ {
1013+ "latest event status" : "A183 1st Colonoscopy Assessment Appointment Requested"
1014+ },
1015+ )
1016+
1017+ batch_processing (
1018+ page ,
1019+ "A183" ,
1020+ "Practitioner Clinic 1st Appointment" ,
1021+ "A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent" ,
1022+ )
1023+
1024+ batch_processing (
1025+ page ,
1026+ "A183" ,
1027+ "GP Result (Abnormal)" ,
1028+ "A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent" ,
1029+ )
1030+
1031+
1032+ def switch_to_screening_centre_manager (page : Page ) -> None :
1033+ """
1034+ Logs out and switches to Screening Centre Manager at BCS001
1035+ """
1036+ LogoutPage (page ).log_out (close_page = False )
1037+ BasePage (page ).go_to_log_in_page ()
1038+ UserTools .user_login (page , "Screening Centre Manager at BCS001" )
0 commit comments