Skip to content

Commit 44dd07d

Browse files
Megha PrasannanMegha Prasannan
authored andcommitted
progressing the compartment 3 task 1,2,3,4
1 parent 942b1c8 commit 44dd07d

File tree

4 files changed

+78
-41
lines changed

4 files changed

+78
-41
lines changed

tests/Smokescreen/test_compartment_2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no
77
from utils.fit_kit_generation import create_fit_id_df
88

9-
@pytest.mark.wip2
9+
1010
@pytest.mark.smokescreen
1111
def test_compartment_2(page: Page) -> None:
1212
page.goto("/")

tests/Smokescreen/test_compartment_3.py

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,69 @@
44
from my_pages import *
55
from utils import oracle, fit_kit_logged
66
from utils.fit_kit_generation import create_fit_id_df
7+
from utils.fit_kit_logged import process_kit_data, update_kit_service_management_entity
78
from utils.oracle import OracleDB
89
from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no
910

10-
11+
@pytest.mark.wip2
1112
def test_compartment_3(page: Page) -> None:
1213
UserTools.user_login(page, "Hub Manager State Registered")
1314

1415
# Add results to the test records in the KIT_QUEUE table (i.e. mimic receiving results from the middleware)
15-
fit_kit_logged.process_kit_data()
16-
16+
# and get device IDs and their flags
17+
device_ids = process_kit_data()
1718
# (STEP - 4) Run two stored procedures to process any kit queue records at status BCSS_READY
18-
fit_kit_logged.execute_stored_procedures()
19-
20-
# (STEP - 5) Check the results of the processed FIT kits have correctly updated the status of the associated subjects
21-
# Navigate to log devices page
22-
MainMenu(page).go_to_fit_test_kits_page()
23-
FITTestKits(page).go_to_log_devices_page()
24-
25-
# Get a fit device id
26-
subjectdf = create_fit_id_df()
27-
28-
# Log fit device
29-
for subject in range(4):
30-
fit_device_id = subjectdf["fit_device_id"].iloc[subject]
31-
LogDevices(page).fill_fit_device_id_field(fit_device_id)
32-
sample_date = datetime.now().strftime("%#d %b %Y")
33-
LogDevices(page).fill_sample_date_field(sample_date)
34-
LogDevices(page).verify_successfully_logged_device_text()
35-
36-
# Check statuses of 'normal' FIT kit subjects has moved to S2
37-
nhs_no = subjectdf["subject_nhs_number"].iloc[0]
38-
verify_subject_event_status_by_nhs_no(page, nhs_no, "S2 - Normal")
39-
40-
# Check status of 'abnormal' FIT kit subjects has moved to A8
41-
nhs_no = subjectdf["subject_nhs_number"].iloc[0]
42-
verify_subject_event_status_by_nhs_no(page, nhs_no, "A8 - Abnormal")
19+
try:
20+
fit_kit_logged.execute_stored_procedures()
21+
logging.info("Stored procedures executed successfully.")
22+
except Exception as e:
23+
logging.error(f"Error executing stored procedures: {str(e)}")
24+
raise
25+
26+
# Retrieve NHS numbers for each device_id and determine normal/abnormal status
27+
nhs_numbers = []
28+
normal_flags = []
29+
30+
for device_id, is_normal in device_ids:
31+
nhs_number = update_kit_service_management_entity(device_id, is_normal)
32+
nhs_numbers.append(nhs_number)
33+
normal_flags.append(is_normal) # Store the flag (True for normal, False for abnormal)
34+
35+
# Verify subject event status based on normal or abnormal classification
36+
for nhs_number, is_normal in zip(nhs_numbers, normal_flags):
37+
expected_status = "S2 - Normal" if is_normal else "A8 - Abnormal" # S2 for normal, A8 for abnormal
38+
logging.info(f"Verifying NHS number: {nhs_number} with expected status: {expected_status}")
39+
40+
try:
41+
verify_subject_event_status_by_nhs_no(page, nhs_number, expected_status)
42+
logging.info(f"Successfully verified NHS number {nhs_number} with status {expected_status}")
43+
except Exception as e:
44+
logging.error(f"Verification failed for NHS number {nhs_number} with status {expected_status}: {str(e)}")
45+
raise
46+
47+
48+
49+
#
50+
# # (STEP - 5) Check the results of the processed FIT kits have correctly updated the status of the associated subjects
51+
# # Navigate to log devices page
52+
# MainMenu(page).go_to_fit_test_kits_page()
53+
# FITTestKits(page).go_to_log_devices_page()
54+
#
55+
# # Get a fit device id
56+
# subjectdf = create_fit_id_df()
57+
#
58+
# # Log fit device
59+
# for subject in range(4):
60+
# fit_device_id = subjectdf["fit_device_id"].iloc[subject]
61+
# LogDevices(page).fill_fit_device_id_field(fit_device_id)
62+
# sample_date = datetime.now().strftime("%#d %b %Y")
63+
# LogDevices(page).fill_sample_date_field(sample_date)
64+
# LogDevices(page).verify_successfully_logged_device_text()
65+
#
66+
# # Check statuses of 'normal' FIT kit subjects has moved to S2
67+
# nhs_no = subjectdf["subject_nhs_number"].iloc[0]
68+
# verify_subject_event_status_by_nhs_no(page, nhs_no, "S2 - Normal")
69+
#
70+
# # Check status of 'abnormal' FIT kit subjects has moved to A8
71+
# nhs_no = subjectdf["subject_nhs_number"].iloc[0]
72+
# verify_subject_event_status_by_nhs_no(page, nhs_no, "A8 - Abnormal")

