Class: EMISRedis::MilitaryInformation

Inherits:
Model show all
Defined in:
app/models/emis_redis/military_information.rb

Overview

EMIS military information redis cached model

Constant Summary collapse

CLASS_NAME =

Class name of Service object used to fetch the data

'MilitaryInformationService'
DISCHARGE_TYPES =

Mapping of discharge type codes to discharge types

{
  'A' => 'honorable',
  'B' => 'general',
  'D' => 'bad-conduct',
  'F' => 'dishonorable',
  'J' => 'honorable',
  'K' => 'dishonorable'
}.freeze
EXTERNAL_DISCHARGE_TYPES =

Mapping of discharge type codes to discharge types used in veteran verification API

{
  'A' => 'honorable',
  'B' => 'general',
  'D' => 'bad-conduct',
  'E' => 'other-than-honorable',
  'F' => 'dishonorable',
  'H' => 'honorable-absence-of-negative-report',
  'J' => 'honorable-for-va-purposes',
  'K' => 'dishonorable-for-va-purposes',
  'Y' => 'uncharacterized',
  'Z' => 'unknown'
}.freeze
PREFILL_METHODS =

Data methods used to populate FormMilitaryInformation prefill class

%i[
  hca_last_service_branch
  last_service_branch
  currently_active_duty
  currently_active_duty_hash
  tours_of_duty
  last_entry_date
  last_discharge_date
  is_va_service_connected
  post_nov111998_combat
  sw_asia_combat
  compensable_va_service_connected
  discharge_type
  service_branches
  va_compensation_type
  service_periods
  guard_reserve_service_history
  latest_guard_reserve_service_period
].freeze
LOWER_DISABILITY_RATINGS =

Disability ratings counted as lower

[10, 20, 30, 40].freeze
HIGHER_DISABILITY_RATING =

Disability ratings counted as higher

50
NOV_1998 =
Date.new(1998, 11, 11)
GULF_WAR_RANGE =

Date range for the Gulf War

(Date.new(1990, 8, 2)..NOV_1998)
SOUTHWEST_ASIA =

ISO Country codes for southwest Asia

%w[
  ARM
  AZE
  BHR
  CYP
  GEO
  IRQ
  ISR
  JOR
  KWT
  LBN
  OMN
  QAT
  SAU
  SYR
  TUR
  ARE
  YEM
].freeze
EVSS_COMBINED_SERVICE_BRANCHES =

In github.com/department-of-veterans-affairs/va.gov-team/issues/41046 we updated the military service branches 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, we may consider udpating this constant to a dynamic value populated by a call to Lighthouse BRD, but that is not necessary now.

