Skip to content

Commit 68c68d1

Browse files
Feature/bcss 20438 fit kit logged docstrings and md (#57)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description Updated docstrings for fit kit logged functions and added a utility guide <!-- Describe your changes in detail. --> ## Context Updated docstrings for fit kit logged functions and added a utility guide for better usability of functions and to make it easier for new testers to work with our framework. <!-- Why is this change required? What problem does it solve? --> ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [x] Refactoring (non-breaking change) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md) - [x] I have followed the code style of the project - [ ] I have added tests to cover my changes (where appropriate) - [x] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes. --------- Co-authored-by: adrianoaru-nhs <[email protected]> Co-authored-by: Adriano Aru <[email protected]>
1 parent 7a7e169 commit 68c68d1

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
```

utils/fit_kit_logged.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from oracle.oracle import OracleDB
21
from oracle.oracle_specific_functions import get_kit_id_logged_from_db
32
import pandas as pd
43
import logging
@@ -7,11 +6,17 @@
76

87
def process_kit_data(smokescreen_properties: dict) -> list:
98
"""
10-
This method retrieved the test data needed for compartment 3 and then splits it into two data frames:
9+
This method retrieves the test data needed for compartment 3 and then, by using the split_fit_kits method, it splits it into two data frames:
1110
- 1 normal
1211
- 1 abnormal
12+
1313
Once the dataframe is split in two it then creates two lists, one for normal and one for abnormal
1414
Each list will either have true or false appended depending on if it is normal or abnormal
15+
Args:
16+
smokescreen_properties (dict): A dictionary containing properties required to retrieve and process kit data.
17+
18+
Returns:
19+
list: A list of tuples where each tuple contains a device ID (str) and a boolean flag (True for normal, False for abnormal).
1520
"""
1621
# Get test data for compartment 3
1722
kit_id_df = get_kit_id_logged_from_db(smokescreen_properties)
@@ -48,9 +53,22 @@ def process_kit_data(smokescreen_properties: dict) -> list:
4853
return device_ids
4954

5055

51-
def split_fit_kits(kit_id_df: pd.DataFrame, smokescreen_properties: dict) -> pd.DataFrame:
56+
def split_fit_kits(
57+
kit_id_df: pd.DataFrame, smokescreen_properties: dict
58+
) -> pd.DataFrame:
5259
"""
5360
This method splits the dataframe into two, 1 normal and 1 abnormal
61+
Args:
62+
kit_id_df (pd.DataFrame): A dataframe containing fit kit IDs.
63+
smokescreen_properties (dict): A dictionary containing the number of normal and
64+
abnormal fit kits to split. It should include the keys:
65+
- "c3_eng_number_of_normal_fit_kits" (str): Number of normal fit kits.
66+
- "c3_eng_number_of_abnormal_fit_kits" (str): Number of abnormal fit kits.
67+
68+
Returns:
69+
tuple: A tuple containing two dataframes:
70+
- normal_fit_kit_df (pd.DataFrame): Dataframe containing normal fit kits.
71+
- abnormal_fit_kit_df (pd.DataFrame): Dataframe containing abnormal fit kits.
5472
"""
5573
number_of_normal = int(smokescreen_properties["c3_eng_number_of_normal_fit_kits"])
5674
number_of_abnormal = int(

0 commit comments

Comments
 (0)