Skip to content

Commit 00f6101

Browse files
authored
Feature/bcss 20622 oracle markdown improvements (#92)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description Changing the markdown doc to address feedback found during reviews. ## Context Allows for easier understanding of how and when to use the utility. ## 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) - [ ] 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.
1 parent 106c205 commit 00f6101

File tree

1 file changed

+69
-25
lines changed

1 file changed

+69
-25
lines changed

docs/utility-guides/Oracle.md

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
# Utility Guide: Oracle
22

3-
The Oracle Utility can be used to run SQL queries or stored procedures on the Oracle database.
3+
The Oracle Utility provides an easy way to interact with an Oracle database directly from your Playwright test suite.It can be used to run SQL queries or stored procedures on the Oracle database.
4+
5+
## When and Why to Use the Oracle Utility
6+
7+
You might need to use this utility in scenarios such as:
8+
9+
- To run SQL queries or stored procedures on the Oracle database.
10+
- Verifying that data is correctly written to or updated in the database after a workflow is completed in your application.
411

512
## Table of Contents
613

714
- [Utility Guide: Oracle](#utility-guide-oracle)
15+
- [When and Why to Use the Oracle Utility](#when-and-why-to-use-the-oracle-utility)
816
- [Table of Contents](#table-of-contents)
917
- [Using the Oracle Utility](#using-the-oracle-utility)
1018
- [Required arguments](#required-arguments)
19+
- [Oracle Utility Methods](#oracle-utility-methods)
1120
- [Example usage](#example-usage)
1221
- [Oracle Specific Functions](#oracle-specific-functions)
22+
- [How to Add New Oracle-Specific Functions](#how-to-add-new-oracle-specific-functions)
1323
- [Example Usage](#example-usage-1)
1424

1525
## Using the Oracle Utility
@@ -22,29 +32,45 @@ The functions in this class require different arguments.<br>
2232
Look at the docstrings for each function to see what arguments are required.<br>
2333
The docstrings also specify when arguments are optional, and what the default values are when no argument is provided.
2434

25-
## Example usage
35+
## Oracle Utility Methods
36+
37+
**The main methods provided by OracleDB are:**
2638

27-
from utils.oracle.oracle import OracleDB
39+
- **connect_to_db(self)**: Connects to the Oracle database using credentials from environment variables.
40+
- **disconnect_from_db(self, conn)**: Closes the provided Oracle database connection.
41+
- **execute_query(self, query, params=None)**: Executes a SQL query with optional parameters and returns the results as a pandas DataFrame.
42+
- **execute_stored_procedure(self, `procedure_name`, params=None)**: Executes a named stored procedure with optional parameters.
43+
- **exec_bcss_timed_events(self, nhs_number_df)**: Runs the `bcss_timed_events` stored procedure for each NHS number provided in a DataFrame.
44+
- **get_subject_id_from_nhs_number(self, nhs_number)**: Retrieves the `subject_screening_id` for a given NHS number.
2845

29-
def test_oracle_query() -> None:
46+
For full implementation details, see utils/oracle/oracle.py.
3047

31-
query = """select column_a,
32-
column_b,
33-
column_c
34-
from example_table
35-
where condition_1 = :condition1
36-
and condition_2 = :condition2"""
48+
## Example usage
3749

38-
params = {
50+
```python
51+
from utils.oracle.oracle import OracleDB
52+
53+
def test_oracle_query() -> None:
54+
query = """
55+
SELECT column_a,
56+
column_b,
57+
column_c
58+
FROM example_table
59+
WHERE condition_1 = :condition1
60+
AND condition_2 = :condition2
61+
"""
62+
params = {
3963
"condition1": 101,
4064
"condition2": 202,
41-
}
42-
43-
result_df = OracleDB().execute_query(query, params)
65+
}
66+
result_df = OracleDB().execute_query(query, params)
67+
print(result_df)
4468

45-
def run_stored_procedure() -> None:
69+
def run_stored_procedure() -> None:
70+
OracleDB().execute_stored_procedure("bcss_timed_events")
71+
```
4672

47-
OracleDB().execute_stored_procedure("bcss_timed_events")
73+
---
4874

4975
## Oracle Specific Functions
5076

@@ -53,15 +79,33 @@ These are all stored in one location to make it easier to edit the query at a la
5379

5480
Common values are placed in the `SqlQueryValues` class to avoid repeating the same values in the queries.
5581

56-
## Example Usage
82+
## How to Add New Oracle-Specific Functions
5783

58-
from oracle.oracle import OracleDB
84+
- Define a new function in `utils/oracle/oracle_specific_functions.py`.
85+
- Create your SQL query, `parameterizing` as needed.
86+
- Call the relevant methods from the oracle `util` based on your needs (e.g., `execute_query`, stored procedure methods, etc.).
87+
- Return the result in the appropriate format for your function.
88+
- Document the function with a clear docstring.
5989

60-
def example_query() -> pd.DataFrame:
61-
62-
example_df = OracleDB().execute_query(
63-
f"""subject_nhs_number
64-
from ep_subject_episode_t
65-
where se.latest_event_status_id in ({SqlQueryValues.S10_EVENT_STATUS}, {SqlQueryValues.S19_EVENT_STATUS})""")
90+
## Example Usage
6691

67-
return example_df
92+
```python
93+
from utils.oracle.oracle import OracleDB
94+
95+
def example_query() -> pd.DataFrame:
96+
"""
97+
Example function to demonstrate OracleDB usage for querying subject NHS numbers.
98+
Returns:
99+
pd.DataFrame: Query results as a pandas DataFrame.
100+
"""
101+
example_df = OracleDB().execute_query(
102+
f"""subject_nhs_number
103+
from ep_subject_episode_t
104+
where se.latest_event_status_id in ({SqlQueryValues.S10_EVENT_STATUS}, {SqlQueryValues.S19_EVENT_STATUS})""")
105+
106+
return example_df
107+
```
108+
109+
> **Note:**<br>
110+
> The Oracle utility and its helper functions are available under utils/oracle/.<br>
111+
> See the source code for more details.

0 commit comments

Comments
 (0)