[
  '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
VIETNAM =

Vietnam ISO country code

'VNM'
VIETNAM_WAR_RANGE =

Date range for Vietnam War

(Date.new(1962, 1, 9)..Date.new(1975, 5, 7))

Constants inherited from Common::RedisStore

Common::RedisStore::REQ_CLASS_INSTANCE_VARS

Instance Attribute Summary

Attributes inherited from Model

#user

Instance Method Summary collapse

Methods inherited from Model

for_user

Methods included from Common::CacheAside

#cache, #cached?, #do_cached_with

Methods inherited from Common::RedisStore

create, delete, #destroy, #destroyed?, exists?, #expire, find, find_or_build, #initialize, #initialize_dup, keys, #persisted?, pop, redis_key, redis_store, redis_ttl, #save, #save!, #ttl, #update, #update!

Constructor Details

This class inherits a constructor from Common::RedisStore

Instance Method Details

#compensable_va_service_connectedBoolean

Returns true if veteran is paid for a disability with a low disability percentage.

Returns:

  • (Boolean)

    true if veteran is paid for a disability with a low disability percentage



295
296
297
298
299
300
301
302
# File 'app/models/emis_redis/military_information.rb', line 295

def compensable_va_service_connected
  disabilities.each do |disability|
    return true if disability.get_pay_amount.positive? &&
                   LOWER_DISABILITY_RATINGS.include?(disability.get_disability_percent)
  end

  false
end

#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



133
134
135
# File 'app/models/emis_redis/military_information.rb', line 133

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



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/models/emis_redis/military_information.rb', line 138

def currently_active_duty_hash
  value =
    if latest_service_episode.present?
      end_date = latest_service_episode.end_date
      end_date.nil? || end_date.future?
    else
      false
    end

  {
    yes: value
  }
end

#deployed_to?(countries, date_range) ⇒ Boolean

Returns true if veteran was deployed to any of of the countries within the specified date range.

Parameters:

  • countries (Array<String>)

    Array of ISO3 country codes

  • date_range (Range)

    Date range

Returns:

  • (Boolean)

    true if veteran was deployed to any of of the countries within the specified date range



253
254
255
256
257
258
259
260
261
# File 'app/models/emis_redis/military_information.rb', line 253

def deployed_to?(countries, date_range)
  deployments.each do |deployment|
    deployment.locations.each do |location|
      return true if countries.include?(location.iso_alpha3_country) && date_range.overlaps?(location.date_range)
    end
  end

  false
end

#deploymentsEMIS::Models::Deployment

Returns Cached array of the Veteran’s deployments.

Returns:



289
290
291
# File 'app/models/emis_redis/military_information.rb', line 289

def deployments
  @deployments ||= items_from_response('get_deployment')
end

#disabilitiesArray<EMIS::Models::Disability>

Returns Cached array of the Veteran’s disability data.

Returns:



340
341
342
# File 'app/models/emis_redis/military_information.rb', line 340

def disabilities
  @disabilities ||= items_from_response('get_disabilities')
end

#discharge_typeString

Returns Discharge type from last service episode in readable format.

Returns:

  • (String)

    Discharge type from last service episode in readable format



227
228
229
230
231
# File 'app/models/emis_redis/military_information.rb', line 227

def discharge_type
  return if latest_service_episode.blank?

  DISCHARGE_TYPES[latest_service_episode&.discharge_character_of_service_code]
end

#guard_reserve_service_by_dateArray<EMIS::Models::GuardReserveServicePeriod>

Returns Cached array of veteran’s Guard and reserve service periods sorted by end date.

Returns:



389
390
391
392
393
# File 'app/models/emis_redis/military_information.rb', line 389

def guard_reserve_service_by_date
  @guard_reserve_service_by_date ||= guard_reserve_service_periods.sort_by do |per|
    per.end_date || Time.zone.today + 3650
  end.reverse
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



397
398
399
400
401
402
403
404
# File 'app/models/emis_redis/military_information.rb', line 397

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

#guard_reserve_service_periodsArray<EMIS::Models::GuardReserveServicePeriod>

Returns Cached array of veteran’s Guard and reserve service periods.

Returns:



382
383
384
# File 'app/models/emis_redis/military_information.rb', line 382

def guard_reserve_service_periods
  @guard_reserve_service_periods ||= items_from_response('get_guard_reserve_service_periods')
end

#hca_last_service_branchString

Returns Last service branch the veteran served under in HCA schema format.

Returns:

  • (String)

    Last service branch the veteran served under in HCA schema format



221
222
223
# File 'app/models/emis_redis/military_information.rb', line 221

def hca_last_service_branch
  latest_service_episode&.hca_branch_of_service
end

#is_va_service_connectedBoolean

Returns true if veteran is paid for a disability with a high disability percentage.

Returns:

  • (Boolean)

    true if veteran is paid for a disability with a high disability percentage



309
310
311
312
313
314
315
316
317
318
# File 'app/models/emis_redis/military_information.rb', line 309

def is_va_service_connected
  disabilities.each do |disability|
    pay_amount = disability.get_pay_amount
    disability_percent = disability.get_disability_percent

    return true if pay_amount.positive? && disability_percent >= HIGHER_DISABILITY_RATING
  end

  false
end

#last_discharge_dateString

Returns Date string of the last service episode’s end date.

Returns:

  • (String)

    Date string of the last service episode’s end date



283
284
285
# File 'app/models/emis_redis/military_information.rb', line 283

def last_discharge_date
  latest_service_episode&.end_date&.to_s
end

#last_entry_dateString

Returns Date string of the last service episode’s start date.

Returns:

  • (String)

    Date string of the last service episode’s start date



271
272
273
# File 'app/models/emis_redis/military_information.rb', line 271

def 
  latest_service_episode&.begin_date&.to_s
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



215
216
217
# File 'app/models/emis_redis/military_information.rb', line 215

def last_service_branch
  latest_service_episode&.branch_of_service
end

#latest_guard_reserve_service_periodHash

periods sorted by end date

Returns:

  • (Hash)

    Cached array of veteran’s Guard and reserve service



408
409
410
# File 'app/models/emis_redis/military_information.rb', line 408

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

#latest_service_episodeEMIS::Models::MilitaryServiceEpisode

Returns Most recent military service episode.

Returns:



277
278
279
# File 'app/models/emis_redis/military_information.rb', line 277

def latest_service_episode
  service_episodes_by_date.try(:[], 0)
end

#military_service_episodesArray<EMIS::Models::MilitaryServiceEpisode>

Returns Cached array of veteran’s military service episodes.

Returns:



346
347
348
# File 'app/models/emis_redis/military_information.rb', line 346

def military_service_episodes
  @military_service_episodes ||= items_from_response('get_military_service_episodes')
end

#post_nov111998_combatBoolean

Returns true if veteran served a tour of duty after November 1998.

Returns:

  • (Boolean)

    true if veteran served a tour of duty after November 1998



235
236
237
238
239
240
241
# File 'app/models/emis_redis/military_information.rb', line 235

def post_nov111998_combat
  deployments.each do |deployment|
    return true if deployment.end_date > NOV_1998
  end

  false
end

#service_branch_used_in_disability(military_service_episode) ⇒ String

Convert service branch code from a military service episode into a formatted readable string. EVSS requires the reserve/national guard category to be a part of the service branch field.

Parameters:

Returns:

  • (String)

    Readable service branch name formatted for EVSS



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'app/models/emis_redis/military_information.rb', line 173

def service_branch_used_in_disability(military_service_episode)
  category = case military_service_episode.personnel_category_type_code
             when 'A'
               ''
             when 'N'
               'National Guard'
             when 'V' || 'Q'
               'Reserve'
             else
               ''
             end

  service_name = "#{military_service_episode.branch_of_service} #{category}".strip
  service_name.gsub!('Air Force National Guard', 'Air National Guard')
  service_name if EVSS_COMBINED_SERVICE_BRANCHES.include? service_name
end

#service_branchesArray<String>

Returns Veteran’s unique service branch codes.

Returns:

  • (Array<String>)

    Veteran’s unique service branch codes



209
210
211
# File 'app/models/emis_redis/military_information.rb', line 209

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

#service_episodes_by_begin_dateArray<EMIS::Models::MilitaryServiceEpisode>

Returns Cached array of veteran’s military service episodes sorted by begin_date.

Returns:



360
361
362
363
364
# File 'app/models/emis_redis/military_information.rb', line 360

def service_episodes_by_begin_date
  @service_episodes_by_date ||= lambda do
    military_service_episodes.sort_by { |ep| ep.begin_date || Time.zone.today + 3650 }
  end.call
end

#service_episodes_by_dateArray<EMIS::Models::MilitaryServiceEpisode>

Returns Cached array of veteran’s military service episodes sorted by end_date.

Returns:



352
353
354
355
356
# File 'app/models/emis_redis/military_information.rb', line 352

def service_episodes_by_date
  @service_episodes_by_date ||= lambda do
    military_service_episodes.sort_by { |ep| ep.end_date || Time.zone.today + 3650 }.reverse
  end.call
end

#service_historyArray<Hash>

Returns Veteran’s military service episodes sorted by date in hash format including data about branch of service, date range, and personnel category codes.

Returns:

  • (Array<Hash>)

    Veteran’s military service episodes sorted by date in hash format including data about branch of service, date range, and personnel category codes



369
370
371
372
373
374
375
376
377
378
# File 'app/models/emis_redis/military_information.rb', line 369

def service_history
  service_episodes_by_date.map do |episode|
    {
      branch_of_service: episode.branch_of_service,
      begin_date: episode.begin_date,
      end_date: episode.end_date,
      personnel_category_type_code: episode.personnel_category_type_code
    }
  end
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



193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'app/models/emis_redis/military_information.rb', line 193

def service_periods
  service_episodes_by_date.map do |military_service_episode|
    service_branch = service_branch_used_in_disability(military_service_episode)
    return {} unless service_branch

    {
      service_branch:,
      date_range: {
        from: military_service_episode.begin_date.to_s,
        to: military_service_episode.end_date.to_s
      }
    }
  end
end

#sw_asia_combatBoolean

Returns true if the veteran served in southwest Asia during the Gulf war.

Returns:

  • (Boolean)

    true if the veteran served in southwest Asia during the Gulf war



265
266
267
# File 'app/models/emis_redis/military_information.rb', line 265

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



154
155
156
157
158
159
160
161
162
163
164
# File 'app/models/emis_redis/military_information.rb', line 154

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

#va_compensation_typeString

Returns If veteran is paid for a disability this method will return which type of disability it is (highDisability or lowDisability).

Returns:

  • (String)

    If veteran is paid for a disability this method will return which type of disability it is (highDisability or lowDisability)



324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'app/models/emis_redis/military_information.rb', line 324

def va_compensation_type
  # while supporting fallback support for the old fields,
  # make a consistent number of calls to the properties to
  # support specs that will be removed or updated
  high_disability = is_va_service_connected
  low_disability = compensable_va_service_connected

  if high_disability
    'highDisability'
  elsif low_disability
    'lowDisability'
  end
end

#vietnam_serviceBoolean

Returns true if veteran served in the Vietnam War.

Returns:

  • (Boolean)

    true if veteran served in the Vietnam War



245
246
247
# File 'app/models/emis_redis/military_information.rb', line 245

def vietnam_service
  deployed_to?([VIETNAM], VIETNAM_WAR_RANGE)
end