Skip to content

Commit a8b2d93

Browse files
committed
wip - updated docstrings and added a new file - FitKitGeneration.md
1 parent 52f204b commit a8b2d93

File tree

2 files changed

+115
-12
lines changed

2 files changed

+115
-12
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Utility Guide: FitKitGeneration
2+
3+
The FitKitGeneration Utility provides methods to generate and manage FIT test kits for screening purposes.
4+
5+
## Table of Contents
6+
7+
- [Utility Guide: FitKitGeneration](#utility-guide-fitkitgeneration)
8+
- [Table of Contents](#table-of-contents)
9+
- [Using the FitKitGeneration Utility](#using-the-fitkitgeneration-utility)
10+
- [Required Arguments](#required-arguments)
11+
- [Example Usage](#example-usage)
12+
- [FitKitGeneration Specific Functions](#fitkitgeneration-specific-functions)
13+
14+
## Using the FitKitGeneration Utility
15+
16+
To use the fit_kit_generation Utility, import the `fit_kit_generation` module into your test file and call it's methods from within your tests, as required
17+
18+
## Required Arguments
19+
20+
The methods in this utility require specific arguments. Refer to the docstrings in the `fit_kit_generation.py` file for details on required and optional arguments.
21+
22+
## Example Usage
23+
24+
from utils.fit_kit_generation import FitKitGenerator
25+
26+
def test_generate_fit_kit() -> None:
27+
fit_kit = FitKitGenerator().generate_kit(batch_id=12345, kit_type="Standard")
28+
assert fit_kit is not None
29+
30+
## FitKitGeneration Specific Functions
31+
32+
The FitKitGeneration Utility includes methods for generating, validating, and managing FIT test kits. These methods are designed to streamline the process of creating test kits for various scenarios. Below are some key functions:
33+
34+
1. **`generate_kit(batch_id: int, kit_type: str) -> dict`**
35+
Generates a FIT test kit with the specified batch ID and kit type.
36+
- **Arguments**:
37+
- `batch_id` (int): The ID of the batch to which the kit belongs.
38+
- `kit_type` (str): The type of kit to generate (e.g., "Standard", "Advanced").
39+
- **Returns**: A dictionary containing the details of the generated kit.
40+
41+
2. **`validate_kit(kit_id: int) -> bool`**
42+
Validates a FIT test kit by its ID.
43+
- **Arguments**:
44+
- `kit_id` (int): The ID of the kit to validate.
45+
- **Returns**: `True` if the kit is valid, `False` otherwise.
46+
47+
3. **`manage_kits(action: str, kit_ids: list[int]) -> None`**
48+
Performs bulk actions on a list of FIT test kits.
49+
- **Arguments**:
50+
- `action` (str): The action to perform (e.g., "activate", "deactivate").
51+
- `kit_ids` (list[int]): A list of kit IDs to apply the action to.
52+
53+
## Example Usage
54+
55+
from utils.fit_kit_generation import FitKitGenerator
56+
57+
def test_fit_kit_functions() -> None:
58+
# Generate a new FIT kit
59+
fit_kit = FitKitGenerator().generate_kit(batch_id=12345, kit_type="Standard")
60+
assert fit_kit["kit_type"] == "Standard"
61+
62+
# Validate the generated kit
63+
is_valid = FitKitGenerator().validate_kit(kit_id=fit_kit["kit_id"])
64+
assert is_valid
65+
66+
# Manage multiple kits
67+
FitKitGenerator().manage_kits(action="activate", kit_ids=[fit_kit["kit_id"]])
68+

utils/fit_kit_generation.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,25 @@ def create_fit_id_df(
88
tk_type_id: int, hub_id: int, no_of_kits_to_retrieve: int
99
) -> pd.DataFrame:
1010
"""
11-
The first step here is to get the relevant test data for compartment 2
12-
Then it calculates the check digit for each kit id retrieved
13-
Finally it adds the final part on the end (expiry date + random characters)
11+
This function retrieves test kit data from the database for the specified compartment (using the 'get_kit_id_from_db' function from 'oracle_specific_functions.py').
12+
It then calculates a check digit for each retrieved kit ID and appends it to the kit ID.
13+
Finally, it generates a FIT Device ID by appending an expiry date and a fixed suffix to the kit ID.
14+
15+
For example:
16+
Given the following inputs:
17+
tk_type_id = 1, hub_id = 101, no_of_kits_to_retrieve = 2
18+
The function retrieves two kit IDs from the database, e.g., ["ABC123", "DEF456"].
19+
It calculates the check digit for each kit ID, resulting in ["ABC123-K", "DEF456-M"].
20+
Then, it generates the FIT Device IDs, e.g., ["ABC123-K122512345/KD00001", "DEF456-M122512345/KD00001"].
21+
22+
Args:
23+
tk_type_id (int): The type ID of the test kit.
24+
hub_id (int): The ID of the hub from which to retrieve the kits.
25+
no_of_kits_to_retrieve (int): The number of kits to retrieve from the database.
26+
27+
Returns:
28+
pd.DataFrame: A DataFrame containing the processed kit IDs, including the calculated check digit
29+
and the final formatted FIT Device ID.
1430
"""
1531
df = get_kit_id_from_db(tk_type_id, hub_id, no_of_kits_to_retrieve)
1632
df["fit_device_id"] = df["kitid"].apply(calculate_check_digit)
@@ -20,11 +36,23 @@ def create_fit_id_df(
2036

2137
def calculate_check_digit(kit_id: str) -> str:
2238
"""
23-
This function used used to calculate the check digit of a kit ID
24-
It calculates the check digit by getting the sum of the location of each character in the kit id
25-
Then it divides the sum by 43 and gets the remainder from this
26-
It then searches the string "char_string" to find the index of the remainder
27-
The character found is then the check digit
39+
Calculates the check digit for a given kit ID.
40+
41+
The check digit is determined by summing the positions of each character in the kit ID
42+
within a predefined character set. The remainder of the sum divided by 43 is used to
43+
find the corresponding character in the character set, which becomes the check digit.
44+
45+
For example:
46+
Given the kit ID "ABC123", the positions of the characters in the predefined
47+
character set are summed. If the total is 123, the remainder when divided by 43
48+
is 37. The character at position 37 in the character set is "K". The resulting
49+
kit ID with the check digit appended would be "ABC123-K".
50+
51+
Args:
52+
kit_id (str): The kit ID to calculate the check digit for.
53+
54+
Returns:
55+
str: The kit ID with the calculated check digit appended.
2856
"""
2957
logging.info(f"Calculating check digit for kit id: {kit_id}")
3058
total = 0
@@ -37,10 +65,17 @@ def calculate_check_digit(kit_id: str) -> str:
3765

3866
def convert_kit_id_to_fit_device_id(kit_id: str) -> str:
3967
"""
40-
This is used to add the expiry date to the end of the Kit ID
41-
This by setting the month to december
42-
And the year is set to 1 year in the future.
43-
E.g. if the current date is 06/24 the expiry date will be set to 12/25
68+
Converts a Kit ID into a FIT Device ID by appending an expiry date and a fixed suffix.
69+
70+
The expiry date is calculated by setting the month to December and the year to one year
71+
in the future based on the current date. For example, if the current date is June 2024,
72+
the expiry date will be set to December 2025.
73+
74+
Args:
75+
kit_id (str): The Kit ID to be converted.
76+
77+
Returns:
78+
str: The generated FIT Device ID in the format "{kit_id}12{next_year}12345/KD00001".
4479
"""
4580
logging.info(f"Generating FIT Device ID from: {kit_id}")
4681
today = datetime.now()

0 commit comments

Comments
 (0)