From 04463221c14ffe91b199f44ebfef5e414f97a25f Mon Sep 17 00:00:00 2001 From: Adriano Aru Date: Tue, 22 Jul 2025 09:30:11 +0100 Subject: [PATCH 1/5] Adding tests for an LNPCP result --- .../endoscopy/polypcategories/test_lnpcp.py | 938 ++++++++++++++++++ 1 file changed, 938 insertions(+) create mode 100644 tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.py 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..2f112363 --- /dev/null +++ b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.py @@ -0,0 +1,938 @@ +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, + DrugTypeOptions, + BowelPreparationQualityOptions, + ComfortOptions, + EndoscopyLocationOptions, + YesNoOptions, + InsufflationOptions, + OutcomeAtTimeOfProcedureOptions, + LateOutcomeOptions, + FailureReasonsOptions, + PolypClassificationOptions, + PolypAccessOptions, + PolypInterventionModalityOptions, + PolypInterventionDeviceOptions, + PolypInterventionExcisionTechniqueOptions, + PolypTypeOptions, + SerratedLesionSubTypeOptions, + PolypExcisionCompleteOptions, + PolypDysplasiaOptions, + YesNoUncertainOptions, + AdenomaSubTypeOptions, + CompletionProofOptions, +) +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, +) +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, +) + +lnpcp_string = "LNPCP" + +general_information = { + "site": -1, + "practitioner": -1, + "testing clinician": -1, + "aspirant endoscopist": None, +} + +drug_information = { + "drug_type1": DrugTypeOptions.MANNITOL, + "drug_dose1": "3", +} + +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, +} + +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, + } + + 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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + mark_dataset_not_complete_and_assert(page) + + +@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, + } + + 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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "21") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + mark_dataset_not_complete_and_assert(page) + + +@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, + } + + 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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "22") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + mark_dataset_not_complete_and_assert(page) + + +@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, + } + + 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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + mark_dataset_not_complete_and_assert(page) + + +@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", + } + + 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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + mark_dataset_not_complete_and_assert(page) + + +@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, + } + + 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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "21") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + mark_dataset_not_complete_and_assert(page) + + +@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, + } + + 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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + mark_dataset_not_complete_and_assert(page) + + +@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, + } + + 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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "22") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + mark_dataset_not_complete_and_assert(page) + + +@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, + } + + 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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "21") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + mark_dataset_not_complete_and_assert(page) + + +@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, + } + + 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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + mark_dataset_not_complete_and_assert(page) + + +@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, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible("Abnormal") + 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" + + polyp_information = [polyp_1_information] + 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, + completion_information=completion_information, + polyp_information=polyp_information, + polyp_intervention=polyp_intervention, + polyp_histology=polyp_histology, + ) + + InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) + InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") + InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) + + 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_alogrithm_size(1, None) + InvestigationDatasetsPage(page).assert_polyp_categrory(1, None) + LogoutPage(page).log_out() From 4c3794e11d7bd14029561ba0f143fae24c905b95 Mon Sep 17 00:00:00 2001 From: Adriano Aru Date: Tue, 22 Jul 2025 10:07:31 +0100 Subject: [PATCH 2/5] Reducing duplicate code --- .../test_advanced_colorectal_polyp.py | 538 +++++++----------- ...st_diminutive_rectal_hyperplastic_polyp.py | 39 +- .../endoscopy/polypcategories/test_lnpcp.py | 373 +++++------- .../endoscopy/polypcategories/test_setup.py | 43 +- utils/datasets/investigation_datasets.py | 106 ++++ 5 files changed, 482 insertions(+), 617 deletions(-) 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..182c85b7 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, 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 index 2f112363..5e216517 100644 --- a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.py +++ b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.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, @@ -28,7 +22,6 @@ CompletionProofOptions, ) 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 +37,19 @@ 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 = { - "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, @@ -87,6 +60,7 @@ } +@pytest.mark.wip @pytest.mark.vpn_required @pytest.mark.regression @pytest.mark.investigation_dataset_tests @@ -137,26 +111,19 @@ def test_identify_lnpcp_from_histology_a( "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, - 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=lnpcp_string, + expected_size="20", ) - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - mark_dataset_not_complete_and_assert(page) - @pytest.mark.vpn_required @pytest.mark.regression @@ -208,26 +175,19 @@ def test_identify_lnpcp_from_histology_b( "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, - 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=lnpcp_string, + expected_size="21", ) - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "21") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - mark_dataset_not_complete_and_assert(page) - @pytest.mark.vpn_required @pytest.mark.regression @@ -279,26 +239,19 @@ def test_identify_lnpcp_from_histology_c( "polyp carcinoma": YesNoUncertainOptions.UNCERTAIN, } - 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=lnpcp_string, + expected_size="22", ) - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "22") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - mark_dataset_not_complete_and_assert(page) - @pytest.mark.vpn_required @pytest.mark.regression @@ -351,26 +304,19 @@ def test_identify_lnpcp_from_histology_d( "polyp carcinoma": YesNoUncertainOptions.UNCERTAIN, } - 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=lnpcp_string, + expected_size="20", ) - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - mark_dataset_not_complete_and_assert(page) - @pytest.mark.vpn_required @pytest.mark.regression @@ -425,27 +371,20 @@ def test_identify_lnpcp_from_histology_e( "polyp size": "20", } - 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, + 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, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, ) - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - mark_dataset_not_complete_and_assert(page) - @pytest.mark.vpn_required @pytest.mark.regression @@ -502,27 +441,20 @@ def test_identify_lnpcp_from_histology_f( "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, + 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, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, ) - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "21") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - mark_dataset_not_complete_and_assert(page) - @pytest.mark.vpn_required @pytest.mark.regression @@ -577,27 +509,20 @@ def test_identify_lnpcp_from_histology_g( "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, + 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, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, ) - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - mark_dataset_not_complete_and_assert(page) - @pytest.mark.vpn_required @pytest.mark.regression @@ -653,27 +578,20 @@ def test_identify_lnpcp_from_histology_h( "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, + 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, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, ) - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "22") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - mark_dataset_not_complete_and_assert(page) - @pytest.mark.vpn_required @pytest.mark.regression @@ -729,27 +647,20 @@ def test_identify_lnpcp_from_histology_i( "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, + 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, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, ) - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "21") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - mark_dataset_not_complete_and_assert(page) - @pytest.mark.vpn_required @pytest.mark.regression @@ -806,27 +717,20 @@ def test_identify_lnpcp_from_histology_r( "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, + 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, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, ) - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - mark_dataset_not_complete_and_assert(page) - @pytest.mark.vpn_required @pytest.mark.regression @@ -904,35 +808,16 @@ def test_identify_lnpcp_from_histology_s( polyp_1_information["estimate of whole polyp size"] = "20" polyp_1_histology["polyp size"] = "20" - polyp_information = [polyp_1_information] - 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, + 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, - polyp_information=polyp_information, - polyp_intervention=polyp_intervention, - polyp_histology=polyp_histology, ) - - InvestigationDatasetsPage(page).expect_text_to_be_visible(lnpcp_string) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, "20") - InvestigationDatasetsPage(page).assert_polyp_categrory(1, lnpcp_string) - - 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_alogrithm_size(1, None) - InvestigationDatasetsPage(page).assert_polyp_categrory(1, None) - LogoutPage(page).log_out() diff --git a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup.py b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup.py index 42400dd0..2279f8e0 100644 --- a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup.py +++ b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup.py @@ -85,6 +85,7 @@ def before_each(page: Page, request: FixtureRequest) -> None: setup_appointments(page) +@pytest.mark.setup @pytest.mark.vpn_required def test_setup_subjects_as_a99(page: Page, subjects_to_run_for: int) -> None: """ @@ -122,27 +123,27 @@ def test_setup_subjects_as_a259(page: Page, subjects_to_run_for: int) -> None: """ page = page.context.new_page() page.goto("/") - criteria = { - "latest episode status": "open", - "latest episode latest investigation dataset": "colonoscopy_new", - "latest episode started": "less than 4 years ago", - } - user = User() - subject = Subject() - - builder = SubjectSelectionQueryBuilder() - - query, bind_vars = builder.build_subject_selection_query( - criteria=criteria, - user=user, - subject=subject, - subjects_to_retrieve=subjects_to_run_for, - ) - - df = OracleDB().execute_query(query, bind_vars) - - if df.shape[0] == subjects_to_run_for: - pytest.skip("Enough subjects found, no need to run test setup") + # criteria = { + # "latest episode status": "open", + # "latest episode latest investigation dataset": "colonoscopy_new", + # "latest episode started": "less than 4 years ago", + # } + # user = User() + # subject = Subject() + + # builder = SubjectSelectionQueryBuilder() + + # query, bind_vars = builder.build_subject_selection_query( + # criteria=criteria, + # user=user, + # subject=subject, + # subjects_to_retrieve=subjects_to_run_for, + # ) + + # df = OracleDB().execute_query(query, bind_vars) + + # if df.shape[0] == subjects_to_run_for: + # pytest.skip("Enough subjects found, no need to run test setup") criteria = { "latest event status": "S9", diff --git a/utils/datasets/investigation_datasets.py b/utils/datasets/investigation_datasets.py index 1c1d8d6d..1e1ae410 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_alogrithm_size(1, expected_size) + InvestigationDatasetsPage(page).assert_polyp_categrory(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_alogrithm_size(1, None) + InvestigationDatasetsPage(page).assert_polyp_categrory(1, None) + LogoutPage(page).log_out() From d725c62d803cbbd35d44e1db763233b1c0688a40 Mon Sep 17 00:00:00 2001 From: Adriano Aru Date: Tue, 22 Jul 2025 10:12:13 +0100 Subject: [PATCH 3/5] Fixing issues --- .../endoscopy/polypcategories/test_setup.py | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup.py b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup.py index 2279f8e0..42400dd0 100644 --- a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup.py +++ b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup.py @@ -85,7 +85,6 @@ def before_each(page: Page, request: FixtureRequest) -> None: setup_appointments(page) -@pytest.mark.setup @pytest.mark.vpn_required def test_setup_subjects_as_a99(page: Page, subjects_to_run_for: int) -> None: """ @@ -123,27 +122,27 @@ def test_setup_subjects_as_a259(page: Page, subjects_to_run_for: int) -> None: """ page = page.context.new_page() page.goto("/") - # criteria = { - # "latest episode status": "open", - # "latest episode latest investigation dataset": "colonoscopy_new", - # "latest episode started": "less than 4 years ago", - # } - # user = User() - # subject = Subject() - - # builder = SubjectSelectionQueryBuilder() - - # query, bind_vars = builder.build_subject_selection_query( - # criteria=criteria, - # user=user, - # subject=subject, - # subjects_to_retrieve=subjects_to_run_for, - # ) - - # df = OracleDB().execute_query(query, bind_vars) - - # if df.shape[0] == subjects_to_run_for: - # pytest.skip("Enough subjects found, no need to run test setup") + criteria = { + "latest episode status": "open", + "latest episode latest investigation dataset": "colonoscopy_new", + "latest episode started": "less than 4 years ago", + } + user = User() + subject = Subject() + + builder = SubjectSelectionQueryBuilder() + + query, bind_vars = builder.build_subject_selection_query( + criteria=criteria, + user=user, + subject=subject, + subjects_to_retrieve=subjects_to_run_for, + ) + + df = OracleDB().execute_query(query, bind_vars) + + if df.shape[0] == subjects_to_run_for: + pytest.skip("Enough subjects found, no need to run test setup") criteria = { "latest event status": "S9", From 9078933243cc617b9bf0b1f258d2c63d16b028b8 Mon Sep 17 00:00:00 2001 From: Adriano Aru Date: Tue, 22 Jul 2025 12:07:07 +0100 Subject: [PATCH 4/5] Addressing PR comments --- pages/datasets/investigation_dataset_page.py | 4 +-- ...st_diminutive_rectal_hyperplastic_polyp.py | 28 +++++++++---------- .../endoscopy/polypcategories/test_lnpcp.py | 1 - utils/datasets/investigation_datasets.py | 8 +++--- 4 files changed, 20 insertions(+), 21 deletions(-) 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_diminutive_rectal_hyperplastic_polyp.py b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_diminutive_rectal_hyperplastic_polyp.py index 182c85b7..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 @@ -207,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() @@ -304,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" ) @@ -313,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 index 5e216517..2c241aae 100644 --- a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.py +++ b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.py @@ -60,7 +60,6 @@ } -@pytest.mark.wip @pytest.mark.vpn_required @pytest.mark.regression @pytest.mark.investigation_dataset_tests diff --git a/utils/datasets/investigation_datasets.py b/utils/datasets/investigation_datasets.py index 1e1ae410..629ef1fc 100644 --- a/utils/datasets/investigation_datasets.py +++ b/utils/datasets/investigation_datasets.py @@ -282,8 +282,8 @@ def complete_and_assert_investigation( completion_information=completion_information, ) - InvestigationDatasetsPage(page).assert_polyp_alogrithm_size(1, expected_size) - InvestigationDatasetsPage(page).assert_polyp_categrory(1, expected_category) + InvestigationDatasetsPage(page).assert_polyp_algorithm_size(1, expected_size) + InvestigationDatasetsPage(page).assert_polyp_category(1, expected_category) mark_dataset_not_complete_and_assert(page) @@ -296,6 +296,6 @@ def mark_dataset_not_complete_and_assert(page: Page) -> None: 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() From fe0ed29777b35bf93227a4cf1589cc6386e80264 Mon Sep 17 00:00:00 2001 From: Adriano Aru Date: Tue, 22 Jul 2025 12:17:31 +0100 Subject: [PATCH 5/5] Added logging as per PR comments --- .../investigation/endoscopy/polypcategories/test_lnpcp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 index 2c241aae..25128024 100644 --- a/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.py +++ b/tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_lnpcp.py @@ -799,7 +799,11 @@ def test_identify_lnpcp_from_histology_s( polyp_histology=polyp_histology, ) - InvestigationDatasetsPage(page).expect_text_to_be_visible("Abnormal") + 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()