Skip to content

Commit ea3bc92

Browse files
BCSS - Playwright - Compartment 6 - Utils - Oracle Specific Functions (#74)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description <!-- Describe your changes in detail. --> Created an oracle specific function to return test subjects for the compartment 6 test. ## Context <!-- Why is this change required? What problem does it solve? --> Finds and returns relevant test data for the compartment 6 test. ## 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 - [ ] I have added tests to cover my changes (where appropriate) - [ ] 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 795a4db commit ea3bc92

File tree

3 files changed

+73
-11
lines changed

3 files changed

+73
-11
lines changed

tests/smokescreen/bcss_smokescreen_tests.properties

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# ----------------------------------
4343
# compartment 6
4444
# ----------------------------------
45-
# c6_eng_org_id=23159
45+
c6_eng_org_id=23159
4646
# c6_eng_site_id=35317
4747
# c6_eng_practitioner_id=243
4848
# c6_eng_testing_clinician_id=805
@@ -90,8 +90,4 @@
9090
# ----------------------------------
9191
# compartment 6
9292
# ----------------------------------
93-
# c6_eng_number_of_normal_results_to_record=1
94-
# c6_eng_number_of_lnpcp_results_to_record=1
95-
# c6_eng_number_of_high_risk_findings_results_to_record=1
96-
# c6_eng_number_of_lnpcp_results_over_74_to_record=1
97-
# c6_eng_number_of_high_risk_findings_results_over_74_to_record=1
93+
c6_eng_number_of_subjects_to_record=5

tests/smokescreen/test_compartment_6.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
AdvanceFOBTScreeningEpisodePage,
4949
)
5050
from utils.dataset_field_util import DatasetFieldUtil
51+
from utils.oracle.oracle_specific_functions import get_subjects_for_investigation_dataset_updates
52+
from utils.subject_demographics import SubjectDemographicUtil
5153

5254

5355
# This should go into a util. Adding it here to avoid SonarQube duplication errors:
@@ -311,9 +313,12 @@ def test_compartment_6(page: Page, smokescreen_properties: dict) -> None:
311313

312314
# This needs to be repeated for two subjects, one old and one not - High Risk Result
313315
# Older patient
314-
nhs_no = "9765492782"
316+
subjects_df = get_subjects_for_investigation_dataset_updates(smokescreen_properties["c6_eng_number_of_subjects_to_record"], smokescreen_properties["c6_eng_org_id"])
317+
nhs_no = subjects_df["subject_nhs_number"].iloc[0]
318+
SubjectDemographicUtil(page).update_subject_dob(nhs_no, False)
315319
go_to_investigation_datasets_page(page, nhs_no)
316320

321+
317322
# The following code is on the investigation datasets page
318323
default_investigation_dataset_forms(page)
319324
InvestigationDatasetsPage(page).select_theraputic_procedure_type()
@@ -326,7 +331,8 @@ def test_compartment_6(page: Page, smokescreen_properties: dict) -> None:
326331
handover_subject_to_symptomatic_care(page)
327332

328333
# Younger patient
329-
nhs_no = "9801085703"
334+
nhs_no = subjects_df["subject_nhs_number"].iloc[1]
335+
SubjectDemographicUtil(page).update_subject_dob(nhs_no, True)
330336
go_to_investigation_datasets_page(page, nhs_no)
331337

332338
# The following code is on the investigation datasets page
@@ -356,7 +362,8 @@ def test_compartment_6(page: Page, smokescreen_properties: dict) -> None:
356362

357363
# This needs to be repeated for two subjects, one old and one not - LNPCP Result
358364
# Older patient
359-
nhs_no = "9840970194"
365+
nhs_no = subjects_df["subject_nhs_number"].iloc[2]
366+
SubjectDemographicUtil(page).update_subject_dob(nhs_no, False)
360367
go_to_investigation_datasets_page(page, nhs_no)
361368

362369
# The following code is on the investigation datasets page
@@ -371,7 +378,8 @@ def test_compartment_6(page: Page, smokescreen_properties: dict) -> None:
371378
handover_subject_to_symptomatic_care(page)
372379

373380
# Younger patient
374-
nhs_no = "9717136637"
381+
nhs_no = subjects_df["subject_nhs_number"].iloc[3]
382+
SubjectDemographicUtil(page).update_subject_dob(nhs_no, True)
375383
go_to_investigation_datasets_page(page, nhs_no)
376384

