/
survey.php
249 lines (211 loc) · 6.93 KB
/
survey.php
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
$firstPrompt = 'Thanks for calling the Mobile Assessment of Damage hotline.';
/*
* TODO: resume a past session by entering a reference number
$questions[] = array(
'key' => 'hasreferencenumber',
'name' => 'Reference Number',
'prompt' => 'Do you already have a reference number?',
'prompt2' => didntUnderstand() . 'Do you want to continue a past session by entering a reference number?',
'choices' => '[BOOLEAN]'
);
if(defined('SURVEY_MODE') && ($callID = surveyVal('hasreferencenumber')) !== FALSE)
{
if($callID)
{
// Resume a previous session
}
else
{
$questions[] = array(
'key' => 'referencenumber',
'name' => 'Reference Number',
'prompt' => 'What is your reference number?',
'prompt2' => 'Please speak the digits of your reference number.',
'choices' => '[DIGITS]'
);
}
}
*/
if(defined('SURVEY_MODE'))
{
$refnum = implode(' ', str_split($_SESSION['callID']));
$firstPrompt .= ' If we get disconnected, you can continue this call by entering the following reference number. . ';
// TODO: Say "Please say ok when you have a pen and paper ready." and wait for up to 60 seconds rather than the default 10
$firstPrompt .= ' Your reference number is ' . $refnum . '. Once again, that number is ' . $refnum . '.';
}
$questions[] = array(
'key' => 'wanttohearinstructions',
'name' => 'Want to hear instructions?',
'prompt' => 'Do you want to know what questions we are going to ask you?',
'prompt2' => didntUnderstand() . 'Please say yes or no.',
'choices' => '[BOOLEAN]'
);
if(defined('SURVEY_MODE') && surveyVal('wanttohearinstructions') !== FALSE)
{
$questions[] = array(
'say' => 'You will need to know the zip code of the damaged property, the primary cause of damage, your insurance provider, if any, and the estimated dollar amount of damages, and a few other questions. Let\'s get started.'
);
}
$questions[] = array(
'key' => 'name',
'name' => 'Name',
'prompt' => 'What is your full name?',
'prompt2' => didntUnderstand() . 'What is your name?',
'choices' => '[RECORD]'
);
$questions[] = array(
'key' => 'postcode',
'name' => 'Zip Code',
'prompt' => 'What is the zip code of the property?',
'prompt2' => didntUnderstand() . 'Speak each digit of the zip code slowly.',
'choices' => '[5 DIGITS]'
);
if(defined('SURVEY_MODE') && ($zip = surveyVal('postcode')) !== FALSE && surveyVal('county') == FALSE)
{
// Look up the counties for this zip code
$counties = getCountiesForZipcode($zip);
if(count($counties) > 1)
{
$countyChoices = array();
foreach($counties as $fips=>$c)
$countyChoices[] = $fips . '(' . $c . ')';
$questions[] = array(
'key' => 'county',
'name' => 'County',
'prompt' => 'Which county is the property in?',
'prompt2' => didntUnderstand() . 'What county is the property in?',
'choices' => implode(', ', $countyChoices)
);
}
else
{
$fips = array_pop(array_flip($counties));
storeSurveyResponse('county', $fips);
storeSurveyResponse('state', getStateForFIPS($fips));
}
}
else
{
// define the key/name pair for the web view, and optionally a way to look up foreign keys in the database
$questions[] = array(
'key' => 'county',
'name' => 'County',
'lookup' => array('table'=>'counties', 'key'=>'fips', 'value'=>'countyName')
);
}
$questions[] = array(
'key' => 'street1',
'name' => 'Address',
'prompt' => 'What is the address of the property?',
'prompt2' => didntUnderstand() . 'What is the address?',
'choices' => '[RECORD]'
);
$questions[] = array(
'key' => 'habitable',
'name' => 'Is Habitable?',
'prompt' => 'Is the property currently habitable?',
'prompt2' => didntUnderstand() . 'Please say yes or no.',
'choices' => '[BOOLEAN]'
);
$questions[] = array(
'key' => 'accessible',
'name' => 'Accessible?',
'prompt' => 'Is the property currently accessible?',
'prompt2' => didntUnderstand() . 'Please say yes or no.',
'choices' => '[BOOLEAN]'
);
$questions[] = array(
'key' => 'damagetoday',
'name' => 'Date of Damage',
'prompt' => 'Did the damage happen today?',
'prompt2' => didntUnderstand() . 'Was today the day the damage happened?',
'choices' => '[BOOLEAN]'
);
if(defined('SURVEY_MODE') && ($today = surveyVal('damagetoday')) !== FALSE)
{
if($today)
{
storeSurveyResponse('date', date('Y-m-d'));
}
else
{
$questions[] = array(
'key' => 'date',
'name' => 'Date of Damage',
'prompt' => 'What day did the damage happen?',
'prompt2' => 'Please tell me the full date.',
'choices' => '[DATE]'
);
}
}
$questions[] = array(
'key' => 'damage_type',
'name' => 'Type of Damage',
'prompt' => 'What type of damage happened? You can say structural, roadway, or land.',
'prompt2' => didntUnderstand() . 'Please say structural, road, or land.',
'choices' => 'structural(structural, structure, building), roadway(roadway, road), land(land)'
);
$questions[] = array(
'key' => 'cause',
'name' => 'Primary Cause',
'prompt' => 'What was the primary cause of the damage? You can say things like fire, flood, earthquake, and others.',
'prompt2' => didntUnderstand() . 'The options are fire, flood, earthquake, wind, volcano, snow, ice, vandalism, other.',
'choices' => 'fire(fire), flood(flood), earthquake(earthquake), wind(wind), volcano(volcano), snow(snow), ice(ice), vandalism(vandalism), other(other)'
);
$questions[] = array(
'key' => 'description',
'name' => 'Description',
'prompt' => 'Please provide a brief description of the damages.',
'prompt2' => didntUnderstand(),
'choices' => '[RECORD]'
);
$questions[] = array(
'key' => 'owner',
'name' => 'Owner?',
'prompt' => 'Are you an owner or a renter?',
'prompt2' => didntUnderstand() . 'Do you own or rent?',
'choices' => '1(owner, own, 1, yes), 0(renter, rent, 2)'
);
$questions[] = array(
'key' => 'insurance',
'name' => 'Has Insurance',
'prompt' => 'Do you have insurance?',
'prompt2' => didntUnderstand() . 'Do you have insurance? Yes or no.',
'choices' => '[BOOLEAN]'
);
if(surveyVal('insurance'))
{
$questions[] = array(
'key' => 'provider',
'name' => 'Insurance Provider',
'prompt' => 'Who is your insurance provider?',
'prompt2' => didntUnderstand() . 'Who is your provides your insurance?',
'choices' => '[RECORD]'
);
}
$questions[] = array(
'key' => 'eststructloss',
'name' => 'Est. Structural Damage',
'prompt' => 'What is the estimated dollar amount of the structural loss?',
'prompt2' => didntUnderstand() . 'Say the dollar amount slowly',
'choices' => '[CURRENCY]'
);
$questions[] = array(
'key' => 'estperproploss',
'name' => 'Est. Personal Loss',
'prompt' => 'What is the estimated dollar amount of the personal property loss?',
'prompt2' => didntUnderstand() . 'Please say the dollar amount slowly',
'choices' => '[CURRENCY]'
);
function didntUnderstand()
{
$res[] = 'Sorry, I didn\'t understand that.';
$res[] = 'Sorry, I didn\'t get that.';
$res[] = 'I\'m sorry, I didn\'t get that.';
$res[] = 'Sorry, I\'m having trouble understanding you.';
$res[] = 'Can you please repeat that?';
$res[] = 'Can you say that again?';
return $res[array_rand($res)] . ' ';
}
?>