Class: FormProfiles::VA10203

Inherits:
FormProfile
  • Object
show all
Defined in:
app/models/form_profiles/va_10203.rb

Instance Method Summary collapse

Instance Method Details

#get_gi_bill_statusObject (private)



54
55
56
57
58
59
60
# File 'app/models/form_profiles/va_10203.rb', line 54

def get_gi_bill_status
  service = BenefitsEducation::Service.new(user.icn)
  service.get_gi_bill_status
rescue => e
  Rails.logger.error "Failed to retrieve GiBillStatus data: #{e.message}"
  {}
end

#initialize_entitlement_information(gi_bill_status) ⇒ Object (private)



62
63
64
65
66
67
68
69
# File 'app/models/form_profiles/va_10203.rb', line 62

def initialize_entitlement_information(gi_bill_status)
  return {} if gi_bill_status == {} || gi_bill_status.remaining_entitlement.blank?

  VA10203::FormEntitlementInformation.new(
    months: gi_bill_status.remaining_entitlement.months,
    days: gi_bill_status.remaining_entitlement.days
  )
end

#initialize_school_information(gi_bill_status) ⇒ Object (private)



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/models/form_profiles/va_10203.rb', line 71

def initialize_school_information(gi_bill_status)
  return {} if gi_bill_status == {}

  most_recent = gi_bill_status.enrollments.max_by(&:begin_date)

  return {} if most_recent.blank?

  service = GIDSRedis.new
  profile_response = service.get_institution_details_v0({ id: most_recent.facility_code })

  VA10203::FormInstitutionInfo.new(
    name: profile_response[:data][:attributes][:name],
    city: profile_response[:data][:attributes][:city],
    state: profile_response[:data][:attributes][:state],
    country: profile_response[:data][:attributes][:country]
  )
rescue => e
  Rails.logger.error "Failed to retrieve GIDS data: #{e.message}"
  {}
end

#metadataObject



44
45
46
47
48
49
50
# File 'app/models/form_profiles/va_10203.rb', line 44

def 
  {
    version: 0,
    prefill: true,
    returnUrl: '/applicant/information'
  }
end

#prefillObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/form_profiles/va_10203.rb', line 29

def prefill
  authorized = user.authorize :evss, :access?

  if authorized
    gi_bill_status = get_gi_bill_status
    @remaining_entitlement = initialize_entitlement_information(gi_bill_status)
    @school_information = initialize_school_information(gi_bill_status)
  else
    @remaining_entitlement = {}
    @school_information = {}
  end

  super
end