Skip to content

Commit 3672442

Browse files
Completing scenario 11
Editting batch_processing to make event status checks optional editting book post investigation appointments to increase appointment start time by 15 minutes if it is unable to book at the original time
1 parent fa841f2 commit 3672442

File tree

5 files changed

+250
-30
lines changed

5 files changed

+250
-30
lines changed

pages/screening_practitioner_appointments/appointment_detail_page.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def select_reason_for_cancellation_option(self, option: str) -> None:
8888
"""
8989
self.reason_for_cancellation_dropdown.select_option(value=option)
9090

91-
9291
def mark_appointment_as_attended(self, date: datetime) -> None:
9392
"""
9493
Marks an appointment as attended.
@@ -118,3 +117,5 @@ class ReasonForCancellationOptions(StrEnum):
118117
CLINIC_UNAVAILABLE = "6001"
119118
PRACTITIONER_UNAVAILABLE = "6000"
120119
PATIENT_CANCELLED_OTHER_REASON = "6004"
120+
PATIENT_CANCELLED = "6020"
121+
SCREENING_CENTRE_CANCELLED = "6019"

pages/screening_practitioner_appointments/book_appointment_page.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ def click_save_button(self) -> None:
4949
"""Clicks the save button."""
5050
self.safe_accept_dialog(self.save_button)
5151

52+
def click_save_button_and_return_message(self) -> str | None:
53+
"""
54+
Clicks the save button and returns the dialog message if a dialog appears.
55+
Returns None if no dialog appears.
56+
"""
57+
dialog_message = None
58+
59+
def handle_dialog(dialog):
60+
nonlocal dialog_message
61+
dialog_message = dialog.message
62+
dialog.accept()
63+
64+
self.page.once("dialog", handle_dialog)
65+
self.click(self.save_button)
66+
return dialog_message
67+
5268
def appointment_booked_confirmation_is_displayed(self, message: str) -> None:
5369
"""Checks if the appointment booked confirmation message is displayed."""
5470
expect(self.page.get_by_text(message)).to_be_visible(timeout=10000)

tests/regression/regression_tests/fobt_regression_tests/test_scenario_11.py

Lines changed: 202 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
from utils.appointments import book_appointments, book_post_investigation_appointment
1515
from utils.oracle.oracle import OracleDB
1616
from utils.investigation_dataset import InvestigationDatasetCompletion
17-
from utils.datasets.investigation_datasets import (
18-
get_default_general_information,
19-
get_default_drug_information,
20-
get_default_endoscopy_information,
21-
get_normal_smokescreen_information,
22-
)
23-
from utils.sspi_change_steps import SSPIChangeSteps
2417
from pages.screening_subject_search.subject_screening_summary_page import (
2518
SubjectScreeningSummaryPage,
2619
)
@@ -35,6 +28,7 @@
3528
)
3629
from pages.screening_practitioner_appointments.appointment_detail_page import (
3730
AppointmentDetailPage,
31+
ReasonForCancellationOptions,
3832
)
3933
from pages.screening_subject_search.advance_fobt_screening_episode_page import (
4034
AdvanceFOBTScreeningEpisodePage,
@@ -50,10 +44,6 @@
5044
ColonoscopyDatasetsPage,
5145
FitForColonoscopySspOptions,
5246
)
53-
from pages.screening_subject_search.contact_with_patient_page import (
54-
ContactWithPatientPage,
55-
)
56-
from pages.organisations.organisations_page import OrganisationSwitchPage
5747
from pages.datasets.investigation_dataset_page import (
5848
InvestigationDatasetsPage,
5949
FailureReasonsOptions,
@@ -66,32 +56,22 @@
6656
OutcomeAtTimeOfProcedureOptions,
6757
YesNoOptions,
6858
CompletionProofOptions,
69-
AdenomaSubTypeOptions,
7059
EndoscopyLocationOptions,
7160
OpticalDiagnosisConfidenceOptions,
7261
OpticalDiagnosisOptions,
7362
PolypAccessOptions,
7463
PolypClassificationOptions,
75-
PolypDysplasiaOptions,
7664
PolypExcisionCompleteOptions,
7765
PolypInterventionDeviceOptions,
78-
PolypInterventionExcisionTechniqueOptions,
7966
PolypInterventionModalityOptions,
8067
PolypInterventionRetrievedOptions,
81-
PolypInterventionSuccessOptions,
82-
PolypReasonLeftInSituOptions,
8368
PolypTypeOptions,
84-
ReasonPathologyLostOptions,
8569
SerratedLesionSubTypeOptions,
86-
YesNoUncertainOptions,
87-
)
88-
from pages.screening_subject_search.reopen_fobt_screening_episode_page import (
89-
ReopenFOBTScreeningEpisodePage,
9070
)
9171
from classes.repositories.person_repository import PersonRepository
72+
from pages.login.select_job_role_page import SelectJobRolePage
9273

