1- import logging
2- from math import exp
31import pytest
42from playwright .sync_api import Page , expect
53from pages .logout .log_out_page import Logout
64from pages .base_page import BasePage
75from pages .screening_practitioner_appointments .screening_practitioner_appointments import (
86 ScreeningPractitionerAppointmentsPage ,
97)
10- from pages .screening_practitioner_appointments .set_availability_page import (
11- SetAvailabilityPage ,
12- )
13- from pages .screening_practitioner_appointments .practitioner_availability_page import (
14- PractitionerAvailabilityPage ,
15- )
16- from pages .screening_practitioner_appointments .colonoscopy_assessment_appointments_page import (
17- ColonoscopyAssessmentAppointments ,
18- )
19- from pages .screening_practitioner_appointments .book_appointment_page import (
20- BookAppointmentPage ,
21- )
228from pages .screening_subject_search .subject_screening_summary import (
239 SubjectScreeningSummary ,
2410)
25- from pages .screening_subject_search .episode_events_and_notes_page import (
26- EpisodeEventsAndNotesPage ,
27- )
2811from utils .user_tools import UserTools
2912from utils .load_properties_file import PropertiesFile
13+ from utils .screening_subject_page_searcher import verify_subject_event_status_by_nhs_no
3014from utils .calendar_picker import CalendarPicker
31- from utils .batch_processing import batch_processing
32- from datetime import datetime
33- from sqlalchemy .orm import Session
15+ from datetime import datetime , timedelta
3416
3517
3618@pytest .fixture
3719def smokescreen_properties () -> dict :
3820 return PropertiesFile ().get_smokescreen_properties ()
3921
4022
41- # --------------
42- # DATA SETUP
43- # --------------
44-
45- # The data setup steps below have been translated directly from the selenium tests and need to be refactored
46-
47-
48- # Get required test data from the DB
49- def find_test_data (session : Session , region ):
50- all_data_found = True
51- error_message = ""
52-
53- required_number_of_kits = get_properties ().get_c5_number_of_appointments_to_attend (
54- region
55- )
56- if required_number_of_kits == 0 :
57- print ("application properties specifies Zero appointments" )
58- else :
59- print ("Finding recent appointments" )
60- appointments = (
61- session .query (Appointment )
62- .filter (
63- Appointment .org_id
64- == get_properties ().get_appointments_test_org_id (region ),
65- Appointment .kit_type == KitType .Any ,
66- )
67- .order_by (Appointment .date_created .desc ())
68- .limit (required_number_of_kits )
69- .all ()
70- )
71-
72- if not appointments or len (appointments ) < required_number_of_kits :
73- all_data_found = False
74- error_message = f"{ required_number_of_kits } appointments could not be found that had an abnormal result ({ region } ). Instead found { len (appointments )} "
75- print (
76- f"{ required_number_of_kits } appointments could not be found that had an abnormal result ({ region } )"
77- )
78- else :
79- print (f"{ len (appointments )} appointments found with abnormal results" )
80-
81- print (
82- f"Appointments found: { ', ' .join ([str (appointment .screening_subject .name_and_nhs_number ) for appointment in appointments ])} "
83- )
84-
85- return all_data_found , error_message , appointments
86-
87-
88- # Find subjects requiring screening outcomes
89- def test_find_subjects_requiring_screening_outcomes (setup_browser , region , page : Page ):
90- browser , _ = setup_browser
91- # Assume testData is initialized somewhere in your test setup.
92-
93- # Use SQLAlchemy session to fetch data
94- session = get_session (region ) # Replace with actual session setup
95- all_data_found , error_message , appointments = find_test_data (session , region )
96-
97- assert all_data_found , error_message
98-
99- logging .trace ("exit: findSubjectsRequiringScreeningOutcomes(region={})" , region )
100-
101- # --------------
102- # TEST STEPS
103- # --------------
104- @pytest .mark .vpn_required
105- @pytest .mark .smokescreen
106- @pytest .mark .compartment5
107- def test_compartment_5 (page : Page , smokescreen_properties : dict ) -> None :
108- """This is the main compartment 5 method"""
23+ @pytest .mark .vpn_required
24+ @pytest .mark .smokescreen
25+ @pytest .mark .compartment5
26+ def test_compartment_5 (page : Page , smokescreen_properties : dict ) -> None :
27+ """
28+ This is the main compartment 5 method
29+ """
10930
11031 # --------------
11132 # Attendance of Screening
@@ -114,117 +35,144 @@ def test_compartment_5(page: Page, smokescreen_properties: dict) -> None:
11435
11536 # Log in as a Screening Centre user
11637 UserTools .user_login (page , "Screening Centre Manager at BCS001" )
117- BasePage (page ).go_to_screening_practitioner_appointments_page ()
11838
11939 # From the Main Menu, choose the 'Screening Practitioner Appointments' and then 'View Appointments' option
40+ BasePage (page ).go_to_screening_practitioner_appointments_page ()
12041 ScreeningPractitionerAppointmentsPage (page ).go_to_view_appointments_page ()
12142
122- # Select the Appointment Type, Site, and Screening Practitioner
123- ScreeningPractitionerAppointmentsPage (page ).select_appointment_type (
124- "Any Practitioner Appointment"
125- )
126- ScreeningPractitionerAppointmentsPage (page ).select_site_dropdown_option (
127- "BCS001 - Wolverhampton Bowel Cancer Screening Centre"
128- )
129- ScreeningPractitionerAppointmentsPage (page ).select_practitioner_dropdown_option (
130- "Astonish, Ethanol"
43+ # Select the Appointment Type, Site, Screening Practitioner and required date of the appointment and click 'View appointments on this day' button
44+ page .locator ("#UI_APPOINTMENT_TYPE" ).select_option (label = "Colonoscopy Assessment" )
45+ page .locator ("#UI_SCREENING_CENTRE" ).select_option (
46+ label = "BCS001 - Wolverhampton Bowel Cancer Screening Centre"
13147 )
132- # Select the required date of the appointment
133- # TODO: Add logic to select the date of the appointmentonce the C4 calendar picker is implemented
134-
135- # Click 'View appointments on this day' button
136- ScreeningPractitionerAppointmentsPage (
137- page
138- ).click_view_appointments_on_this_day_button ()
139- # 'View Appointments' screen displayed
140- BasePage .bowel_cancer_screening_page_title_contains_text (
141- "Screening Practitioner Day View"
142- )
143-
144- # Select the first positive (abnormal ) patient
145- page .get_by_role ("link" , name = "SCALDING COD" ).click ()
146-
147-
148- # Select Attendance radio button, tick Attended checkbox,
149- # set Attended Date to yesterday's (system) date and then press Save
150- # Appointment attendance details saved Status set to J10
151-
152- # Repeat for the 2nd and 3rd Abnormal patients
153- # Appointment attendance details saved Status set to J10
154-
155- # --------------
156- # Invite for colonoscopy
157- # --------------
158- # Navigate to the 'Subject Screening Summary' screen for the 1st Abnormal patient
159- # ''Subject Screening Summary' screen of the 1st Abnormal patient is displayed
160-
161- # Click on 'Datasets' link
162- # 'There should be a '1 dataset' for Colonoscopy Assessment
163-
164- # Click on 'Show Dataset' next to the Colonoscopy Assessment
165- # Populate Colonoscopy Assessment Details fields
166- # ASA Grade - I - Fit
167- # Fit for Colonoscopy (SSP) - Yes
168- # Click 'Yes' for Dataset Complete?
169- # Click Save Dataset button
170- # Click Back
171- # Data set marked as **Completed**. The subject event status stays at J10.
48+ page .locator ("#UI_SITE" ).select_option (label = "The Royal Hospital (Wolverhampton)" )
17249
173- # On the Subject Screening Summary click on the 'Advance FOBT Screening Episode' button and then click on the 'Suitable for Endoscopic Test' button
174- # Click OK after message
175- # Pop up message states
176- # This will change the status to:
177- # A99 - Suitable for Endoscopic Test.
178- # No other pop up message should be displayed
50+ # Add calender util method for selecting date retrieved from inital test data util
17951
180- # Enter a 'First Offered Appointment Date' (enter a date after the attended appt)
181-
182- # Select 'Colonoscopy' from the 'Type of Test' from the drop down list
183-
184- # Click the 'Invite for Diagnostic Test >>' button
185- # Pop-up box displayed informing user that the patient will be set to A59 - Invited for Diagnostic Test
186-
187- # Click 'OK'
188- # Pop-box removed from screen
189- # 'Advance Screening Episode' redisplayed
190- # Status set to A59 - Invited for Diagnostic Test
191-
192- # Click 'Attend Diagnostic Test' button
52+ # Select subject from inital test data util
53+ page .get_by_role ("link" , name = "SCALDING COD" ).click ()
19354
194- # Select Colonoscopy from drop down list. Enter the actual appointment date as today's date and select 'Save'
195- # Status set to A259 - Attended Diagnostic Test
55+ # Select Attendance radio button, tick Attended checkbox, set Attended Date to yesterday's (system) date and then press Save
56+ page .get_by_role ("radio" , name = "Attendance" ).check ()
57+ page .locator ("#UI_ATTENDED" ).check ()
58+ page .get_by_role ("button" , name = "Calendar" ).click ()
59+ CalendarPicker (page ).v1_calender_picker (datetime .today () - timedelta (1 ))
60+ page .get_by_role ("button" , name = "Save" ).click ()
61+ expect (page .get_by_text ("Record updated" )).to_be_visible ()
19662
197- # Repeat for the 2nd & 3rd Abnormal patients
198- # Status set to A259 - Attended Diagnostic Test
63+ # Repeat for x Abnormal patients
19964
200- # --------------
201- # Advance the screening episode
202- # --------------
65+ # Navigate to the 'Subject Screening Summary' screen for the 1st Abnormal patient
66+ nhs_no = "9934032236" # Test NHS NO for Scaliding Cod
67+ verify_subject_event_status_by_nhs_no (
68+ page , nhs_no , "J10 - Attended Colonoscopy Assessment Appointment"
69+ )
20370
204- # Click on 'Advance FOBT Screening Episode' button for the 1st Abnormal patient
71+ # Click on 'Datasets' link
72+ page .get_by_role ("link" , name = "Datasets" ).click ()
73+
74+ # Click on 'Show Dataset' next to the Colonoscopy Assessment
75+
76+ # Populate Colonoscopy Assessment Details fields
77+
78+ # ASA Grade - I - Fit
79+ # Fit for Colonoscopy (SSP) - Yes
80+
81+ # Click 'Yes' for Dataset Complete?
82+ # Click Save Dataset button
83+ # Click Back
84+ page .get_by_role ("link" , name = "Show Dataset" ).click ()
85+ page .get_by_label ("ASA Grade" ).select_option ("17009" )
86+ page .get_by_label ("Fit for Colonoscopy (SSP)" ).select_option ("17058" )
87+ page .get_by_role ("radio" , name = "Yes" ).check ()
88+ page .locator ("#UI_DIV_BUTTON_SAVE1" ).get_by_role (
89+ "button" , name = "Save Dataset"
90+ ).click ()
91+ BasePage (page ).click_back_button ()
92+ BasePage (page ).click_back_button ()
93+ # This brings you back to the subject screening summary page
94+
95+ # On the Subject Screening Summary click on the 'Advance FOBT Screening Episode' button and then click on the 'Suitable for Endoscopic Test' button
96+ # Click OK after message
97+ page .get_by_role ("button" , name = "Advance FOBT Screening Episode" ).click ()
98+ page .once ("dialog" , lambda dialog : dialog .dismiss ())
99+ page .get_by_role ("button" , name = "Suitable for Endoscopic Test" ).click ()
100+
101+ # Enter a 'First Offered Appointment Date' (enter a date after the attended appt)
102+ page .get_by_role ("button" , name = "Calendar" ).click ()
103+ CalendarPicker (page ).v1_calender_picker (datetime .today ())
104+
105+ # Select 'Colonoscopy' from the 'Type of Test' from the drop down list
106+ page .locator ("#UI_EXT_TEST_TYPE_2233" ).select_option (label = "Colonoscopy" )
107+
108+ # Click the 'Invite for Diagnostic Test >>' button
109+ # Click 'OK'
110+ page .once ("dialog" , lambda dialog : dialog .dismiss ())
111+ page .get_by_role ("button" , name = "Invite for Diagnostic Test >>" ).click ()
112+ SubjectScreeningSummary (page ).verify_latest_event_status_value (
113+ "A59 - Invited for Diagnostic Test"
114+ )
205115
206- # Click 'Other Post-investigation Contact Required ' button
207- # Confirmation pop-up box displayed
116+ # Click 'Attend Diagnostic Test ' button
117+ page . get_by_role ( "button" , name = "Attend Diagnostic Test" ). click ()
208118
209- # Click 'OK'
210- # Status set to A361 - Other Post-investigation Contact Required'Advance FOBT Screening Episode' screen re-displayed
119+ # Select Colonoscopy from drop down list. Enter the actual appointment date as today's date and select 'Save'
120+ page .locator ("#UI_CONFIRMED_TYPE_OF_TEST" ).select_option (label = "Colonoscopy" )
121+ page .get_by_role ("button" , name = "Calendar" ).click ()
122+ CalendarPicker (page ).v1_calender_picker (datetime .today ())
123+ page .get_by_role ("button" , name = "Save" ).click ()
124+ SubjectScreeningSummary (page ).verify_latest_event_status_value (
125+ "A259 - Attended Diagnostic Test"
126+ )
127+ # Repeat above for x number of subjects
211128
212- # Select 'Record other post-investigation contact' button
213- # 'Contact with Patient' screen displayed
129+ # Click on 'Advance FOBT Screening Episode' button for the 1st Abnormal patient
130+ verify_subject_event_status_by_nhs_no (
131+ page , nhs_no , "A259 - Attended Diagnostic Test"
132+ )
133+ page .get_by_role ("button" , name = "Advance FOBT Screening Episode" ).click ()
134+
135+ # Click 'Other Post-investigation Contact Required' button
136+ # Click 'OK'
137+ page .once ("dialog" , lambda dialog : dialog .dismiss ())
138+ page .get_by_role ("button" , name = "Other Post-investigation" ).click ()
139+ expect (
140+ page .get_by_role (
141+ "cell" , name = "A361 - Other Post-investigation Contact Required" , exact = True
142+ )
143+ ).to_be_visible ()
144+
145+ # Select 'Record other post-investigation contact' button
146+ page .get_by_role ("button" , name = "Record other post-" ).click ()
147+
148+ # Complete 'Contact Direction', To patient
149+ # 'Contact made between patient and', Selects the top option in the dropdown
150+ # 'Date of Patient Contact', Today
151+ # 'Duration', 01:00
152+ # 'Start Time', 11:00
153+ # 'End Time', 12:00
154+ # 'Discussion Record' TEST AUTOMATION
155+ # select 'Outcome' - 'Post-investigation Appointment Not Required' and click 'Save'
156+ page .locator ("#UI_DIRECTION" ).select_option (label = "To patient" )
157+ page .locator ("#UI_CALLER_ID" ).select_option (index = 0 )
158+ page .get_by_role ("button" , name = "Calendar" ).click ()
159+ page .get_by_role ("cell" , name = "29" , exact = True ).click ()
160+ page .locator ("#UI_START_TIME" ).click ()
161+ page .locator ("#UI_START_TIME" ).fill ("11:00" )
162+ page .locator ("#UI_END_TIME" ).click ()
163+ page .locator ("#UI_END_TIME" ).fill ("12:00" )
164+ page .locator ("#UI_COMMENT_ID" ).click ()
165+ page .locator ("#UI_COMMENT_ID" ).fill ("Test Automation" )
166+ page .locator ("#UI_OUTCOME" ).select_option (
167+ label = "Post-investigation Appointment Not Required"
168+ )
169+ page .get_by_role ("button" , name = "Save" ).click ()
214170
215- # Complete 'Contact Direction',
216- # 'Contact made between patient and',
217- # 'Date of Patient Contact',
218- # 'Start Time', 'End Time',
219- # 'Discussion Record' and
220- # select 'Outcome' - 'Post-investigation Appointment Not Required'
221- # and click 'Save'
222- # ''Contact with Patient' screen re-displayed readonly
171+ # Click 'Back' link
172+ BasePage (page ).click_back_button ()
173+ BasePage (page ).click_back_button ()
174+ # This brings you back to the subject search criteria page
223175
224- # Click 'Back' button
225- # ''Subject Screening Summary' screen displayed
226- # Status set to A323 - Post-investigation Appointment NOT Required
176+ # Repeat above for x subjects
227177
228- # Repeat for the 2nd & 3rd Abnormal patients
229- # ''Subject Screening Summary' screen displayed
230- # Status set to A323 - Post-investigation Appointment NOT Required
178+ Logout (page ).log_out ()
0 commit comments