377385
# The following code is on the investigation datasets page
@@ -399,7 +407,7 @@ def test_compartment_6(page: Page, smokescreen_properties: dict) -> None:
399407
)
400408

401409
# This needs to be repeated for 1 subject, age does not matter - Normal Result
402-
nhs_no_normal = "9673858853"
410+
nhs_no_normal = subjects_df["subject_nhs_number"].iloc[4]
403411
go_to_investigation_datasets_page(page, nhs_no_normal)
404412

405413
# The following code is on the investigation datasets page

utils/oracle/oracle_specific_functions.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class SqlQueryValues(IntEnum):
1212
OPEN_EPISODE_STATUS_ID = 11352
1313
A8_EVENT_STATUS = 11132
1414
POSITIVE_APPOINTMENT_BOOKED = 11119
15+
POST_INVESTIGATION_APPOINTMENT_NOT_REQUIRED = 160182
1516

1617

1718
def get_kit_id_from_db(
@@ -364,3 +365,60 @@ def get_subjects_with_booked_appointments(subjects_to_retrieve: int) -> pd.DataF
364365
subjects_df = OracleDB().execute_query(query, params)
365366

366367
return subjects_df
368+
369+
370+
def get_subjects_for_investigation_dataset_updates(
371+
number_of_subjects: int, hub_id: str
372+
) -> pd.DataFrame:
373+
"""
374+
This is used to get subjects for compartment 6
375+
It finds subjects with latest envent status of A323 - Post-investigation Appointment
376+
377+
Args:
378+
number_of_subjects (int): The number of subjects to retrieve
379+
hub_id (str): hub id to use
380+
381+
Returns:
382+
subjects_df (pd.DataFrame): A pandas DataFrame containing the result of the query
383+
"""
384+
385+
query = """SELECT distinct(ss.subject_nhs_number)
386+
from
387+
(
388+
select count(*), eset.screening_subject_id
389+
from ep_subject_episode_t eset
390+
inner join screening_subject_t sst on (eset.screening_subject_id = sst.screening_subject_id)
391+
inner join external_tests_t ext on (eset.subject_epis_id = ext.subject_epis_id)
392+
inner join ds_colonoscopy_t dct on (ext.ext_test_id = dct.ext_test_id)
393+
where dct.dataset_completed_date is null
394+
and dct.deleted_flag ='N'
395+
and ext.void = 'N'
396+
group by eset.screening_subject_id
397+
having
398+
count(*)= 1 ) sst
399+
inner join ep_subject_episode_t eset on ( sst.screening_subject_id = eset.screening_subject_id )
400+
inner join screening_subject_t ss on (eset.screening_subject_id = ss.screening_subject_id)
401+
inner join sd_contact_t c ON ss.subject_nhs_number = c.nhs_number
402+
inner join EXTERNAL_TESTS_T ext on (eset.subject_epis_id = ext.subject_epis_id)
403+
inner join DS_COLONOSCOPY_T dct on (ext.ext_test_id = dct.ext_test_id)
404+
inner join sd_contact_t sd on (ss.subject_nhs_number = sd.nhs_number)
405+
inner join sd_address_t sda on (sd.contact_id = sda.address_id)
406+
inner join org on (sd.gp_practice_id = org.org_id)
407+
where eset.latest_event_status_id = :latest_event_status_id -- A323 - Post-investigation Appointment NOT Required
408+
and ext.void = 'N'
409+
and dct.dataset_new_flag = 'Y'
410+
and dct.deleted_flag = 'N'
411+
and sd.GP_PRACTICE_ID is not null
412+
and eset.start_hub_id = :start_hub_id
413+
fetch first :subjects_to_retrieve rows only
414+
"""
415+
416+
params = {
417+
"latest_event_status_id": SqlQueryValues.POST_INVESTIGATION_APPOINTMENT_NOT_REQUIRED,
418+
"start_hub_id": hub_id,
419+
"subjects_to_retrieve": number_of_subjects,
420+
}
421+
422+
subjects_df = OracleDB().execute_query(query, params)
423+
424+
return subjects_df

0 commit comments

Comments
 (0)