9374

94-
@pytest.mark.wip
9575
@pytest.mark.usefixtures("setup_org_and_appointments")
9676
@pytest.mark.vpn_required
9777
@pytest.mark.regression
@@ -640,5 +620,205 @@ def test_scenario_11(page: Page) -> None:
640620
EpisodeEventsAndNotesPage(page).click_most_recent_view_appointment_link()
641621

642622
# And The Screening Centre cancels the practitioner appointment with reason "Screening Centre Cancelled"
623+
AppointmentDetailPage(page).check_cancel_radio()
624+
AppointmentDetailPage(page).select_reason_for_cancellation_option(
625+
ReasonForCancellationOptions.SCREENING_CENTRE_CANCELLED
626+
)
627+
628+
# And I press OK on my confirmation prompt
629+
AppointmentDetailPage(page).click_save_button(accept_dialog=True)
630+
631+
# Then my subject has been updated as follows:
632+
subject_assertion(
633+
nhs_no,
634+
{
635+
"latest event status": "A417 Post-investigation Appointment Cancelled by SC",
636+
},
637+
)
638+
639+
# And there is a "A417" letter batch for my subject with the exact title "Post-Investigation Appointment Cancelled (Screening Centre)"
640+
# When I process the open "A417" letter batch for my subject
641+
batch_processing(
642+
page,
643+
"A417",
644+
"Post-Investigation Appointment Cancelled (Screening Centre)",
645+
"A422 - Post-investigation Appointment Cancellation Letter Printed",
646+
)
647+
648+
# When I advance the subject's episode for "Post-investigation Appointment Required"
649+
SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button()
650+
AdvanceFOBTScreeningEpisodePage(
651+
page
652+
).click_post_investigation_appointment_required_button()
653+
654+
# Then my subject has been updated as follows:
655+
subject_assertion(
656+
nhs_no,
657+
{
658+
"latest event status": "A360 - Post-investigation Appointment Required",
659+
},
660+
)
661+
662+
# When I view the subject
663+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
643664

