Class: VAProfile::Prefill::MilitaryInformation

Inherits:
Object
  • Object
show all
Defined in:
lib/va_profile/prefill/military_information.rb

Constant Summary collapse

PREFILL_METHODS =
%w[
  currently_active_duty
  currently_active_duty_hash
  discharge_type
  guard_reserve_service_history
  hca_last_service_branch
  last_discharge_date
  last_entry_date
  last_service_branch
  latest_guard_reserve_service_period
  post_nov111998_combat
  service_branches
  service_episodes_by_date
  service_periods
  sw_asia_combat
  tours_of_duty
].freeze
HCA_SERVICE_BRANCHES =
{
  'A' => 'army',
  'C' => 'coast guard',
  'F' => 'air force',
  'H' => 'usphs',
  'M' => 'marine corps',
  'N' => 'navy',
  'O' => 'noaa'
}.freeze
DISCHARGE_TYPES =
{
  'A' => 'honorable',
  'B' => 'general',
  'D' => 'bad-conduct',
  'F' => 'dishonorable',
  'J' => 'honorable',
  'K' => 'dishonorable'
}.freeze
SOUTHWEST_ASIA =
%w[
  AM
  AZ
  BH
  CY
  GE
  IQ
  IL
  JO
  KW
  LB
  OM
  QA
  SA
  SY
  TR
  AE
  YE
].freeze
NOV_1998 =
Date.new(1998, 11, 11)
GULF_WAR_RANGE =
(Date.new(1990, 8, 2)..NOV_1998)
COMBINED_SERVICE_BRANCHES =

In github.com/department-of-veterans-affairs/va.gov-team/issues/41046 military service branches were modified to use an updated list from Lighthouse BRD. The list below combines the branches from the former list that was in the previous vets_json_schema, and the new list, from BRD. In the future, consider udpating this constant to a dynamic value populated by a call to Lighthouse BRD.

