diff --git a/.github/workflows/stage-1-commit.yaml b/.github/workflows/stage-1-commit.yaml index 2eb4ba786..bd999b8ec 100644 --- a/.github/workflows/stage-1-commit.yaml +++ b/.github/workflows/stage-1-commit.yaml @@ -47,7 +47,7 @@ jobs: check-file-format: name: "Check file format" runs-on: ubuntu-latest - timeout-minutes: 5 + timeout-minutes: 10 steps: - name: "Checkout code" uses: actions/checkout@v4 @@ -58,7 +58,7 @@ jobs: check-markdown-format: name: "Check Markdown format" runs-on: ubuntu-latest - timeout-minutes: 5 + timeout-minutes: 15 steps: - name: "Checkout code" uses: actions/checkout@v4 @@ -69,7 +69,7 @@ jobs: check-english-usage: name: "Check English usage" runs-on: ubuntu-latest - timeout-minutes: 5 + timeout-minutes: 15 steps: - name: "Checkout code" uses: actions/checkout@v4 @@ -92,7 +92,7 @@ jobs: permissions: id-token: write contents: read - timeout-minutes: 5 + timeout-minutes: 10 steps: - name: "Checkout code" uses: actions/checkout@v4 @@ -111,7 +111,7 @@ jobs: permissions: id-token: write contents: read - timeout-minutes: 5 + timeout-minutes: 10 steps: - name: "Checkout code" uses: actions/checkout@v4 diff --git a/conftest.py b/conftest.py index 696a014b3..4cc82f124 100644 --- a/conftest.py +++ b/conftest.py @@ -351,26 +351,25 @@ def record_consent_details_and_click_continue_to_vaccinate(consent_decision, co attach_screenshot("patient_decided_to_not_consent_saved_and_returned") def enter_vaccine_details_and_click_continue_to_check_and_confirm(vaccinate_decision, care_model, vaccination_date, vaccine, vaccine_type2, vaccination_site, batch_number, batch_expiry_date, dose_amount, vaccinator, vaccination_comments, legal_mechanism, no_vaccination_reason=None): + set_vaccination_date(vaccination_date) + attach_screenshot("vaccination_date_is_set") + logging.debug("Vaccination legal mechanism is: " + legal_mechanism) + logging.debug("Vaccinator to select is: " + vaccinator) + if (legal_mechanism) != "Patient Group Direction (PGD)": + select_vaccinator_name_and_council(vaccinator) + attach_screenshot("selected_vaccinator_name_and_council") + enter_vaccination_comments(vaccination_comments) + attach_screenshot("entered_vaccination_comments") + click_care_model_option(care_model) + attach_screenshot("clicked_care_model_option") + if care_model == "Care home": + enter_care_home_details("WHITESTONES CARE HOME") + attach_screenshot("entered_care_home_details") if vaccinate_decision.lower() == 'yes': click_yes_vaccinated_radiobutton() attach_screenshot("clicked_yes_vaccinated_radiobutton") - click_vaccine_type(vaccine_type2) attach_screenshot("clicked_vaccine_type") - set_vaccination_date(vaccination_date) - attach_screenshot("vaccination_date_is_set") - click_care_model_option(care_model) - attach_screenshot("clicked_care_model_option") - if care_model == "Care home": - enter_care_home_details("WHITESTONES CARE HOME") - attach_screenshot("entered_care_home_details") - logging.debug("Vaccination legal mechanism is: " + legal_mechanism) - logging.debug("Vaccinator to select is: " + vaccinator) - if (legal_mechanism) != "Patient Group Direction (PGD)": - select_vaccinator_name_and_council(vaccinator) - attach_screenshot("selected_vaccinator_name_and_council") - enter_vaccination_comments(vaccination_comments) - attach_screenshot("entered_vaccination_comments") select_vaccination_site(vaccination_site) attach_screenshot("selected_vaccination_site") batch_number_to_select = batch_number.upper() + " - " + batch_expiry_date @@ -381,22 +380,62 @@ def enter_vaccine_details_and_click_continue_to_check_and_confirm(vaccinate_deci attach_screenshot("entered_dose_amount_value") if click_continue_to_check_and_confirm_screen_button() == True: - vaccination_date = format_date(vaccination_date, "safari") - set_vaccination_date(vaccination_date) attach_screenshot("vaccination_date_is_set") select_batch_number(batch_number_to_select) attach_screenshot("selected_batch_number") - click_continue_to_check_and_confirm_screen_button() attach_screenshot("clicked_continue_to_check_and_confirm_screen_button") + else: + click_not_vaccinated_radiobutton() + attach_screenshot("clicked_not_vaccinated_radiobutton") + if no_vaccination_reason is not None: + select_reason_for_no_vaccination(no_vaccination_reason) + attach_screenshot("selected_reason_for_no_vaccination") + click_save_and_return_button_on_record_vaccinated_page() + attach_screenshot("clicked_save_and_return_button_on_record_vaccinated_page") + attach_screenshot("patient_decided_to_not_vaccinate_saved_and_returned") +def enter_vaccine_details_and_click_save_and_return(vaccinate_decision, care_model, vaccination_date, vaccine, vaccine_type2, vaccination_site, batch_number, batch_expiry_date, dose_amount, vaccinator, vaccination_comments, legal_mechanism, no_vaccination_reason=None): + set_vaccination_date(vaccination_date) + attach_screenshot("vaccination_date_is_set") + logging.debug("Vaccination legal mechanism is: " + legal_mechanism) + logging.debug("Vaccinator to select is: " + vaccinator) + if (legal_mechanism) != "Patient Group Direction (PGD)": + select_vaccinator_name_and_council(vaccinator) + attach_screenshot("selected_vaccinator_name_and_council") + enter_vaccination_comments(vaccination_comments) + attach_screenshot("entered_vaccination_comments") + click_care_model_option(care_model) + attach_screenshot("clicked_care_model_option") + if care_model == "Care home": + enter_care_home_details("WHITESTONES CARE HOME") + attach_screenshot("entered_care_home_details") + if vaccinate_decision.lower() == 'yes': + click_yes_vaccinated_radiobutton() + attach_screenshot("clicked_yes_vaccinated_radiobutton") + click_vaccine_type(vaccine_type2) + attach_screenshot("clicked_vaccine_type") + select_vaccination_site(vaccination_site) + attach_screenshot("selected_vaccination_site") + batch_number_to_select = batch_number.upper() + " - " + batch_expiry_date + logging.debug("Batch number to select is: " + batch_number_to_select) + select_batch_number(batch_number_to_select) + attach_screenshot("selected_batch_number") + enter_dose_amount_value(dose_amount) + attach_screenshot("entered_dose_amount_value") + if click_continue_to_check_and_confirm_screen_button() == True: + attach_screenshot("vaccination_date_is_set") + select_batch_number(batch_number_to_select) + attach_screenshot("selected_batch_number") + click_continue_to_check_and_confirm_screen_button() + attach_screenshot("clicked_continue_to_check_and_confirm_screen_button") else: click_not_vaccinated_radiobutton() attach_screenshot("clicked_not_vaccinated_radiobutton") if no_vaccination_reason is not None: select_reason_for_no_vaccination(no_vaccination_reason) attach_screenshot("selected_reason_for_no_vaccination") - click_save_and_return_button_on_record_vaccinated_page + click_save_and_return_button_on_record_vaccinated_page() attach_screenshot("clicked_save_and_return_button_on_record_vaccinated_page") click_save_and_return_button_on_record_vaccinated_page() attach_screenshot("patient_decided_to_not_vaccinate_saved_and_returned") @@ -525,6 +564,25 @@ def step_enter_vaccination_details_and_continue_to_check_and_confirm_screen(shar attach_screenshot("entered_vaccination_details") logging.info(shared_data) +@when(parse("I record {vaccination} details and date as {vaccination_date} and click Save and return button")) +def step_enter_vaccination_details_and_continue_to_check_and_confirm_screen(shared_data, vaccination, vaccination_date): + shared_data["vaccinated_decision"] = vaccination + if shared_data["consent_decision"].lower() == "yes": + if shared_data["eligibility_assessment_outcome"].lower() == "give vaccine": + shared_data["vaccination_date"] = format_date(str(get_date_value(vaccination_date)), config["browser"]) + chosen_vaccine = shared_data["chosen_vaccine"] + shared_data["vaccination_site"] = get_vaccination_site(shared_data["index"]) + shared_data["dose_amount"] = str(get_vaccine_dose_amount(shared_data["chosen_vaccine_type"])) + if shared_data['legal_mechanism'] == "Patient Group Direction (PGD)": + shared_data['vaccinator'] = shared_data['eligibility_assessing_clinician'] + else: + shared_data["vaccinator"] = get_vaccinator(shared_data["index"]) + shared_data["vaccination_comments"] = shared_data["chosen_vaccine_type"] + "vaccination given on " + shared_data["vaccination_date"] + " for " + shared_data["patient_name"] + shared_data["no_vaccination_reason"] = get_vaccination_not_given_reason(shared_data["index"]) + enter_vaccine_details_and_click_save_and_return(shared_data["vaccinated_decision"], shared_data["care_model"], shared_data["vaccination_date"], chosen_vaccine, shared_data["chosen_vaccine_type"], shared_data["vaccination_site"], shared_data["batch_number"], shared_data["batch_expiry_date"], shared_data["dose_amount"], shared_data["vaccinator"], shared_data["vaccination_comments"], shared_data["legal_mechanism"], shared_data["no_vaccination_reason"]) + attach_screenshot("entered_vaccination_details") + logging.info(shared_data) + @then(parse("I need to be able to see the patient {name}, {dob}, {address} and vaccination details on the check and confirm screen")) def step_see_patient_details_on_check_and_confirm_screen(shared_data, name, dob, address): if shared_data["vaccinated_decision"].lower() == "Yes".lower() and shared_data["consent_decision"].lower() == "Yes".lower() and shared_data["eligibility_assessment_outcome"].lower() == "Give vaccine".lower(): @@ -537,6 +595,7 @@ def step_see_patient_details_on_check_and_confirm_screen(shared_data, name, dob, assert get_patient_eligibility_assessment_date_value() == date_format_with_day_of_week(shared_data['eligibility_assessment_date']) assert get_patient_vaccinated_date_value() == date_format_with_day_of_week(shared_data['vaccination_date']) assert get_patient_dob_value() == date_format_with_age(dob) + shared_data['dob'] = date_format_with_age(dob) assert get_patient_vaccination_batch_expiry_date_value() == date_format_with_name_of_month(shared_data['batch_expiry_date']) assert get_patient_eligibility_assessing_clinician_vaccine_value() == shared_data['eligibility_assessing_clinician'] assert get_patient_consent_recorded_by_clinician_value() == shared_data['consent_clinician_details'] @@ -565,7 +624,10 @@ def immunisation_history_should_be_updated(shared_data): def immunisation_history_should_be_updated(shared_data): attach_screenshot("immunisation_history_records_count_after_vaccination") immunisation_history_records_count_after_vaccination = get_count_of_immunisation_history_records(shared_data["chosen_vaccine"]) - assert int(immunisation_history_records_count_after_vaccination) >= int(shared_data["immunisation_history_records_count_before_vaccination"]) + 1 + if shared_data['vaccinated_decision'].lower() == "yes": + assert int(immunisation_history_records_count_after_vaccination) >= int(shared_data["immunisation_history_records_count_before_vaccination"]) + 1 + else: + assert int(immunisation_history_records_count_after_vaccination) == int(shared_data["immunisation_history_records_count_before_vaccination"]) @then("when I click confirm and save button, the immunisation history of the patient should be updated in the patient details page") def click_confirm_and_save_button_immunisation_history_should_be_updated(shared_data): diff --git a/features/reports.feature b/features/reports.feature index c8f805f35..9cc8e742b 100644 --- a/features/reports.feature +++ b/features/reports.feature @@ -84,7 +84,6 @@ Scenario Outline: Choose data page is displayed And I select the site and click continue Then the choose data page should be displayed and all data options should be checked by default - Examples: |vaccineType | site | | COVID-19 | Albert House | @@ -178,3 +177,29 @@ Scenario Outline: User can download the report | index | nhs_number | site | care_model | eligibility | assess_date | consent | vaccination | vaccination_date | name | dob | address | chosen_vaccine | batch_number | batch_expiry_date | | 0 | 9693632109 | Albert House | Vaccination Centre open to the public | yes | today | yes | yes | today | Bill GARTON | 23/6/1946 | 1 MOUNT AVENUE, BARTON-UPON-HUMBER, S HUMBERSIDE, DN18 5DW | COVID-19 | AUTOMATION-SJ1 | 19/10/2026 | | 0 | 9693632109 | Albert House | Vaccination Centre open to the public | yes | today | yes | yes | today-32 | Bill GARTON | 23/6/1946 | 1 MOUNT AVENUE, BARTON-UPON-HUMBER, S HUMBERSIDE, DN18 5DW | COVID-19 | AUTOMATION-SJ1 | 19/10/2026 | + + Scenario Outline: Record a vaccine and generate a report for no vaccination decision on the last screen + Given I am logged into the RAVS app + And I login to RAVS and set vaccinator details with and and get patient details for with option and choose to vaccinate with vaccine details as , with + And I search for a patient with the NHS number in the find a patient screen + And I open the patient record by clicking on patient + When I click choose vaccine button and choose the , with and click continue + And I assess the patient's with the details and date as and click continue to record consent screen button + And I record with the details and click continue to vaccinate button + And I record details and date as and click Save and return button + Then I search for a patient with the NHS number in the find a patient screen + And I open the patient record by clicking on patient + And the immunisation history of the patient should be updated in the patient details page and not be deleted + When I click the reports navigation link + And I click the create report button + And I click the Today radio button and click Continue + And I select the vaccine type and click continue + And I select the site and click continue + And I click continue on the data page + And I click Confirm and create report button in the check and confirm page + And I click download report button + Then the report is downloaded successfully and contains the vaccine record for + + Examples: + | index | nhs_number | site | care_model | eligibility | assess_date | consent | vaccination | vaccination_date | name | dob | address | chosen_vaccine | batch_number | batch_expiry_date | + | 4 | 9437541817 | KINGSTON HOUSE | Outreach event | yes | today | yes | no | today | FLORINDA DUNNER | 27/3/1957 | 32 HOLLAND ROAD, MANCHESTER, M8 4NP | Flu | AUTOMATION-SJ1 | 19/10/2026 | diff --git a/helpers/playwrightHelper.py b/helpers/playwrightHelper.py index 70885410b..dd70b4fff 100644 --- a/helpers/playwrightHelper.py +++ b/helpers/playwrightHelper.py @@ -323,7 +323,7 @@ def find_element_and_perform_action(self, locator_or_element, action, inputValue if element.is_visible(): if element.text_content() != '': element.clear() # Clear existing text - element.type(inputValue) + element.type(inputValue, delay=50) print(f"Typed text '{inputValue}' successfully.") else: print(f"Unsupported action: {action}") @@ -381,7 +381,7 @@ def get_element_by_type(self, locator_type_or_selector, locator_value=None, name elif locator_type_or_selector == "text": return self.page.get_by_text(locator_value, exact=exact) elif locator_type_or_selector == "label": - return self.page.get_by_label(locator_value, exact=exact) + return self.page.get_by_label(locator_value, exact=exact).nth(0) elif locator_type_or_selector == "placeholder": return self.page.get_by_placeholder(locator_value) elif locator_type_or_selector == "xpath": diff --git a/pages/find_a_patient_page.py b/pages/find_a_patient_page.py index f7441e48c..6237a7d82 100644 --- a/pages/find_a_patient_page.py +++ b/pages/find_a_patient_page.py @@ -15,14 +15,14 @@ PAGE_LOADING_ELEMENT = ("text", "Loading...Loading...") # Shared -NHS_NUMBER_INPUT = ("label", "Enter a 10 digit NHS number") - -FIRST_NAME_INPUT = ("label", "First name") -LAST_NAME_INPUT = ("label", "Last name") -GENDER_OPTIONAL_SELECT = ("label", "Gender field optional") -POSTCODE_OPTIONAL_INPUT = ("label", "Postcode field optional") -GENDER_SELECT = ("label", "Gender") -POSTCODE_INPUT = ("label", "Postcode") +NHS_NUMBER_INPUT = ("id", "NhsNumber") + +FIRST_NAME_INPUT = ("id", "FirstName") +LAST_NAME_INPUT = ("id", "LastName") +GENDER_OPTIONAL_SELECT = ("id", "GenderId") +POSTCODE_OPTIONAL_INPUT = ("id", "Postcode") +GENDER_SELECT = ("id", "GenderId") +POSTCODE_INPUT = ("id", "Postcode") DOB_DAY_INPUT = ("label", "Day") DOB_MONTH_INPUT = ("label", "Month") DOB_YEAR_INPUT = ("label", "Year") diff --git a/pages/record_vaccinated_page.py b/pages/record_vaccinated_page.py index 986947fcc..6e738f341 100644 --- a/pages/record_vaccinated_page.py +++ b/pages/record_vaccinated_page.py @@ -3,7 +3,7 @@ from test_data.get_values_from_models import get_covid_vaccine_xpath, get_flu_vaccine_xpath YES_VACCINATED_RADIO_BUTTON=("label", "Yes") -NO_VACCINATED_RADIO_BUTTON=("label", "No") +NO_VACCINATED_RADIO_BUTTON=("label", "No", True) VACCINATOR_DROPDOWN_ELEMENT = ("label","Vaccinator") SAVE_AND_RETURN_BUTTON=("role", "button", "Save and return") CONTINUE_TO_CHECK_AND_CONFIRM_BUTTON=("role", "button", "Continue") @@ -62,10 +62,12 @@ def check_no_to_vaccinated_radiobutton_exists(): return check_element_exists(NO_VACCINATED_RADIO_BUTTON, True) def click_yes_vaccinated_radiobutton(): + wait_for_element_to_appear(YES_VACCINATED_RADIO_BUTTON) find_element_and_perform_action(YES_VACCINATED_RADIO_BUTTON, "click") def click_not_vaccinated_radiobutton(): - find_element_and_perform_action(NO_VACCINATED_RADIO_BUTTON, "click") + wait_for_element_to_appear(NO_VACCINATED_RADIO_BUTTON) + find_element_and_perform_action(NO_VACCINATED_RADIO_BUTTON, "check") def select_vaccinator_name_and_council(nameandcouncil): if check_element_enabled(VACCINATOR_DROPDOWN_ELEMENT): diff --git a/pages/reports_data_selection_page.py b/pages/reports_data_selection_page.py index ef1e6bfec..8e47a0a48 100644 --- a/pages/reports_data_selection_page.py +++ b/pages/reports_data_selection_page.py @@ -41,7 +41,7 @@ def check_continue_to_reports_check_and_confirm_button_exists(): wait_for_element_to_disappear(PAGE_LOADING_ELEMENT) wait_for_element_to_appear(CONTINUE_TO_REPORTS_CHECK_AND_CONFIRM_BUTTON) return check_element_exists(CONTINUE_TO_REPORTS_CHECK_AND_CONFIRM_BUTTON) - + def click_continue_to_reports_select_data_button(): wait_for_element_to_disappear(PAGE_LOADING_ELEMENT) wait_for_element_to_appear(CONTINUE_TO_REPORTS_CHECK_AND_CONFIRM_BUTTON) diff --git a/tests/test_reports_steps.py b/tests/test_reports_steps.py index c42db545b..f9bccf0b8 100644 --- a/tests/test_reports_steps.py +++ b/tests/test_reports_steps.py @@ -226,15 +226,6 @@ def I_click_today_date_range_and_click_continue(shared_data): attach_screenshot("clicked_continue_to_reports_select_vaccine_button") logging.info("clicked_continue_to_reports_select_vaccine_button") -@when(parse('I select the vaccine type {vaccineType} and click continue')) -def I_select_vaccinetype_and_click_continue(shared_data, vaccineType): - click_vaccine_check_box_on_reports_page(vaccineType) - attach_screenshot("clicked_" + vaccineType.lower() + "_check_box_on_reports_page") - logging.info("clicked_" + vaccineType.lower() + "_check_box_on_reports_page") - click_continue_to_reports_select_site_button() - attach_screenshot("clicked_continue_to_reports_select_site_button") - logging.info("clicked_continue_to_reports_select_site_button") - @then("the choose sites page should be displayed") def the_choose_sites_page_should_be_displayed(): assert check_site_check_box_exists("ALBERT HOUSE") == True @@ -261,12 +252,6 @@ def the_choose_data_page_should_be_displayed(): attach_screenshot("check_choose_data_pages_reports_exists") logging.info("check_choose_data_pages_reports_exists") -@when(parse('I click continue on the data page')) -def I_select_data_and_click_continue(shared_data): - click_continue_to_reports_select_data_button() - attach_screenshot("clicked_continue_to_reports_select_data_button") - logging.info("clicked_continue_to_reports_select_data_button") - @then("the check and confirm page should be displayed") def the_check_and_confirm_page_should_be_displayed(): assert check_reports_change_data_button_exists() == True @@ -331,6 +316,7 @@ def the_report_is_downloaded_successfully(shared_data, nhs_number): vaccinated_decision = shared_data["vaccinated_decision"] consent_given_by = shared_data['consent_given_by'] eligibility_type = shared_data['eligibility_type'] + patient_name = shared_data['patient_name'] if vaccination_date: # Convert the vaccination date from shared_data to a datetime object @@ -344,69 +330,163 @@ def the_report_is_downloaded_successfully(shared_data, nhs_number): with open(shared_data['report_download_path'], mode="r", newline="", encoding="utf-8") as file: reader = csv.DictReader(file) - for row in reader: - # For each row, ensure that all columns have non-empty values + rows = list(reader) + last_row = rows[-1] if rows else None + + if last_row: + logger.info(f"Validating the latest row for vaccination date: {vaccination_date}...") + + if 0 <= date_diff <= 31: + # If vaccination date is within the last 31 days, ensure all columns have values + logger.info(f"Vaccination date '{vaccination_date}' is within the last 31 days. Verifying all columns in the last row...") + for header in expected_headers: - if header == "NoVaccinationReason": - # If vaccinated_decision is "yes", NoVaccinationReason should be empty + if vaccinated_decision.lower() == "no": + for field in ["Vaccine", "VaccineProduct", "DoseAmount", "VaccineRoute"]: + assert not last_row[field], ( + f"Column '{field}' should be empty for NHS number {shared_data['nhs_number']} as vaccinated_decision is 'No'." + ) + + elif header == "NoVaccinationReason": if vaccinated_decision.lower() == "yes": - assert not row[header], f"Column 'NoVaccinationReason' should be empty for NHS number {shared_data['nhs_number']} as vaccinated_decision is 'yes'." + assert not last_row[header], ( + f"Column 'NoVaccinationReason' should be empty for NHS number {shared_data['nhs_number']} as vaccinated_decision is 'yes'." + ) else: - assert row[header], f"Missing value in column '{header}' for NHS number {shared_data['nhs_number']}." - elif header == "ConsentingPersonName" or header == "ConsentingPersonRelationship": + assert last_row[header], ( + f"Missing value in column 'NoVaccinationReason' for NHS number {shared_data['nhs_number']}." + ) + elif header in ["ConsentingPersonName", "ConsentingPersonRelationship"]: if consent_given_by == "Patient (informed consent)": - assert not row[header], f"Column 'ConsentingPersonName' and 'ConsentingPersonRelationship' should be empty for NHS number {shared_data['nhs_number']} as consent given by patient (informed consent)" + assert not last_row[header], ( + f"Column '{header}' should be empty for NHS number {shared_data['nhs_number']} as consent given by patient (informed consent)." + ) else: - assert row[header], f"Missing value in column '{header}' for NHS number {shared_data['nhs_number']}." + assert last_row[header], ( + f"Missing value in column '{header}' for NHS number {shared_data['nhs_number']}." + ) elif header == "StaffType": if eligibility_type == "Healthcare workers": - assert row[header], f"Column 'StaffType' should not be empty for NHS number {shared_data['nhs_number']} as eligibility_type is 'Healthcare workers'." + assert last_row[header], ( + f"Column 'StaffType' should not be empty for NHS number {shared_data['nhs_number']} as eligibility_type is 'Healthcare workers'." + ) else: - assert not row[header], f"Column 'StaffType' should be empty for NHS number {shared_data['nhs_number']} as eligibility_type is not 'Healthcare workers'." + assert not last_row[header], ( + f"Column 'StaffType' should be empty for NHS number {shared_data['nhs_number']} as eligibility_type is not 'Healthcare workers'." + ) else: # For other columns, ensure they are not empty - assert row[header], f"Missing value in column '{header}' for NHS number {shared_data['nhs_number']}." - - # Validate the presence of the vaccination date in the report - is_vaccination_date_present = validate_value_in_header( - shared_data['report_download_path'], - "VaccinationDate", - vaccination_date - ) - assert is_vaccination_date_present, ( - f"Value '{vaccination_date}' not found under header 'VaccinationDate' in the report." - ) - - # Validate the presence of the NHS number only if the vaccination date is within the last 31 days - is_nhsNumber_present = validate_value_in_header(shared_data['report_download_path'], "NhsNumber", shared_data["nhs_number"]) - assert is_nhsNumber_present, f"Value '{shared_data['nhs_number']}' not found under header 'NhsNumber' in the report." - + assert last_row[header], ( + f"Missing value in column '{header}' for NHS number {shared_data['nhs_number']}." + ) + + # Validate the presence of the vaccination date in the last row + assert last_row["VaccinationDate"] == vaccination_date, ( + f"Value '{vaccination_date}' not found in the 'VaccinationDate' column of the last row." + ) + + # Validate the presence of the NHS number in the last row + assert last_row["NhsNumber"] == shared_data["nhs_number"], ( + f"Value '{shared_data['nhs_number']}' not found in the 'NhsNumber' column of the last row." + ) + + assert last_row["PatientName"].lower() == shared_data["patient_name"].lower(), ( + f"Mismatch in 'PatientName': expected '{shared_data['patient_name']}' but found '{last_row['PatientName']}'." + ) + + assert last_row["AssessmentDate"] == shared_data["eligibility_assessment_date"], ( + f"Mismatch in 'AssessmentDate': expected '{shared_data['eligibility_assessment_date']}' but found '{last_row['AssessmentDate']}'." + ) + + assert last_row["AssessingClinician"].lower() == shared_data["eligibility_assessing_clinician"].lower(), ( + f"Mismatch in 'AssessingClinician': expected '{shared_data['eligibility_assessing_clinician']}' but found '{last_row['AssessingClinician']}'." + ) + + assert last_row["SiteName"].lower() == shared_data["site"].lower(), ( + f"Mismatch in 'SiteName': expected '{shared_data['site']}' but found '{last_row['SiteName']}'." + ) + + assert last_row["CareModel"].lower() == shared_data["care_model"].lower(), ( + f"Mismatch in 'CareModel': expected '{shared_data['care_model']}' but found '{last_row['CareModel']}'." + ) + + assert last_row["Consented"].lower() == shared_data["consent_decision"].lower(), ( + f"Mismatch in 'Consented': expected '{shared_data['consent_decision']}' but found '{last_row['Consented']}'." + ) + + assert last_row["ConsentType"].lower() == shared_data["consent_given_by"].lower(), ( + f"Mismatch in 'ConsentType': expected '{shared_data['consent_given_by']}' but found '{last_row['ConsentType']}'." + ) + + assert last_row["EligibilityType"].lower() == shared_data["eligibility_type"].lower(), ( + f"Mismatch in 'EligibilityType': expected '{shared_data['eligibility_type']}' but found '{last_row['EligibilityType']}'." + ) + + assert last_row["AssessmentComments"].lower() == shared_data["assessment_comments"].lower(), ( + f"Mismatch in 'AssessmentComments': expected '{shared_data['assessment_comments']}' but found '{last_row['AssessmentComments']}'." + ) + + if shared_data["consent_given_by"] != "Patient (informed consent)": + assert last_row["ConsentingPersonName"].lower() == "Automation tester".lower(), ( + f"Mismatch in 'ConsentingPersonName': expected 'Automation tester' but found '{last_row['ConsentingPersonName']}'." + ) + assert last_row["ConsentingPersonRelationship"].lower() == "RAVS tester".lower(), ( + f"Mismatch in 'ConsentingPersonRelationship': expected 'RAVS tester' but found '{last_row['ConsentingPersonRelationship']}'." + ) + + else: + # If vaccination date is more than 31 days old, ensure the last row does not have this date + assert last_row["VaccinationDate"] != vaccination_date, ( + f"Row with vaccination date '{vaccination_date}' found in the last row, but it should not be present since it's older than 31 days." + ) + + logger.info(f"Vaccination date '{vaccination_date}' is correctly not present in the last row of the report.") else: - # If vaccination date is more than 31 days old, ensure no rows for that date - logger.info(f"Vaccination date '{vaccination_date}' is more than 31 days old. Ensuring no rows exist with this date in the report.") + logger.warning("The report file is empty. No rows to validate.") - with open(shared_data['report_download_path'], mode="r", newline="", encoding="utf-8") as file: - reader = csv.DictReader(file) - found_invalid_row = False - for row in reader: - if row["VaccinationDate"] == vaccination_date: - found_invalid_row = True - break - - assert not found_invalid_row, ( - f"Row with vaccination date '{vaccination_date}' found in the report, but it should not be present since it's older than 31 days." - ) - - logger.info(f"Vaccination date '{vaccination_date}' is correctly not present in the report.") - attach_screenshot("click_" + site.lower() + "_check_box_on_reports_page") - logging.info("click_" + site.lower() + "_check_box_on_reports_page") + +@when(parse('I select the vaccine type {vaccineType} and click continue')) +def I_select_vaccinetype_and_click_continue(shared_data, vaccineType): + click_vaccine_check_box_on_reports_page(vaccineType) + attach_screenshot("clicked_" + vaccineType.lower() + "_check_box_on_reports_page") + logging.info("clicked_" + vaccineType.lower() + "_check_box_on_reports_page") + click_continue_to_reports_select_site_button() + attach_screenshot("clicked_continue_to_reports_select_site_button") + logging.info("clicked_continue_to_reports_select_site_button") + +@then("the choose sites page should be displayed") +def the_choose_sites_page_should_be_displayed(): + assert check_site_check_box_exists("ALBERT HOUSE") == True + attach_screenshot("check_choose_sites_page_is_displayed") + logging.info("check_choose_sites_page_is_displayed") + +@when(parse('I click continue on the data page')) +def I_select_data_and_click_continue(shared_data): click_continue_to_reports_select_data_button() - attach_screenshot("click_continue_to_reports_select_data_button") - logging.info("click_continue_to_reports_select_data_button") + attach_screenshot("clicked_continue_to_reports_select_data_button") + logging.info("clicked_continue_to_reports_select_data_button") + +@then("the report is downloaded successfully") +def the_report_is_downloaded_successfully(shared_data): + assert os.path.exists(shared_data['report_download_path']), f"Downloaded file not found: {shared_data['report_download_path']}" + attach_screenshot("check_report_downloaded") + logger.info("check_report_downloaded_to_" + str(shared_data['report_download_path'])) + expected_headers = [ + "NhsNumber", "PatientName", "Gender", "DateOfBirth", "Address", "Postcode", + "SiteName", "SiteODS", "OrganisationName", "OrganisationODS", "CareModel", + "Vaccinated", "NoVaccinationReason", "AssessmentDate", "Consented", "ConsentType", + "ConsentingPersonName", "ConsentingPersonRelationship", "EligibilityType", "StaffType", + "AssessmentComments", "VaccinationDate", "Vaccine", "VaccineProduct", "DoseAmount", + "VaccineRoute", "PrescribingMethod", "BatchNumber", "BatchExpiryDate", "AuditType", + "DateEntered", "UserEnteringData", "VaccinationComments", "AssessingClinician", + "VaccinatingClinician", "ConsentingClinician" +] + is_valid, _ = validate_report_headers(shared_data['report_download_path'], expected_headers) + assert is_valid, "Report headers are invalid. See logs for details." @then("the choose data page should be displayed") def the_choose_data_page_should_be_displayed(): - assert check_data_check_box_exists("Patients") == True + assert check_reports_data_check_box_exists("Patients") == True attach_screenshot("check_choose_data_pages_reports_exists") logging.info("check_choose_data_pages_reports_exists")