Class: VAProfile::Prefill::MilitaryInformation
- Inherits:
-
Object
- Object
- VAProfile::Prefill::MilitaryInformation
- Defined in:
- lib/va_profile/prefill/military_information.rb
Direct Known Subclasses
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
-
#military_personnel_service ⇒ Object
readonly
Returns the value of attribute military_personnel_service.
Instance Method Summary collapse
-
#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 private
- #deployments ⇒ Object
- #discharge_type ⇒ Object
-
#guard_reserve_service_by_date ⇒ Array<Hash] array of veteran's Guard and reserve service periods by period of service end date, DESC
private
Array<Hash] array of veteran’s Guard and reserve service periods by period of service end date, DESC.
-
#guard_reserve_service_history ⇒ Array<Hash>
Veteran’s guard and reserve service episode date ranges sorted by end_date.
- #hca_last_service_branch ⇒ Object
-
#initialize(user) ⇒ MilitaryInformation
constructor
A new instance of MilitaryInformation.
- #last_discharge_date ⇒ Object
- #last_entry_date ⇒ Object
-
#last_service_branch ⇒ String
Last service branch the veteran served under in readable format.
-
#latest_guard_reserve_service_period ⇒ Hash
Date range of the most recently completed service in the guard or reserve service.
- #latest_service_episode ⇒ Object private
- #military_service_episodes ⇒ Object
-
#military_service_episodes_by_date ⇒ Object
private
episodes is an array of Military Services Episodes and Service Academy Episodes.
- #national_guard?(code) ⇒ Boolean private
- #post_nov111998_combat ⇒ Object
- #reserve?(code) ⇒ Boolean private
-
#service_branch_used_in_disability(military_service_episode) ⇒ String
private
Convert period of service type code from a military service episode into a formatted readable string.
-
#service_branches ⇒ Array<String>
Veteran’s unique service branch codes.
- #service_episodes_by_date ⇒ Object
- #service_history ⇒ Object private
-
#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 ⇒ Object
-
#tours_of_duty ⇒ Array<Hash>
Data about the veteran’s tours of duty including service branch served under and date range of each tour.
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_service ⇒ Object (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_duty ⇒ Boolean
Returns 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_hash ⇒ Hash
Returns 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 |
#deployed_to?(countries, date_range) ⇒ Boolean (private)
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/va_profile/prefill/military_information.rb', line 252 def deployed_to?(countries, date_range) deployments.each do |deployment| next if deployment['deployment_locations'].nil? # Skip if deployment_locations is nil deployment['deployment_locations'].each do |location| location_date_range = location['deployment_location_begin_date']..location['deployment_location_end_date'] if countries.include?(location['deployment_country_code']) && date_range.overlaps?(location_date_range) return true end end end false end |
#deployments ⇒ Object
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_type ⇒ Object
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_by_date ⇒ Array<Hash] array of veteran's Guard and reserve service periods by period of service end date, DESC (private)
Returns Array<Hash] array of veteran’s Guard and reserve service periods by period of service end date, DESC.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/va_profile/prefill/military_information.rb', line 269 def guard_reserve_service_by_date all_episodes = military_service_episodes_by_date.select do |episode| code = episode.personnel_category_type_code national_guard?(code) || reserve?(code) end all_episodes.sort_by do |episode| if episode.end_date.blank? # Handles nil and empty string Time.zone.today + 3650 else Date.parse(episode.end_date) end end.reverse end |
#guard_reserve_service_history ⇒ Array<Hash>
Returns 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_branch ⇒ Object
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_date ⇒ Object
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_date ⇒ Object
169 170 171 |
# File 'lib/va_profile/prefill/military_information.rb', line 169 def last_entry_date latest_service_episode&.begin_date end |
#last_service_branch ⇒ String
Returns 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_period ⇒ Hash
Returns 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 |
#latest_service_episode ⇒ Object (private)
284 285 286 |
# File 'lib/va_profile/prefill/military_information.rb', line 284 def latest_service_episode service_episodes_by_date.try(:[], 0) end |
#military_service_episodes ⇒ Object
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 |
#military_service_episodes_by_date ⇒ Object (private)
episodes is an array of Military Services Episodes and Service Academy Episodes. We’re only
interested in Military Service Episodes, so we filter out the Service Academy Episodes by checking
if the episode has a period_of_service_end_date.
291 292 293 294 295 |
# File 'lib/va_profile/prefill/military_information.rb', line 291 def military_service_episodes_by_date service_episodes_by_date.select do |episode| episode.service_type == 'Military Service' end end |
#national_guard?(code) ⇒ Boolean (private)
297 298 299 |
# File 'lib/va_profile/prefill/military_information.rb', line 297 def national_guard?(code) code == 'N' end |
#post_nov111998_combat ⇒ Object
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 |
#reserve?(code) ⇒ Boolean (private)
301 302 303 |
# File 'lib/va_profile/prefill/military_information.rb', line 301 def reserve?(code) %w[V Q].include?(code) end |
#service_branch_used_in_disability(military_service_episode) ⇒ String (private)
Convert period of service type code from a military service episode
into a formatted readable string.
EVSS requires the reserve/national guard category to be a part
of the period of service type field.
312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/va_profile/prefill/military_information.rb', line 312 def service_branch_used_in_disability(military_service_episode) category = case military_service_episode.personnel_category_type_code 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 COMBINED_SERVICE_BRANCHES.include? service_name end |
#service_branches ⇒ Array<String>
Returns 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_date ⇒ Object
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_history ⇒ Object (private)
327 328 329 |
# File 'lib/va_profile/prefill/military_information.rb', line 327 def service_history @service_history ||= @military_personnel_service.get_service_history 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.
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_combat ⇒ Object
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_duty ⇒ Array<Hash>
Returns 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 |