[
  'Army Air Corps or Army Air Force',
  'Air Force Academy',
  'Air Force',
  'Air Force Reserve',
  'Air Force Reserves',
  'Air National Guard',
  'Army Reserve',
  'Army Reserves',
  'Army',
  'Army National Guard',
  'Coast Guard Academy',
  'Coast Guard',
  'Coast Guard Reserve',
  'Coast Guard Reserves',
  'Marine Corps',
  'Marine Corps Reserve',
  'Marine Corps Reserves',
  'Merchant Marine',
  'Naval Academy',
  'Navy',
  'National Oceanic & Atmospheric Administration',
  'NOAA',
  'Navy Reserve',
  'Navy Reserves',
  'Other',
  'Public Health Service',
  'Space Force',
  'US Military Academy',
  "Women's Army Corps"
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ MilitaryInformation

Returns a new instance of MilitaryInformation.



108
109
110
# File 'lib/va_profile/prefill/military_information.rb', line 108

def initialize(user)
  @military_personnel_service = VAProfile::MilitaryPersonnel::Service.new(user)
end

Instance Attribute Details

#military_personnel_serviceObject (readonly)

Returns the value of attribute military_personnel_service.



106
107
108
# File 'lib/va_profile/prefill/military_information.rb', line 106

def military_personnel_service
  @military_personnel_service
end

Instance Method Details

#currently_active_dutyBoolean

Returns true if the user is currently serving in active duty.

Returns:

  • (Boolean)

    true if the user is currently serving in active duty



114
115
116
# File 'lib/va_profile/prefill/military_information.rb', line 114

def currently_active_duty
  currently_active_duty_hash[:yes]
end

#currently_active_duty_hashHash

Returns currently active duty data in hash format.

Returns:

  • (Hash)

    currently active duty data in hash format



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/va_profile/prefill/military_information.rb', line 119

def currently_active_duty_hash
  is_active = false

  service_episodes_by_date.each do |episode|
    if episode.end_date && (episode.end_date.empty? || DateTime.parse(episode.end_date).to_date.future?)
      is_active = true
      break
    end
  end

  { yes: is_active }
end

#deploymentsObject



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/va_profile/prefill/military_information.rb', line 132

def deployments
  @deployments ||= lambda do
    return_val = []

    service_history.episodes.each do |episode|
      return_val += episode.deployments if episode.deployments.present?
    end

    return_val
  end.call
end

#discharge_typeObject



144
145
146
147
148
# File 'lib/va_profile/prefill/military_information.rb', line 144

def discharge_type
  return if latest_service_episode.blank?

  DISCHARGE_TYPES[latest_service_episode&.character_of_discharge_code]
end

#guard_reserve_service_historyArray<Hash>

Returns Veteran’s guard and reserve service episode date ranges sorted by end_date.

Returns:

  • (Array<Hash>)

    Veteran’s guard and reserve service episode date ranges sorted by end_date



152
153
154
155
156
157
158
159
# File 'lib/va_profile/prefill/military_information.rb', line 152

def guard_reserve_service_history
  guard_reserve_service_by_date.map do |period|
    {
      from: period.begin_date,
      to: period.end_date
    }
  end
end

#hca_last_service_branchObject



161
162
163
# File 'lib/va_profile/prefill/military_information.rb', line 161

def hca_last_service_branch
  HCA_SERVICE_BRANCHES[latest_service_episode&.branch_of_service_code] || 'other'
end

#last_discharge_dateObject



165
166
167
# File 'lib/va_profile/prefill/military_information.rb', line 165

def last_discharge_date
  latest_service_episode&.end_date
end

#last_entry_dateObject



169
170
171
# File 'lib/va_profile/prefill/military_information.rb', line 169

def 
  latest_service_episode&.begin_date
end

#last_service_branchString

Returns Last service branch the veteran served under in readable format.

Returns:

  • (String)

    Last service branch the veteran served under in readable format



175
176
177
# File 'lib/va_profile/prefill/military_information.rb', line 175

def last_service_branch
  latest_service_episode&.branch_of_service
end

#latest_guard_reserve_service_periodHash

Returns Date range of the most recently completed service in the guard or reserve service.

Returns:

  • (Hash)

    Date range of the most recently completed service in the guard or reserve service.



181
182
183
# File 'lib/va_profile/prefill/military_information.rb', line 181

def latest_guard_reserve_service_period
  guard_reserve_service_history.try(:[], 0)
end

#military_service_episodesObject



185
186
187
188
189
# File 'lib/va_profile/prefill/military_information.rb', line 185

def military_service_episodes
  service_history.episodes.find_all do |episode|
    episode.service_type == 'Military Service'
  end
end

#post_nov111998_combatObject



191
192
193
194
195
196
197
# File 'lib/va_profile/prefill/military_information.rb', line 191

def post_nov111998_combat
  deployments.each do |deployment|
    return true if deployment['deployment_end_date'] && (Date.parse(deployment['deployment_end_date']) > NOV_1998)
  end

  false
end

#service_branchesArray<String>

Returns Veteran’s unique service branch codes.

Returns:

  • (Array<String>)

    Veteran’s unique service branch codes



200
201
202
# File 'lib/va_profile/prefill/military_information.rb', line 200

def service_branches
  military_service_episodes.map(&:branch_of_service_code).uniq
end

#service_episodes_by_dateObject



204
205
206
207
208
209
210
211
212
# File 'lib/va_profile/prefill/military_information.rb', line 204

def service_episodes_by_date
  @service_episodes_by_date ||= military_service_episodes.sort_by do |ep|
    if ep.end_date.blank?
      Time.zone.today + 3650
    else
      Date.parse(ep.end_date)
    end
  end.reverse
end

#service_periodsArray<Hash>

Returns Data about the veteran’s service periods including service branch served under and date range of each service period; used only for Form 526 - Disability form.

Returns:

  • (Array<Hash>)

    Data about the veteran’s service periods including service branch served under and date range of each service period; used only for Form 526 - Disability form



217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/va_profile/prefill/military_information.rb', line 217

def service_periods
  valid_episodes = military_service_episodes_by_date.select do |military_service_episode|
    service_branch_used_in_disability(military_service_episode)
  end
  valid_episodes.map do |valid_episode|
    {
      service_branch: service_branch_used_in_disability(valid_episode),
      date_range: {
        from: valid_episode.begin_date,
        to: valid_episode.end_date
      }
    }
  end
end

#sw_asia_combatObject



232
233
234
# File 'lib/va_profile/prefill/military_information.rb', line 232

def sw_asia_combat
  deployed_to?(SOUTHWEST_ASIA, GULF_WAR_RANGE)
end

#tours_of_dutyArray<Hash>

Returns Data about the veteran’s tours of duty including service branch served under and date range of each tour.

Returns:

  • (Array<Hash>)

    Data about the veteran’s tours of duty including service branch served under and date range of each tour



238
239
240
241
242
243
244
245
246
247
248
# File 'lib/va_profile/prefill/military_information.rb', line 238

def tours_of_duty
  military_service_episodes.map do |military_service_episode|
    {
      service_branch: military_service_episode.branch_of_service,
      date_range: {
        from: military_service_episode.begin_date.to_s,
        to: military_service_episode.end_date.to_s
      }
    }
  end
end