665+
# And I choose to book a practitioner clinic for my subject
666+
SubjectScreeningSummaryPage(page).click_book_practitioner_clinic_button()
667+
668+
# And I set the practitioner appointment date to "today"
669+
# And I book the earliest available post investigation appointment on this date
670+
book_post_investigation_appointment(page, "The Royal Hospital (Wolverhampton)", 1)
671+
672+
# Then my subject has been updated as follows:
673+
subject_assertion(
674+
nhs_no,
675+
{
676+
"latest event status": "A410 - Post-investigation Appointment Made",
677+
},
678+
)
679+
680+
# And there is a "A410" letter batch for my subject with the exact title "Post-Investigation Appointment Invitation Letter"
681+
# When I process the open "A410 - Post-Investigation Appointment Invitation Letter" letter batch for my subject
682+
batch_processing(
683+
page,
684+
"A410",
685+
"Post-Investigation Appointment Invitation Letter",
686+
"A415 - Post-investigation Appointment Invitation Letter Printed",
687+
)
688+
689+
# When I view the subject
690+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
691+
692+
# And I view the event history for the subject's latest episode
693+
SubjectScreeningSummaryPage(page).expand_episodes_list()
694+
SubjectScreeningSummaryPage(page).click_first_fobt_episode_link()
695+
696+
# And I view the latest practitioner appointment in the subject's episode
697+
EpisodeEventsAndNotesPage(page).click_most_recent_view_appointment_link()
698+
699+
# And I attend the subject's practitioner appointment "yesterday"
700+
AppointmentDetailPage(page).mark_appointment_as_attended(
701+
datetime.today() - timedelta(days=1)
702+
)
703+
704+
# Then my subject has been updated as follows:
705+
subject_assertion(
706+
nhs_no,
707+
{
708+
"latest event status": "A416 - Post-investigation Appointment Attended",
709+
},
710+
)
711+
712+
# When I view the subject
713+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
714+
715+
# And I view the advance episode options
716+
SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button()
717+
718+
# And I select the advance episode option for "Record Diagnosis Date"
719+
AdvanceFOBTScreeningEpisodePage(page).click_record_diagnosis_date_button()
720+
721+
# And I enter a Diagnosis Date of "today"
722+
RecordDiagnosisDatePage(page).enter_date_in_diagnosis_date_field(datetime.today())
723+
724+
# And I save Diagnosis Date Information
725+
RecordDiagnosisDatePage(page).click_save_button()
726+
727+
# Then my subject has been updated as follows:
728+
criteria = {
729+
"latest episode diagnosis date reason": "Null",
730+
"latest episode has diagnosis date": "Yes",
731+
"latest episode includes event status": "A50 Diagnosis date recorded",
732+
"latest event status": "A416 Post-investigation Appointment Attended",
733+
}
734+
subject_assertion(nhs_no, criteria)
735+
736+
# When I view the subject
737+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
738+
739+
# And I select the advance episode option for "Enter Diagnostic Test Outcome"
740+
SubjectScreeningSummaryPage(page).click_advance_fobt_screening_episode_button()
741+
AdvanceFOBTScreeningEpisodePage(page).click_enter_diagnostic_test_outcome_button()
742+
743+
# And I select Outcome of Investigation Complete
744+
DiagnosticTestOutcomePage(page).select_test_outcome_option(
745+
OutcomeOfDiagnosticTest.INVESTIGATION_COMPLETE
746+
)
747+
748+
# And I save the Diagnostic Test Outcome
749+
DiagnosticTestOutcomePage(page).click_save_button()
750+
751+
# Then my subject has been updated as follows:
752+
criteria = {
753+
"latest episode includes event status": "A316 Post-investigation Appointment Attended",
754+
"latest event status": "A430 Post-investigation Appointment Attended - Diagnostic Result Letter not Printed",
755+
}
756+
subject_assertion(nhs_no, criteria)
757+
758+
# When I switch users to BCSS "England" as user role "Hub Manager"
759+
LogoutPage(page).log_out(close_page=False)
760+
BasePage(page).go_to_log_in_page()
761+
UserTools.user_login(page, "Hub Manager State Registered at BCS01")
762+
763+
# And I process the open "A183 - GP Result (Abnormal)" letter batch for my subject
764+
batch_processing(
765+
page,
766+
"A183",
767+
"GP Result (Abnormal)",
768+
)
769+
770+
# Then my subject has been updated as follows:
771+
criteria = {
772+
"latest episode includes event status": "A167 GP Abnormal FOBT Result Sent",
773+
"latest event status": "A430 Post-investigation Appointment Attended - Diagnostic Result Letter not Printed",
774+
}
775+
subject_assertion(nhs_no, criteria)
776+
777+
# When I switch users to BCSS "England" as user role "Screening Centre Clerk"
778+
LogoutPage(page).log_out(close_page=False)
779+
BasePage(page).go_to_log_in_page()
780+
UserTools.user_login(page, "Screening Centre Clerk at BCS001")
781+
SelectJobRolePage(page).select_option_for_job_role("Screening Centre Clerk")
782+
SelectJobRolePage(page).click_continue_button()
783+
784+
# And there is a "A430" letter batch for my subject with the exact title "Result Letters Following Post-investigation Appointment"
785+
# And I process the open "A430" letter batch for my subject
786+
batch_processing(
787+
page,
788+
"A430",
789+
"Result Letters Following Post-investigation Appointment",
790+
)
791+
# Then my subject has been updated as follows:
792+
criteria = {
793+
"which diagnostic test": "Latest not-void test in latest episode",
794+
"calculated fobt due date": "2 years from diagnostic test",
795+
"calculated lynch due date": "Null",
796+
"calculated surveillance due date": "Unchanged",
797+
"ceased confirmation date": "Null",
798+
"ceased confirmation details": "Null",
799+
"ceased confirmation user id": "Null",
800+
"clinical reason for cease": "Null",
801+
"latest episode accumulated result": "Abnormal",
802+
"latest episode recall calculation method": "Diagnostic test date",
803+
"latest episode recall episode type": "FOBT Screening",
804+
"latest episode recall surveillance type": "Null",
805+
"latest episode status": "Closed",
806+
"latest episode status reason": "Episode Complete",
807+
"latest event status": "A65 Abnormal",
808+
"lynch due date": "Null",
809+
"lynch due date reason": "Unchanged",
810+
"lynch due date date of change": "Unchanged",
811+
"screening due date": "Calculated FOBT Due Date",
812+
"screening due date date of change": "Today",
813+
"screening due date reason": "Recall",
814+
"screening status": "Recall",
815+
"screening status reason": "Recall",
816+
"surveillance due date": "Null",
817+
"surveillance due date date of change": "Unchanged",
818+
"surveillance due date reason": "Unchanged",
819+
"symptomatic procedure date": "Null",
820+
"symptomatic procedure result": "Null",
821+
"screening referral type": "Null",
822+
}
823+
subject_assertion(nhs_no, criteria)
644824
LogoutPage(page).log_out()

