@@ -49,53 +49,6 @@ def initialize(
4949 end
5050 end
5151
52- def to_h
53- {
54- batch_name :,
55- consent_deadline :,
56- consent_link :,
57- consented_vaccine_methods_message :,
58- day_month_year_of_vaccination :,
59- delay_vaccination_review_context :,
60- full_and_preferred_patient_name :,
61- invitation_to_clinic_generic_message :,
62- location_name :,
63- invitation_to_clinic_custom_mmr_message :,
64- mmr_or_mmrv_vaccine :,
65- mmr_second_dose_message :,
66- mmr_second_dose_required :,
67- next_or_today_session_date :,
68- next_or_today_session_dates :,
69- next_or_today_session_dates_or :,
70- next_session_date :,
71- next_session_dates :,
72- next_session_dates_or :,
73- patient_date_of_birth :,
74- reason_did_not_vaccinate :,
75- reason_for_refusal :,
76- short_patient_name :,
77- short_patient_name_apos :,
78- subsequent_session_dates_offered_message :,
79- subteam_email :,
80- subteam_name :,
81- subteam_phone :,
82- survey_deadline_date :,
83- talk_to_your_child_message :,
84- team_privacy_notice_url :,
85- team_privacy_policy_url :,
86- today_or_date_of_vaccination :,
87- vaccination :,
88- vaccination_and_dates :,
89- vaccination_and_dates_sms :,
90- vaccination_and_method :,
91- vaccine :,
92- vaccine_and_dose :,
93- vaccine_and_method :,
94- vaccine_brand :,
95- vaccine_side_effects :
96- } . compact
97- end
98-
9952 attr_reader :academic_year ,
10053 :consent ,
10154 :consent_form ,
@@ -113,14 +66,7 @@ def batch_name
11366 end
11467
11568 def consent_deadline
116- return nil if session . nil?
117-
118- next_date = session . future_dates . first
119-
120- close_consent_at =
121- next_date ? ( next_date - 1 . day ) : session . close_consent_at
122-
123- close_consent_at &.to_fs ( :short_day_of_week )
69+ session &.consent_deadline_date &.to_fs ( :short_day_of_week )
12470 end
12571
12672 def consent_link
@@ -206,7 +152,7 @@ def mmr_second_dose_message
206152 end
207153
208154 def mmr_second_dose_required?
209- mmr_programme . present? && patient_eligible_for_additional_dose ?
155+ mmr_programme . present? && patient_on_last_dose ?
210156 end
211157
212158 def mmr_second_dose_required
@@ -259,29 +205,17 @@ def next_mmr_dose_date
259205 return if patient . nil?
260206 return if mmr_programme . nil?
261207
262- programme_status = patient . programme_status ( mmr_programme , academic_year :)
263-
264- date =
265- if programme_status . cannot_vaccinate_delay_vaccination?
266- programme_status . date
267- elsif ( first_dose_date = programme_status . date )
268- ( first_dose_date + 28 . days ) . to_date
269- end
270-
271- date . to_fs ( :long )
208+ patient
209+ . programme_status ( mmr_programme , academic_year :)
210+ . next_dose_eligible_date
211+ &.to_fs ( :long )
272212 end
273213
274- def patient_eligible_for_additional_dose ?
214+ def patient_on_last_dose ?
275215 return unless patient
276216 return if mmr_programme . nil?
277217
278- next_dose =
279- patient
280- . reload
281- . programme_status ( mmr_programme , academic_year :)
282- . dose_sequence
283-
284- next_dose == mmr_programme . maximum_dose_sequence
218+ patient . reload . programme_status ( mmr_programme , academic_year :) . on_last_dose?
285219 end
286220
287221 def mmr_or_mmrv_vaccine
@@ -302,13 +236,7 @@ def delay_vaccination_review_context
302236 return if patient . nil? || session . nil?
303237
304238 latest_delayed_triage =
305- patient
306- . triages
307- . not_invalidated
308- . where ( programme_type : session . programme_types )
309- . delay_vaccination
310- . order ( created_at : :desc )
311- . first
239+ patient . latest_delayed_triage ( programme_types : session . programme_types )
312240
313241 return if latest_delayed_triage . nil?
314242
@@ -393,12 +321,7 @@ def reason_for_refusal
393321 end
394322
395323 def short_patient_name
396- [
397- consent_form &.preferred_given_name ,
398- consent_form &.given_name ,
399- patient &.preferred_given_name ,
400- patient &.given_name
401- ] . compact_blank . first
324+ ( consent_form || patient ) &.short_name
402325 end
403326
404327 def short_patient_name_apos
@@ -532,13 +455,8 @@ def vaccine_is?(method)
532455 elsif programmes . present?
533456 if patient
534457 programmes . any? do |programme |
535- # We pick the first method as it's the one most likely to be used
536- # to vaccinate the patient. For example, in the case of Flu, the
537- # parents will approve nasal (and then optionally injection).
538- patient
539- . vaccine_criteria ( programme :, academic_year :)
540- . vaccine_methods
541- . first == method
458+ patient . vaccine_criteria ( programme :, academic_year :) . primary_method ==
459+ method
542460 end
543461 else
544462 Vaccine . for_programmes ( programmes ) . exists? ( method :)
@@ -553,18 +471,7 @@ def vaccine_side_effects
553471 elsif programmes . present?
554472 if patient
555473 programmes . flat_map do |programme |
556- # We pick the first method as it's the one most likely to be used
557- # to vaccinate the patient. For example, in the case of Flu, the
558- # parents will approve nasal (and then optionally injection).
559- method =
560- patient
561- . vaccine_criteria ( programme :, academic_year :)
562- . vaccine_methods
563- . first
564- Vaccine
565- . for_programme ( programme )
566- . where ( method :)
567- . flat_map ( &:side_effects )
474+ patient . vaccine_criteria ( programme :, academic_year :) . side_effects
568475 end
569476 else
570477 Vaccine . for_programmes ( programmes ) . flat_map ( &:side_effects )
@@ -620,10 +527,10 @@ def programme_names_and_methods
620527 vaccination_record . delivery_method
621528 )
622529 elsif patient
623- patient
624- . vaccine_criteria ( programme :, academic_year : )
625- . vaccine_methods
626- . first
530+ patient . vaccine_criteria (
531+ programme :,
532+ academic_year :
533+ ) . primary_method
627534 end
628535
629536 method_prefix =
0 commit comments