|
| 1 | +# Utility Guide: Call and Recall |
| 2 | + |
| 3 | +The **Call and Recall utility** provides helper methods for executing Call and Recall stored procedures in BCSS.<br> |
| 4 | +These utilities interact directly with the **OracleDB** backend to run failsafe checks and initiate FOBT screening invitations. |
| 5 | + |
| 6 | +## Table of Contents |
| 7 | + |
| 8 | +- [Utility Guide: Call and Recall](#utility-guide-call-and-recall) |
| 9 | + - [Table of Contents](#table-of-contents) |
| 10 | + - [Summary of Utility Methods](#summary-of-utility-methods) |
| 11 | + - [Main Methods](#main-methods) |
| 12 | + - [`run_failsafe`](#run_failsafe) |
| 13 | + - [`invite_subject_for_fobt_screening`](#invite_subject_for_fobt_screening) |
| 14 | + - [Supporting Classes](#supporting-classes) |
| 15 | + - [Example Usage](#example-usage) |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Summary of Utility Methods |
| 20 | + |
| 21 | +| Method | Purpose | Key Arguments | Expected Behaviour | |
| 22 | +|----------------------------------------|-------------------------------------------------------------------------|--------------------------------------|--------------------| |
| 23 | +| `run_failsafe` | Runs the **failsafe trawl** for a given subject. | `nhs_no` (`str`) | Executes stored procedure `pkg_fobt_call.p_failsafe_trawl` and checks success. | |
| 24 | +| `invite_subject_for_fobt_screening` | Transitions a subject into an **invited state** for FOBT screening. | `nhs_no` (`str`), `user_role` (`UserRoleType`) | Executes database transition (ID `58`) to create an FOBT episode. | |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## Main Methods |
| 29 | + |
| 30 | +### `run_failsafe` |
| 31 | + |
| 32 | +Runs the failsafe trawl stored procedure for a subject identified by their NHS number. |
| 33 | + |
| 34 | +**Arguments:** |
| 35 | + |
| 36 | +- `nhs_no` (`str`): The NHS number of the subject. |
| 37 | + |
| 38 | +**How it works:** |
| 39 | + |
| 40 | +1. Looks up the subject ID for the provided NHS number. |
| 41 | +2. Connects to the OracleDB with a 30-second call timeout. |
| 42 | +3. Executes `pkg_fobt_call.p_failsafe_trawl`. |
| 43 | +4. Asserts that the stored procedure reports success. |
| 44 | +5. Cleans up database connections and cursors. |
| 45 | +6. Logs success/failure. |
| 46 | + |
| 47 | +**Raises:** |
| 48 | + |
| 49 | +- `AssertionError` if the stored procedure does not report success. |
| 50 | +- Database connection errors if OracleDB cannot be accessed. |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +### `invite_subject_for_fobt_screening` |
| 55 | + |
| 56 | +Transitions the subject into an **invited state** for FOBT screening. |
| 57 | + |
| 58 | +**Arguments:** |
| 59 | + |
| 60 | +- `nhs_no` (`str`): The NHS number of the subject. |
| 61 | +- `user_role` (`UserRoleType`): The role of the user initiating the transition. |
| 62 | + |
| 63 | +**How it works:** |
| 64 | + |
| 65 | +1. Resolves the subject ID for the given NHS number. |
| 66 | +2. Fetches the **PIO user ID** for the given `user_role` from the `UserRepository`. |
| 67 | +3. Creates a `DatabaseTransitionParameters` object with: |
| 68 | + - `transition_id = 58` (invite to FOBT screening), |
| 69 | + - `subject_id` for the subject, |
| 70 | + - `user_id` of the PIO, |
| 71 | + - `rollback_on_failure = 'Y'`. |
| 72 | +4. Executes the transition using `GeneralRepository`. |
| 73 | +5. Logs success/failure. |
| 74 | + |
| 75 | +**Raises:** |
| 76 | + |
| 77 | +- `oracledb.DatabaseError` if the stored procedure execution fails. |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## Supporting Classes |
| 82 | + |
| 83 | +These classes are required by the utility: |
| 84 | + |
| 85 | +- `OracleDB` — Provides database connection and helper functions (e.g. resolve subject ID from NHS number). |
| 86 | +- `GeneralRepository` — Executes transitions in the database. |
| 87 | +- `DatabaseTransitionParameters` — Holds configuration for a transition (IDs, rollback policy). |
| 88 | +- `UserRoleType` — Enum-like class describing different user roles. |
| 89 | +- `UserRepository` — Maps user roles to PIO IDs. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## Example Usage |
| 94 | + |
| 95 | +```python |
| 96 | +from utils.call_and_recall_utils import CallAndRecallUtils |
| 97 | +from classes.user_role_type import UserRoleType |
| 98 | + |
| 99 | +# Log in with a user and populate the user_role variable |
| 100 | +user_role = UserTools.user_login( |
| 101 | + page, "Hub Manager State Registered at BCS01", return_role_type=True |
| 102 | +) |
| 103 | + |
| 104 | +# Create the utility |
| 105 | +call_and_recall = CallAndRecallUtils() |
| 106 | + |
| 107 | +# Example 1: Run failsafe for a subject |
| 108 | +call_and_recall.run_failsafe("9434765919") |
| 109 | + |
| 110 | +# Example 2: Invite a subject to FOBT screening |
| 111 | +call_and_recall.invite_subject_for_fobt_screening( |
| 112 | + nhs_no="9434765919", |
| 113 | + user_role=user_role, |
| 114 | +) |
| 115 | +``` |
0 commit comments