11# frozen_string_literal: true
22
33describe "Triage" do
4- scenario "nurse can triage a patient" do
4+ scenario "nurse can triage a patient for an HPV programme " do
55 given_a_programme_with_a_running_session
66 and_a_patient_who_needs_triage_exists
77 and_a_patient_who_doesnt_need_triage_exists
2828 and_vaccination_will_happen_emails_are_sent_to_both_parents
2929 end
3030
31+ scenario "nurse can triage patients for a flu programme with different consent types" do
32+ given_a_flu_programme_with_a_running_session
33+ and_patients_with_different_flu_consent_types_exist
34+
35+ when_i_go_to_the_session_triage_tab
36+ then_i_see_both_patients_who_need_triage
37+
38+ # First patient - injection only consent
39+ when_i_go_to_the_first_patient_that_needs_triage
40+ then_i_see_the_triage_options_for_injection_only_consent
41+
42+ when_i_record_that_they_need_triage_for_flu
43+ then_i_see_the_triage_page
44+ and_needs_triage_emails_are_sent_to_both_parents
45+
46+ when_i_record_that_they_are_safe_to_vaccinate_with_injection
47+ then_i_see_the_update_triage_link
48+ and_vaccination_will_happen_emails_are_sent_to_both_parents
49+ and_the_vaccine_method_is_recorded_as_injection
50+
51+ # Second patient - nasal only consent
52+ when_i_go_to_the_session_triage_tab
53+ and_i_go_to_the_second_patient_that_needs_triage
54+ then_i_see_the_triage_options_for_nasal_only_consent
55+
56+ when_i_record_that_they_need_triage_for_flu
57+ then_i_see_the_triage_page
58+ and_needs_triage_emails_are_sent_to_both_parents
59+
60+ when_i_go_to_the_second_patient
61+ and_i_record_that_they_are_safe_to_vaccinate_with_nasal
62+ then_i_see_the_update_triage_link
63+ and_vaccination_will_happen_emails_are_sent_to_both_parents
64+ and_the_vaccine_method_is_recorded_as_nasal
65+ end
66+
3167 def given_a_programme_with_a_running_session
3268 programmes = [ create ( :programme , :hpv ) ]
3369 @organisation = create ( :organisation , :with_one_nurse , programmes :)
@@ -42,6 +78,20 @@ def given_a_programme_with_a_running_session
4278 @session = create ( :session , organisation : @organisation , programmes :)
4379 end
4480
81+ def given_a_flu_programme_with_a_running_session
82+ programmes = [ create ( :programme , :flu ) ]
83+ @organisation = create ( :organisation , :with_one_nurse , programmes :)
84+
85+ @batch =
86+ create (
87+ :batch ,
88+ organisation : @organisation ,
89+ vaccine : programmes . first . vaccines . first
90+ )
91+
92+ @session = create ( :session , organisation : @organisation , programmes :)
93+ end
94+
4595 def and_a_patient_who_needs_triage_exists
4696 @patient_triage_needed =
4797 create (
@@ -62,6 +112,25 @@ def and_a_patient_who_needs_triage_exists
62112 @patient_triage_needed . reload # Make sure both consents are accessible
63113 end
64114
115+ def and_patients_with_different_flu_consent_types_exist
116+ @patient_injection_only =
117+ create (
118+ :patient_session ,
119+ :consent_given_injection_only_triage_needed ,
120+ session : @session
121+ ) . patient
122+
123+ @patient_nasal_only =
124+ create (
125+ :patient_session ,
126+ :consent_given_nasal_only_triage_needed ,
127+ session : @session
128+ ) . patient
129+
130+ @patient_injection_only . reload
131+ @patient_nasal_only . reload
132+ end
133+
65134 def and_a_patient_who_doesnt_need_triage_exists
66135 @patient_triage_not_needed =
67136 create (
@@ -80,6 +149,11 @@ def then_i_see_the_patient_who_needs_triage
80149 expect ( page ) . to have_content ( @patient_triage_needed . full_name )
81150 end
82151
152+ def then_i_see_both_patients_who_need_triage
153+ expect ( page ) . to have_content ( @patient_injection_only . full_name )
154+ expect ( page ) . to have_content ( @patient_nasal_only . full_name )
155+ end
156+
83157 def and_i_dont_see_the_patient_who_doesnt_need_triage
84158 expect ( page ) . not_to have_content ( @patient_triage_not_needed . full_name )
85159 end
@@ -90,10 +164,6 @@ def when_i_go_to_the_patient_that_needs_triage
90164 click_link @patient_triage_needed . full_name
91165 end
92166
93- def when_i_go_to_the_patient
94- click_link @patient_triage_needed . full_name , match : :first
95- end
96-
97167 def then_i_see_the_triage_options
98168 expect ( page ) . to have_selector :heading , "Is it safe to vaccinate"
99169 end
@@ -103,12 +173,27 @@ def when_i_record_that_they_need_triage
103173 click_button "Save triage"
104174 end
105175
176+ def when_i_record_that_they_need_triage_for_flu
177+ choose "No, keep in triage"
178+ click_button "Save triage"
179+ end
180+
106181 def when_i_record_that_they_are_safe_to_vaccinate
107182 click_link "Update triage"
108183 choose "Yes, it’s safe to vaccinate"
109184 click_button "Save triage"
110185 end
111186
187+ def when_i_record_that_they_are_safe_to_vaccinate_with_injection
188+ choose "Yes, it’s safe to vaccinate with injected vaccine"
189+ click_button "Save triage"
190+ end
191+
192+ def and_i_record_that_they_are_safe_to_vaccinate_with_nasal
193+ choose "Yes, it’s safe to vaccinate with nasal spray"
194+ click_button "Save triage"
195+ end
196+
112197 def when_i_do_not_vaccinate
113198 choose "No, do not vaccinate"
114199 click_button "Save triage"
@@ -126,21 +211,84 @@ def then_i_see_the_update_triage_link
126211 expect ( page ) . to have_link "Update triage"
127212 end
128213
214+ def then_i_see_the_triage_page
215+ expect ( page ) . to have_selector :heading , "Is it safe to vaccinate"
216+ end
217+
129218 def and_needs_triage_emails_are_sent_to_both_parents
130- @patient_triage_needed . parents . each do |parent |
219+ current_patient =
220+ @patient_triage_needed || @patient_injection_only || @patient_nasal_only
221+ current_patient . parents . each do |parent |
131222 expect_email_to parent . email , :consent_confirmation_triage , :any
132223 end
133224 end
134225
135226 def and_vaccination_wont_happen_emails_are_sent_to_both_parents
136- @patient_triage_needed . parents . each do |parent |
227+ current_patient =
228+ @patient_triage_needed || @patient_injection_only || @patient_nasal_only
229+ current_patient . parents . each do |parent |
137230 expect_email_to parent . email , :triage_vaccination_wont_happen , :any
138231 end
139232 end
140233
141234 def and_vaccination_will_happen_emails_are_sent_to_both_parents
142- @patient_triage_needed . parents . each do |parent |
235+ current_patient =
236+ @patient_triage_needed || @patient_injection_only || @patient_nasal_only
237+ current_patient . parents . each do |parent |
143238 expect_email_to parent . email , :triage_vaccination_will_happen , :any
144239 end
145240 end
241+
242+ def and_the_vaccine_method_is_recorded_as_injection
243+ current_patient =
244+ @patient_triage_needed || @patient_injection_only || @patient_nasal_only
245+ triage = current_patient . triages . last
246+ expect ( triage . vaccine_method ) . to eq ( "injection" )
247+ end
248+
249+ def when_i_go_to_the_first_patient_that_needs_triage
250+ choose "Needs triage"
251+ click_on "Update results"
252+ click_link @patient_injection_only . full_name
253+ end
254+
255+ def then_i_see_the_triage_options_for_injection_only_consent
256+ expect ( page ) . to have_selector :heading ,
257+ "Is it safe to vaccinate #{ @patient_injection_only . given_name } ?"
258+ expect ( page ) . to have_content (
259+ "The parent has consented to the injected vaccine only"
260+ )
261+ expect ( page ) . to have_field (
262+ "Yes, it’s safe to vaccinate with injected vaccine" ,
263+ type : "radio"
264+ )
265+ end
266+
267+ def and_i_go_to_the_second_patient_that_needs_triage
268+ choose "Needs triage"
269+ click_on "Update results"
270+ click_link @patient_nasal_only . full_name
271+ end
272+
273+ def then_i_see_the_triage_options_for_nasal_only_consent
274+ expect ( page ) . to have_selector :heading ,
275+ "Is it safe to vaccinate #{ @patient_nasal_only . given_name } ?"
276+ expect ( page ) . to have_content (
277+ "The parent has consented to the nasal spray only"
278+ )
279+ expect ( page ) . to have_field (
280+ "Yes, it’s safe to vaccinate with nasal spray" ,
281+ type : "radio"
282+ )
283+ end
284+
285+ def when_i_go_to_the_second_patient
286+ click_link "Triage"
287+ click_link @patient_nasal_only . full_name , match : :first
288+ end
289+
290+ def and_the_vaccine_method_is_recorded_as_nasal
291+ triage = @patient_nasal_only . triages . last
292+ expect ( triage . vaccine_method ) . to eq ( "nasal" )
293+ end
146294end
0 commit comments