Skip to content

Commit d4d77cb

Browse files
Updating compartment 1 to obtain nhs_numbers of the batches from the DB instead of the downloaded file
Edited compartment 1 so IOM can be toggled on/off as currently we have a data issue
1 parent 36d0802 commit d4d77cb

File tree

3 files changed

+55
-37
lines changed

3 files changed

+55
-37
lines changed

tests/Smokescreen/test_compartment_1.py

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44
from utils.batch_processing import batch_processing
55
from utils.oracle import OracleDB
66

7-
# To Do:
8-
# Create a common click() function -> this aims to solve an issue where sometimes it thinks it has clicked the element but the page does not change
9-
107
@pytest.mark.smoke
118
@pytest.mark.smokescreen
12-
@pytest.mark.wip
139
def test_compartment_1(page: Page) -> None:
10+
execute_iom = False
11+
1412
page.goto("/")
1513
BcssLoginPage(page).login_as_user("BCSS401")
1614

1715
# Create plan
16+
# England
1817
MainMenu(page).go_to_call_and_recall_page()
1918
CallAndRecall(page).go_to_planning_and_monitoring_page()
20-
InvitationsMonitoring(page).go_to_bcss001_invitations_plan_page() # This code is for bcss001 (IOM)
19+
InvitationsMonitoring(page).go_to_bcss001_invitations_plan_page()
2120
InvitationsPlans(page).go_to_create_a_plan_page()
2221
CreateAPlan(page).click_set_all_button()
2322
CreateAPlan(page).fill_daily_invitation_rate_field("10")
@@ -27,18 +26,20 @@ def test_compartment_1(page: Page) -> None:
2726
CreateAPlan(page).fill_note_field("test data")
2827
CreateAPlan(page).click_saveNote_button()
2928
InvitationsPlans(page).invitations_plans_title.wait_for()
30-
NavigationBar(page).click_back_link()
3129

32-
InvitationsMonitoring(page).go_to_bcss009_invitations_plan_page() # This code is Replicated for bcss009 (IOM)
33-
InvitationsPlans(page).go_to_create_a_plan_page()
34-
CreateAPlan(page).click_set_all_button()
35-
CreateAPlan(page).fill_daily_invitation_rate_field("1")
36-
CreateAPlan(page).click_update_button()
37-
CreateAPlan(page).click_confirm_button()
38-
CreateAPlan(page).click_save_button()
39-
CreateAPlan(page).fill_note_field("test data")
40-
CreateAPlan(page).click_saveNote_button()
41-
InvitationsPlans(page).invitations_plans_title.wait_for()
30+
# Isle Of Man
31+
if execute_iom:
32+
NavigationBar(page).click_back_link()
33+
InvitationsMonitoring(page).go_to_bcss009_invitations_plan_page()
34+
InvitationsPlans(page).go_to_create_a_plan_page()
35+
CreateAPlan(page).click_set_all_button()
36+
CreateAPlan(page).fill_daily_invitation_rate_field("1") # This step will fail as currently there are insufficient subjects in the next invitations shortlist (we are working on this with compartment 0)
37+
CreateAPlan(page).click_update_button()
38+
CreateAPlan(page).click_confirm_button()
39+
CreateAPlan(page).click_save_button()
40+
CreateAPlan(page).fill_note_field("test data")
41+
CreateAPlan(page).click_saveNote_button()
42+
InvitationsPlans(page).invitations_plans_title.wait_for()
4243

4344
# Generate Invitations
4445
NavigationBar(page).click_main_menu_link()
@@ -49,24 +50,26 @@ def test_compartment_1(page: Page) -> None:
4950

5051
# Print the batch of Pre-Invitation Letters - England
5152
batch_processing(page, "S1", "Pre-invitation (FIT) (digital leaflet)", "S9 - Pre-invitation Sent")
52-
s1_nhs_numbers = batch_processing(page, "S1", "Pre-invitation (FIT)", "S9 - Pre-invitation Sent") # New batch processing for S1 IOM TODO
53-
for nhs_no in range(len(s1_nhs_numbers)): # Change this to get nhs numbers from DF instead of list TODO
54-
OracleDB().exec_bcss_timed_events(s1_nhs_numbers[nhs_no-1])
53+
nhs_number_df = batch_processing(page, "S1", "Pre-invitation (FIT)", "S9 - Pre-invitation Sent")
54+
for index, row in nhs_number_df.iterrows():
55+
OracleDB().exec_bcss_timed_events(row["subject_nhs_number"])
5556

56-
# Print the batch of Pre-Invitation Letters - IsleMan
57-
s1_nhs_numbers = batch_processing(page, "S1", "Pre-invitation (gFOBT)", "S9 - Pre-invitation Sent") # New batch processing for S1 IOM TODO
58-
for nhs_no in range(len(s1_nhs_numbers)): # Change this to get nhs numbers from DF instead of list TODO
59-
OracleDB().exec_bcss_timed_events(s1_nhs_numbers[nhs_no-1])
57+
# Print the batch of Pre-Invitation Letters - Isle Of Man
58+
if execute_iom:
59+
nhs_number_df = batch_processing(page, "S1", "Pre-invitation (gFOBT)", "S9 - Pre-invitation Sent")
60+
for index, row in nhs_number_df.iterrows():
61+
OracleDB().exec_bcss_timed_events(row["subject_nhs_number"])
6062

