1
# -*- coding: utf-8 -*-
4
Incident Reporting System - Model
8
if deployment_settings.has_module(module):
12
tablename = "%s_%s" % (module, resource)
13
table = db.define_table(tablename,
14
Field("audit_read", "boolean"),
15
Field("audit_write", "boolean"),
18
irs_incident_type_opts = {
19
1:T("animalHealth.animalDieOff"),
20
2:T("animalHealth.animalFeed"),
21
3:T("aviation.aircraftCrash"),
22
4:T("aviation.aircraftHijacking"),
23
5:T("aviation.airportClosure"),
24
6:T("aviation.airspaceClosure"),
25
7:T("aviation.noticeToAirmen"),
26
8:T("aviation.spaceDebris"),
27
9:T("civil.demonstrations"),
28
10:T("civil.dignitaryVisit"),
29
11:T("civil.displacedPopulations"),
30
12:T("civil.emergency"),
31
13:T("civil.looting"),
32
14:T("civil.publicEvent"),
34
16:T("civil.volunteerRequest"),
36
18:T("crime.bombExplosion"),
37
19:T("crime.bombThreat"),
38
20:T("crime.dangerousPerson"),
40
22:T("crime.homeCrime"),
41
23:T("crime.illegalImmigrant"),
42
24:T("crime.industrialCrime"),
43
25:T("crime.poisoning"),
44
26:T("crime.retailCrime"),
45
27:T("crime.shooting"),
46
28:T("crime.stowaway"),
47
29:T("crime.terrorism"),
48
30:T("crime.vehicleCrime"),
49
31:T("fire.forestFire"),
51
33:T("fire.industryFire"),
53
35:T("fire.urbanFire"),
54
36:T("fire.wildFire"),
55
37:T("flood.damOverflow"),
56
38:T("flood.flashFlood"),
57
39:T("flood.highWater"),
58
40:T("flood.overlandFlowFlood"),
59
41:T("flood.tsunami"),
60
42:T("geophysical.avalanche"),
61
43:T("geophysical.earthquake"),
62
44:T("geophysical.lahar"),
63
45:T("geophysical.landslide"),
64
46:T("geophysical.magneticStorm"),
65
47:T("geophysical.meteorite"),
66
48:T("geophysical.pyroclasticFlow"),
67
49:T("geophysical.pyroclasticSurge"),
68
50:T("geophysical.volcanicAshCloud"),
69
51:T("geophysical.volcanicEvent"),
70
52:T("hazardousMaterial.biologicalHazard"),
71
53:T("hazardousMaterial.chemicalHazard"),
72
54:T("hazardousMaterial.explosiveHazard"),
73
55:T("hazardousMaterial.fallingObjectHazard"),
74
56:T("hazardousMaterial.infectiousDisease"),
75
57:T("hazardousMaterial.poisonousGas"),
76
58:T("hazardousMaterial.radiologicalHazard"),
77
59:T("health.infectiousDisease"),
78
60:T("health.infestation"),
80
62:T("ice.icePressure"),
81
63:T("ice.rapidCloseLead"),
82
64:T("ice.specialIce"),
83
65:T("marine.marineSecurity"),
84
66:T("marine.nauticalAccident"),
85
67:T("marine.nauticalHijacking"),
86
68:T("marine.portClosure"),
87
69:T("marine.specialMarine"),
88
70:T("meteorological.blizzard"),
89
71:T("meteorological.blowingSnow"),
90
72:T("meteorological.drought"),
91
73:T("meteorological.dustStorm"),
92
74:T("meteorological.fog"),
93
75:T("meteorological.freezingDrizzle"),
94
76:T("meteorological.freezingRain"),
95
77:T("meteorological.freezingSpray"),
96
78:T("meteorological.hail"),
97
79:T("meteorological.hurricane"),
98
80:T("meteorological.rainFall"),
99
81:T("meteorological.snowFall"),
100
82:T("meteorological.snowSquall"),
101
83:T("meteorological.squall"),
102
84:T("meteorological.stormSurge"),
103
85:T("meteorological.thunderstorm"),
104
86:T("meteorological.tornado"),
105
87:T("meteorological.tropicalStorm"),
106
88:T("meteorological.waterspout"),
107
89:T("meteorological.winterStorm"),
108
90:T("missingPerson.amberAlert"),
109
91:T("missingPerson.missingVulnerablePerson"),
110
92:T("missingPerson.silver"),
111
93:T("publicService.emergencySupportFacility"),
112
94:T("publicService.emergencySupportService"),
113
95:T("publicService.schoolClosure"),
114
96:T("publicService.schoolLockdown"),
115
97:T("publicService.serviceOrFacility"),
116
98:T("publicService.transit"),
117
99:T("railway.railwayAccident"),
118
100:T("railway.railwayHijacking"),
119
101:T("roadway.bridgeClosure"),
120
102:T("roadway.hazardousRoadConditions"),
121
103:T("roadway.roadwayAccident"),
122
104:T("roadway.roadwayClosure"),
123
105:T("roadway.roadwayDelay"),
124
106:T("roadway.roadwayHijacking"),
125
107:T("roadway.roadwayUsageCondition"),
126
108:T("roadway.trafficReport"),
127
109:T("temperature.arcticOutflow"),
128
110:T("temperature.coldWave"),
129
111:T("temperature.flashFreeze"),
130
112:T("temperature.frost"),
131
113:T("temperature.heatAndHumidity"),
132
114:T("temperature.heatWave"),
133
115:T("temperature.windChill"),
134
116:T("wind.galeWind"),
135
117:T("wind.hurricaneForceWind"),
136
118:T("wind.stormForceWind"),
137
119:T("wind.strongWind")
141
# This is the current status of an Incident
142
resource = "incident"
143
tablename = "%s_%s" % (module, resource)
144
table = db.define_table(tablename, timestamp, uuidstamp, authorstamp, deletion_status,
146
Field("category", "integer"),
149
Field("time", "datetime"),
150
Field("persons_affected", "integer"),
151
Field("persons_injured", "integer"),
152
Field("persons_deceased", "integer"),
155
table.name.requires = IS_NOT_EMPTY()
156
table.category.requires = IS_NULL_OR(IS_IN_SET(irs_incident_type_opts))
157
table.category.represent = lambda opt: irs_incident_type_opts.get(opt, opt)
160
ADD_INCIDENT = T("Add Incident")
161
LIST_INCIDENTS = T("List Incidents")
162
s3.crud_strings[tablename] = Storage(
163
title_create = ADD_INCIDENT,
164
title_display = T("Incident Details"),
165
title_list = LIST_INCIDENTS,
166
title_update = T("Edit Incident"),
167
title_search = T("Search Incidents"),
168
subtitle_create = T("Add New Incident"),
169
subtitle_list = T("Incidents"),
170
label_list_button = LIST_INCIDENTS,
171
label_create_button = ADD_INCIDENT,
172
msg_record_created = T("Incident added"),
173
msg_record_modified = T("Incident updated"),
174
msg_record_deleted = T("Incident deleted"),
175
msg_list_empty = T("No Incidents currently registered"))
177
incident_id = db.Table(None, "incident_id",
178
Field("incident_id", table,
179
requires = IS_NULL_OR(IS_ONE_OF(db, "irs_incident.id", "%(id)s")),
180
represent = lambda id: id,
181
label = T("Incident"),
182
ondelete = "RESTRICT"))
183
s3xrc.model.configure(table,
190
# -----------------------------------------------------------------------------
192
# This is a report of an Incident
193
# A single incident may generate many reports
195
tablename = "%s_%s" % (module, resource)
196
table = db.define_table(tablename, timestamp, uuidstamp, authorstamp, deletion_status,
199
Field("category", "integer"),
203
Field("time", "datetime"),
204
Field("persons_affected", "integer"),
205
Field("persons_injured", "integer"),
206
Field("persons_deceased", "integer"),
209
table.name.requires = IS_NOT_EMPTY()
210
table.category.requires = IS_NULL_OR(IS_IN_SET(irs_incident_type_opts))
211
table.category.represent = lambda opt: irs_incident_type_opts.get(opt, opt)
212
table.person_id.default = session.auth.user.id if auth.is_logged_in() else None
214
table.name.label = T("Short Description")
215
table.name.comment = SPAN("*", _class="req")
216
table.person_id.label = T("Reporter Name")
217
table.persons_affected.label = T("Number of People Affected")
218
table.persons_injured.label = T("Number of People Injured")
219
table.persons_deceased.label = T("Number of People Deceased")
222
ADD_REPORT = T("Add Report")
223
LIST_REPORTS = T("List Reports")
224
s3.crud_strings[tablename] = Storage(
225
title_create = ADD_REPORT,
226
title_display = T("Report Details"),
227
title_list = LIST_REPORTS,
228
title_update = T("Edit Report"),
229
title_search = T("Search Reports"),
230
subtitle_create = T("Add New Report"),
231
subtitle_list = T("Reports"),
232
label_list_button = LIST_REPORTS,
233
label_create_button = ADD_REPORT,
234
msg_record_created = T("Report added"),
235
msg_record_modified = T("Report updated"),
236
msg_record_deleted = T("Report deleted"),
237
msg_list_empty = T("No Reports currently registered"))
239
s3xrc.model.add_component(module, resource,
241
joinby = dict(irs_incident="incident_id"),
245
# -----------------------------------------------------------------------------
246
irs_assessment_type_opts = {
247
1:T("initial assessment"),
248
2:T("follow-up assessment"),
253
irs_event_type_opts = {
254
1:T("primary incident"),
255
2:T("secondary effect"),
256
3:T("collateral event"),
260
irs_cause_type_opts = {
261
1:T("natural hazard"),
262
2:T("technical failure"),
264
4:T("criminal intent"),
265
5:T("operational intent"),
270
# This is a follow-up assessment of an Incident
271
resource = "iassessment"
272
tablename = "%s_%s" % (module, resource)
273
table = db.define_table(tablename,
274
timestamp, uuidstamp, authorstamp, deletion_status,
276
Field("datetime", "datetime"),
277
Field("itype", "integer",
278
requires = IS_IN_SET(irs_assessment_type_opts, zero=None),
280
label = T("Report Type"),
281
represent = lambda opt: irs_assessment_type_opts.get(opt, UNKNOWN_OPT)),
282
Field("event_type", "integer",
283
requires = IS_IN_SET(irs_event_type_opts, zero=None),
285
label = T("Event type"),
286
represent = lambda opt: irs_event_type_opts.get(opt, UNKNOWN_OPT)),
287
Field("cause_type", "integer",
288
requires = IS_IN_SET(irs_cause_type_opts, zero=None),
290
label = T("Type of cause"),
291
represent = lambda opt: irs_cause_type_opts.get(opt, UNKNOWN_OPT)),
292
Field("report", "text"),
293
Field("persons_affected", "integer"),
294
Field("persons_injured", "integer"),
295
Field("persons_deceased", "integer"),
298
table.modified_by.label = T("Reporter")
299
table.modified_by.readable = True
301
table.datetime.label = T("Date/Time")
304
ADD_ASSESSMENT = T("Add Assessment")
305
LIST_ASSESSMENTS = T("List Assessments")
306
s3.crud_strings[tablename] = Storage(
307
title_create = ADD_ASSESSMENT,
308
title_display = T("Assessment Details"),
309
title_list = LIST_ASSESSMENTS,
310
title_update = T("Edit Assessment"),
311
title_search = T("Search Assessments"),
312
subtitle_create = T("Add New Assessment"),
313
subtitle_list = T("Assessments"),
314
label_list_button = LIST_ASSESSMENTS,
315
label_create_button = ADD_ASSESSMENT,
316
msg_record_created = T("Assessment added"),
317
msg_record_modified = T("Assessment updated"),
318
msg_record_deleted = T("Assessment deleted"),
319
msg_list_empty = T("No Assessments currently registered"))
321
s3xrc.model.configure(table,
329
s3xrc.model.add_component(module, resource,
331
joinby = dict(irs_incident="incident_id"),
335
# -----------------------------------------------------------------------------
336
irs_image_type_opts = {
339
3:T("Document Scan"),
344
tablename = "%s_%s" % (module, resource)
345
table = db.define_table(tablename,
346
timestamp, uuidstamp, authorstamp, deletion_status,
347
Field("report_id", db.irs_ireport),
349
Field("assessment_id", db.irs_iassessment),
350
Field("type", "integer",
351
requires = IS_IN_SET(irs_image_type_opts, zero=None),
353
label = T("Image Type"),
354
represent = lambda opt: irs_image_type_opts.get(opt, UNKNOWN_OPT)),
355
Field("image", "upload", autodelete=True),
357
Field("description"),
362
ADD_IMAGE = T("Add Image")
363
LIST_IMAGES = T("List Images")
364
s3.crud_strings[tablename] = Storage(
365
title_create = ADD_IMAGE,
366
title_display = T("Image Details"),
367
title_list = LIST_IMAGES,
368
title_update = T("Edit Image"),
369
title_search = T("Search Images"),
370
subtitle_create = T("Add New Image"),
371
subtitle_list = T("Images"),
372
label_list_button = LIST_IMAGES,
373
label_create_button = ADD_IMAGE,
374
msg_record_created = T("Image added"),
375
msg_record_modified = T("Image updated"),
376
msg_record_deleted = T("Image deleted"),
377
msg_list_empty = T("No Images currently registered"))
379
s3xrc.model.add_component(module, resource,
381
joinby = dict(irs_incident="incident_id",
382
irs_ireport="report_id",
383
irs_iassessment="assessment_id"),
387
# -----------------------------------------------------------------------------
388
irs_response_type_opts = {
395
resource = "iresponse"
396
tablename = "%s_%s" % (module, resource)
397
table = db.define_table(tablename,
398
timestamp, uuidstamp, authorstamp, deletion_status,
400
Field("datetime", "datetime"),
401
Field("itype", "integer",
402
requires = IS_IN_SET(irs_response_type_opts, zero=None),
405
represent = lambda opt: irs_response_type_opts.get(opt, UNKNOWN_OPT)),
406
Field("report", "text"),
410
ADD_RESPONSE = T("Add Response")
411
LIST_RESPONSES = T("List Responses")
412
s3.crud_strings[tablename] = Storage(
413
title_create = ADD_RESPONSE,
414
title_display = T("Response Details"),
415
title_list = LIST_RESPONSES,
416
title_update = T("Edit Response"),
417
title_search = T("Search Responses"),
418
subtitle_create = T("Add New Response"),
419
subtitle_list = T("Responses"),
420
label_list_button = LIST_RESPONSES,
421
label_create_button = ADD_RESPONSE,
422
msg_record_created = T("Response added"),
423
msg_record_modified = T("Response updated"),
424
msg_record_deleted = T("Response deleted"),
425
msg_list_empty = T("No Responses currently registered"))
427
s3xrc.model.add_component(module, resource,
429
joinby = dict(irs_incident="incident_id"),
433
# -----------------------------------------------------------------------------