Skip to content

Commit 5d84161

Browse files
Docstrings added for utils/fit_kit_generation and utils/oracle/oracle_specific_functions
1 parent 7713ece commit 5d84161

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

utils/fit_kit_generation.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55

66

77
def create_fit_id_df() -> pd.DataFrame:
8+
"""
9+
The first step here is to get the relevant test data for compartment 2
10+
Then it calculates the check digit for each kit id retrieved
11+
Finally it adds the final part on the end (expiry date + random characters)
12+
"""
813
df = get_kit_id_from_db()
914
df["fit_device_id"] = df["kitid"].apply(calculate_check_digit)
1015
df["fit_device_id"] = df["fit_device_id"].apply(convert_kit_id_to_fit_device_id)
1116
return df
1217

1318
def calculate_check_digit(kit_id: str) -> str:
19+
"""
20+
This function used used to calculate the check digit of a kit ID
21+
It calculates the check digit by getting the sum of the location of each character in the kit id
22+
Then it divides the sum by 43 and gets the remainder from this
23+
It then searches the string "char_string" to find the index of the remainder
24+
The character found is then the check digit
25+
"""
1426
logging.info(f"Calculating check digit for kit id: {kit_id}")
1527
total = 0
1628
char_string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
@@ -20,6 +32,12 @@ def calculate_check_digit(kit_id: str) -> str:
2032
return f"{kit_id}-{check_digit}"
2133

2234
def convert_kit_id_to_fit_device_id(kit_id: str) -> str:
35+
"""
36+
This is used to add the expiry date to the end of the Kit ID
37+
This by setting the month to december
38+
And the year is set to 1 year in the future.
39+
E.g. if the current date is 06/24 the expiry date will be set to 12/25
40+
"""
2341
logging.info(f"Generating FIT Device ID from: {kit_id}")
2442
today = datetime.now()
2543
year = today.strftime("%y") # Get the year from todays date in YY format

utils/oracle/oracle_specific_functions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
import pandas as pd
44

55
def get_kit_id_from_db() -> pd.DataFrame:
6+
"""
7+
This query is used to obtain test kits used in compartment 2
8+
It searches for kits that have not been logged and meet the following criteria:
9+
- tk.tk_type_id = 2 (Only FIT Kits)
10+
- sdc.hub_id = 23159 (Hub ID that the compartments are running in)
11+
- se.latest_event_status_id is 11198 or 11213 (Only kits at the status we want S10/S19 are retrieved)
12+
"""
613
logging.info("Retrieving useable test kit ids")
714
kit_id_df = OracleDB().execute_query("""select tk.kitid, tk.screening_subject_id, sst.subject_nhs_number
815
from tk_items_t tk
@@ -20,6 +27,10 @@ def get_kit_id_from_db() -> pd.DataFrame:
2027
return kit_id_df
2128

2229
def get_nhs_no_from_batch_id(batch_id) -> pd.DataFrame:
30+
"""
31+
This query returns a dataframe of NHS Numbers of the subjects in a certain batch
32+
We provide the batch ID e.g. 8812 and then we have a list of NHS Numbers we can verify the statuses of
33+
"""
2334
nhs_number_df = OracleDB().execute_query(f"""
2435
SELECT SUBJECT_NHS_NUMBER
2536
FROM SCREENING_SUBJECT_T ss

0 commit comments

Comments
 (0)