Skip to content

Commit 720f35c

Browse files
Altering comparment 1 utils to be able to process more than 1 subject
Changing csv_reader to be able to generate fit device ids
1 parent 41e34f3 commit 720f35c

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pandas>=2.2.3
77
dotenv~=0.9.9
88
python-dotenv~=1.0.1
99
Flask~=3.0.3
10+
fastparquet>=2024.11.0

tests/Smokescreen/test_compartment_1.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_example(page: Page) -> None:
1919
InvitationsMonitoring(page).go_to_bcss001_invitations_plan_page()
2020
InvitationsPlans(page).go_to_create_a_plan_page()
2121
CreateAPlan(page).click_set_all_button()
22-
CreateAPlan(page).fill_daily_invitation_rate_field("1")
22+
CreateAPlan(page).fill_daily_invitation_rate_field("10")
2323
CreateAPlan(page).click_update_button()
2424
CreateAPlan(page).click_confirm_button()
2525
CreateAPlan(page).click_save_button()
@@ -35,13 +35,15 @@ def test_example(page: Page) -> None:
3535
GenerateInvitations(page).wait_for_invitation_generation_complete()
3636

3737
# Print the batch of Pre-Invitation Letters
38-
s1_nhs_no = batch_processing(page, "S1", "Pre-invitation (FIT)", "S9 - Pre-invitation Sent")
38+
s1_nhs_numbers = batch_processing(page, "S1", "Pre-invitation (FIT)", "S9 - Pre-invitation Sent")
3939
batch_processing(page, "S1", "Pre-invitation (FIT) (digital leaflet)", "S9 - Pre-invitation Sent")
40-
OracleDB().exec_bcss_timed_events(s1_nhs_no)
40+
for nhs_no in range(len(s1_nhs_numbers)):
41+
OracleDB().exec_bcss_timed_events(s1_nhs_numbers[nhs_no-1])
4142

4243
# Print the batch of Invitation & Test Kit Letters
43-
s9_nhs_no = batch_processing(page, "S9", "Invitation & Test Kit (FIT)", "S10 - Invitation & Test Kit Sent")
44-
OracleDB().exec_bcss_timed_events(s9_nhs_no)
44+
s9_nhs_numbers = batch_processing(page, "S9", "Invitation & Test Kit (FIT)", "S10 - Invitation & Test Kit Sent")
45+
for nhs_no in range(len(s9_nhs_numbers)):
46+
OracleDB().exec_bcss_timed_events(s9_nhs_numbers[nhs_no-1])
4547

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

utils/batch_processing.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
5555
# Wait for the download process to complete and save the downloaded file in a temp folder
5656
download_file.save_as(file)
5757
if file.endswith(".pdf"):
58-
nhs_no = extract_nhs_no_from_pdf(file)
58+
nhs_numbers = extract_nhs_no_from_pdf(file)
59+
first_nhs_no = nhs_numbers[0]
5960
os.remove(file) # Deletes the file after extracting the necessary data
6061
elif file.endswith(".csv"):
6162
csv_df = convert_csv_to_df(file) # Currently no use in compartment 1, will be necessary for future compartments
63+
csv_df.to_parquet('subject_kit_number.parquet', engine='fastparquet')
6264
os.remove(file) # Deletes the file after extracting the necessary data
6365

6466
# This loops through each Confirm printed button and clicks each one
@@ -74,5 +76,5 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
7476
ArchivedBatchList(page).enter_id_filter(link_text)
7577
ArchivedBatchList(page).verify_table_data(link_text)
7678

77-
verify_subject_event_status_by_nhs_no(page, nhs_no, latest_event_status)
78-
return nhs_no
79+
verify_subject_event_status_by_nhs_no(page, first_nhs_no, latest_event_status)
80+
return nhs_numbers

utils/csv_reader.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import pandas as pd
2+
from datetime import datetime
23

34
def convert_csv_to_df(file: str):
45
csv_df = pd.read_csv(file)
5-
return csv_df
6+
csv_df.drop(csv_df.columns[[0,2,3,4,5,6,7,8,9,10,12]], axis = 1, inplace = True) # Removing unnecessary columns
7+
df = csv_df.rename(columns={csv_df.columns[0]: "NHS_Number",csv_df.columns[1]: "Kit_ID"}) # Renaming the columns to something more meaningful
8+
df.dropna(inplace = True) # Deleting any Null records
9+
df["NHS_Number"] = df["NHS_Number"].str.replace(" ", "") # Removing the space from the nhs number
10+
df["FIT_Device_ID"] = df["Kit_ID"].apply(convert_kit_id_to_fit_device_id)
11+
return df
12+
13+
def convert_kit_id_to_fit_device_id(kit_id):
14+
today = datetime.now()
15+
year = today.strftime("%y") # Get the year from todays date in YY format
16+
return f"{kit_id}12{int(year)+1}12345/KD00001" # Creating the fit device id with an expiry date set to December next year

utils/pdf_reader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
def extract_nhs_no_from_pdf(file: str):
44
reader = PdfReader(file)
5-
5+
nhs_number = []
66
# For loop looping through all pages of the file to find the NHS Number
77
for pages in reader.pages:
88
text = pages.extract_text()
@@ -13,5 +13,6 @@ def extract_nhs_no_from_pdf(file: str):
1313
if "NHS No" in split_text:
1414
# If a string is found containing "NHS No" only digits are stored into nhs_no
1515
nhs_no = "".join([ele for ele in split_text if ele.isdigit()])
16+
nhs_number.append(nhs_no)
1617
break
17-
return nhs_no
18+
return nhs_number

0 commit comments

Comments
 (0)