Class: EMISRedis::MilitaryInformation
- Inherits:
-
Model
- Object
- Common::RedisStore
- Model
- EMISRedis::MilitaryInformation
- 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
Instance Method Summary collapse
-
#compensable_va_service_connected ⇒ Boolean
True if veteran is paid for a disability with a low disability percentage.
-
#currently_active_duty ⇒ Boolean
True if the user is currently serving in active duty.
-
#currently_active_duty_hash ⇒ Hash
Currently active duty data in hash format.
-
#deployed_to?(countries, date_range) ⇒ Boolean
True if veteran was deployed to any of of the countries within the specified date range.
-
#deployments ⇒ EMIS::Models::Deployment
Cached array of the Veteran’s deployments.
-
#disabilities ⇒ Array<EMIS::Models::Disability>
Cached array of the Veteran’s disability data.
-
#discharge_type ⇒ String
Discharge type from last service episode in readable format.
-
#guard_reserve_service_by_date ⇒ Array<EMIS::Models::GuardReserveServicePeriod>
Cached array of veteran’s Guard and reserve service periods sorted by end date.
-
#guard_reserve_service_history ⇒ Array<Hash>
Veteran’s guard and reserve service episode date ranges sorted by end_date.
-
#guard_reserve_service_periods ⇒ Array<EMIS::Models::GuardReserveServicePeriod>
Cached array of veteran’s Guard and reserve service periods.
-
#hca_last_service_branch ⇒ String
Last service branch the veteran served under in HCA schema format.
-
#is_va_service_connected ⇒ Boolean
True if veteran is paid for a disability with a high disability percentage.
-
#last_discharge_date ⇒ String
Date string of the last service episode’s end date.
-
#last_entry_date ⇒ String
Date string of the last service episode’s start date.
-
#last_service_branch ⇒ String
Last service branch the veteran served under in readable format.
-
#latest_guard_reserve_service_period ⇒ Hash
periods sorted by end date.
-
#latest_service_episode ⇒ EMIS::Models::MilitaryServiceEpisode
Most recent military service episode.
-
#military_service_episodes ⇒ Array<EMIS::Models::MilitaryServiceEpisode>
Cached array of veteran’s military service episodes.
-
#post_nov111998_combat ⇒ Boolean
True if veteran served a tour of duty after November 1998.
-
#service_branch_used_in_disability(military_service_episode) ⇒ String
Convert service branch code from a military service episode into a formatted readable string.
-
#service_branches ⇒ Array<String>
Veteran’s unique service branch codes.
-
#service_episodes_by_begin_date ⇒ Array<EMIS::Models::MilitaryServiceEpisode>
Cached array of veteran’s military service episodes sorted by begin_date.
-
#service_episodes_by_date ⇒ Array<EMIS::Models::MilitaryServiceEpisode>
Cached array of veteran’s military service episodes sorted by end_date.
-
#service_history ⇒ 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.
-
#service_periods ⇒ 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.
-
#sw_asia_combat ⇒ Boolean
True if the veteran served in southwest Asia during the Gulf war.
-
#tours_of_duty ⇒ Array<Hash>
Data about the veteran’s tours of duty including service branch served under and date range of each tour.
-
#va_compensation_type ⇒ String
If veteran is paid for a disability this method will return which type of disability it is (highDisability or lowDisability).
-
#vietnam_service ⇒ Boolean
True if veteran served in the Vietnam War.
Methods inherited from Model
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_connected ⇒ Boolean
Returns 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_duty ⇒ Boolean
Returns 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_hash ⇒ Hash
Returns 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.
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 |
#deployments ⇒ EMIS::Models::Deployment
Returns Cached array of the Veteran’s deployments.
289 290 291 |
# File 'app/models/emis_redis/military_information.rb', line 289 def deployments @deployments ||= items_from_response('get_deployment') end |
#disabilities ⇒ Array<EMIS::Models::Disability>
Returns Cached array of the Veteran’s disability data.
340 341 342 |
# File 'app/models/emis_redis/military_information.rb', line 340 def disabilities @disabilities ||= items_from_response('get_disabilities') end |
#discharge_type ⇒ String
Returns 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_date ⇒ Array<EMIS::Models::GuardReserveServicePeriod>
Returns Cached array of veteran’s Guard and reserve service periods sorted by end date.
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_history ⇒ Array<Hash>
Returns 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_periods ⇒ Array<EMIS::Models::GuardReserveServicePeriod>
Returns Cached array of veteran’s Guard and reserve service periods.
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_branch ⇒ String
Returns 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_connected ⇒ Boolean
Returns 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_date ⇒ String
Returns 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_date ⇒ String
Returns Date string of the last service episode’s start date.
271 272 273 |
# File 'app/models/emis_redis/military_information.rb', line 271 def last_entry_date latest_service_episode&.begin_date&.to_s end |
#last_service_branch ⇒ String
Returns 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_period ⇒ Hash
periods sorted by end date
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_episode ⇒ EMIS::Models::MilitaryServiceEpisode
Returns Most recent military service episode.
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_episodes ⇒ Array<EMIS::Models::MilitaryServiceEpisode>
Returns Cached array of veteran’s military service episodes.
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_combat ⇒ Boolean
Returns 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.
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_branches ⇒ Array<String>
Returns 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_date ⇒ Array<EMIS::Models::MilitaryServiceEpisode>
Returns Cached array of veteran’s military service episodes sorted by begin_date.
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_date ⇒ Array<EMIS::Models::MilitaryServiceEpisode>
Returns Cached array of veteran’s military service episodes sorted by end_date.
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_history ⇒ Array<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.
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_periods ⇒ Array<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.
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_combat ⇒ Boolean
Returns 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_duty ⇒ Array<Hash>
Returns 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_type ⇒ String
Returns 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_service ⇒ Boolean
Returns 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 |