Skip to content

Commit 652f977

Browse files
Migrating LynchRegressionTests Scenario 7.1
1 parent 8e702f7 commit 652f977

File tree

1 file changed

+398
-0
lines changed

1 file changed

+398
-0
lines changed
Lines changed: 398 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,398 @@
1+
import logging
2+
import pytest
3+
from datetime import datetime, timedelta
4+
from playwright.sync_api import Page
5+
from classes.repositories.general_repository import GeneralRepository
6+
from pages.base_page import BasePage
7+
from pages.datasets.colonoscopy_dataset_page import (
8+
ColonoscopyDatasetsPage,
9+
FitForColonoscopySspOptions,
10+
)
11+
from pages.datasets.subject_datasets_page import SubjectDatasetsPage
12+
from pages.logout.log_out_page import LogoutPage
13+
from pages.screening_practitioner_appointments.appointment_detail_page import (
14+
AppointmentDetailPage,
15+
)
16+
from pages.screening_subject_search.advance_lynch_surveillance_episode_page import (
17+
AdvanceLynchSurveillanceEpisodePage,
18+
)
19+
from pages.screening_subject_search.contact_with_patient_page import (
20+
ContactWithPatientPage,
21+
)
22+
from pages.screening_subject_search.episode_events_and_notes_page import (
23+
EpisodeEventsAndNotesPage,
24+
)
25+
from pages.screening_subject_search.subject_screening_summary_page import (
26+
SubjectScreeningSummaryPage,
27+
)
28+
from utils import screening_subject_page_searcher
29+
from utils.appointments import book_appointments
30+
from utils.batch_processing import batch_processing
31+
from utils.calendar_picker import CalendarPicker
32+
from utils.lynch_utils import LynchUtils
33+
from utils.oracle.oracle import OracleDB
34+
from utils.subject_assertion import subject_assertion
35+
from utils.user_tools import UserTools
36+
37+
38+
@pytest.mark.usefixtures("setup_org_and_appointments")
39+
@pytest.mark.vpn_required
40+
@pytest.mark.regression
41+
@pytest.mark.lynch_regression_tests
42+
def test_lynch_scenario_7_1(page: Page) -> None:
43+
"""
44+
Scenario: 7.1 - Discharge patient choice (no result) - self referral
45+
46+
G4-G2-G3-A183-A25-J10-A99-A59-A306-A396-A392-A350-C203 Lynch over age [SSCL14b(A350)]
47+
48+
This scenario tests where the subject is invited for a diagnostic test, but cancels the test (giving an episode result of "No result") and decides not to continue.
49+
50+
Subject summary:
51+
52+
> Process Lynch diagnosis for a new over-age subject suitable for immediate self-referral
53+
> Self refer the subject
54+
> Run Lynch invitations > G4 (5.1)
55+
> Process G4 letter batch > G2 (5.1)
56+
> Run timed events > G3 (5.1)
57+
> Book appointment > A183 (1.11)
58+
> Process A183 letter batch > A25 (1.11)
59+
> Attend appointment > J10 (1.12)
60+
> Suitable for Endoscopic Test > A99 (2.1)
61+
> Invite for Diagnostic Test > A59 (2.1)
62+
> Cancel Diagnostic Test > A306 (2.1)
63+
> Close Episode - Patient Choice > A396 (2.3)
64+
> Process A396 letter batch > A392 (2.3)
65+
> Process A392 letter batch > A350 (2.3)
66+
> Check recall [SSCL14b(A350)]
67+
"""
68+
# Given I log in to BCSS "England" as user role "Hub Manager"
69+
user_role = UserTools.user_login(
70+
page, "Hub Manager State Registered at BCS01", return_role_type=True
71+
)
72+
if user_role is None:
73+
raise ValueError("User cannot be assigned to a UserRoleType")
74+
75+
# When I receive Lynch diagnosis "EPCAM" for a new subject in my hub aged "75" with diagnosis date "3 years ago" and last colonoscopy date "2 years ago"
76+
nhs_no = LynchUtils(page).insert_validated_lynch_patient_from_new_subject_with_age(
77+
age="75",
78+
gene="EPCAM",
79+
when_diagnosis_took_place="3 years ago",
80+
when_last_colonoscopy_took_place="2 years ago",
81+
user_role=user_role,
82+
)
83+
84+
# Then Comment: NHS number
85+
assert nhs_no is not None
86+
logging.info(f"[SUBJECT CREATION] Created Lynch subject with NHS number: {nhs_no}")
87+
88+
# When I self refer the subject
89+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
90+
SubjectScreeningSummaryPage(page).click_self_refer_button()
91+
92+
# Then my subject has been updated as follows:
93+
subject_assertion(
94+
nhs_no,
95+
{
96+
"Calculated FOBT due date": "Null",
97+
"Calculated lynch due date": "Today",
98+
"Calculated surveillance due date": "Null",
99+
"Lynch due date": "Today",
100+
"Lynch due date date of change": "Null",
101+
"Lynch due date reason": "Self-referral",
102+
"Previous screening status": "Lynch Surveillance",
103+
"Screening due date": "Null",
104+
"Screening due date date of change": "Null",
105+
"Screening due date reason": "Null",
106+
"Subject has lynch diagnosis": "Yes",
107+
"Subject lower FOBT age": "Default",
108+
"Subject lower lynch age": "25",
109+
"Screening status": "Lynch Self-referral",
110+
"Screening status date of change": "Today",
111+
"Screening status reason": "Self-referral",
112+
"Subject age": "75",
113+
"Surveillance due date": "Null",
114+
"Surveillance due date date of change": "Null",
115+
"Surveillance due date reason": "Null",
116+
},
117+
)
118+
119+
# When I set the Lynch invitation rate for all screening centres to 50
120+
LynchUtils(page).set_lynch_invitation_rate(rate=50)
121+
122+
# And I run the Lynch invitations process
123+
GeneralRepository().run_lynch_invitations()
124+
125+
# And my subject has been updated as follows:
126+
subject_assertion(
127+
nhs_no,
128+
{
129+
"latest episode type": "Lynch Surveillance",
130+
"latest episode sub-type": "Over Age",
131+
"latest event status": "G4 Selected for Lynch Surveillance (Self-referral)",
132+
"calculated fobt due date": "Null",
133+
"calculated lynch due date": "Today",
134+
"calculated surveillance due date": "Null",
135+
"lynch due date": "Today",
136+
"lynch due date date of change": "Null",
137+
"lynch due date reason": "Self-referral",
138+
"previous screening status": "Lynch Surveillance",
139+
"screening due date": "Null",
140+
"screening due date date of change": "Null",
141+
"screening due date reason": "Null",
142+
"subject has lynch diagnosis": "Yes",
143+
"subject lower fobt age": "Default",
144+
"subject lower lynch age": "25",
145+
"screening status": "Lynch Self-referral",
146+
"screening status date of change": "Today",
147+
"screening status reason": "Self-referral",
148+
"subject age": "75",
149+
"surveillance due date": "Null",
150+
"surveillance due date date of change": "Null",
151+
"surveillance due date reason": "Null",
152+
},
153+
)
154+
155+
# And there is a "G4" letter batch for my subject with the exact title "Lynch Surveillance Invitation (Self-referral)"
156+
# When I process the open "G4" letter batch for my subject
157+
batch_processing(
158+
page,
159+
"G4",
160+
"Lynch Surveillance Invitation (Self-referral)",
161+
)
162+
163+
# Then my subject has been updated as follows:
164+
subject_assertion(nhs_no, {"latest event status": "G2 Lynch Pre-invitation Sent"})
165+
166+
# When I run Timed Events for my subject
167+
OracleDB().exec_bcss_timed_events(nhs_number=nhs_no)
168+
169+
# Then my subject has been updated as follows:
170+
subject_assertion(
171+
nhs_no,
172+
{
173+
"latest event status": "G3 Lynch Surveillance Colonoscopy Assessment Appointment Required"
174+
},
175+
)
176+
177+
logging.info("Progress the episode through to closure")
178+
179+
# When I view the subject
180+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
181+
182+
# And I view the practitioner appointment booking screen
183+
SubjectScreeningSummaryPage(page).click_book_practitioner_clinic_button()
184+
185+
# And I select "BCS001" as the screening centre where the practitioner appointment will be held
186+
# And I set the practitioner appointment date to "today"
187+
# And I book the "earliest" available practitioner appointment on this date
188+
book_appointments(
189+
page,
190+
"BCS001 - Wolverhampton Bowel Cancer Screening Centre",
191+
"The Royal Hospital (Wolverhampton)",
192+
)
193+
194+
# Then my subject has been updated as follows:
195+
subject_assertion(
196+
nhs_no,
197+
{
198+
"latest event status": "A183 1st Colonoscopy Assessment Appointment Requested",
199+
},
200+
)
201+
202+
# And there is a "A183" letter batch for my subject with the exact title "Practitioner Clinic 1st Appointment (Lynch)"
203+
# When I process the open "A183" letter batch for my subject
204+
batch_processing(page, "A183", "Practitioner Clinic 1st Appointment (Lynch)")
205+
206+
# Then my subject has been updated as follows:
207+
subject_assertion(
208+
nhs_no,
209+
{
210+
"latest event status": "A25 1st Colonoscopy Assessment Appointment Booked, letter sent",
211+
},
212+
)
213+
214+
# When I switch users to BCSS "England" as user role "Screening Centre Manager"
215+
LogoutPage(page).log_out(close_page=False)
216+
BasePage(page).go_to_log_in_page()
217+
user_role = UserTools.user_login(page, "Screening Centre Manager at BCS001", True)
218+
if user_role is None:
219+
raise ValueError("User cannot be assigned to a UserRoleType")
220+
221+
# And I view the subject
222+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
223+
224+
# And I view the event history for the subject's latest episode
225+
SubjectScreeningSummaryPage(page).expand_episodes_list()
226+
SubjectScreeningSummaryPage(page).click_first_lynch_surveillance_episode_link()
227+
228+
# And I view the latest practitioner appointment in the subject's episode
229+
EpisodeEventsAndNotesPage(page).click_most_recent_view_appointment_link()
230+
231+
# And I attend the subject's practitioner appointment "2 days ago"
232+
AppointmentDetailPage(page).mark_appointment_as_attended(
233+
datetime.today() - timedelta(days=2)
234+
)
235+
236+
# Then my subject has been updated as follows:
237+
subject_assertion(
238+
nhs_no,
239+
{
240+
"latest event status": "J10 Attended Colonoscopy Assessment Appointment",
241+
},
242+
)
243+
244+
# When I view the subject
245+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
246+
247+
# And I edit the Colonoscopy Assessment Dataset for this subject
248+
SubjectScreeningSummaryPage(page).click_datasets_link()
249+
SubjectDatasetsPage(page).click_colonoscopy_show_datasets()
250+
251+
# And I update the Colonoscopy Assessment Dataset with the following values:
252+
ColonoscopyDatasetsPage(page).select_fit_for_colonoscopy_option(
253+
FitForColonoscopySspOptions.YES
254+
)
255+
ColonoscopyDatasetsPage(page).click_dataset_complete_radio_button_yes()
256+
257+
# And I save the Colonoscopy Assessment Dataset
258+
ColonoscopyDatasetsPage(page).save_dataset()
259+
260+
# And I view the subject
261+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
262+
263+
# And I advance the subject's episode for "Suitable for Endoscopic Test"
264+
SubjectScreeningSummaryPage(page).click_advance_lynch_surveillance_episode_button()
265+
AdvanceLynchSurveillanceEpisodePage(
266+
page
267+
).click_suitable_for_endoscopic_test_button()
268+
269+
# Then my subject has been updated as follows:
270+
subject_assertion(
271+
nhs_no,
272+
{
273+
"latest event status": "A99 Suitable for Endoscopic Test",
274+
},
275+
)
276+
277+
# When I view the advance episode options
278+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
279+
SubjectScreeningSummaryPage(page).click_advance_lynch_surveillance_episode_button()
280+
281+
# And I select Diagnostic Test Type "Colonoscopy"
282+
AdvanceLynchSurveillanceEpisodePage(page).select_test_type_dropdown_option(
283+
"Colonoscopy"
284+
)
285+
286+
# And I enter a Diagnostic Test First Offered Appointment Date of "today"
287+
AdvanceLynchSurveillanceEpisodePage(page).click_calendar_button()
288+
CalendarPicker(page).v1_calender_picker(datetime.today())
289+
290+
# And I advance the subject's episode for "Invite for Diagnostic Test >>"
291+
AdvanceLynchSurveillanceEpisodePage(page).click_invite_for_diagnostic_test_button()
292+
293+
# Then my subject has been updated as follows:
294+
subject_assertion(
295+
nhs_no,
296+
{
297+
"latest event status": "A59 Invited for Diagnostic Test",
298+
},
299+
)
300+
301+
# When I view the subject
302+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
303+
304+
# And I advance the subject's episode for "Cancel Diagnostic Test"
305+
SubjectScreeningSummaryPage(page).click_advance_lynch_surveillance_episode_button()
306+
AdvanceLynchSurveillanceEpisodePage(page).click_cancel_diagnostic_test_button()
307+
308+
# Then my subject has been updated as follows:
309+
subject_assertion(
310+
nhs_no,
311+
{
312+
"latest event status": "A306 Cancel Diagnostic Test",
313+
},
314+
)
315+
316+
# When I select the advance episode option for "Record Contact with Patient"
317+
AdvanceLynchSurveillanceEpisodePage(page).click_record_contact_with_patient_button()
318+
319+
# And I record contact with the subject with outcome "Close Episode - Patient Choice"
320+
ContactWithPatientPage(page).record_contact("Close Episode - Patient Choice")
321+
322+
# Then my subject has been updated as follows:
323+
subject_assertion(
324+
nhs_no,
325+
{
326+
"latest event status": "A396 Discharged from Screening Round - Patient Choice",
327+
},
328+
)
329+
330+
# And there is a "A396" letter batch for my subject with the exact title "Discharge from screening round - patient decision (letter to patient) (Lynch)"
331+
# When I process the open "A396" letter batch for my subject
332+
batch_processing(
333+
page,
334+
"A396",
335+
"Discharge from screening round - patient decision (letter to patient) (Lynch)",
336+
)
337+
338+
# Then my subject has been updated as follows:
339+
subject_assertion(
340+
nhs_no,
341+
{
342+
"latest event status": "A392 Patient Discharge Letter Printed - Patient Choice",
343+
},
344+
)
345+
346+
# And there is a "A392" letter batch for my subject with the exact title "Discharge from screening round - patient decision (letter to GP) (Lynch)"
347+
# When I process the open "A392" letter batch for my subject
348+
batch_processing(
349+
page,
350+
"A392",
351+
"Discharge from screening round - patient decision (letter to GP) (Lynch)",
352+
)
353+
354+
logging.info("Check subject details against closure scenario SSCL14b (A350)")
355+
356+
# Then my subject has been updated as follows:
357+
subject_assertion(
358+
nhs_no,
359+
{
360+
"Calculated FOBT Due Date": "Null",
361+
"Calculated Lynch due date": "2 years from episode end",
362+
"Calculated Surveillance Due Date": "Null",
363+
"Ceased confirmation date": "Today",
364+
"Ceased confirmation details": "Outside screening population at recall.",
365+
"Ceased confirmation user ID": "User's ID",
366+
"Clinical reason for cease": "Null",
367+
"Latest episode accumulated result": "No result",
368+
"Latest episode recall calculation method": "Episode end date",
369+
"Latest episode recall episode type": "Lynch Surveillance",
370+
"Latest episode recall surveillance type": "Null",
371+
"Latest episode status reason": "Informed dissent",
372+
"Latest event status": "A350 Letter of Non-agreement to Continue with Investigation sent to GP",
373+
"Lynch due date": "Null",
374+
"Lynch due date date of change": "Today",
375+
"Lynch due date reason": "Ceased",
376+
"Lynch incident episode": "Null",
377+
"Screening due date": "Null",
378+
"Screening due date date of change": "Unchanged",
379+
"Screening due date reason": "Unchanged",
380+
"Screening status": "Ceased",
381+
"Screening status date of change": "Today",
382+
"Screening status reason": "Outside Screening Population",
383+
"Surveillance due date": "Null",
384+
"Surveillance due date date of change": "Unchanged",
385+
"Surveillance due date reason": "Unchanged",
386+
},
387+
user_role,
388+
)
389+
390+
# When I view the subject
391+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
392+
393+
# Then I "can" see a button with value of "Self-refer Lynch Surveillance"
394+
SubjectScreeningSummaryPage(page).button_with_value_present(
395+
"Self-refer Lynch Surveillance", True
396+
)
397+
398+
LogoutPage(page).log_out()

0 commit comments

Comments
 (0)