utils/fit_kit_generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_kit_id_from_db():
2727
and device_id is null
2828
and tk.invalidated_date is null
2929
and se.latest_event_status_id in (11198, 11213)
30-
fetch first 5 rows only""")
30+
fetch first 10 rows only""")
3131

3232
return kit_id_df
3333

utils/fit_kit_logged.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,36 @@
44
import logging
55

66

7+
78
def process_kit_data():
89
# Get test data for compartment 3
910
kit_id_df = get_kit_id_logged_from_db()
1011

1112
# Split dataframe into two different dataframes, normal and abnormal
1213
normal_fit_kit_df, abnormal_fit_kit_df = split_fit_kits(kit_id_df)
1314

15+
# Prepare a list to store device IDs and their respective flags
16+
device_ids = []
17+
1418
# Process normal kits (only 1)
1519
if not normal_fit_kit_df.empty:
1620
device_id = normal_fit_kit_df["device_id"].iloc[0]
1721
logging.info(f"Processing normal kit with Device ID: {device_id}") # Logging normal device_id
18-
update_kit_service_management_entity(device_id, True)
22+
device_ids.append((device_id, True)) # Add to the list with normal flag
1923
else:
2024
logging.warning("No normal kits found for processing.") # Log warning
2125

22-
# Process abnormal kits (multiple, loop through)
26+
# Process abnormal kits (multiple, loop through)
2327
if not abnormal_fit_kit_df.empty:
2428
for index, row in abnormal_fit_kit_df.iterrows():
2529
device_id = row["device_id"]
2630
logging.info(f"Processing abnormal kit with Device ID: {device_id}") # Logging abnormal device_id
27-
update_kit_service_management_entity(device_id, False)
31+
device_ids.append((device_id, False)) # Add to the list with abnormal flag
2832
else:
2933
logging.warning("No abnormal kits found for processing.") # Log warning
3034

35+
return device_ids
36+
3137

3238
def get_kit_id_logged_from_db():
3339
kit_id_df = OracleDB().execute_query("""SELECT tk.kitid,tk.device_id,tk.screening_subject_id
@@ -101,6 +107,9 @@ def execute_stored_procedures():
101107

102108
def update_kit_service_management_entity(device_id, normal):
103109
get_service_management_df = get_service_management_by_device_id(device_id)
110+
111+
# Extract the NHS number from the DataFrame
112+
subject_nhs_number = get_service_management_df["subject_nhs_number"].iloc[0]
104113
test_kit_name = get_service_management_df["test_kit_name"].iloc[0]
105114
test_kit_type = get_service_management_df["test_kit_type"].iloc[0]
106115
logged_by_hub = get_service_management_df["logged_by_hub"].iloc[0]
@@ -127,7 +136,7 @@ def update_kit_service_management_entity(device_id, normal):
127136
kq.test_result = :test_result,
128137
kq.calculated_result = :calculated_result,
129138
kq.error_code = NULL,
130-
kq.analyser_code = 'HMJackalt1',
139+
kq.analyser_code = '3Wjvy',
131140
kq.date_time_authorised = TO_TIMESTAMP(:date_time_authorised, 'DD-Mon-YY HH24.MI.SS.FF9'),
132141
kq.authoriser_user_code = 'AUTO1',
133142
kq.post_response = :post_response,
@@ -147,8 +156,8 @@ def update_kit_service_management_entity(device_id, normal):
147156
"test_result": int(test_result),
148157
"calculated_result": calculated_result,
149158
"date_time_authorised": str(date_time_authorised),
150-
"post_response": int(post_response),
151-
"post_attempts": int(post_attempts),
159+
"post_response":int(post_response)if post_response is not None else 0,
160+
"post_attempts":int(post_attempts)if post_attempts is not None else 0,
152161
"put_response": put_response,
153162
"put_attempts": put_attempts,
154163
"device_id": device_id
@@ -158,10 +167,8 @@ def update_kit_service_management_entity(device_id, normal):
158167
print("Parameters before execution:", params)
159168
rows_affected = OracleDB().update_or_insert_data_to_table(update_query, params)
160169
print(f"Rows affected: {rows_affected}")
170+
# Return the subject NHS number
171+
return subject_nhs_number
172+
161173

162174

163-
def get_nhs_number_from_subject_id(subject_ids, df):
164-
temp_df = OracleDB().execute_query(
165-
f"SELECT SCREENING_SUBJECT_ID, SUBJECT_NHS_NUMBER FROM SCREENING_SUBJECT_T WHERE SCREENING_SUBJECT_ID = {subject_ids}")
166-
df = df.merge(temp_df[["screening_subject_id", "subject_nhs_number"]], on="screening_subject_id", how="left")
167-
return df

0 commit comments

Comments
 (0)