class NotificationParentSelector
Public Class Methods
Source
# File app/lib/notification_parent_selector.rb, line 4 def initialize(vaccination_record:, consents: nil) @vaccination_record = vaccination_record @consents = if @vaccination_record.patient.send_notifications?( team: @vaccination_record.team, send_to_archived: true ) && @vaccination_record.notify_parents != false consents || @vaccination_record.patient.consents else [] end end
Public Instance Methods
Source
# File app/lib/notification_parent_selector.rb, line 41 def latest_consents @latest_consents ||= ConsentGrouper.call( consents, programme_type:, academic_year: AcademicYear.current ) end
Source
# File app/lib/notification_parent_selector.rb, line 33 def parents = parents_with_consent.map(&:first) private attr_reader :vaccination_record, :consents delegate :patient, :programme_type, :academic_year, to: :vaccination_record def latest_consents @latest_consents ||= ConsentGrouper.call( consents, programme_type:, academic_year: AcademicYear.current ) end end
Source
# File app/lib/notification_parent_selector.rb, line 17 def parents_with_consent if (self_consent = latest_consents.find(&:via_self_consent?)) patient .parents .select(&:contactable?) .map { |parent| [parent, self_consent] } else latest_consents .select(&:response_given?) .filter_map do |consent| parent = consent.parent [parent, consent] if parent&.contactable? end end end