6163
# Print the batch of Invitation & Test Kit Letters - England
62-
s9_nhs_numbers = batch_processing(page, "S9", "Invitation & Test Kit (FIT)", "S10 - Invitation & Test Kit Sent") # New batch processing for S9 IOM TODO
63-
for nhs_no in range(len(s9_nhs_numbers)):
64-
OracleDB().exec_bcss_timed_events(s9_nhs_numbers[nhs_no-1]) # Change this to get nhs numbers from DF instead of list TODO
64+
nhs_number_df = batch_processing(page, "S9", "Invitation & Test Kit (FIT)", "S10 - Invitation & Test Kit Sent")
65+
for index, row in nhs_number_df.iterrows():
66+
OracleDB().exec_bcss_timed_events(row["subject_nhs_number"])
6567

66-
# Print the batch of Pre-Invitation Letters - IsleMan
67-
s9_nhs_numbers = batch_processing(page, "S9", "Invitation & Test Kit (gFOBT)", "S10 - Invitation & Test Kit Sent") # New batch processing for S9 IOM TODO
68-
for nhs_no in range(len(s9_nhs_numbers)):
69-
OracleDB().exec_bcss_timed_events(s9_nhs_numbers[nhs_no-1]) # Change this to get nhs numbers from DF instead of list TODO
68+
# Print the batch of Pre-Invitation Letters - Isle Of Man
69+
if execute_iom:
70+
nhs_number_df = batch_processing(page, "S9", "Invitation & Test Kit (gFOBT)", "S10 - Invitation & Test Kit Sent")
71+
for index, row in nhs_number_df.iterrows():
72+
OracleDB().exec_bcss_timed_events(row["subject_nhs_number"])
7073

7174
# Print a set of reminder letters
7275
batch_processing(page, "S10", "Test Kit Reminder", "S19 - Reminder of Initial Test Sent")

utils/batch_processing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pages.archived_batch_list_page import ArchivedBatchList
77
from utils.pdf_reader import extract_nhs_no_from_pdf
88
from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no
9+
from utils.get_nhs_no_from_batch_id import get_nhs_no_from_batch_id
910
import os
1011
import pytest
1112
from playwright.sync_api import Page
@@ -28,18 +29,18 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
2829
row = batch_description_cells.nth(i).locator("..") # Get the parent row
2930

3031
# Check if the row contains "Prepared" or "Open"
31-
if row.locator("td", has_text="Prepared").count() > 0 or row.locator("td", has_text="Open").count() > 0: #Within if statement get nhs_number from DB TODO
32+
if row.locator("td", has_text="Prepared").count() > 0 or row.locator("td", has_text="Open").count() > 0:
3233
# Find the first link in that row and click it
3334
link = row.locator("a").first
3435
link_text = link.inner_text() # Get the batch id dynamically
35-
# new code here query DB (getSubjectsFromLetterBatchID function in selenium code) passing in a batch id to get the nhs numbers of the subjects TODO
36+
nhs_no_df = get_nhs_no_from_batch_id(link_text)
3637
link.click()
3738
break
3839
else:
3940
pytest.fail(f"No open/prepared '{batch_type} - {batch_description}' batch found")
4041

4142
ManageActiveBatch(page).click_prepare_button()
42-
43+
page.wait_for_timeout(1000) # This one second timeout does not affect the time to execute, as it is just used to ensure the reprepare batch button is clicked and does not instantly advance to the next step
4344
ManageActiveBatch(page).reprepare_batch_text.wait_for()
4445

4546
# This loops through each Retrieve button and clicks each one
@@ -55,8 +56,6 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
5556
# Wait for the download process to complete and save the downloaded file in a temp folder
5657
download_file.save_as(file)
5758
if file.endswith(".pdf"):
58-
nhs_numbers = extract_nhs_no_from_pdf(file) # Remove pdf_reader TODO
59-
first_nhs_no = nhs_numbers[0]
6059
os.remove(file) # Deletes the file after extracting the necessary data
6160
elif file.endswith(".csv"):
6261
os.remove(file) # Deletes the file after extracting the necessary data
@@ -74,5 +73,6 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
7473
ArchivedBatchList(page).enter_id_filter(link_text)
7574
ArchivedBatchList(page).verify_table_data(link_text)
7675

77-
verify_subject_event_status_by_nhs_no(page, first_nhs_no, latest_event_status) # This needs to be changed to pass an NHS number from the new DF first_nhs_no = df["COL NAME"].iloc[0] TODO
78-
return nhs_numbers
76+
first_nhs_no = nhs_no_df["subject_nhs_number"].iloc[0]
77+
verify_subject_event_status_by_nhs_no(page, first_nhs_no, latest_event_status)
78+
return nhs_no_df

utils/get_nhs_no_from_batch_id.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pandas as pd
2+
from oracle import OracleDB
3+
4+
def get_nhs_no_from_batch_id(batch_id):
5+
nhs_number_df = OracleDB().execute_query(f"""
6+
SELECT SUBJECT_NHS_NUMBER
7+
FROM SCREENING_SUBJECT_T ss
8+
INNER JOIN sd_contact_t c ON ss.subject_nhs_number = c.nhs_number
9+
INNER JOIN LETT_BATCH_RECORDS lbr
10+
ON ss.SCREENING_SUBJECT_ID = lbr.SCREENING_SUBJECT_ID
11+
WHERE lbr.BATCH_ID IN {batch_id}
12+
AND ss.screening_status_id != 4008
13+
ORDER BY ss.subject_nhs_number
14+
FETCH FIRST 5 ROWS ONLY""")
15+
return nhs_number_df

0 commit comments

Comments
 (0)