diff --git a/pages/datasets/investigation_dataset_page.py b/pages/datasets/investigation_dataset_page.py index 7bfd0171..e8609c8e 100644 --- a/pages/datasets/investigation_dataset_page.py +++ b/pages/datasets/investigation_dataset_page.py @@ -386,7 +386,7 @@ def click_edit_dataset_button(self) -> None: """ self.click(self.edit_dataset_button) - def assert_polyp_alogrithm_size( + def assert_polyp_algorithm_size( self, polyp_number: int, expected_value: Optional[str] ) -> None: """ @@ -418,7 +418,7 @@ def assert_polyp_alogrithm_size( str(actual_value).strip() == str(expected_value).strip() ), f"Expected '{expected_value}', but got '{actual_value}'" - def assert_polyp_categrory( + def assert_polyp_category( self, polyp_number: int, expected_value: Optional[str] ) -> None: """ diff --git a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_advanced_colorectal_polyp.py b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_advanced_colorectal_polyp.py index 88aa4ce6..83983bdd 100644 --- a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_advanced_colorectal_polyp.py +++ b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_advanced_colorectal_polyp.py @@ -5,15 +5,8 @@ from playwright.sync_api import Page from pages.base_page import BasePage from pages.datasets.investigation_dataset_page import ( - InvestigationDatasetsPage, - DrugTypeOptions, - BowelPreparationQualityOptions, - ComfortOptions, EndoscopyLocationOptions, YesNoOptions, - InsufflationOptions, - OutcomeAtTimeOfProcedureOptions, - LateOutcomeOptions, CompletionProofOptions, FailureReasonsOptions, PolypClassificationOptions, @@ -29,7 +22,6 @@ YesNoUncertainOptions, ) from pages.datasets.subject_datasets_page import SubjectDatasetsPage -from pages.logout.log_out_page import LogoutPage from pages.screening_subject_search.subject_screening_summary_page import ( SubjectScreeningSummaryPage, ) @@ -44,39 +36,20 @@ go_from_investigation_dataset_complete_to_a259_status, get_subject_with_a99_status, go_from_a99_status_to_a259_status, + get_default_endoscopy_information, + get_default_drug_information, + get_default_general_information, + complete_and_assert_investigation, ) from utils.user_tools import UserTools # Defining dictionaries used in tests -general_information = { - "site": -1, - "practitioner": -1, - "testing clinician": -1, - "aspirant endoscopist": None, -} +general_information = get_default_general_information() -drug_information = { - "drug_type1": DrugTypeOptions.MANNITOL, - "drug_dose1": "3", -} +drug_information = get_default_drug_information() -endoscopy_information = { - "endoscope inserted": "yes", - "procedure type": "therapeutic", - "bowel preparation quality": BowelPreparationQualityOptions.GOOD, - "comfort during examination": ComfortOptions.NO_DISCOMFORT, - "comfort during recovery": ComfortOptions.NO_DISCOMFORT, - "endoscopist defined extent": EndoscopyLocationOptions.APPENDIX, - "scope imager used": YesNoOptions.YES, - "retroverted view": YesNoOptions.NO, - "start of intubation time": "09:00", - "start of extubation time": "09:30", - "end time of procedure": "10:00", - "scope id": "Autotest", - "insufflation": InsufflationOptions.AIR, - "outcome at time of procedure": OutcomeAtTimeOfProcedureOptions.LEAVE_DEPARTMENT, - "late outcome": LateOutcomeOptions.NO_COMPLICATIONS, -} +endoscopy_information = get_default_endoscopy_information() +endoscopy_information["endoscopist defined extent"] = EndoscopyLocationOptions.APPENDIX failure_information = { "failure reasons": FailureReasonsOptions.ADHESION, @@ -86,6 +59,8 @@ "completion proof": CompletionProofOptions.VIDEO_APPENDIX, } +category_as_string = "Advanced colorectal polyp" + @pytest.fixture(autouse=True) def before_test(page: Page, request: FixtureRequest) -> None: @@ -137,22 +112,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_a(page: Page) -> None ) del polyp_1_histology["adenoma sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="9", ) - assert_test_results(page, "9") - @pytest.mark.vpn_required @pytest.mark.regression @@ -182,22 +154,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_b(page: Page) -> None ) del polyp_1_histology["adenoma sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="8", ) - assert_test_results(page, "8") - @pytest.mark.vpn_required @pytest.mark.regression @@ -223,22 +192,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_c(page: Page) -> None polyp_1_histology = make_polyp_1_histology() del polyp_1_histology["adenoma sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="10", ) - assert_test_results(page, "10") - @pytest.mark.vpn_required @pytest.mark.regression @@ -268,22 +234,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_d(page: Page) -> None ) del polyp_1_histology["adenoma sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="11", ) - assert_test_results(page, "11") - @pytest.mark.vpn_required @pytest.mark.regression @@ -318,22 +281,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_e(page: Page) -> None del polyp_1_histology["polyp carcinoma"] del polyp_1_histology["adenoma sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="11", ) - assert_test_results(page, "11") - @pytest.mark.vpn_required @pytest.mark.regression @@ -365,22 +325,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_f(page: Page) -> None del polyp_1_histology["polyp dysplasia"] del polyp_1_histology["adenoma sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="10", ) - assert_test_results(page, "10") - @pytest.mark.vpn_required @pytest.mark.regression @@ -410,22 +367,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_g(page: Page) -> None ) del polyp_1_histology["serrated lesion sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="10", ) - assert_test_results(page, "10") - @pytest.mark.vpn_required @pytest.mark.regression @@ -457,22 +411,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_h(page: Page) -> None ) del polyp_1_histology["serrated lesion sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="12", ) - assert_test_results(page, "12") - @pytest.mark.vpn_required @pytest.mark.regression @@ -507,22 +458,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_i(page: Page) -> None ) del polyp_1_histology["serrated lesion sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="11", ) - assert_test_results(page, "11") - @pytest.mark.vpn_required @pytest.mark.regression @@ -551,22 +499,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_j(page: Page) -> None ) del polyp_1_histology["serrated lesion sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="13", ) - assert_test_results(page, "13") - @pytest.mark.vpn_required @pytest.mark.regression @@ -597,22 +542,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_k(page: Page) -> None ) del polyp_1_histology["adenoma sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="7", ) - assert_test_results(page, "7") - @pytest.mark.vpn_required @pytest.mark.regression @@ -644,22 +586,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_l(page: Page) -> None ) del polyp_1_histology["adenoma sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="6", ) - assert_test_results(page, "6") - @pytest.mark.vpn_required @pytest.mark.regression @@ -691,22 +630,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_m(page: Page) -> None ) del polyp_1_histology["serrated lesion sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="5", ) - assert_test_results(page, "5") - @pytest.mark.vpn_required @pytest.mark.regression @@ -740,22 +676,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_n(page: Page) -> None ) del polyp_1_histology["serrated lesion sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="4", ) - assert_test_results(page, "4") - @pytest.mark.vpn_required @pytest.mark.regression @@ -790,22 +723,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_o(page: Page) -> None ) del polyp_1_histology["serrated lesion sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="3", ) - assert_test_results(page, "3") - @pytest.mark.vpn_required @pytest.mark.regression @@ -838,22 +768,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_p(page: Page) -> None ) del polyp_1_histology["serrated lesion sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="2", ) - assert_test_results(page, "2") - @pytest.mark.vpn_required @pytest.mark.regression @@ -885,22 +812,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_q(page: Page) -> None ) del polyp_1_histology["serrated lesion sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="20", ) - assert_test_results(page, "20") - @pytest.mark.vpn_required @pytest.mark.regression @@ -964,18 +888,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_r(page: Page) -> None SubjectScreeningSummaryPage(page).click_datasets_link() SubjectDatasetsPage(page).click_investigation_show_datasets() - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="6", ) - assert_test_results(page, "6") - @pytest.mark.vpn_required @pytest.mark.regression @@ -1005,22 +930,19 @@ def test_identify_advanced_colorectal_polyp_from_histology_s(page: Page) -> None ) del polyp_1_histology["adenoma sub type"] - polyp_information = [polyp_1_information] - polyp_intervention = [polyp_1_intervention] - polyp_histology = [polyp_1_histology] - - InvestigationDatasetCompletion(page).complete_dataset_with_args( - general_information=general_information, - drug_information=drug_information, - endoscopy_information=endoscopy_information, - failure_information=failure_information, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=category_as_string, + expected_size="32", ) - assert_test_results(page, "32") - def make_polyp_1_information(**overrides): """ @@ -1098,25 +1020,3 @@ def make_polyp_1_histology(**overrides): } data.update(overrides) return data - - -def assert_test_results(page: Page, expected_size: str) -> None: - """ - This function asserts that the polyp algorithm size and category match the expected values. - """ - logging.info( - f"Asserting test results\nExpected result: Abnormal\nExpected size: {expected_size}\nExpected category: Advanced colorectal polyp" - ) - InvestigationDatasetsPage(page).expect_text_to_be_visible("Abnormal") - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, expected_size) - InvestigationDatasetsPage(page).assert_polyp_categrory( - 1, "Advanced colorectal polyp" - ) - InvestigationDatasetsPage(page).click_edit_dataset_button() - InvestigationDatasetsPage(page).check_dataset_incomplete_checkbox() - InvestigationDatasetsPage(page).click_save_dataset_button() - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, None) - InvestigationDatasetsPage(page).assert_polyp_categrory(1, None) - logging.info("Test results asserted successfully.") - - LogoutPage(page).log_out() diff --git a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_diminutive_rectal_hyperplastic_polyp.py b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_diminutive_rectal_hyperplastic_polyp.py index 0c5613ca..9f71e113 100644 --- a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_diminutive_rectal_hyperplastic_polyp.py +++ b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_diminutive_rectal_hyperplastic_polyp.py @@ -5,14 +5,8 @@ from pages.base_page import BasePage from pages.datasets.investigation_dataset_page import ( InvestigationDatasetsPage, - DrugTypeOptions, - BowelPreparationQualityOptions, - ComfortOptions, EndoscopyLocationOptions, YesNoOptions, - InsufflationOptions, - OutcomeAtTimeOfProcedureOptions, - LateOutcomeOptions, FailureReasonsOptions, PolypClassificationOptions, PolypAccessOptions, @@ -40,37 +34,16 @@ go_from_investigation_dataset_complete_to_a259_status, get_subject_with_a99_status, go_from_a99_status_to_a259_status, + get_default_general_information, + get_default_drug_information, + get_default_endoscopy_information, ) -general_information = { - "site": -1, - "practitioner": -1, - "testing clinician": -1, - "aspirant endoscopist": None, -} +general_information = get_default_general_information() -drug_information = { - "drug_type1": DrugTypeOptions.MANNITOL, - "drug_dose1": "3", -} +drug_information = get_default_drug_information() -endoscopy_information = { - "endoscope inserted": "yes", - "procedure type": "therapeutic", - "bowel preparation quality": BowelPreparationQualityOptions.GOOD, - "comfort during examination": ComfortOptions.NO_DISCOMFORT, - "comfort during recovery": ComfortOptions.NO_DISCOMFORT, - "endoscopist defined extent": EndoscopyLocationOptions.DESCENDING_COLON, - "scope imager used": YesNoOptions.YES, - "retroverted view": YesNoOptions.NO, - "start of intubation time": "09:00", - "start of extubation time": "09:30", - "end time of procedure": "10:00", - "scope id": "Autotest", - "insufflation": InsufflationOptions.AIR, - "outcome at time of procedure": OutcomeAtTimeOfProcedureOptions.LEAVE_DEPARTMENT, - "late outcome": LateOutcomeOptions.NO_COMPLICATIONS, -} +endoscopy_information = get_default_endoscopy_information() failure_information = { "failure reasons": FailureReasonsOptions.ADHESION, @@ -234,22 +207,22 @@ def test_identify_diminutive_rectal_hyperplastic_polyp_from_histology_a( polyp_category_string = "Diminutive rectal hyperplastic polyp" InvestigationDatasetsPage(page).expect_text_to_be_visible("Abnormal") - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "5") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, polyp_category_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(2, "1") - InvestigationDatasetsPage(page).assert_polyp_categrory(2, polyp_category_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(3, "3") - InvestigationDatasetsPage(page).assert_polyp_categrory(3, polyp_category_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(4, "5") - InvestigationDatasetsPage(page).assert_polyp_categrory(4, polyp_category_string) + InvestigationDatasetsPage(page).assert_polyp_algorithm_size(1, "5") + InvestigationDatasetsPage(page).assert_polyp_category(1, polyp_category_string) + InvestigationDatasetsPage(page).assert_polyp_algorithm_size(2, "1") + InvestigationDatasetsPage(page).assert_polyp_category(2, polyp_category_string) + InvestigationDatasetsPage(page).assert_polyp_algorithm_size(3, "3") + InvestigationDatasetsPage(page).assert_polyp_category(3, polyp_category_string) + InvestigationDatasetsPage(page).assert_polyp_algorithm_size(4, "5") + InvestigationDatasetsPage(page).assert_polyp_category(4, polyp_category_string) logging.info("Marking investigation dataset not complete") InvestigationDatasetsPage(page).click_edit_dataset_button() InvestigationDatasetsPage(page).check_dataset_incomplete_checkbox() InvestigationDatasetsPage(page).click_save_dataset_button() for polyp_number in range(1, 5): - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(polyp_number, None) - InvestigationDatasetsPage(page).assert_polyp_categrory(polyp_number, None) + InvestigationDatasetsPage(page).assert_polyp_algorithm_size(polyp_number, None) + InvestigationDatasetsPage(page).assert_polyp_category(polyp_number, None) LogoutPage(page).log_out() @@ -331,8 +304,8 @@ def test_identify_diminutive_rectal_hyperplastic_polyp_from_histology_b( ) InvestigationDatasetsPage(page).expect_text_to_be_visible("Abnormal") - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "2") - InvestigationDatasetsPage(page).assert_polyp_categrory( + InvestigationDatasetsPage(page).assert_polyp_algorithm_size(1, "2") + InvestigationDatasetsPage(page).assert_polyp_category( 1, "Diminutive rectal hyperplastic polyp" ) @@ -340,6 +313,6 @@ def test_identify_diminutive_rectal_hyperplastic_polyp_from_histology_b( InvestigationDatasetsPage(page).click_edit_dataset_button() InvestigationDatasetsPage(page).check_dataset_incomplete_checkbox() InvestigationDatasetsPage(page).click_save_dataset_button() - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, None) - InvestigationDatasetsPage(page).assert_polyp_categrory(1, None) + InvestigationDatasetsPage(page).assert_polyp_algorithm_size(1, None) + InvestigationDatasetsPage(page).assert_polyp_category(1, None) LogoutPage(page).log_out() diff --git a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.py b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.py new file mode 100644 index 00000000..25128024 --- /dev/null +++ b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.py @@ -0,0 +1,826 @@ +import logging +import pytest +from datetime import datetime +from playwright.sync_api import Page +from pages.base_page import BasePage +from pages.datasets.investigation_dataset_page import ( + InvestigationDatasetsPage, + EndoscopyLocationOptions, + YesNoOptions, + FailureReasonsOptions, + PolypClassificationOptions, + PolypAccessOptions, + PolypInterventionModalityOptions, + PolypInterventionDeviceOptions, + PolypInterventionExcisionTechniqueOptions, + PolypTypeOptions, + SerratedLesionSubTypeOptions, + PolypExcisionCompleteOptions, + PolypDysplasiaOptions, + YesNoUncertainOptions, + AdenomaSubTypeOptions, + CompletionProofOptions, +) +from pages.datasets.subject_datasets_page import SubjectDatasetsPage +from pages.screening_subject_search.subject_screening_summary_page import ( + SubjectScreeningSummaryPage, +) +from utils.investigation_dataset import ( + InvestigationDatasetCompletion, +) +from utils.screening_subject_page_searcher import ( + search_subject_episode_by_nhs_number, +) +from utils.user_tools import UserTools +from utils.datasets.investigation_datasets import ( + get_subject_with_investigation_dataset_ready, + go_from_investigation_dataset_complete_to_a259_status, + get_subject_with_a99_status, + go_from_a99_status_to_a259_status, + get_default_general_information, + get_default_drug_information, + get_default_endoscopy_information, + complete_and_assert_investigation, +) + +lnpcp_string = "LNPCP" + +general_information = get_default_general_information() + +drug_information = get_default_drug_information() + +endoscopy_information = get_default_endoscopy_information() + +failure_information = { + "failure reasons": FailureReasonsOptions.ADHESION, +} + +completion_information = { + "completion proof": CompletionProofOptions.VIDEO_APPENDIX, +} + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_a( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - A) + """ + df = get_subject_with_investigation_dataset_ready() + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + BasePage(page).click_main_menu_link() + BasePage(page).go_to_screening_subject_search_page() + search_subject_episode_by_nhs_number(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + polyp_1_information = { + "location": EndoscopyLocationOptions.ANUS, + "classification": PolypClassificationOptions.ISP, + "estimate of whole polyp size": "20", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.POLYPECTOMY, + "device": PolypInterventionDeviceOptions.HOT_SNARE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.EN_BLOC, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.SERRATED_LESION, + "serrated lesion sub type": SerratedLesionSubTypeOptions.MIXED_POLYP, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "20", + "polyp dysplasia": PolypDysplasiaOptions.NO_DYSPLASIA, + "polyp carcinoma": YesNoUncertainOptions.NO, + } + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="20", + ) + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_b( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - B) + """ + df = get_subject_with_investigation_dataset_ready() + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + BasePage(page).click_main_menu_link() + BasePage(page).go_to_screening_subject_search_page() + search_subject_episode_by_nhs_number(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + polyp_1_information = { + "location": EndoscopyLocationOptions.RECTUM, + "classification": PolypClassificationOptions.IS, + "estimate of whole polyp size": "20", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.EMR, + "device": PolypInterventionDeviceOptions.HOT_SNARE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.EN_BLOC, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.ADENOMA, + "adenoma sub type": AdenomaSubTypeOptions.TUBULOVILLOUS_ADENOMA, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "21", + "polyp dysplasia": PolypDysplasiaOptions.HIGH_GRADE_DYSPLASIA, + "polyp carcinoma": YesNoUncertainOptions.NO, + } + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="21", + ) + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_c( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - C) + """ + df = get_subject_with_investigation_dataset_ready() + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + BasePage(page).click_main_menu_link() + BasePage(page).go_to_screening_subject_search_page() + search_subject_episode_by_nhs_number(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + polyp_1_information = { + "location": EndoscopyLocationOptions.SIGMOID_COLON, + "classification": PolypClassificationOptions.IIA, + "estimate of whole polyp size": "22", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.ESD, + "device": PolypInterventionDeviceOptions.ENDOSCOPIC_KNIFE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.EN_BLOC, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.ADENOMA, + "adenoma sub type": AdenomaSubTypeOptions.VILLOUS_ADENOMA, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "22", + "polyp dysplasia": PolypDysplasiaOptions.HIGH_GRADE_DYSPLASIA, + "polyp carcinoma": YesNoUncertainOptions.UNCERTAIN, + } + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="22", + ) + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_d( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - D) + """ + df = get_subject_with_investigation_dataset_ready() + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + BasePage(page).click_main_menu_link() + BasePage(page).go_to_screening_subject_search_page() + search_subject_episode_by_nhs_number(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + polyp_1_information = { + "location": EndoscopyLocationOptions.DESCENDING_COLON, + "classification": PolypClassificationOptions.IIB, + "estimate of whole polyp size": "20", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.POLYPECTOMY, + "device": PolypInterventionDeviceOptions.COLD_SNARE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.PIECE_MEAL, + "polyp appears fully resected endoscopically": YesNoOptions.YES, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.ADENOMA, + "adenoma sub type": AdenomaSubTypeOptions.NOT_REPORTED, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "19", + "polyp dysplasia": PolypDysplasiaOptions.HIGH_GRADE_DYSPLASIA, + "polyp carcinoma": YesNoUncertainOptions.UNCERTAIN, + } + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="20", + ) + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_e( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - E) + """ + df = get_subject_with_investigation_dataset_ready() + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + BasePage(page).click_main_menu_link() + BasePage(page).go_to_screening_subject_search_page() + search_subject_episode_by_nhs_number(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + endoscopy_information["endoscopist defined extent"] = ( + EndoscopyLocationOptions.APPENDIX + ) + + polyp_1_information = { + "location": EndoscopyLocationOptions.SPLENIC_FLEXURE, + "classification": PolypClassificationOptions.IIC, + "estimate of whole polyp size": "19", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.EMR, + "device": PolypInterventionDeviceOptions.COLD_SNARE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.PIECE_MEAL, + "polyp appears fully resected endoscopically": YesNoOptions.YES, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.SERRATED_LESION, + "serrated lesion sub type": SerratedLesionSubTypeOptions.HYPERPLASTIC_POLYP, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "20", + } + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="20", + completion_information=completion_information, + ) + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_f( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - F) + """ + df = get_subject_with_investigation_dataset_ready() + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + BasePage(page).click_main_menu_link() + BasePage(page).go_to_screening_subject_search_page() + search_subject_episode_by_nhs_number(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + endoscopy_information["endoscopist defined extent"] = ( + EndoscopyLocationOptions.APPENDIX + ) + + polyp_1_information = { + "location": EndoscopyLocationOptions.TRANSVERSE_COLON, + "classification": PolypClassificationOptions.LST_G, + "estimate of whole polyp size": "21", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.ESD, + "device": PolypInterventionDeviceOptions.HOT_SNARE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.PIECE_MEAL, + "polyp appears fully resected endoscopically": YesNoOptions.YES, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.SERRATED_LESION, + "serrated lesion sub type": SerratedLesionSubTypeOptions.MIXED_POLYP, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "21", + "polyp dysplasia": PolypDysplasiaOptions.HIGH_GRADE_DYSPLASIA, + "polyp carcinoma": YesNoUncertainOptions.NO, + } + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="21", + completion_information=completion_information, + ) + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_g( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - G) + """ + df = get_subject_with_investigation_dataset_ready() + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + BasePage(page).click_main_menu_link() + BasePage(page).go_to_screening_subject_search_page() + search_subject_episode_by_nhs_number(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + endoscopy_information["endoscopist defined extent"] = ( + EndoscopyLocationOptions.APPENDIX + ) + + polyp_1_information = { + "location": EndoscopyLocationOptions.HEPATIC_FLEXURE, + "classification": PolypClassificationOptions.LST_NG, + "estimate of whole polyp size": "18", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.POLYPECTOMY, + "device": PolypInterventionDeviceOptions.HOT_SNARE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.EN_BLOC, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.SERRATED_LESION, + "serrated lesion sub type": SerratedLesionSubTypeOptions.SESSILE_SERRATED_LESION, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "20", + "polyp carcinoma": YesNoUncertainOptions.NO, + } + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="20", + completion_information=completion_information, + ) + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_h( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - H) + """ + df = get_subject_with_investigation_dataset_ready() + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + BasePage(page).click_main_menu_link() + BasePage(page).go_to_screening_subject_search_page() + search_subject_episode_by_nhs_number(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + endoscopy_information["endoscopist defined extent"] = ( + EndoscopyLocationOptions.APPENDIX + ) + + polyp_1_information = { + "location": EndoscopyLocationOptions.ASCENDING_COLON, + "classification": PolypClassificationOptions.IIA, + "estimate of whole polyp size": "20", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.EMR, + "device": PolypInterventionDeviceOptions.HOT_SNARE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.EN_BLOC, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.SERRATED_LESION, + "serrated lesion sub type": SerratedLesionSubTypeOptions.SESSILE_SERRATED_LESION_WITH_DYSPLASIA, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "22", + "polyp dysplasia": PolypDysplasiaOptions.HIGH_GRADE_DYSPLASIA, + "polyp carcinoma": YesNoUncertainOptions.NO, + } + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="22", + completion_information=completion_information, + ) + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_i( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - I) + """ + df = get_subject_with_investigation_dataset_ready() + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + BasePage(page).click_main_menu_link() + BasePage(page).go_to_screening_subject_search_page() + search_subject_episode_by_nhs_number(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + endoscopy_information["endoscopist defined extent"] = ( + EndoscopyLocationOptions.APPENDIX + ) + + polyp_1_information = { + "location": EndoscopyLocationOptions.CAECUM, + "classification": PolypClassificationOptions.ISP, + "estimate of whole polyp size": "21", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.ESD, + "device": PolypInterventionDeviceOptions.ENDOSCOPIC_KNIFE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.EN_BLOC, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.SERRATED_LESION, + "serrated lesion sub type": SerratedLesionSubTypeOptions.TRADITIONAL_SERRATED_ADENOMA, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "21", + "polyp dysplasia": PolypDysplasiaOptions.LOW_GRADE_DYSPLASIA, + "polyp carcinoma": YesNoUncertainOptions.NO, + } + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="21", + completion_information=completion_information, + ) + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_r( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - R) + """ + df = get_subject_with_investigation_dataset_ready() + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + BasePage(page).click_main_menu_link() + BasePage(page).go_to_screening_subject_search_page() + search_subject_episode_by_nhs_number(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + endoscopy_information["endoscopist defined extent"] = ( + EndoscopyLocationOptions.APPENDIX + ) + + polyp_1_information = { + "location": EndoscopyLocationOptions.TRANSVERSE_COLON, + "classification": PolypClassificationOptions.IS, + "estimate of whole polyp size": "19", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.ESD, + "device": PolypInterventionDeviceOptions.HOT_SNARE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.PIECE_MEAL, + "polyp appears fully resected endoscopically": YesNoOptions.YES, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.ADENOMA, + "adenoma sub type": AdenomaSubTypeOptions.TUBULAR_ADENOMA, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "20", + "polyp dysplasia": PolypDysplasiaOptions.HIGH_GRADE_DYSPLASIA, + "polyp carcinoma": YesNoUncertainOptions.NO, + } + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="20", + completion_information=completion_information, + ) + + +@pytest.mark.vpn_required +@pytest.mark.regression +@pytest.mark.investigation_dataset_tests +def test_identify_lnpcp_from_histology_s( + page: Page, +) -> None: + """ + This test identifies an LNPCP result from histology. (BCSS-5568 - S) + """ + df = get_subject_with_a99_status() + + nhs_no = df.iloc[0]["subject_nhs_number"] + logging.info(f"NHS Number: {nhs_no}") + + UserTools.user_login(page, "Screening Centre Manager at BCS001") + go_from_a99_status_to_a259_status(page, nhs_no) + + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + endoscopy_information["endoscopist defined extent"] = ( + EndoscopyLocationOptions.APPENDIX + ) + + polyp_1_information = { + "location": EndoscopyLocationOptions.SIGMOID_COLON, + "classification": PolypClassificationOptions.LST_NG, + "estimate of whole polyp size": "5", + "polyp access": PolypAccessOptions.EASY, + "left in situ": YesNoOptions.NO, + } + + polyp_1_intervention = { + "modality": PolypInterventionModalityOptions.ESD, + "device": PolypInterventionDeviceOptions.HOT_SNARE, + "excised": YesNoOptions.YES, + "retrieved": YesNoOptions.YES, + "excision technique": PolypInterventionExcisionTechniqueOptions.EN_BLOC, + } + + polyp_1_histology = { + "date of receipt": datetime.today(), + "date of reporting": datetime.today(), + "pathology provider": -1, + "pathologist": -1, + "polyp type": PolypTypeOptions.ADENOMA, + "adenoma sub type": AdenomaSubTypeOptions.VILLOUS_ADENOMA, + "polyp excision complete": PolypExcisionCompleteOptions.R1, + "polyp size": "5", + "polyp dysplasia": PolypDysplasiaOptions.NOT_REPORTED, + "polyp carcinoma": YesNoUncertainOptions.NO, + } + + polyp_information = [polyp_1_information] + polyp_intervention = [polyp_1_intervention] + polyp_histology = [polyp_1_histology] + + InvestigationDatasetCompletion(page).complete_dataset_with_args( + general_information=general_information, + drug_information=drug_information, + endoscopy_information=endoscopy_information, + failure_information=failure_information, + polyp_information=polyp_information, + completion_information=completion_information, + polyp_intervention=polyp_intervention, + polyp_histology=polyp_histology, + ) + + try: + InvestigationDatasetsPage(page).expect_text_to_be_visible("Abnormal") + logging.info("Found 'Abnormal' result.") + except Exception as e: + logging.error(f"Expected text not found: {e}") + go_from_investigation_dataset_complete_to_a259_status(page) + SubjectScreeningSummaryPage(page).click_datasets_link() + SubjectDatasetsPage(page).click_investigation_show_datasets() + + polyp_1_information["estimate of whole polyp size"] = "20" + polyp_1_histology["polyp size"] = "20" + + complete_and_assert_investigation( + page, + general_information, + drug_information, + endoscopy_information, + failure_information, + polyp_1_information, + polyp_1_intervention, + polyp_1_histology, + expected_category=lnpcp_string, + expected_size="20", + completion_information=completion_information, + ) diff --git a/utils/datasets/investigation_datasets.py b/utils/datasets/investigation_datasets.py index 1c1d8d6d..629ef1fc 100644 --- a/utils/datasets/investigation_datasets.py +++ b/utils/datasets/investigation_datasets.py @@ -27,6 +27,23 @@ from utils.screening_subject_page_searcher import ( search_subject_episode_by_nhs_number, ) +from pages.datasets.investigation_dataset_page import ( + DrugTypeOptions, + BowelPreparationQualityOptions, + ComfortOptions, + EndoscopyLocationOptions, + YesNoOptions, + InsufflationOptions, + OutcomeAtTimeOfProcedureOptions, + LateOutcomeOptions, + InvestigationDatasetsPage, +) +from typing import Optional +from utils.investigation_dataset import ( + InvestigationDatasetCompletion, +) +import logging +from pages.logout.log_out_page import LogoutPage def get_subject_with_investigation_dataset_ready() -> pd.DataFrame: @@ -193,3 +210,92 @@ def go_from_investigation_dataset_complete_to_a259_status(page: Page) -> None: SubjectScreeningSummaryPage(page).verify_latest_event_status_value( "A259 - Attended Diagnostic Test" ) + + +def get_default_general_information() -> dict: + """Return default general information for investigation dataset tests.""" + return { + "site": -1, + "practitioner": -1, + "testing clinician": -1, + "aspirant endoscopist": None, + } + + +def get_default_drug_information() -> dict: + """Return default drug information for investigation dataset tests.""" + return { + "drug_type1": DrugTypeOptions.MANNITOL, + "drug_dose1": "3", + } + + +def get_default_endoscopy_information() -> dict: + """Return default endoscopy information for investigation dataset tests.""" + return { + "endoscope inserted": "yes", + "procedure type": "therapeutic", + "bowel preparation quality": BowelPreparationQualityOptions.GOOD, + "comfort during examination": ComfortOptions.NO_DISCOMFORT, + "comfort during recovery": ComfortOptions.NO_DISCOMFORT, + "endoscopist defined extent": EndoscopyLocationOptions.DESCENDING_COLON, + "scope imager used": YesNoOptions.YES, + "retroverted view": YesNoOptions.NO, + "start of intubation time": "09:00", + "start of extubation time": "09:30", + "end time of procedure": "10:00", + "scope id": "Autotest", + "insufflation": InsufflationOptions.AIR, + "outcome at time of procedure": OutcomeAtTimeOfProcedureOptions.LEAVE_DEPARTMENT, + "late outcome": LateOutcomeOptions.NO_COMPLICATIONS, + } + + +def complete_and_assert_investigation( + page: Page, + general_information: dict, + drug_information: dict, + endoscopy_information: dict, + failure_information: dict, + polyp_1_information: dict, + polyp_1_intervention: dict, + polyp_1_histology: dict, + expected_category: str, + expected_size: str, + completion_information: Optional[dict] = None, +) -> None: + """ + Fills the investigation dataset, asserts results, and marks dataset not complete. + """ + polyp_information = [polyp_1_information] + polyp_intervention = [polyp_1_intervention] + polyp_histology = [polyp_1_histology] + + InvestigationDatasetCompletion(page).complete_dataset_with_args( + general_information=general_information, + drug_information=drug_information, + endoscopy_information=endoscopy_information, + failure_information=failure_information, + polyp_information=polyp_information, + polyp_intervention=polyp_intervention, + polyp_histology=polyp_histology, + completion_information=completion_information, + ) + + InvestigationDatasetsPage(page).assert_polyp_algorithm_size(1, expected_size) + InvestigationDatasetsPage(page).assert_polyp_category(1, expected_category) + + mark_dataset_not_complete_and_assert(page) + + +def mark_dataset_not_complete_and_assert(page: Page) -> None: + """ + Marks the investigation dataset as not complete and asserts that the polyp size and category are None. + """ + logging.info("Marking investigation dataset not complete") + InvestigationDatasetsPage(page).click_edit_dataset_button() + InvestigationDatasetsPage(page).check_dataset_incomplete_checkbox() + InvestigationDatasetsPage(page).click_save_dataset_button() + InvestigationDatasetsPage(page).assert_polyp_algorithm_size(1, None) + InvestigationDatasetsPage(page).assert_polyp_category(1, None) + LogoutPage(page).log_out()