utils/appointments.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,21 @@ def book_appointments(page: Page, screening_centre: str, site: str) -> None:
133133

134134

135135
def book_post_investigation_appointment(
136-
page: Page, site: str, screening_practitioner_index: int, appointment_start_time: str = "08:00"
136+
page: Page,
137+
site: str,
138+
screening_practitioner_index: int,
139+
appointment_start_time: str = "08:00",
137140
) -> None:
138141
"""
139142
Book a post-investigation appointment for a subject.
140143
Sets the appointment date to today and the start time to '08:00'.
144+
If a dialog about overlapping appointments is triggered, increases the start time by 15 minutes and retries.
145+
Loops until a successful booking or until 17:00.
141146
Args:
142147
page (Page): The Playwright page object.
143148
site (str): The name of the site.
144149
screening_practitioner_index (int): The index of the screening practitioner to select.
150+
appointment_start_time (str): The start time for the appointment.
145151
"""
146152
book_appointments_page = BookAppointmentPage(page)
147153
book_appointments_page.select_site_dropdown_option(
@@ -154,8 +160,24 @@ def book_post_investigation_appointment(
154160
screening_practitioner_index
155161
)
156162
book_appointments_page.enter_appointment_date(datetime.today())
157-
book_appointments_page.enter_appointment_start_time(appointment_start_time)
158-
book_appointments_page.click_save_button()
163+
164+
overlap_message = "Overlaps a Post Investigation, Surveillance appointment or Colonoscopy Assessment appointment"
165+
hour, minute = map(int, appointment_start_time.split(":"))
166+
167+
while True:
168+
current_time = f"{hour:02d}:{minute:02d}"
169+
book_appointments_page.enter_appointment_start_time(current_time)
170+
dialog_message = book_appointments_page.click_save_button_and_return_message()
171+
if dialog_message is None or overlap_message not in dialog_message:
172+
# Success or no overlap dialog
173+
break
174+
# Increase time by 15 minutes
175+
minute += 15
176+
if minute >= 60:
177+
hour += 1
178+
minute -= 60
179+
if hour >= 17:
180+
raise ValueError("Could not book appointment before 17:00 due to overlaps.")
159181

160182

161183
class AppointmentAttendance(BasePage):

utils/batch_processing.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def batch_processing(
2727
page: Page,
2828
batch_type: str,
2929
batch_description: str,
30-
latest_event_status: str | list,
30+
latest_event_status: Optional[str | list] = None,
3131
run_timed_events: bool = False,
3232
get_subjects_from_pdf: bool = False,
3333
save_csv_as_df: bool = False,
@@ -100,9 +100,10 @@ def batch_processing(
100100
if nhs_no_df is None:
101101
raise ValueError("No NHS numbers were retrieved for the batch")
102102

103-
for subject in range(len(nhs_no_df)):
104-
nhs_no = nhs_no_df["subject_nhs_number"].iloc[subject]
105-
verify_subject_event_status_by_nhs_no(page, nhs_no, latest_event_status)
103+
if latest_event_status:
104+
for subject in range(len(nhs_no_df)):
105+
nhs_no = nhs_no_df["subject_nhs_number"].iloc[subject]
106+
verify_subject_event_status_by_nhs_no(page, nhs_no, latest_event_status)
106107

107108
if run_timed_events:
108109
OracleDB().exec_bcss_timed_events(nhs_no_df)

0 commit comments

Comments
 (0)