Module: PdfFill::Forms::CommonPtsd

Includes:
FormHelper
Included in:
Va210781, Va210781a
Defined in:
lib/pdf_fill/forms/common_ptsd.rb

Instance Method Summary collapse

Methods included from FormHelper

#address_block, #combine_date_ranges, #expand_checkbox_as_hash, #extract_country, #extract_middle_i, #format_boolean, #select_checkbox, #select_radio_button, #split_date, #split_postal_code, #split_ssn, #validate_date

Instance Method Details

#combine_date_range(date_range) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/pdf_fill/forms/common_ptsd.rb', line 99

def combine_date_range(date_range)
  return if date_range.nil?

  from = "from: #{date_range['from']}" if date_range['from'].present?
  to = "to: #{date_range['to']}" if date_range['to'].present?
  "#{from} #{to}".strip
end

#expand_incident_date(incident) ⇒ Object



27
28
29
30
31
32
# File 'lib/pdf_fill/forms/common_ptsd.rb', line 27

def expand_incident_date(incident)
  incident_date = incident['incidentDate']
  return if incident_date.blank?

  split_approximate_date(incident_date)
end

#expand_incident_location(incident) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pdf_fill/forms/common_ptsd.rb', line 34

def expand_incident_location(incident)
  incident_location = incident['incidentLocation']
  return if incident_location.blank?

  split_incident_location = {}
  s_location = incident_location.scan(/(.{1,30})(\s+|$)/)

  s_location.each_with_index do |row, index|
    split_incident_location["row#{index}"] = row[0]
  end

  split_incident_location
end

#expand_incident_unit_assignment(incident) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pdf_fill/forms/common_ptsd.rb', line 85

def expand_incident_unit_assignment(incident)
  incident_unit_assignment = incident['unitAssigned']
  return if incident_unit_assignment.blank?

  split_incident_unit_assignment = {}
  s_incident_unit_assignment = incident_unit_assignment.scan(/(.{1,30})(\s+|$)/)

  s_incident_unit_assignment.each_with_index do |row, index|
    split_incident_unit_assignment["row#{index}"] = row[0]
  end

  split_incident_unit_assignment
end

#expand_ssn(hash) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/pdf_fill/forms/common_ptsd.rb', line 10

def expand_ssn(hash)
  ssn = hash['veteranSocialSecurityNumber']
  return hash if ssn.blank?

  ['', '1', '2'].each do |suffix|
    hash["veteranSocialSecurityNumber#{suffix}"] = split_ssn(ssn)
  end
  hash
end

#expand_unit_assigned_dates(incident) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pdf_fill/forms/common_ptsd.rb', line 48

def expand_unit_assigned_dates(incident)
  incident_unit_assigned_dates = incident['unitAssignedDates']
  return if incident_unit_assigned_dates.blank?

  from_dates = split_approximate_date(incident_unit_assigned_dates['from'])
  to_dates = split_approximate_date(incident_unit_assigned_dates['to'])
  unit_assignment_dates = {
    'fromMonth' => from_dates['month'],
    'fromDay' => from_dates['day'],
    'fromYear' => from_dates['year'],
    'toMonth' => to_dates['month'],
    'toDay' => to_dates['day'],
    'toYear' => to_dates['year']
  }

  incident_unit_assigned_dates.except!('to')
  incident_unit_assigned_dates.except!('from')
  incident_unit_assigned_dates.merge!(unit_assignment_dates)
end

#expand_veteran_dob(hash) ⇒ Object



20
21
22
23
24
25
# File 'lib/pdf_fill/forms/common_ptsd.rb', line 20

def expand_veteran_dob(hash)
  veteran_date_of_birth = hash['veteranDateOfBirth']
  return if veteran_date_of_birth.blank?

  split_date(veteran_date_of_birth)
end

#format_incident(incident, index) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/pdf_fill/forms/common_ptsd.rb', line 112

def format_incident(incident, index)
  return if incident.blank?

  incident_overflow = ["Incident Number: #{index}"]

  incident_date = incident['incidentDate'] || ''
  incident_overflow.push("Incident Date: #{incident_date}")

  incident_overflow.push("Dates of Unit Assignment: #{get_unit_date_overflow(incident['unitAssignedDates'])}")

  incident_location = incident['incidentLocation'] || ''
  incident_overflow.push("Incident Location: \n\n#{incident_location}")

  incident_unit_assigned = incident['unitAssigned'] || ''
  incident_overflow.push("Unit Assignment During Incident: \n\n#{incident_unit_assigned}")

  incident_description = incident['incidentDescription'] || ''
  incident_overflow.push("Description of Incident: \n\n#{incident_description}")

  incident_overflow
end

#get_unit_date_overflow(unit_assigned_dates) ⇒ Object



107
108
109
110
# File 'lib/pdf_fill/forms/common_ptsd.rb', line 107

def get_unit_date_overflow(unit_assigned_dates)
  unit_assigned_dates_overflow = combine_date_range(unit_assigned_dates)
  unit_assigned_dates_overflow || ''
end

#split_approximate_date(date) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/pdf_fill/forms/common_ptsd.rb', line 68

def split_approximate_date(date)
  # from/to are optional but need to be accounted for
  date = 'XXXX-XX-XX' if date.blank?
  year, month, day = date.split('-')

  # year/month/day are optional and can be XXed out
  year = nil if year == 'XXXX'
  month = nil if month == 'XX'
  day = nil if day == 'XX'

  {
    'year' => year,
    'month' => month,
    'day' => day
  }
end