Skip to content

Commit ee73810

Browse files
get_subjects_for_investigations oracle util
1 parent 795a4db commit ee73810

File tree

3 files changed

+76
-11
lines changed

3 files changed

+76
-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: 16 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_investigations
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_investigations(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,9 @@ 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 = "9840970194"
366+
nhs_no = subjects_df["subject_nhs_number"].iloc[2]
367+
SubjectDemographicUtil(page).update_subject_dob(nhs_no, False)
360368
go_to_investigation_datasets_page(page, nhs_no)
361369

362370
# The following code is on the investigation datasets page
@@ -371,7 +379,9 @@ def test_compartment_6(page: Page, smokescreen_properties: dict) -> None:
371379
handover_subject_to_symptomatic_care(page)
372380

373381
# Younger patient
374-
nhs_no = "9717136637"
382+
# nhs_no = "9717136637"
383+
nhs_no = subjects_df["subject_nhs_number"].iloc[3]
384+
SubjectDemographicUtil(page).update_subject_dob(nhs_no, True)
375385
go_to_investigation_datasets_page(page, nhs_no)
376386

377387
# The following code is on the investigation datasets page
@@ -399,7 +409,8 @@ def test_compartment_6(page: Page, smokescreen_properties: dict) -> None:
399409
)
400410

401411
# This needs to be repeated for 1 subject, age does not matter - Normal Result
402-
nhs_no_normal = "9673858853"
412+
# nhs_no_normal = "9673858853"
413+
nhs_no_normal = subjects_df["subject_nhs_number"].iloc[4]
403414
go_to_investigation_datasets_page(page, nhs_no_normal)
404415

405416
# 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_investigations(
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)