Skip to content

Commit e95889d

Browse files
Adding scenario 13 and relevant classes / utils (#145)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description <!-- Describe your changes in detail. --> Migrating scenario 13 from FOBTRegressionTests from selenium to playwright ## Context <!-- Why is this change required? What problem does it solve? --> Migrating scenario 13 from FOBTRegressionTests from selenium to playwright ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [ ] 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 - [x] 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 5c2fbf5 commit e95889d

File tree

3 files changed

+827
-1
lines changed

3 files changed

+827
-1
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from typing import Optional
2+
from utils.oracle.oracle import OracleDB
3+
4+
5+
class EpisodeRepository:
6+
"""
7+
Repository for accessing episode data from the database.
8+
"""
9+
10+
def get_episode_result(self, episode_id: int) -> str:
11+
"""
12+
Gets the episode result description for a given episode ID.
13+
Args:
14+
episode_id (int): The ID of the episode.
15+
Returns:
16+
str: The episode result description.
17+
"""
18+
sql = """
19+
SELECT vv.description
20+
FROM ep_subject_episode_t ep
21+
INNER JOIN valid_values vv ON vv.valid_value_id = ep.episode_result_id
22+
WHERE ep.subject_epis_id = :episode_id
23+
"""
24+
params = {"episode_id": episode_id}
25+
episode_result_df = OracleDB().execute_query(sql, params)
26+
episode_result = episode_result_df["description"].iloc[0]
27+
return episode_result
28+
29+
def find_episode_id_for_subject(self, nhs_no: str) -> int:
30+
"""
31+
Finds the latest episode id for a subject.
32+
Args:
33+
nhs_no (str): The subject's NHS Number.
34+
Returns:
35+
int: The latest episode ID for the subject.
36+
"""
37+
subject_id = OracleDB().get_subject_id_from_nhs_number(nhs_no)
38+
sql_query = """
39+
SELECT
40+
ep.subject_epis_id,
41+
ep.screening_subject_id,
42+
ep.episode_type_id,
43+
ep.episode_status_id
44+
FROM ep_subject_episode_t ep
45+
WHERE ep.screening_subject_id = :subject_id
46+
ORDER BY ep.subject_epis_id DESC
47+
"""
48+
params = {"subject_id": subject_id}
49+
episode_df = OracleDB().execute_query(sql_query, params)
50+
episode_id = episode_df["subject_epis_id"].iloc[0]
51+
return int(episode_id)
52+
53+
def confirm_episode_result(self, nhs_no: str, expected_episode_result: str) -> None:
54+
"""
55+
Confirms that the episode result for a subject matches the expected value.
56+
Args:
57+
nhs_no (str): The subject's NHS Number.
58+
expected_episode_result (str): The expected episode result description.
59+
"""
60+
episode_id = self.find_episode_id_for_subject(nhs_no)
61+
episode_result = self.get_episode_result(episode_id)
62+
assert (
63+
episode_result == expected_episode_result
64+
), f"Expected episode result to be '{expected_episode_result}' but got '{episode_result}'"

0 commit comments

Comments
 (0)