Skip to content

Commit 70de74f

Browse files
Fixing file formatting errors and adding util guide
1 parent 7ac686d commit 70de74f

File tree

3 files changed

+142
-72
lines changed

3 files changed

+142
-72
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Utility Guide: SSPIChangeSteps
2+
3+
The `SSPIChangeSteps` utility provides a simple interface for simulating an SSPI update to change a subject's date of birth in the BCSS system. This is particularly useful for automated testing scenarios where you need to set a subject's age to a specific value.
4+
5+
---
6+
7+
## Table of Contents
8+
9+
- [Utility Guide: SSPIChangeSteps](#utility-guide-sspichangesteps)
10+
- [Table of Contents](#table-of-contents)
11+
- [Overview](#overview)
12+
- [Example Usage](#example-usage)
13+
- [Method Reference](#method-reference)
14+
- [Implementation Details](#implementation-details)
15+
16+
---
17+
18+
## Overview
19+
20+
The main method provided by this utility is:
21+
22+
```python
23+
sspi_update_to_change_dob_received(nhs_no: str, age_to_change_to: int)
24+
```
25+
26+
This method will:
27+
28+
- Retrieve the subject by NHS number.
29+
- Calculate the correct date of birth for the specified age (taking leap years into account).
30+
- Update the subject's date of birth in the database as if it was received from an SSPI update.
31+
32+
## Example Usage
33+
34+
```python
35+
from utils.sspi_change_steps import SSPIChangeSteps
36+
37+
nhs_no = "1234567890"
38+
target_age = 75
39+
40+
SSPIChangeSteps().sspi_update_to_change_dob_received(nhs_no, target_age)
41+
```
42+
43+
This will update the subject with NHS number `1234567890` to have an age of 75.
44+
45+
---
46+
47+
## Method Reference
48+
49+
`sspi_update_to_change_dob_received`
50+
51+
```python
52+
def sspi_update_to_change_dob_received(nhs_no: str, age_to_change_to: int) -> None
53+
```
54+
55+
**Parameters:**
56+
57+
- `nhs_no` (str): The NHS number of the subject to update.
58+
- `age_to_change_to` (int): The age to change the subject's date of birth to.
59+
60+
**Description:**
61+
62+
Calculates the correct date of birth for the given age and updates the subject in the database as if the change was received from an SSPI update.
63+
64+
---
65+
66+
## Implementation Details
67+
68+
- The utility uses the `Subject` and `PISubject` classes to represent and update subject data.
69+
- The date of birth is calculated using `DateTimeUtils.calculate_birth_date_for_age`, which ensures the correct age is set, accounting for leap years.
70+
- The update is performed as the automated process user (user ID 2).
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
from playwright.sync_api import Page
2-
from pages.base_page import BasePage
3-
4-
5-
class ReopenFOBTScreeningEpisodePage(BasePage):
6-
"""Reopen FOBT Screening Episode Page locators, and methods for interacting with the page."""
7-
8-
def __init__(self, page: Page):
9-
super().__init__(page)
10-
self.page = page
11-
12-
self.reopen_to_book_an_assessment_button = self.page.get_by_role(
13-
"button", name="Reopen to book an assessment"
14-
)
15-
16-
def click_reopen_to_book_an_assessment_button(self) -> None:
17-
"""Click the 'Reopen to book an assessment' button."""
18-
self.safe_accept_dialog(self.reopen_to_book_an_assessment_button)
1+
from playwright.sync_api import Page
2+
from pages.base_page import BasePage
3+
4+
5+
class ReopenFOBTScreeningEpisodePage(BasePage):
6+
"""Reopen FOBT Screening Episode Page locators, and methods for interacting with the page."""
7+
8+
def __init__(self, page: Page):
9+
super().__init__(page)
10+
self.page = page
11+
12+
self.reopen_to_book_an_assessment_button = self.page.get_by_role(
13+
"button", name="Reopen to book an assessment"
14+
)
15+
16+
def click_reopen_to_book_an_assessment_button(self) -> None:
17+
"""Click the 'Reopen to book an assessment' button."""
18+
self.safe_accept_dialog(self.reopen_to_book_an_assessment_button)

utils/sspi_change_steps.py

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
import logging
2-
from datetime import date
3-
from typing import Optional
4-
from classes.subject import Subject
5-
from classes.repositories.subject_repository import SubjectRepository
6-
from classes.pi_subject import PISubject
7-
from utils.date_time_utils import DateTimeUtils
8-
9-
10-
class SSPIChangeSteps:
11-
def sspi_update_to_change_dob_received(
12-
self, nhs_no: str, age_to_change_to: int
13-
) -> None:
14-
"""
15-
Receives an SSPI update to change the subject's date of birth to the specified age.
16-
Args:
17-
nhs_no (str): The NHS number of the subject to update.
18-
age_to_change_to (int): The age to change the subject's date of birth to.
19-
"""
20-
logging.debug(
21-
f"start: sspi_update_to_change_dob_received(age_to_change_to={age_to_change_to})"
22-
)
23-
24-
subject = Subject().populate_subject_object_from_nhs_no(nhs_no)
25-
# Calculate the new birth date
26-
birth_date = DateTimeUtils.calculate_birth_date_for_age(age_to_change_to)
27-
logging.debug(f"change date of birth to: {birth_date}")
28-
29-
# Pass control to handle_update to make the DB changes
30-
self.handle_update(subject, birth_date)
31-
32-
logging.debug("exit: sspi_update_to_change_dob_received()")
33-
34-
def handle_update(self, subject, birth_date: Optional[date]) -> None:
35-
"""
36-
Performs the SSPI update to make the changes in the database.
37-
Args:
38-
subject (Subject): The subject object to update.
39-
birth_date (Optional[date]): The new birth date to set.
40-
"""
41-
logging.debug("start: handle_update(Subject, date)")
42-
43-
subject_repo = SubjectRepository()
44-
45-
pi_subject = PISubject().from_subject(subject)
46-
pi_subject.pi_reference = "AUTOMATED TEST"
47-
# Check if a date of birth change needs to be made first
48-
if birth_date is not None:
49-
pi_subject.birth_date = birth_date
50-
51-
# Run the update into the DB (SSPI updates are always run as automated process user 2)
52-
subject_repo.update_pi_subject(2, pi_subject)
53-
54-
logging.debug("exit: handle_update()")
1+
import logging
2+
from datetime import date
3+
from typing import Optional
4+
from classes.subject import Subject
5+
from classes.repositories.subject_repository import SubjectRepository
6+
from classes.pi_subject import PISubject
7+
from utils.date_time_utils import DateTimeUtils
8+
9+
10+
class SSPIChangeSteps:
11+
def sspi_update_to_change_dob_received(
12+
self, nhs_no: str, age_to_change_to: int
13+
) -> None:
14+
"""
15+
Receives an SSPI update to change the subject's date of birth to the specified age.
16+
Args:
17+
nhs_no (str): The NHS number of the subject to update.
18+
age_to_change_to (int): The age to change the subject's date of birth to.
19+
"""
20+
logging.debug(
21+
f"start: sspi_update_to_change_dob_received(age_to_change_to={age_to_change_to})"
22+
)
23+
24+
subject = Subject().populate_subject_object_from_nhs_no(nhs_no)
25+
# Calculate the new birth date
26+
birth_date = DateTimeUtils.calculate_birth_date_for_age(age_to_change_to)
27+
logging.debug(f"change date of birth to: {birth_date}")
28+
29+
# Pass control to handle_update to make the DB changes
30+
self.handle_update(subject, birth_date)
31+
32+
logging.debug("exit: sspi_update_to_change_dob_received()")
33+
34+
def handle_update(self, subject, birth_date: Optional[date]) -> None:
35+
"""
36+
Performs the SSPI update to make the changes in the database.
37+
Args:
38+
subject (Subject): The subject object to update.
39+
birth_date (Optional[date]): The new birth date to set.
40+
"""
41+
logging.debug("start: handle_update(Subject, date)")
42+
43+
subject_repo = SubjectRepository()
44+
45+
pi_subject = PISubject().from_subject(subject)
46+
pi_subject.pi_reference = "AUTOMATED TEST"
47+
# Check if a date of birth change needs to be made first
48+
if birth_date is not None:
49+
pi_subject.birth_date = birth_date
50+
51+
# Run the update into the DB (SSPI updates are always run as automated process user 2)
52+
subject_repo.update_pi_subject(2, pi_subject)
53+
54+
logging.debug("exit: handle_update()")

0 commit comments

Comments
 (0)