-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathoverseas-passports.rb
216 lines (178 loc) · 5.92 KB
/
overseas-passports.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
module SmartAnswer
class OverseasPassportsFlow < Flow
def define
content_id "dd113259-fcaf-4e9b-83d5-d1148f33cf34"
name 'overseas-passports'
status :published
satisfies_need "100131"
data_query = Calculators::PassportAndEmbassyDataQuery.new
exclude_countries = %w(holy-see british-antarctic-territory)
# Q1
country_select :which_country_are_you_in?, exclude_countries: exclude_countries do
save_input_as :current_location
calculate :location do
loc = WorldLocation.find(current_location)
if Calculators::PassportAndEmbassyDataQuery::ALT_EMBASSIES.has_key?(current_location)
loc = WorldLocation.find(Calculators::PassportAndEmbassyDataQuery::ALT_EMBASSIES[current_location])
end
raise InvalidResponse unless loc
loc
end
calculate :birth_location do
nil
end
calculate :embassy_address do
nil
end
calculate :send_colour_photocopy_bulletpoint do
nil
end
next_node_calculation :ineligible_country do |response|
%w{iran libya syria yemen}.include?(response)
end
next_node_calculation :apply_in_neighbouring_countries do |response|
%w(british-indian-ocean-territory north-korea south-georgia-and-south-sandwich-islands).include?(response)
end
next_node(permitted: :auto) do |response|
if ineligible_country
outcome :cannot_apply
elsif response == 'the-occupied-palestinian-territories'
question :which_opt?
elsif apply_in_neighbouring_countries
outcome :apply_in_neighbouring_country
else
question :renewing_replacing_applying?
end
end
end
# Q1a
multiple_choice :which_opt? do
option :gaza
option :"jerusalem-or-westbank"
save_input_as :current_location
next_node :renewing_replacing_applying?
end
# Q2
multiple_choice :renewing_replacing_applying? do
option :renewing_new
option :renewing_old
option :applying
option :replacing
save_input_as :application_action
precalculate :organisation do
location.fco_organisation
end
calculate :overseas_passports_embassies do
if organisation
organisation.offices_with_service 'Overseas Passports Service'
else
[]
end
end
calculate :general_action do |response|
response =~ /^renewing_/ ? 'renewing' : response
end
calculate :passport_data do
data_query.find_passport_data(current_location)
end
calculate :application_type do
passport_data['type']
end
calculate :is_ips_application do
%w{ips_application_1 ips_application_2 ips_application_3}.include?(application_type)
end
calculate :ips_number do
application_type.split("_")[2] if is_ips_application
end
calculate :application_form do
passport_data['app_form']
end
calculate :supporting_documents do
passport_data['group']
end
calculate :application_address do
passport_data['address']
end
calculate :ips_docs_number do
supporting_documents.split("_")[3] if is_ips_application
end
calculate :ips_result_type do
passport_data['online_application'] ? :ips_application_result_online : :ips_application_result
end
data_query.passport_costs.each do |k, v|
calculate "costs_#{k}".to_sym do
v
end
end
calculate :waiting_time do
passport_data[application_action]
end
calculate :optimistic_processing_time do
passport_data['optimistic_processing_time?']
end
next_node :child_or_adult_passport?
end
# Q3
multiple_choice :child_or_adult_passport? do
option :adult
option :child
save_input_as :child_or_adult
next_node(permitted: :auto) do
if is_ips_application
if %w(applying renewing_old).include?(application_action)
question :country_of_birth?
elsif ips_result_type == :ips_application_result_online
outcome :ips_application_result_online
else
outcome :ips_application_result
end
end
end
end
# Q4
country_select :country_of_birth?, include_uk: true, exclude_countries: exclude_countries do
save_input_as :birth_location
calculate :application_group do |response|
data_query.find_passport_data(response)['group']
end
calculate :supporting_documents do |response|
response == 'united-kingdom' ? supporting_documents : application_group
end
calculate :ips_docs_number do
supporting_documents.split("_")[3]
end
next_node(permitted: :auto) do
if is_ips_application
if ips_result_type == :ips_application_result_online
outcome :ips_application_result_online
else
outcome :ips_application_result
end
end
end
end
## Online IPS Application Result
outcome :ips_application_result_online do
precalculate :birth_location do
birth_location
end
end
## IPS Application Result
outcome :ips_application_result do
precalculate :data_query do
data_query
end
precalculate :birth_location do
birth_location
end
end
## No-op outcome.
outcome :cannot_apply
outcome :apply_in_neighbouring_country do
precalculate :title_output do
location.name
end
end
end
end
end