|
| 1 | +# Utility Guide: Fit Kit Logged Utility |
| 2 | + |
| 3 | +The Fit Kit Logged Utility provides methods to retrieve test data (fit kit test results) used by the compartment 3 tests, and splits them into two dataframes (one 'normal', one 'abnormal'). |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Utility Guide: Fit Kit Logged Utility](#utility-guide-fit-kit-logged-utility) |
| 8 | + - [Table of Contents](#table-of-contents) |
| 9 | + - [Using the Fit Kit Logged Utility](#using-the-fit-kit-logged-utility) |
| 10 | + - [Required Arguments](#required-arguments) |
| 11 | + - [Fit Kit Logged Specific Functions](#fit-kit-logged-specific-functions) |
| 12 | + - [Example Usage](#example-usage) |
| 13 | + |
| 14 | +## Using the Fit Kit Logged Utility |
| 15 | + |
| 16 | +To use the Fit Kit Logged Utility, import the `fit_kit_logged.py` module, from the `utils` directory, into your test file and call the `process_kit_data` method as required. |
| 17 | + |
| 18 | +## Required Arguments |
| 19 | + |
| 20 | +The methods in this utility require specific arguments. Below is a summary of the required arguments for key methods: |
| 21 | + |
| 22 | +- `process_kit_data`: Requires `smokescreen_properties`(dict) |
| 23 | +- `split_fit_kits`: Requires `kit_id_df`(pd.DataFrame), `smokescreen_properties`(dict) |
| 24 | + |
| 25 | +## Fit Kit Logged Specific Functions |
| 26 | + |
| 27 | +The `fit_kit_logged` Utility includes methods for retrieving FIT test kits from the DB and splitting them into 'Normal' and 'Abnormal' results. Below are their key functions: |
| 28 | + |
| 29 | +1. **`process_kit_data(smokescreen_properties: dict) -> list`** |
| 30 | +Retrieves the test data needed for compartment 3 and then splits it into two data frames, using the `split_fit_kits` method. |
| 31 | + |
| 32 | +- **Arguments**: |
| 33 | + - `smokescreen_properties` (dict): A dictionary containing properties required to retrieve and process kit data. |
| 34 | + |
| 35 | +- **Returns**: |
| 36 | + A list of tuples where each tuple contains a device ID (str) and a `boolean` flag (True for normal, False for abnormal). |
| 37 | + |
| 38 | +1. **`split_fit_kits(kit_id_df: pd.DataFrame, smokescreen_properties: dict) -> tuple`** |
| 39 | +This method splits the `dataframe` into two dataframes, one normal and one abnormal. It determines the number of normal and abnormal kits by using the `c3_eng_number_of_normal_fit_kits` parameter from `smokescreen_properties` for the number of normal, and then the rest are marked as abnormal. |
| 40 | + |
| 41 | +- **Arguments**: |
| 42 | + - `kit_id_df` (pd.DataFrame): A `dataframe` containing fit kit IDs. |
| 43 | + - `smokescreen_properties` (dict): A dictionary containing the number of normal and abnormal fit kits to split. |
| 44 | + |
| 45 | +- **Returns**: |
| 46 | + A tuple containing two dataframes: |
| 47 | + - `normal_fit_kit_df` (pd.DataFrame): `dataframe` containing normal fit kits. |
| 48 | + - `abnormal_fit_kit_df` (pd.DataFrame): `dataframe` containing abnormal fit kits. |
| 49 | + |
| 50 | +## Example Usage |
| 51 | + |
| 52 | +```python |
| 53 | +from utils.fit_kit_logged import process_kit_data |
| 54 | + |
| 55 | +def test_example_usage(smokescreen_properties: dict) -> None: |
| 56 | + # Find data, separate it into normal and abnormal, add results to the test records in the KIT_QUEUE table (i.e. mimic receiving results from the middleware) and get device IDs and their flags. |
| 57 | + device_ids = process_kit_data(smokescreen_properties) |
| 58 | + # Note: In this example, all of the code below this line is for context only and uses functions from other utilities. |
| 59 | + # Retrieve NHS numbers for each device_id and determine normal/abnormal status |
| 60 | + nhs_numbers = [] |
| 61 | + normal_flags = [] |
| 62 | + |
| 63 | + for device_id, is_normal in device_ids: |
| 64 | + nhs_number = update_kit_service_management_entity( |
| 65 | + device_id, is_normal, smokescreen_properties |
| 66 | + ) |
| 67 | + nhs_numbers.append(nhs_number) |
| 68 | + normal_flags.append(is_normal) # Store the flag (True for normal, False for abnormal). |
| 69 | + |
| 70 | +test_example_usage() |
| 71 | +``` |
0 commit comments