Class: VAProfile::Models::ServiceHistory

Inherits:
Base
  • Object
show all
Includes:
Concerns::Defaultable
Defined in:
lib/va_profile/models/service_history.rb

Constant Summary collapse

MILITARY_SERVICE =
'Military Service'
MILITARY_SERVICE_EPISODE =
'military_service_episodes'
ACADEMY_ATTENDANCE =
'Academy Attendance'
ACADEMY_ATTENDANCE_EPISODE =
'service_academy_episodes'

Constants inherited from Base

Base::SOURCE_SYSTEM

Class Method Summary collapse

Methods included from Concerns::Defaultable

#set_defaults

Class Method Details

.build_from(episode, episode_type) ⇒ VAProfile::Models::ServiceHistory

Converts a decoded JSON response from VAProfile to an instance of the ServiceHistory model

Parameters:

  • episodes (Hash)

    the decoded response episodes from VAProfile

Returns:



47
48
49
50
51
52
53
# File 'lib/va_profile/models/service_history.rb', line 47

def self.build_from(episode, episode_type)
  return nil unless episode

  return build_from_military_episode(episode) if episode_type == MILITARY_SERVICE_EPISODE

  build_from_academy_episode(episode) if episode_type == ACADEMY_ATTENDANCE_EPISODE
end

.build_from_academy_episode(episode) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/va_profile/models/service_history.rb', line 70

def self.build_from_academy_episode(episode)
  VAProfile::Models::ServiceHistory.new(
    service_type: ACADEMY_ATTENDANCE,
    branch_of_service: episode['branch_of_service_text'],
    begin_date: episode['academy_begin_date'],
    end_date: episode['academy_end_date']
  )
end

.build_from_military_episode(episode) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/va_profile/models/service_history.rb', line 55

def self.build_from_military_episode(episode)
  VAProfile::Models::ServiceHistory.new(
    service_type: MILITARY_SERVICE,
    branch_of_service: episode['branch_of_service_text'],
    branch_of_service_code: episode['branch_of_service_code'],
    begin_date: episode['period_of_service_begin_date'],
    deployments: episode['deployments'],
    character_of_discharge_code: episode['character_of_discharge_code'],
    end_date: episode['period_of_service_end_date'],
    personnel_category_type_code: episode['period_of_service_type_code'],
    termination_reason_code: episode['termination_reason_code'],
    termination_reason_text: episode['termination_reason_text']
  )
end

.in_jsonString

Converts an instance of the ServicyHistory model to a JSON encoded string suitable for use in the body of a request to VAProfile

Returns:

  • (String)

    JSON-encoded string suitable for requests to VAProfile



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/va_profile/models/service_history.rb', line 31

def self.in_json
  {
    bios: [
      {
        bioPath: 'militaryPerson.militaryServiceHistory',
        parameters: {
          scope: 'all'
        }
      }
    ]
  }.to_json
end