Class: BGS::Children
- Inherits:
-
Object
- Object
- BGS::Children
- Defined in:
- lib/bgs/children.rb
Instance Method Summary collapse
- #bgs_service ⇒ Object private
- #child_event_type(event_type) ⇒ Object private
- #create_all ⇒ Object
- #format_date(date) ⇒ Object private
-
#initialize(proc_id:, payload:, user:) ⇒ Children
constructor
A new instance of Children.
- #person_params(calling_object, participant, dependent_info) ⇒ Object private
- #report_child_event(event_type) ⇒ Object private
- #report_children ⇒ Object private
- #report_stepchildren ⇒ Object private
- #send_address(calling_object, participant, address_info) ⇒ Object private
- #step_child_guardian_person(guardian_participant, stepchild_info) ⇒ Object private
- #step_child_parent(child_info) ⇒ Object private
Constructor Details
#initialize(proc_id:, payload:, user:) ⇒ Children
Returns a new instance of Children.
7 8 9 10 11 12 13 14 |
# File 'lib/bgs/children.rb', line 7 def initialize(proc_id:, payload:, user:) @user = user @children = [] @step_children = [] @proc_id = proc_id @views = payload['view:selectable686_options'] @dependents_application = payload['dependents_application'] end |
Instance Method Details
#bgs_service ⇒ Object (private)
160 161 162 |
# File 'lib/bgs/children.rb', line 160 def bgs_service @bgs_service ||= BGS::Service.new(@user) end |
#child_event_type(event_type) ⇒ Object (private)
121 122 123 124 125 126 127 |
# File 'lib/bgs/children.rb', line 121 def child_event_type(event_type) if event_type == 'child_marriage' return BGSDependents::ChildMarriage.new(@dependents_application['child_marriage']) end BGSDependents::ChildStoppedAttendingSchool.new(@dependents_application['child_stopped_attending_school']) end |
#create_all ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bgs/children.rb', line 16 def create_all report_children if @views['add_child'] report_stepchildren if @views['report_stepchild_not_in_household'] report_child_event('child_marriage') if @views['report_marriage_of_child_under18'] report_child_event('not_attending_school') if @views['report_child18_or_older_is_not_attending_school'] { dependents: @children, step_children: @step_children } end |
#format_date(date) ⇒ Object (private)
154 155 156 157 158 |
# File 'lib/bgs/children.rb', line 154 def format_date(date) return nil if date.nil? DateTime.parse("#{date} 12:00:00").to_time.iso8601 end |
#person_params(calling_object, participant, dependent_info) ⇒ Object (private)
110 111 112 |
# File 'lib/bgs/children.rb', line 110 def person_params(calling_object, participant, dependent_info) calling_object.create_person_params(@proc_id, participant[:vnp_ptcpnt_id], dependent_info) end |
#report_child_event(event_type) ⇒ Object (private)
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/bgs/children.rb', line 90 def report_child_event(event_type) child_event = child_event_type(event_type) formatted_info = child_event.format_info participant = bgs_service.create_participant(@proc_id) bgs_service.create_person(person_params(child_event, participant, formatted_info)) @children << child_event.serialize_dependent_result( participant, 'Child', 'Biological', { event_date: formatted_info['event_date'], type: event_type, child_prevly_married_ind: formatted_info['ever_married_ind'], dep_has_income_ind: formatted_info['dependent_income'] } ) end |
#report_children ⇒ Object (private)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bgs/children.rb', line 30 def report_children @dependents_application['children_to_add'].each do |child_info| child = BGSDependents::Child.new(child_info) formatted_info = child.format_info participant = bgs_service.create_participant(@proc_id) bgs_service.create_person(person_params(child, participant, formatted_info)) send_address(child, participant, child.address(@dependents_application)) step_child_parent(child_info) if child['family_relationship_type'] == 'Stepchild' @children << child.serialize_dependent_result( participant, 'Child', formatted_info['family_relationship_type'], { marriage_termination_type_code: formatted_info['reason_marriage_ended'], type: 'child', child_prevly_married_ind: formatted_info['ever_married_ind'], dep_has_income_ind: formatted_info['child_income'] } ) end end |
#report_stepchildren ⇒ Object (private)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bgs/children.rb', line 55 def report_stepchildren @dependents_application['step_children'].each do |stepchild_info| step_child = BGSDependents::StepChild.new(stepchild_info) formatted_info = step_child.format_info participant = bgs_service.create_participant(@proc_id) guardian_participant = bgs_service.create_participant(@proc_id) step_child_guardian_person(guardian_participant, stepchild_info) bgs_service.create_person(person_params(step_child, participant, formatted_info)) send_address(step_child, participant, stepchild_info['address']) @step_children << step_child.serialize_dependent_result( participant, 'Guardian', 'Other', { living_expenses_paid: formatted_info['living_expenses_paid'], guardian_particpant_id: guardian_participant[:vnp_ptcpnt_id], type: 'stepchild' } ) end end |
#send_address(calling_object, participant, address_info) ⇒ Object (private)
114 115 116 117 118 119 |
# File 'lib/bgs/children.rb', line 114 def send_address(calling_object, participant, address_info) address = calling_object.generate_address(address_info) address_params = calling_object.create_address_params(@proc_id, participant[:vnp_ptcpnt_id], address) bgs_service.create_address(address_params) end |
#step_child_guardian_person(guardian_participant, stepchild_info) ⇒ Object (private)
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/bgs/children.rb', line 79 def step_child_guardian_person(guardian_participant, stepchild_info) bgs_service.create_person( { vnp_proc_id: @proc_id, vnp_ptcpnt_id: guardian_participant[:vnp_ptcpnt_id], first_nm: stepchild_info['who_does_the_stepchild_live_with']['first'], last_nm: stepchild_info['who_does_the_stepchild_live_with']['last'] } ) end |
#step_child_parent(child_info) ⇒ Object (private)
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/bgs/children.rb', line 129 def step_child_parent(child_info) parent = bgs_service.create_participant(@proc_id) bgs_service.create_person( { vnp_proc_id: @proc_id, vnp_ptcpnt_id: parent[:vnp_ptcpnt_id], first_nm: child_info['child_status']['stepchild_parent']['first'], last_nm: child_info['child_status']['stepchild_parent']['last'], brthdy_dt: format_date(child_info['child_status']['birth_date']), ssn_nbr: child_info['child_status']['ssn'] } ) @step_children << { vnp_participant_id: parent[:vnp_ptcpnt_id], participant_relationship_type_name: 'Spouse', family_relationship_type_name: 'Spouse', event_date: child_info['child_status']['date_became_dependent'], begin_date: child_info['child_status']['date_became_dependent'], type: 'stepchild_parent' } end |