Class: EMISRedis::MilitaryInformationV2
- Inherits:
-
Model
- Object
- Common::RedisStore
- Model
- EMISRedis::MilitaryInformationV2
- Defined in:
- app/models/emis_redis/military_information_v2.rb
Overview
EMIS military information redis cached model
Constant Summary collapse
- CLASS_NAME =
Class name of Service object used to fetch the data
'MilitaryInformationServiceV2'
- 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 post_nov111998_combat sw_asia_combat discharge_type service_branches service_periods ].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
- 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
-
#build_service_branch(military_service_episode) ⇒ String
Convert service branch code from a military service episode into a formatted readable string.
-
#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.
-
#discharge_type ⇒ String
Discharge type from last service episode in readable format.
- #get_guard_personnel_category_type(guard_service_period) ⇒ Object
-
#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.
-
#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_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_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.
-
#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.
-
#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
#build_service_branch(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.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/models/emis_redis/military_information_v2.rb', line 127 def build_service_branch(military_service_episode) branch = case military_service_episode.hca_branch_of_service when 'noaa' military_service_episode.hca_branch_of_service.upcase when 'usphs' 'Public Health Service' else military_service_episode.hca_branch_of_service.titleize end category = case military_service_episode.personnel_category_type_code when 'A' '' when 'N' 'National Guard' when 'V' || 'Q' 'Reserve' else '' end "#{branch} #{category}".strip end |
#currently_active_duty ⇒ Boolean
Returns true if the user is currently serving in active duty.
87 88 89 |
# File 'app/models/emis_redis/military_information_v2.rb', line 87 def currently_active_duty currently_active_duty_hash[:yes] end |
#currently_active_duty_hash ⇒ Hash
Returns currently active duty data in hash format.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/emis_redis/military_information_v2.rb', line 92 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.
225 226 227 228 229 230 231 232 233 |
# File 'app/models/emis_redis/military_information_v2.rb', line 225 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.
261 262 263 |
# File 'app/models/emis_redis/military_information_v2.rb', line 261 def deployments @deployments ||= items_from_response('get_deployment') end |
#discharge_type ⇒ String
Returns Discharge type from last service episode in readable format.
199 200 201 202 203 |
# File 'app/models/emis_redis/military_information_v2.rb', line 199 def discharge_type return if latest_service_episode.blank? DISCHARGE_TYPES[latest_service_episode&.discharge_character_of_service_code] || 'other' end |
#get_guard_personnel_category_type(guard_service_period) ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'app/models/emis_redis/military_information_v2.rb', line 151 def get_guard_personnel_category_type(guard_service_period) case guard_service_period.personnel_category_type_code when 'N' 'National Guard' when 'V' || 'Q' 'Reserve' else '' end end |
#guard_reserve_service_periods ⇒ Array<EMIS::Models::GuardReserveServicePeriod>
Returns Cached array of veteran’s Guard and reserve service periods.
303 304 305 |
# File 'app/models/emis_redis/military_information_v2.rb', line 303 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.
193 194 195 |
# File 'app/models/emis_redis/military_information_v2.rb', line 193 def hca_last_service_branch latest_service_episode&.hca_branch_of_service end |
#last_discharge_date ⇒ String
Returns Date string of the last service episode’s end date.
255 256 257 |
# File 'app/models/emis_redis/military_information_v2.rb', line 255 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.
243 244 245 |
# File 'app/models/emis_redis/military_information_v2.rb', line 243 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.
187 188 189 |
# File 'app/models/emis_redis/military_information_v2.rb', line 187 def last_service_branch latest_service_episode&.branch_of_service end |
#latest_service_episode ⇒ EMIS::Models::MilitaryServiceEpisode
Returns Most recent military service episode.
249 250 251 |
# File 'app/models/emis_redis/military_information_v2.rb', line 249 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.
267 268 269 |
# File 'app/models/emis_redis/military_information_v2.rb', line 267 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.
207 208 209 210 211 212 213 |
# File 'app/models/emis_redis/military_information_v2.rb', line 207 def post_nov111998_combat deployments.each do |deployment| return true if deployment.end_date > NOV_1998 end false end |
#service_branches ⇒ Array<String>
Returns Veteran’s unique service branch codes.
181 182 183 |
# File 'app/models/emis_redis/military_information_v2.rb', line 181 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.
281 282 283 284 285 |
# File 'app/models/emis_redis/military_information_v2.rb', line 281 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.
273 274 275 276 277 |
# File 'app/models/emis_redis/military_information_v2.rb', line 273 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.
290 291 292 293 294 295 296 297 298 299 |
# File 'app/models/emis_redis/military_information_v2.rb', line 290 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.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'app/models/emis_redis/military_information_v2.rb', line 165 def service_periods service_episodes_by_date.map do |military_service_episode| # avoid prefilling if service branch is 'other' as this breaks validation return {} if military_service_episode.hca_branch_of_service == 'other' { service_branch: build_service_branch(military_service_episode), 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.
237 238 239 |
# File 'app/models/emis_redis/military_information_v2.rb', line 237 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.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/emis_redis/military_information_v2.rb', line 108 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 |
#vietnam_service ⇒ Boolean
Returns true if veteran served in the Vietnam War.
217 218 219 |
# File 'app/models/emis_redis/military_information_v2.rb', line 217 def vietnam_service deployed_to?([VIETNAM], VIETNAM_WAR_RANGE) end |