2828from utils .calendar_picker import CalendarPicker
2929from utils .batch_processing import batch_processing
3030from datetime import datetime
31+ from utils .oracle .oracle_specific_functions import get_subjects_for_appointments
32+ from utils .nhs_number_tools import NHSNumberTools
33+ import logging
3134
3235
3336@pytest .fixture
@@ -48,67 +51,92 @@ def test_compartment_4(page: Page, smokescreen_properties: dict) -> None:
4851 Finally it processes the necessary batches to send out the letters and checks the subjects satus has been updated to what is expected
4952 """
5053
51- # Add method of getting test data using the query below. To remove once subject retrieval logic is created
52- """select tk.kitid, ss.subject_nhs_number, se.screening_subject_id
53- from tk_items_t tk
54- inner join ep_subject_episode_t se on se.screening_subject_id = tk.screening_subject_id
55- inner join screening_subject_t ss on ss.screening_subject_id = se.screening_subject_id
56- inner join sd_contact_t c on c.nhs_number = ss.subject_nhs_number
57- where se.latest_event_status_id = 11132
58- and tk.logged_in_flag = 'Y'
59- and se.episode_status_id = 11352
60- and ss.screening_status_id != 4008
61- and tk.logged_in_at = 23159
62- and c.hub_id = 23159
63- and tk.tk_type_id = 2
64- and tk.datestamp > add_months(sysdate,-24)
65- order by ss.subject_nhs_number desc"""
54+ subjects_df = get_subjects_for_appointments (
55+ smokescreen_properties ["c4_eng_number_of_appointments_to_book" ]
56+ )
6657
58+ logging .info (
59+ f"Compartment 4 - Setting up appointments for { smokescreen_properties ["c4_eng_weeks_to_make_available" ]} Weeks"
60+ )
6761 UserTools .user_login (page , "Screening Centre Manager at BCS001" )
6862 BasePage (page ).go_to_screening_practitioner_appointments_page ()
6963 ScreeningPractitionerAppointmentsPage (page ).go_to_set_availability_page ()
7064 SetAvailabilityPage (page ).go_to_practitioner_availability_page ()
7165 PractitionerAvailabilityPage (page ).select_site_dropdown_option (
72- "THE ROYAL HOSPITAL (WOLVERHAMPTON)"
66+ smokescreen_properties [ "c4_eng_site_name1" ]
7367 )
7468 PractitionerAvailabilityPage (page ).select_practitioner_dropdown_option (
75- "Astonish, Ethanol"
69+ smokescreen_properties [ "c4_eng_practitioner_name" ]
7670 )
7771 PractitionerAvailabilityPage (page ).click_calendar_button ()
78- CalendarPicker (page ).select_day (
79- datetime .today ()
80- ) # This will make it so that we can only run this test once a day, or we need to restore the DB back to the snapshot
72+ CalendarPicker (page ).select_day (datetime .today ())
8173 PractitionerAvailabilityPage (page ).click_show_button ()
8274 PractitionerAvailabilityPage (page ).enter_start_time ("09:00" )
8375 PractitionerAvailabilityPage (page ).enter_end_time ("17:15" )
8476 PractitionerAvailabilityPage (page ).click_calculate_slots_button ()
85- PractitionerAvailabilityPage (page ).enter_number_of_weeks ("6" )
77+ PractitionerAvailabilityPage (page ).enter_number_of_weeks (
78+ smokescreen_properties ["c4_eng_weeks_to_make_available" ]
79+ )
8680 PractitionerAvailabilityPage (page ).click_save_button ()
8781 PractitionerAvailabilityPage (page ).slots_updated_message_is_displayed (
88- "Slots Updated for 6 Weeks"
82+ f "Slots Updated for { smokescreen_properties [ "c4_eng_weeks_to_make_available" ] } Weeks"
8983 )
9084 Logout (page ).log_out (close_page = False )
9185
86+ logging .info (
87+ f"Compartment 4 - Booking { smokescreen_properties ["c4_eng_number_of_appointments_to_book" ]} subjects to appointments"
88+ )
9289 ScreeningPractitionerAppointmentsPage (page ).go_to_log_in_page ()
9390 UserTools .user_login (page , "Hub Manager State Registered at BCS01" )
91+
9492 BasePage (page ).go_to_screening_practitioner_appointments_page ()
9593 ScreeningPractitionerAppointmentsPage (page ).go_to_patients_that_require_page ()
96- # Add for loop to loop x times (depends on how many we want to run it for) 70 - 79
97- ColonoscopyAssessmentAppointments (page ).filter_by_nhs_number ("999 205 6339" )
98- ColonoscopyAssessmentAppointments (page ).click_nhs_number_link ("999 205 6339" )
99- BookAppointmentPage (page ).select_screening_centre_dropdown_option (
100- "BCS001 - Wolverhampton Bowel Cancer Screening Centre"
101- )
102- BookAppointmentPage (page ).select_site_dropdown_option ("Holly Hall Clinic (? km)" )
103- BookAppointmentPage (page ).choose_day_with_available_slots ()
104- # page.locator("#UI_NEW_SLOT_SELECTION_ID_359119").check()
105- # Will be revisited as part of Utilities update
106- BookAppointmentPage (page ).choose_appointment_time ()
107- BookAppointmentPage (page ).click_save_button ()
108- BookAppointmentPage (page ).appointment_booked_confirmation_is_displayed (
109- "Appointment booked"
110- )
11194
95+ for subject_num in range (
96+ int (smokescreen_properties ["c4_eng_number_of_appointments_to_book" ])
97+ ):
98+ nhs_number = subjects_df ["subject_nhs_number" ].iloc [subject_num ]
99+ logging .info (f"Booking appointment for: { nhs_number } " )
100+
101+ nhs_number_spaced = NHSNumberTools ().spaced_nhs_number (nhs_number )
102+ ColonoscopyAssessmentAppointments (page ).filter_by_nhs_number (nhs_number )
103+ ColonoscopyAssessmentAppointments (page ).click_nhs_number_link (nhs_number_spaced )
104+ BookAppointmentPage (page ).select_screening_centre_dropdown_option (
105+ smokescreen_properties ["c4_eng_centre_name" ]
106+ )
107+ BookAppointmentPage (page ).select_site_dropdown_option (
108+ [
109+ f"{ smokescreen_properties ["c4_eng_site_name2" ]} (? km)" ,
110+ f"{ smokescreen_properties ["c4_eng_site_name2" ]} (? km) (attended)" ,
111+ ]
112+ )
113+
114+ current_month_displayed = BookAppointmentPage (
115+ page
116+ ).get_current_month_displayed ()
117+ CalendarPicker (page ).book_first_eligble_appointment (
118+ current_month_displayed ,
119+ BookAppointmentPage (page ).appointment_cell_locators ,
120+ [
121+ BookAppointmentPage (page ).available_background_colour ,
122+ BookAppointmentPage (page ).some_available_background_colour ,
123+ ],
124+ )
125+ BookAppointmentPage (page ).appointments_table .click_first_input_in_column (
126+ "Appt/Slot Time"
127+ )
128+ BasePage (page ).safe_accept_dialog (BookAppointmentPage (page ).save_button )
129+ try :
130+ BookAppointmentPage (page ).appointment_booked_confirmation_is_displayed (
131+ "Appointment booked"
132+ )
133+ logging .info (f"Appointment successfully booked for: { nhs_number } " )
134+ except Exception as e :
135+ pytest .fail (f"Appointment not booked successfully: { e } " )
136+ BasePage (page ).click_back_button ()
137+ ColonoscopyAssessmentAppointments (page ).wait_for_page_header ()
138+
139+ logging .info ("Compartment 4 - Sending out appointment invitations" )
112140 batch_processing (
113141 page ,
114142 "A183" ,
0 commit comments