|
| 1 | +import pytest |
| 2 | +from playwright.sync_api import Page, expect |
| 3 | +from pages.base_page import BasePage |
| 4 | +from utils.user_tools import UserTools |
| 5 | +from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no |
| 6 | +from pages.screening_subject_search.subject_screening_summary_page import ( |
| 7 | + SubjectScreeningSummaryPage, |
| 8 | +) |
| 9 | +from utils.batch_processing import batch_processing |
| 10 | +from pages.logout.log_out_page import LogoutPage |
| 11 | +from pages.datasets.subject_datasets_page import SubjectDatasetsPage |
| 12 | + |
| 13 | + |
| 14 | +# This should go into a util. Adding it here to avoid SonarQube duplication errors: |
| 15 | +def go_to_investigation_datasets_page(page: Page, nhs_no) -> None: |
| 16 | + verify_subject_event_status_by_nhs_no( |
| 17 | + page, nhs_no, "A323 - Post-investigation Appointment NOT Required" |
| 18 | + ) |
| 19 | + |
| 20 | + SubjectScreeningSummaryPage(page).click_datasets_link() |
| 21 | + SubjectDatasetsPage(page).click_investigation_show_datasets() |
| 22 | + |
| 23 | + |
| 24 | +def investigation_dataset_forms(page: Page) -> None: |
| 25 | + page.locator("#UI_SITE_SELECT_LINK").click() |
| 26 | + page.locator("#UI_RESULTS_rljsjnkh").select_option("35317") |
| 27 | + page.locator("#UI_SSP_PIO_SELECT_LINK").click() |
| 28 | + page.locator("#UI_RESULTS_okdvpfko").select_option("1251") |
| 29 | + page.locator("#UI_CONSULTANT_PIO_SELECT_LINK").click() |
| 30 | + page.locator("#UI_RESULTS_sawaeghr").select_option("886") |
| 31 | + page.locator("#UI_ASPIRANT_ENDOSCOPIST_PIO_SELECT_LINK").click() |
| 32 | + page.locator("#anchorDrug").click() |
| 33 | + page.locator("#UI_BOWEL_PREP_DRUG1").select_option("200537~Tablet(s)") |
| 34 | + page.locator("#UI_BOWEL_PREP_DRUG_DOSE1").click() |
| 35 | + page.locator("#UI_BOWEL_PREP_DRUG_DOSE1").fill("10") |
| 36 | + page.get_by_role("link", name="Show details").click() |
| 37 | + page.locator("#radScopeInsertedYes").check() |
| 38 | + page.get_by_role("radio", name="Therapeutic").check() |
| 39 | + page.get_by_label("Bowel preparation quality").select_option("17016") |
| 40 | + page.get_by_label("Comfort during examination").select_option("18505") |
| 41 | + page.get_by_label("Comfort during recovery").select_option("18505") |
| 42 | + page.get_by_label("Endoscopist defined extent").select_option( |
| 43 | + "17240~Colonoscopy Complete" |
| 44 | + ) |
| 45 | + page.get_by_label("Scope imager used").select_option("17058") |
| 46 | + page.get_by_label("Retroverted view").select_option("17059") |
| 47 | + page.get_by_role("textbox", name="Start of intubation time").click() |
| 48 | + page.get_by_role("textbox", name="Start of intubation time").fill("09:00") |
| 49 | + page.get_by_role("textbox", name="Start of extubation time").click() |
| 50 | + page.get_by_role("textbox", name="Start of extubation time").fill("09:15") |
| 51 | + page.get_by_role("textbox", name="End time of procedure").click() |
| 52 | + page.get_by_role("textbox", name="End time of procedure").fill("09:30") |
| 53 | + page.get_by_role("textbox", name="Scope ID").click() |
| 54 | + page.get_by_role("textbox", name="Scope ID").fill("A1") |
| 55 | + page.get_by_label("Insufflation").select_option("200547") |
| 56 | + page.get_by_label("Outcome at time of procedure").select_option( |
| 57 | + "17148~Complications are optional" |
| 58 | + ) |
| 59 | + page.get_by_label("Late outcome").select_option( |
| 60 | + "17216~Complications are not required" |
| 61 | + ) |
| 62 | + page.locator("#anchorCompletionProof").click() |
| 63 | + page.get_by_label("Proof Parameters").select_option("200575") |
| 64 | + |
| 65 | + |
| 66 | +def investigation_datasets_failure_reason_and_adding_initial_polyp(page: Page) -> None: |
| 67 | + page.locator("#anchorFailure").click() |
| 68 | + page.get_by_label("Failure Reasons").select_option("205148") |
| 69 | + page.get_by_role("button", name="Add Polyp").click() |
| 70 | + page.locator("#UI_POLYP_LOCATION1").select_option("17240~Colonoscopy Complete") |
| 71 | + page.get_by_label("Classification ?").select_option("17295") |
| 72 | + page.get_by_role("textbox", name="Estimate of whole polyp size").click() |
| 73 | + |
| 74 | + |
| 75 | +@pytest.mark.vpn_required |
| 76 | +@pytest.mark.smokescreen |
| 77 | +@pytest.mark.compartment5 |
| 78 | +def test_compartment_5(page: Page, smokescreen_properties: dict) -> None: |
| 79 | + """ |
| 80 | + This is the main compartment 6 method |
| 81 | + Filling out the investigation datasets for different subjects to get different results for a diagnostic test. |
| 82 | + Printing the diagnostic test result letters. |
| 83 | + """ |
| 84 | + |
| 85 | + # For the following tests old refers to if they are over 75 at recall |
| 86 | + # The recall period is 2 years from the last diagnostic test for a Normal or Abnormal diagnostic test result |
| 87 | + # or 3 years for someone who is going in to Surveillance (High-risk findings or LNPCP) |
| 88 | + |
| 89 | + UserTools.user_login(page, "Screening Centre Manager at BCS001") |
| 90 | + |
| 91 | + # This needs to be repeated for two subjects, one old and one not - High Risk Result |
| 92 | + nhs_no = "9619187075" # Dummy NHS Number (will not work) |
| 93 | + go_to_investigation_datasets_page(page, nhs_no) |
| 94 | + |
| 95 | + # The following code is on the investigation datasets page |
| 96 | + investigation_dataset_forms(page) |
| 97 | + investigation_datasets_failure_reason_and_adding_initial_polyp(page) |
| 98 | + page.get_by_role("textbox", name="Estimate of whole polyp size").fill("15") |
| 99 | + page.get_by_label("Polyp Access").select_option("17060") |
| 100 | + page.get_by_role("link", name="Add Intervention").click() |
| 101 | + page.locator("#UI_POLYP_THERAPY_MODALITY1_1").select_option("17189~Resection") |
| 102 | + page.locator("#UI_DEVICE1_1").select_option("17070") |
| 103 | + page.get_by_label("Excised").select_option("17058") |
| 104 | + page.get_by_label("Retrieved").select_option("17059") |
| 105 | + page.get_by_label("Excision Technique").select_option("17751") |
| 106 | + page.get_by_role("button", name="Add Polyp").click() |
| 107 | + page.locator("#UI_POLYP_LOCATION2").select_option("17239~Colonoscopy Complete") |
| 108 | + page.locator("#UI_POLYP_CLASS2").select_option("17295") |
| 109 | + page.locator("#UI_POLYP_SIZE2").click() |
| 110 | + page.locator("#UI_POLYP_SIZE2").fill("15") |
| 111 | + page.locator("#UI_POLYP_ACCESS2").select_option("17060") |
| 112 | + page.locator("#spanPolypInterventionLink2").get_by_role( |
| 113 | + "link", name="Add Intervention" |
| 114 | + ).click() |
| 115 | + page.locator("#UI_POLYP_THERAPY_MODALITY2_1").select_option("17193~Resection") |
| 116 | + page.locator("#UI_DEVICE2_1").select_option("17070") |
| 117 | + page.locator("#UI_POLYP_RESECTED2_1").select_option("17058") |
| 118 | + page.locator("#UI_POLYP_RETRIEVED2_1").select_option("17059") |
| 119 | + page.locator("#UI_POLYP_REMOVAL_TYPE2_1").select_option("17751") |
| 120 | + page.locator("#radDatasetCompleteYes").check() |
| 121 | + page.once("dialog", lambda dialog: dialog.accept()) |
| 122 | + page.locator("#UI_DIV_BUTTON_SAVE1").get_by_role( |
| 123 | + "button", name="Save Dataset" |
| 124 | + ).click() |
| 125 | + |
| 126 | + expect(page.get_by_text("High-risk findings")).to_be_visible() |
| 127 | + BasePage(page).click_back_button() |
| 128 | + |
| 129 | + # The following code is on the subject datasets page |
| 130 | + expect(page.get_by_text("** Completed **").nth(1)).to_be_visible() |
| 131 | + BasePage(page).click_back_button() |
| 132 | + |
| 133 | + SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button() |
| 134 | + # The following code is on the advance fobt screening episode page |
| 135 | + page.get_by_role("button", name="Enter Diagnostic Test Outcome").click() |
| 136 | + # The following code is on the diagnostic test outcome page |
| 137 | + expect(page.get_by_role("cell", name="High-risk findings").nth(1)).to_be_visible() |
| 138 | + page.get_by_label("Outcome of Diagnostic Test").select_option("20365") |
| 139 | + page.get_by_role("button", name="Save").click() |
| 140 | + |
| 141 | + # This is if the subject is too old |
| 142 | + SubjectScreeningSummaryPage(page).verify_latest_event_status_value( |
| 143 | + "A394 - Handover into Symptomatic Care for Surveillance - Patient Age" |
| 144 | + ) |
| 145 | + SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button() |
| 146 | + |
| 147 | + # The following code is on the advance fobt screening episode page |
| 148 | + page.get_by_role("button", name="Handover into Symptomatic Care").click() |
| 149 | + |
| 150 | + # The following code is on the handover into symptomatic care page |
| 151 | + page.get_by_label("Referral").select_option("20445") |
| 152 | + page.get_by_role("button", name="Calendar").click() |
| 153 | + page.get_by_role( |
| 154 | + "cell", name="9", exact=True |
| 155 | + ).click() # Todays date (v1 calendar picker) |
| 156 | + page.locator("#UI_NS_CONSULTANT_PIO_SELECT_LINK").click() |
| 157 | + page.locator("#UI_RESULTS_usgwmbob").select_option("201") |
| 158 | + page.locator("#UI_NS_PRACTITIONER_PIO_SELECT_LINK").click() |
| 159 | + page.get_by_role("textbox", name="Notes").click() |
| 160 | + page.get_by_role("textbox", name="Notes").fill("Test Automation") |
| 161 | + page.once("dialog", lambda dialog: dialog.accept()) |
| 162 | + page.get_by_role("button", name="Save").click() |
| 163 | + |
| 164 | + SubjectScreeningSummaryPage(page).verify_latest_event_status_value( |
| 165 | + "A385 - Handover into Symptomatic Care" |
| 166 | + ) |
| 167 | + |
| 168 | + # This is if the subject is not too old |
| 169 | + SubjectScreeningSummaryPage(page).verify_latest_event_status_value( |
| 170 | + "A318 - Post-investigation Appointment NOT Required - Result Letter Created" |
| 171 | + ) |
| 172 | + SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button() |
| 173 | + |
| 174 | + # The following code is on the advance fobt screening episode page |
| 175 | + page.get_by_role("button", name="Record Diagnosis Date").click() |
| 176 | + |
| 177 | + # The following code is on the record diagnosis date page |
| 178 | + page.locator("#diagnosisDate").click() |
| 179 | + page.locator("#diagnosisDate").fill("09 May 2025") # Todays date |
| 180 | + page.get_by_role("button", name="Save").click() |
| 181 | + |
| 182 | + SubjectScreeningSummaryPage(page).verify_latest_event_status_value( |
| 183 | + "A318 - Post-investigation Appointment NOT Required - Result Letter Created" |
| 184 | + ) |
| 185 | + |
| 186 | + # This needs to be repeated for two subjects, one old and one not - LBPCP Result |
| 187 | + nhs_no = "9619187076" # Dummy NHS Number (will not work) |
| 188 | + go_to_investigation_datasets_page(page, nhs_no) |
| 189 | + |
| 190 | + # The following code is on the investigation datasets page |
| 191 | + investigation_dataset_forms(page) |
| 192 | + investigation_datasets_failure_reason_and_adding_initial_polyp(page) |
| 193 | + page.get_by_role("textbox", name="Estimate of whole polyp size").fill("30") |
| 194 | + page.get_by_label("Polyp Access").select_option("17060") |
| 195 | + page.get_by_role("link", name="Add Intervention").click() |
| 196 | + page.locator("#UI_POLYP_THERAPY_MODALITY1_1").select_option("17189~Resection") |
| 197 | + page.locator("#UI_DEVICE1_1").select_option("17070") |
| 198 | + page.get_by_label("Excised").select_option("17058") |
| 199 | + page.get_by_label("Retrieved").select_option("17059") |
| 200 | + page.get_by_label("Excision Technique").select_option("17751") |
| 201 | + page.locator("#radDatasetCompleteYes").check() |
| 202 | + page.once("dialog", lambda dialog: dialog.accept()) |
| 203 | + page.locator("#UI_DIV_BUTTON_SAVE1").get_by_role( |
| 204 | + "button", name="Save Dataset" |
| 205 | + ).click() |
| 206 | + |
| 207 | + expect(page.get_by_text("LNPCP")).to_be_visible() |
| 208 | + BasePage(page).click_back_button() |
| 209 | + |
| 210 | + # The following code is on the subject datasets page |
| 211 | + expect(page.get_by_text("** Completed **").nth(1)).to_be_visible() |
| 212 | + BasePage(page).click_back_button() |
| 213 | + |
| 214 | + SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button() |
| 215 | + |
| 216 | + # The following code is on the advance fobt screening episode page |
| 217 | + page.get_by_role("button", name="Enter Diagnostic Test Outcome").click() |
| 218 | + |
| 219 | + # The following code is on the diagnostic test outcome page |
| 220 | + expect(page.get_by_role("cell", name="LNPCP").nth(1)).to_be_visible() |
| 221 | + page.get_by_label("Outcome of Diagnostic Test").select_option("20365") |
| 222 | + page.get_by_role("button", name="Save").click() |
| 223 | + |
| 224 | + # If the subject is too old |
| 225 | + SubjectScreeningSummaryPage(page).verify_latest_event_status_value( |
| 226 | + "A394 - Handover into Symptomatic Care for Surveillance - Patient Age" |
| 227 | + ) |
| 228 | + SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button() |
| 229 | + |
| 230 | + # The following code is on the advance fobt screening episode page |
| 231 | + page.get_by_role("button", name="Handover into Symptomatic Care").click() |
| 232 | + |
| 233 | + # The following code is on the handover into symptomatic care page |
| 234 | + page.get_by_label("Referral").select_option("20445") |
| 235 | + page.get_by_role("button", name="Calendar").click() |
| 236 | + page.get_by_role( |
| 237 | + "cell", name="9", exact=True |
| 238 | + ).click() # Todays date (v1 calendar picker) |
| 239 | + page.locator("#UI_NS_CONSULTANT_PIO_SELECT_LINK").click() |
| 240 | + page.locator("#UI_RESULTS_ktdtoepq").select_option("201") |
| 241 | + page.locator("#UI_NS_PRACTITIONER_PIO_SELECT_LINK").click() |
| 242 | + page.get_by_role("textbox", name="Notes").click() |
| 243 | + page.get_by_role("textbox", name="Notes").fill("Test Automation") |
| 244 | + page.once("dialog", lambda dialog: dialog.accept()) |
| 245 | + page.get_by_role("button", name="Save").click() |
| 246 | + |
| 247 | + SubjectScreeningSummaryPage(page).verify_latest_event_status_value( |
| 248 | + "A385 - Handover into Symptomatic Care" |
| 249 | + ) |
| 250 | + |
| 251 | + # If the subject is not too old |
| 252 | + SubjectScreeningSummaryPage(page).verify_latest_event_status_value( |
| 253 | + "A318 - Post-investigation Appointment NOT Required - Result Letter Created" |
| 254 | + ) |
| 255 | + SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button() |
| 256 | + |
| 257 | + # The following code is on the advance fobt screening episode page |
| 258 | + page.get_by_role("button", name="Record Diagnosis Date").click() |
| 259 | + |
| 260 | + # The following code is on the record diagnosis date page |
| 261 | + page.locator("#diagnosisDate").click() |
| 262 | + page.locator("#diagnosisDate").fill("09 May 2025") # Todays date |
| 263 | + page.get_by_role("button", name="Save").click() |
| 264 | + |
| 265 | + SubjectScreeningSummaryPage(page).verify_latest_event_status_value( |
| 266 | + "A318 - Post-investigation Appointment NOT Required - Result Letter Created" |
| 267 | + ) |
| 268 | + |
| 269 | + # This needs to be repeated for 1 subject, age does not matter - Normal Result |
| 270 | + nhs_no = "9619187077" # Dummy NHS Number (will not work) |
| 271 | + go_to_investigation_datasets_page(page, nhs_no) |
| 272 | + |
| 273 | + # The following code is on the investigation datasets page |
| 274 | + investigation_dataset_forms(page) |
| 275 | + page.locator("#anchorFailure").click() |
| 276 | + page.get_by_label("Failure Reasons").select_option("18500") |
| 277 | + page.locator("#radDatasetCompleteYes").check() |
| 278 | + page.once("dialog", lambda dialog: dialog.dismiss()) |
| 279 | + page.locator("#UI_DIV_BUTTON_SAVE1").get_by_role( |
| 280 | + "button", name="Save Dataset" |
| 281 | + ).click() |
| 282 | + expect(page.get_by_text("Normal (No Abnormalities")).to_be_visible() |
| 283 | + BasePage(page).click_back_button() |
| 284 | + |
| 285 | + # The following code is on the subject datasets page |
| 286 | + expect(page.get_by_text("** Completed **").nth(1)).to_be_visible() |
| 287 | + BasePage(page).click_back_button() |
| 288 | + |
| 289 | + SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button() |
| 290 | + |
| 291 | + # The following code is on the advance fobt screening episode page |
| 292 | + page.get_by_role("button", name="Enter Diagnostic Test Outcome").click() |
| 293 | + |
| 294 | + # The following code is on the diagnostic test outcome page |
| 295 | + expect( |
| 296 | + page.get_by_role("cell", name="Normal (No Abnormalities").nth(1) |
| 297 | + ).to_be_visible() |
| 298 | + page.get_by_label("Outcome of Diagnostic Test").select_option("") |
| 299 | + page.get_by_label("Outcome of Diagnostic Test").select_option("20360") |
| 300 | + page.get_by_role("button", name="Save").click() |
| 301 | + |
| 302 | + SubjectScreeningSummaryPage(page).verify_latest_event_status_value( |
| 303 | + "A318 - Post-investigation Appointment NOT Required - Result Letter Created" |
| 304 | + ) |
| 305 | + SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button() |
| 306 | + |
| 307 | + # The following code is on the advance fobt screening episode page |
| 308 | + page.get_by_role("button", name="Record Diagnosis Date").click() |
| 309 | + |
| 310 | + # The following code is on the record diagnosis date page |
| 311 | + page.locator("#diagnosisDate").click() |
| 312 | + page.locator("#diagnosisDate").fill("09 May 2025") # Todays date |
| 313 | + page.get_by_role("button", name="Save").click() |
| 314 | + |
| 315 | + # Modification needs to be done to accept this list. it should check if any of the values in this list are present. Something like the following: |
| 316 | + # def get_first_visible_cell(page, values): |
| 317 | + # if isinstance(values, str): |
| 318 | + # values = [values] |
| 319 | + # for name in values: |
| 320 | + # locator = page.get_by_role("cell", name=name) |
| 321 | + # if locator.is_visible(): |
| 322 | + # return locator |
| 323 | + |
| 324 | + batch_processing( |
| 325 | + page, |
| 326 | + "A318", |
| 327 | + "Result Letters - No Post-investigation Appointment", |
| 328 | + [ |
| 329 | + "S61 - Normal (No Abnormalities Found)", |
| 330 | + "A158 - High-risk findings", |
| 331 | + "A157 - LNPCP", |
| 332 | + ], |
| 333 | + ) |
| 334 | + |
| 335 | + batch_processing( |
| 336 | + page, |
| 337 | + "A385", |
| 338 | + "Handover into Symptomatic Care Adenoma Surveillance, Age - GP Letter", |
| 339 | + "A382 - Handover into Symptomatic Care - GP Letter Printed", |
| 340 | + ) |
| 341 | + |
| 342 | + batch_processing( |
| 343 | + page, |
| 344 | + "A382", |
| 345 | + "Handover into Symptomatic Care Adenoma Surveillance - Patient Letter", |
| 346 | + "P202 - Waiting Completion of Outstanding Events", |
| 347 | + ) |
| 348 | + |
| 349 | + LogoutPage(page).log_out() |
0 commit comments