Class: BGS::VnpRelationships

Inherits:
Object
  • Object
show all
Defined in:
lib/bgs/vnp_relationships.rb

Instance Method Summary collapse

Constructor Details

#initialize(proc_id:, veteran:, step_children:, dependents:, user:) ⇒ VnpRelationships

Returns a new instance of VnpRelationships.



7
8
9
10
11
12
13
# File 'lib/bgs/vnp_relationships.rb', line 7

def initialize(proc_id:, veteran:, step_children:, dependents:, user:)
  @user = user
  @veteran = veteran
  @proc_id = proc_id
  @step_children = step_children
  @dependents = dependents
end

Instance Method Details

#bgs_serviceObject (private)



63
64
65
# File 'lib/bgs/vnp_relationships.rb', line 63

def bgs_service
  BGS::Service.new(@user)
end

#create_allObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bgs/vnp_relationships.rb', line 15

def create_all
  spouse_marriages, vet_dependents = @dependents.partition do |dependent|
    dependent[:type] == 'spouse_marriage_history'
  end

  spouse = @dependents.find { |dependent| dependent[:type] == 'spouse' }

  send_step_children_relationships if @step_children.present?
  send_spouse_marriage_history_relationships(spouse, spouse_marriages)
  send_vet_dependent_relationships(vet_dependents)
end

#send_spouse_marriage_history_relationships(spouse, spouse_marriages) ⇒ Object (private)



55
56
57
58
59
60
61
# File 'lib/bgs/vnp_relationships.rb', line 55

def send_spouse_marriage_history_relationships(spouse, spouse_marriages)
  spouse_marriages.each do |dependent|
    bgs_service.create_relationship(
      vnp_relationship.params_for_686c(spouse[:vnp_participant_id], dependent)
    )
  end
end

#send_step_children_relationshipsObject (private)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bgs/vnp_relationships.rb', line 29

def send_step_children_relationships
  step_children, step_children_parents = @step_children.partition do |dependent|
    dependent[:type] == 'stepchild'
  end

  step_children.each do |step_child|
    bgs_service.create_relationship(
      vnp_relationship.params_for_686c(step_child[:guardian_particpant_id], step_child)
    )
  end

  step_children_parents.each do |step_child_parent|
    bgs_service.create_relationship(
      vnp_relationship.params_for_686c(@veteran[:vnp_participant_id], step_child_parent)
    )
  end
end

#send_vet_dependent_relationships(vet_dependents) ⇒ Object (private)



47
48
49
50
51
52
53
# File 'lib/bgs/vnp_relationships.rb', line 47

def send_vet_dependent_relationships(vet_dependents)
  vet_dependents.each do |dependent|
    bgs_service.create_relationship(
      vnp_relationship.params_for_686c(@veteran[:vnp_participant_id], dependent)
    )
  end
end

#vnp_relationshipObject (private)



67
68
69
# File 'lib/bgs/vnp_relationships.rb', line 67

def vnp_relationship
  BGSDependents::Relationship.new(@proc_id)
end