|
1 | 1 | # Utility Guide: Subject Demographics |
2 | 2 |
|
3 | | -The Subject Demographics utility allows for different updates to subjects to be made.<br> |
4 | | -This includes the following: |
| 3 | +The Subject Demographics utility provides helper methods for interacting with and updating subject demographic data within the BCSS Playwright automation framework.<br> |
| 4 | +This includes: |
5 | 5 |
|
6 | | -1. Updating a subjects DOB to the following age ranges: |
7 | | - 1. 50-70 |
8 | | - 2. 75-100 |
| 6 | +1. Updating a subject's date of birth (DOB) to a random value within specific age ranges. |
| 7 | +2. Navigating to the subject demographic page and updating fields such as postcode and DOB. |
9 | 8 |
|
10 | 9 | ## Table of Contents |
11 | 10 |
|
12 | 11 | - [Utility Guide: Subject Demographics](#utility-guide-subject-demographics) |
13 | 12 | - [Table of Contents](#table-of-contents) |
14 | | - - [Using the Subject Demographics class](#using-the-subject-demographics-class) |
| 13 | + - [Using the SubjectDemographicUtil class](#using-the-subjectdemographicutil-class) |
15 | 14 | - [Updating DOB](#updating-dob) |
16 | | - - [Required Args](#required-args) |
| 15 | + - [Arguments](#arguments) |
17 | 16 | - [How to use this method](#how-to-use-this-method) |
| 17 | + - [Other Utility Methods](#other-utility-methods) |
18 | 18 |
|
19 | | -## Using the Subject Demographics class |
| 19 | +## Using the SubjectDemographicUtil class |
20 | 20 |
|
21 | | -You can initialise the Subject Demographics class by using the following code in your test file: |
| 21 | +You can initialise the SubjectDemographicUtil class by using the following code in your test file: |
22 | 22 |
|
23 | | - from utils.subject_demographics import SubjectDemographicUtil |
| 23 | +```python |
| 24 | +from utils.subject_demographics import SubjectDemographicUtil |
| 25 | +``` |
24 | 26 |
|
25 | 27 | ## Updating DOB |
26 | 28 |
|
27 | | -Inside of the SubjectDemographicUtil class there is a method called `update_subject_dob`.<br> |
28 | | -This is used to update the date of birth of a subject to a random age between 50-70 and 75-100 depending on if the argument `younger_subject` is set to True or False.<br> |
29 | | -This method will navigate to the subject demographic page automatically and can be called from any page. |
| 29 | +The `update_subject_dob` method allows you to update a subject's date of birth, either to a specific value or to a random value within a chosen age range. The method will automatically navigate to the subject demographic page, fill in required fields (such as postcode if missing), and update the DOB. |
30 | 30 |
|
31 | | -### Required Args |
| 31 | +### Arguments |
32 | 32 |
|
33 | | -- nhs_no: |
| 33 | +- `nhs_no`: |
34 | 34 | - Type: `str` |
35 | | - - This is the NHS number of the subject you want to update |
36 | | -- younger_subject: |
| 35 | + - The NHS number of the subject you want to update. |
| 36 | +- `random_dob`: |
37 | 37 | - Type: `bool` |
38 | | - - Whether you want the subject to be younger (50-70) or older (75-100). |
| 38 | + - If `True`, the DOB will be set to a random value within the specified age range. |
| 39 | + - If `False`, the DOB will be set to the value provided in `new_dob`. |
| 40 | +- `younger_subject`: |
| 41 | + - Type: `bool | None` |
| 42 | + - Determines the age range for the random DOB update (only used if `random_dob` is `True`): |
| 43 | + - `True`: Random age between 50-70 years old. |
| 44 | + - `False`: Random age between 75-100 years old. |
| 45 | + - `None`: Defaults to `False` (75-100 years old). |
| 46 | +- `new_dob`: |
| 47 | + - Type: `datetime | None` |
| 48 | + - The new date of birth to set (only used if `random_dob` is `False`). |
39 | 49 |
|
40 | 50 | ### How to use this method |
41 | 51 |
|
42 | | -To use this method simply import the SubjectDemographicUtil class and call this method, providing the two arguments: |
| 52 | +To update a subject's DOB to a random value between 50-70: |
43 | 53 |
|
44 | | - nhs_no = "9468743977" |
45 | | - SubjectDemographicUtil(page).update_subject_dob(nhs_no, False) |
| 54 | +```python |
| 55 | +nhs_no = "9468743977" |
| 56 | +SubjectDemographicUtil(page).update_subject_dob(nhs_no, random_dob=True, younger_subject=True) |
| 57 | +``` |
| 58 | + |
| 59 | +To update a subject's DOB to a random value between 75-100: |
| 60 | + |
| 61 | +```python |
| 62 | +nhs_no = "9468743977" |
| 63 | +SubjectDemographicUtil(page).update_subject_dob(nhs_no, random_dob=True, younger_subject=False) |
| 64 | +``` |
| 65 | + |
| 66 | +To update a subject's DOB to a specific date: |
| 67 | + |
| 68 | +```python |
| 69 | +from datetime import datetime |
| 70 | +nhs_no = "9468743977" |
| 71 | +new_dob = datetime(1960, 5, 15) |
| 72 | +SubjectDemographicUtil(page).update_subject_dob(nhs_no, random_dob=False, new_dob=new_dob) |
| 73 | +``` |
| 74 | + |
| 75 | +## Other Utility Methods |
| 76 | + |
| 77 | +- `random_dob_within_range(younger: bool) -> datetime` |
| 78 | + - Generates a random date of birth within the specified age range: |
| 79 | + - If `younger` is `True`, returns a DOB for age 50-70. |
| 80 | + - If `younger` is `False`, returns a DOB for age 75-100. |
| 81 | + |
| 82 | +- `random_datetime(start: datetime, end: datetime) -> datetime` |
| 83 | + Generates a random datetime between two datetime objects. |
| 84 | + |
| 85 | +Refer to the source code in `utils/subject_demographics.py` for more details on available methods and their usage. |
0 commit comments