/
assess.py
2596 lines (2318 loc) · 117 KB
/
assess.py
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Assessments
This module currently contains 2 types of Assessments
* Flexible Impact Assessments (including Mobile access)
* Rapid Assessment Tool (from ECB: http://www.ecbproject.org/page/48)
@ToDo: Migrate this to a Template in the Survey module
@ToDo Validation similar to sitrep_school_report_onvalidation()
http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/annotate/head:/models/sitrep.py#L99
It also contains some Baseline Data:
* Populations
http://eden.sahanafoundation.org/wiki/BluePrintBaselineData
"""
module = request.controller
resourcename = request.function
if not settings.has_module(module):
raise HTTP(404, body="Module disabled: %s" % module)
# -----------------------------------------------------------------------------
# Define the Model
# @ToDo: Move to modules/eden/assess.py
# - here it isn't visible to s3db.load_all_models() or Sync
# -----------------------------------------------------------------------------
assess_severity_opts = {
0: T("Low"),
1: T("Medium"),
2: T("High"),
3: T("Very High"),
}
assess_colour_opts = {
0:"green",
1:"yellow",
2:"orange",
3:"red"
}
def s3_assess_severity_represent(value):
if value:
return IMG(_src="/%s/static/img/%s_circle_16px.png" %
(appname, assess_colour_opts[value]),
_alt= value,
_align="middle"
)
else:
return NONE
repr_select = lambda l: len(l.name) > 48 and "%s..." % l.name[:44] or l.name
s3_get_db_field_value = s3base.s3_get_db_field_value
location_id = s3db.gis_location_id
person_id = s3db.pr_person_id
organisation_id = s3db.org_organisation_id
organisation_represent = s3db.org_organisation_represent
sector_id = s3db.org_sector_id
human_resource_id = s3db.hrm_human_resource_id
ireport_id = s3db.irs_ireport_id
# Impact as component of assessments
s3mgr.model.add_component("impact_impact", assess_assess="assess_id")
def assess_tables():
""" Load the Assess Tables when needed """
module = "assess"
# =========================================================================
# Flexible Impact Assessments
# =========================================================================
# Assessment
#
resourcename = "assess"
tablename = "assess_assess"
table = db.define_table(tablename,
Field("datetime", "datetime",
label = T("Date & Time"),
default = request.utcnow),
location_id(widget = S3LocationAutocompleteWidget(),
requires = IS_LOCATION()),
organisation_id(widget = S3OrganisationAutocompleteWidget(default_from_profile=True)),
person_id("assessor_person_id",
label = T("Assessor"),
default = s3_logged_in_person()),
s3_comments(),
ireport_id(), # Assessment can be linked to an Incident Report
*s3_meta_fields())
assess_id = S3ReusableField("assess_id", table,
requires = IS_NULL_OR(IS_ONE_OF(db, "assess_assess.id", "%(id)s")),
represent = lambda id: id,
label = T("Assessment"),
ondelete = "RESTRICT")
# CRUD strings
ADD_ASSESSMENT = T("Add Assessment")
s3.crud_strings[tablename] = Storage(
title_create = ADD_ASSESSMENT,
title_display = T("Assessment Details"),
title_list = T("Assessments"),
title_update = T("Edit Assessment"),
title_search = T("Search Assessments"),
subtitle_create = T("Add New Assessment"),
label_list_button = T("List Assessments"),
label_create_button = ADD_ASSESSMENT,
label_delete_button = T("Delete Assessment"),
msg_record_created = T("Assessment added"),
msg_record_modified = T("Assessment updated"),
msg_record_deleted = T("Assessment deleted"),
msg_list_empty = T("No Assessments currently registered"),
name_nice = T("Assessment"),
name_nice_plural = T("Assessments"))
# assess_assess as component of org_organisation
s3mgr.model.add_component(table, org_organisation="organisation_id")
# Hide Add Assessment functionality. Users should only add assessments
# through the Basic Assessment.
s3mgr.configure(tablename,
insertable=False)
# =========================================================================
# Baseline Type
#
resourcename = "baseline_type"
tablename = "%s_%s" % (module, resourcename)
table = db.define_table(tablename,
Field("name", length=128, notnull=True, unique=True),
*s3_meta_fields())
# CRUD strings
ADD_BASELINE_TYPE = T("Add Baseline Type")
s3.crud_strings[tablename] = Storage(
title_create = ADD_BASELINE_TYPE,
title_display = T("Baseline Type Details"),
title_list = T("Baseline Types"),
title_update = T("Edit Baseline Type"),
title_search = T("Search Baseline Type"),
subtitle_create = T("Add New Baseline Type"),
label_list_button = T("List Baseline Types"),
label_create_button = ADD_BASELINE_TYPE,
label_delete_button = T("Delete Baseline Type"),
msg_record_created = T("Baseline Type added"),
msg_record_modified = T("Baseline Type updated"),
msg_record_deleted = T("Baseline Type deleted"),
msg_list_empty = T("No Baseline Types currently registered"),
name_nice = T("Baseline Type"),
name_nice_plural = T("Baseline Types"))
def baseline_type_comment():
# ToDo: Is this membership check required?
if auth.has_membership(auth.id_group("'Administrator'")):
return S3AddResourceLink(c="assess",
f="baseline_type",
label=ADD_BASELINE_TYPE)
else:
return None
baseline_type_id = S3ReusableField(
"baseline_type_id",
db.assess_baseline_type, sortby="name",
requires = IS_NULL_OR(IS_ONE_OF(db,
"assess_baseline_type.id",
"%(name)s",
sort=True)),
represent = lambda id: s3_get_db_field_value(tablename = "assess_baseline_type",
fieldname = "name",
look_up_value = id),
label = T("Baseline Type"),
comment = baseline_type_comment(),
ondelete = "RESTRICT"
)
# =========================================================================
# Baseline
#
resourcename = "baseline"
tablename = "%s_%s" % (module, resourcename)
table = db.define_table(tablename,
# Hide FK fields in forms
assess_id(readable = False, writable = False),
baseline_type_id(),
Field("value", "double"),
s3_comments(),
*s3_meta_fields())
# CRUD strings
ADD_BASELINE = T("Add Baseline")
s3.crud_strings[tablename] = Storage(
title_create = ADD_BASELINE,
title_display = T("Baselines Details"),
title_list = T("Baselines"),
title_update = T("Edit Baseline"),
title_search = T("Search Baselines"),
subtitle_create = T("Add New Baseline"),
label_list_button = T("List Baselines"),
label_create_button = ADD_BASELINE,
label_delete_button = T("Delete Baseline"),
msg_record_created = T("Baseline added"),
msg_record_modified = T("Baseline updated"),
msg_record_deleted = T("Baseline deleted"),
msg_list_empty = T("No Baselines currently registered"),
name_nice = T("Baseline"),
name_nice_plural = T("Baselines"))
# Baseline as component of assessments
s3mgr.model.add_component(table, assess_assess="assess_id")
# =========================================================================
# Summary
#
resourcename = "summary"
tablename = "%s_%s" % (module, resourcename)
table = db.define_table(
tablename,
assess_id(readable = False, writable = False),
sector_id(),
#Field("value", "double"),
Field("value", "integer",
default = 0,
label = T("Severity"),
requires = IS_EMPTY_OR(IS_IN_SET(assess_severity_opts)),
widget = SQLFORM.widgets.radio.widget,
represent = s3_assess_severity_represent),
s3_comments(),
*s3_meta_fields())
# CRUD strings
ADD_ASSESS_SUMMARY = T("Add Assessment Summary")
s3.crud_strings[tablename] = Storage(
title_create = ADD_ASSESS_SUMMARY,
title_display = T("Assessment Summary Details"),
title_list = T("Assessment Summaries"),
title_update = T("Edit Assessment Summary"),
title_search = T("Search Assessment Summaries"),
subtitle_create = T("Add New Assessment Summary"),
label_list_button = T("List Assessment Summaries"),
label_create_button = ADD_ASSESS_SUMMARY,
label_delete_button = T("Delete Assessment Summary"),
msg_record_created = T("Assessment Summary added"),
msg_record_modified = T("Assessment Summary updated"),
msg_record_deleted = T("Assessment Summary deleted"),
msg_list_empty = T("No Assessment Summaries currently registered"),
name_nice = T("Assessment"),
name_nice_plural = T("Assessments"))
# Summary as component of assessments
s3mgr.model.add_component(table, assess_assess="assess_id")
# Pass variables back to global scope (response.s3.*)
return dict(
assess_id = assess_id
)
# Provide a handle to this load function
s3mgr.loader(assess_tables,
"assess_assess")
# =========================================================================
# Rapid Assessment Tool
# =========================================================================
def rat_tables():
""" Load the RAT Tables when needed """
module = "assess"
# Load the models we depend on
if deployment_settings.has_module("cr"):
shelter_id = s3db.shelter_id
if deployment_settings.has_module("hrm"):
human_resource_id = s3db.hrm_human_resource_id
else:
human_resource_id = s3db.pr_person_id
# Section CRUD strings
ADD_SECTION = T("Add Section")
rat_section_crud_strings = Storage(
title_create = ADD_SECTION,
title_display = T("Section Details"),
title_list = T("Sections"),
title_update = "",
title_search = T("Search Sections"),
subtitle_create = "",
label_list_button = T("List Sections"),
label_create_button = ADD_SECTION,
label_delete_button = T("Delete Section"),
msg_record_created = T("Section updated"),
msg_record_modified = T("Section updated"),
msg_record_deleted = T("Section deleted"),
msg_list_empty = T("No Sections currently registered"),
name_nice = T("Search"),
name_nice_plural = T("Searches"))
# -------------------------------------------------------------------------
# Common options
rat_walking_time_opts = {
1: T("0-15 minutes"),
2: T("15-30 minutes"),
3: T("30-60 minutes"),
4: T("over one hour"),
999: NOT_APPLICABLE
}
# -------------------------------------------------------------------------
# Helper functions
def rat_represent_multiple(set, opt):
"""
Represent an IS_IN_SET with multiple=True as
comma-separated list of options
@param set: the options set as dict
@param opt: the selected option(s)
"""
if isinstance(opt, (list, tuple)):
opts = opt
vals = [str(set.get(o, o)) for o in opts]
#elif isinstance(opt, basestring):
# opts = opt.split("|")
# vals = [str(set.get(int(o), o)) for o in opts if o]
elif isinstance(opt, int):
opts = [opt]
vals = str(set.get(opt, opt))
else:
return T("None")
if len(opts) > 1:
vals = ", ".join(vals)
else:
vals = len(vals) and vals[0] or ""
return vals
def rat_tooltip(tooltip, multiple=False):
""" Prepare tooltip. """
if multiple:
comment = DIV("(%s)" % T("Select all that apply"),
DIV(_class="tooltipbody",
_title="|%s" % T(tooltip)))
else:
comment = DIV(DIV(_class="tooltipbody",
_title="|%s" % T(tooltip)))
return comment
def rat_label_and_tooltip(label, tooltip, multiple=False):
""" Prepare tooltip that incorporates a field's label. """
label = T(label)
if multiple:
comment = DIV("(%s)" % T("Select all that apply"),
DIV(_class="tooltip",
_title="%s|%s" % (T(label), T(tooltip))))
else:
comment = DIV(DIV(_class="tooltip",
_title="%s|%s" % (T(label), T(tooltip))))
return {"label": label, "comment": comment}
rat_interview_location_opts = {
1:T("Village"),
2:T("Urban area"),
3:T("Collective center"),
4:T("Informal camp"),
5:T("Formal camp"),
6:T("School"),
7:T("Mosque"),
8:T("Church"),
99:T("Other")
}
rat_interviewee_opts = {
1:T("Male"),
2:T("Female"),
3:T("Village Leader"),
4:T("Informal Leader"),
5:T("Community Member"),
6:T("Religious Leader"),
7:T("Police"),
8:T("Healthcare Worker"),
9:T("School Teacher"),
10:T("Womens Focus Groups"),
11:T("Child (< 18 yrs)"),
99:T("Other")
}
rat_accessibility_opts = {
1:T("2x4 Car"),
2:T("4x4 Car"),
3:T("Truck"),
4:T("Motorcycle"),
5:T("Boat"),
6:T("Walking Only"),
7:T("No access at all"),
99:T("Other")
}
# Main Resource -----------------------------------------------------------
# contains Section 1: Identification Information
#
resourcename = "rat"
tablename = "assess_rat"
table = db.define_table(
tablename,
Field("date", "date",
requires = [IS_DATE(format = settings.get_L10n_date_format()),
IS_NOT_EMPTY()],
default = datetime.datetime.today()),
location_id(widget = S3LocationAutocompleteWidget(),
requires = IS_LOCATION()),
human_resource_id("staff_id", label=T("Staff")),
human_resource_id("staff2_id", label=T("Staff2")),
Field("interview_location", "list:integer",
label = T("Interview taking place at"),
requires = IS_NULL_OR(IS_IN_SET(rat_interview_location_opts,
multiple=True,
zero=None)),
#widget = SQLFORM.widgets.checkboxes.widget,
represent = lambda opt, set=rat_interview_location_opts: \
rat_represent_multiple(set, opt),
comment = "(%s)" % T("Select all that apply")),
Field("interviewee", "list:integer",
label = T("Person interviewed"),
requires = IS_NULL_OR(IS_IN_SET(rat_interviewee_opts,
multiple=True,
zero=None)),
#widget = SQLFORM.widgets.checkboxes.widget,
represent = lambda opt, set=rat_interviewee_opts: \
rat_represent_multiple(set, opt),
comment = "(%s)" % T("Select all that apply")),
Field("accessibility", "integer",
label = T("Accessibility of Affected Location"),
requires = IS_NULL_OR(IS_IN_SET(rat_accessibility_opts,
zero=None)),
represent = lambda opt: rat_accessibility_opts.get(opt, opt)),
s3_comments(),
#document_id(), # Better to have multiple Documents on a Tab
s3db.shelter_id(),
*s3_meta_fields())
# CRUD strings
ADD_ASSESSMENT = T("Add Rapid Assessment")
s3.crud_strings[tablename] = Storage(
title_create = ADD_ASSESSMENT,
title_display = T("Rapid Assessment Details"),
title_list = T("Rapid Assessments"),
title_update = T("Edit Rapid Assessment"),
title_search = T("Search Rapid Assessments"),
subtitle_create = T("Add New Rapid Assessment"),
label_list_button = T("List Rapid Assessments"),
label_create_button = ADD_ASSESSMENT,
label_delete_button = T("Delete Rapid Assessment"),
msg_record_created = T("Rapid Assessment added"),
msg_record_modified = T("Rapid Assessment updated"),
msg_record_deleted = T("Rapid Assessment deleted"),
msg_list_empty = T("No Rapid Assessments currently registered"),
name_nice = T("Rapid Assessment"),
name_nice_plural = T("Rapid Assessments"))
# -------------------------------------------------------------------------
def rat_assessment_onaccept(form):
id = form.vars.get("id", None)
if id:
for x in xrange(2, 10):
section = "assess_section%s" % x
set = db(db[section].assessment_id == id)
record = set.select(db[section].id, limitby=(0, 1)).first()
if not record:
db[section].insert(assessment_id=id)
# -------------------------------------------------------------------------
def rat_represent(id):
""" Represent assessment as string """
table = db.assess_rat
row = db(table.id == id).select(table.date,
table.staff_id,
table.staff2_id,
table.location_id,
limitby = (0, 1)).first()
if row:
date = row.date and str(row.date) or ""
location = row.location_id and gis_location_represent(row.location_id) or ""
table = db.org_staff
org = ["", ""]
i = 0
for staff_id in [row.staff_id, row.staff2_id]:
if staff_id:
staff = db(table.id == staff_id).select(table.organisation_id,
limitby=(0, 1)).first()
if staff:
i += 1
org[i] = organisation_represent(staff.organisation_id)
assessment_represent = XML("<div>%s %s, %s %s</div>" % (location, org[0], org[1], date))
else:
assessment_represent = NONE
return assessment_represent
# -------------------------------------------------------------------------
# re-usable field
assessment_id = S3ReusableField("assessment_id", table,
requires = IS_NULL_OR(IS_ONE_OF(db, "assess_rat.id",
rat_represent,
orderby="assess_rat.id")),
#represent = rat_represent,
readable = False, writable = False,
#label = T("Rapid Assessment"),
#comment = A(ADD_ASSESSMENT,
# _class="colorbox",
# _href=URL(c="assess", f="rat",
# args="create",
# vars=dict(format="popup")),
# _target="top",
# _title=ADD_ASSESSMENT),
ondelete = "RESTRICT")
# Assessment as component of cr_shelter.
# RAT has components itself, so best not to constrain within the parent resource tabs
# - therefore disable the listadd & jump out of the tabs for Create/Update
s3mgr.model.add_component(table, cr_shelter="shelter_id")
s3mgr.configure(tablename,
listadd=False, # We override this in the RAT controller for when not a component
onaccept=rat_assessment_onaccept)
# Section 2: Demographic --------------------------------------------------
resourcename = "section2"
tablename = "%s_%s" % (module, resourcename)
table = db.define_table(
tablename,
assessment_id(),
Field("population_total", "integer",
label = T("Total population of site visited"),
comment = T("people")),
Field("households_total", "integer",
label = T("Total # of households of site visited"),
comment = T("households")),
Field("population_affected", "integer",
label = T("Estimated # of people who are affected by the emergency"),
comment = T("people")),
Field("households_affected", "integer",
label = T("Estimated # of households who are affected by the emergency"),
comment = T("households")),
Field("male_05", "double",
label = T("Number/Percentage of affected population that is Male & Aged 0-5")),
Field("male_612", "double",
label = T("Number/Percentage of affected population that is Male & Aged 6-12")),
Field("male_1317", "double",
label = T("Number/Percentage of affected population that is Male & Aged 13-17")),
Field("male_1825", "double",
label = T("Number/Percentage of affected population that is Male & Aged 18-25")),
Field("male_2660", "double",
label = T("Number/Percentage of affected population that is Male & Aged 26-60")),
Field("male_61", "double",
label = T("Number/Percentage of affected population that is Male & Aged 61+")),
Field("female_05", "double",
label = T("Number/Percentage of affected population that is Female & Aged 0-5")),
Field("female_612", "double",
label = T("Number/Percentage of affected population that is Female & Aged 6-12")),
Field("female_1317", "double",
label = T("Number/Percentage of affected population that is Female & Aged 13-17")),
Field("female_1825", "double",
label = T("Number/Percentage of affected population that is Female & Aged 18-25")),
Field("female_2660", "double",
label = T("Number/Percentage of affected population that is Female & Aged 26-60")),
Field("female_61", "double",
label = T("Number/Percentage of affected population that is Female & Aged 61+")),
Field("dead_women", "integer",
label = T("How many Women (18 yrs+) are Dead due to the crisis"),
comment = T("people")), # @ToDo: Should this say "Number of people"?
Field("dead_men", "integer",
label = T("How many Men (18 yrs+) are Dead due to the crisis"),
comment = T("people")),
Field("dead_girl", "integer",
label = T("How many Girls (0-17 yrs) are Dead due to the crisis"),
comment = T("people")),
Field("dead_boy", "integer",
label = T("How many Boys (0-17 yrs) are Dead due to the crisis"),
comment = T("people")),
Field("injured_women", "integer",
label = T("How many Women (18 yrs+) are Injured due to the crisis"),
comment = T("people")),
Field("injured_men", "integer",
label = T("How many Men (18 yrs+) are Injured due to the crisis"),
comment = T("people")),
Field("injured_girl", "integer",
label = T("How many Girls (0-17 yrs) are Injured due to the crisis"),
comment = T("people")),
Field("injured_boy", "integer",
label = T("How many Boys (0-17 yrs) are Injured due to the crisis"),
comment = T("people")),
Field("missing_women", "integer",
label = T("How many Women (18 yrs+) are Missing due to the crisis"),
comment = T("people")),
Field("missing_men", "integer",
label = T("How many Men (18 yrs+) are Missing due to the crisis"),
comment = T("people")),
Field("missing_girl", "integer",
label = T("How many Girls (0-17 yrs) are Missing due to the crisis"),
comment = T("people")),
Field("missing_boy", "integer",
label = T("How many Boys (0-17 yrs) are Missing due to the crisis"),
comment = T("people")),
Field("household_head_elderly", "integer",
label = T("Elderly person headed households (>60 yrs)"),
comment = T("households")),
Field("household_head_female", "integer",
label = T("Female headed households"),
comment = T("households")),
Field("household_head_child", "integer",
label = T("Child headed households (<18 yrs)"),
comment = T("households")),
Field("disabled_physical", "integer",
label = T("Persons with disability (physical)"),
comment = T("people")),
Field("disabled_mental", "integer",
label = T("Persons with disability (mental)"),
comment = T("people")),
Field("pregnant", "integer",
label = T("Pregnant women"),
comment = T("people")),
Field("lactating", "integer",
label = T("Lactating women"),
comment = T("people")),
Field("minorities", "integer",
label = T("Migrants or ethnic minorities"),
comment = T("people")),
s3_comments(),
*s3_meta_fields())
# CRUD strings
s3.crud_strings[tablename] = rat_section_crud_strings
s3mgr.model.add_component(table,
assess_rat=dict(joinby="assessment_id",
multiple=False))
s3mgr.configure(tablename, deletable=False)
# Section 3: Shelter & Essential NFIs -------------------------------------
rat_houses_salvmat_types = {
1: T("Wooden plank"),
2: T("Zinc roof"),
3: T("Bricks"),
4: T("Wooden poles"),
5: T("Door frame"),
6: T("Window frame"),
7: T("Roof tile"),
999: NOT_APPLICABLE
}
rat_water_container_types = {
1: T("Jerry can"),
2: T("Bucket"),
3: T("Water gallon"),
99: T("Other (specify)")
}
resourcename = "section3"
tablename = "%s_%s" % (module, resourcename)
table = db.define_table(
tablename,
assessment_id(),
Field("houses_total", "integer",
label = T("Total number of houses in the area"),
requires = IS_EMPTY_OR(IS_INT_IN_RANGE(0, 99999999)),
),
Field("houses_destroyed", "integer",
requires = IS_EMPTY_OR(IS_INT_IN_RANGE(0, 99999999)),
**rat_label_and_tooltip(
"Number of houses destroyed/uninhabitable",
"How many houses are uninhabitable (uninhabitable = foundation and structure destroyed)?")),
Field("houses_damaged", "integer",
requires = IS_EMPTY_OR(IS_INT_IN_RANGE(0, 99999999)),
**rat_label_and_tooltip(
"Number of houses damaged, but usable",
"How many houses suffered damage but remain usable (usable = windows broken, cracks in walls, roof slightly damaged)?")),
Field("houses_salvmat", "list:integer",
requires = IS_NULL_OR(IS_IN_SET(rat_houses_salvmat_types,
multiple=True,
zero=None)),
represent = lambda opt, set=rat_houses_salvmat_types: \
rat_represent_multiple(set, opt),
**rat_label_and_tooltip(
"Salvage material usable from destroyed houses",
"What type of salvage material can be used from destroyed houses?",
multiple=True)),
Field("water_containers_available", "boolean",
**rat_label_and_tooltip(
"Water storage containers available for HH",
"Do households have household water storage containers?")),
Field("water_containers_sufficient", "boolean",
**rat_label_and_tooltip(
"Water storage containers sufficient per HH",
"Do households each have at least 2 containers (10-20 litres each) to hold water?")),
Field("water_containers_types", "list:integer",
requires = IS_EMPTY_OR(IS_IN_SET(rat_water_container_types,
zero=None,
multiple=True)),
represent = lambda opt, set=rat_water_container_types: \
rat_represent_multiple(set, opt),
**rat_label_and_tooltip(
"Types of water storage containers available",
"What types of household water storage containers are available?",
multiple=True)),
Field("water_containers_types_other",
label = T("Other types of water storage containers")),
Field("cooking_equipment_available", "boolean",
**rat_label_and_tooltip(
"Appropriate cooking equipment/materials in HH",
"Do households have appropriate equipment and materials to cook their food (stove, pots, dished plates, and a mug/drinking vessel, etc)?")),
Field("sanitation_items_available", "boolean",
**rat_label_and_tooltip(
"Reliable access to sanitation/hygiene items",
"Do people have reliable access to sufficient sanitation/hygiene items (bathing soap, laundry soap, shampoo, toothpaste and toothbrush)?")),
Field("sanitation_items_available_women", "boolean",
**rat_label_and_tooltip(
"Easy access to sanitation items for women/girls",
"Do women and girls have easy access to sanitary materials?")),
Field("bedding_materials_available", "boolean",
**rat_label_and_tooltip(
"Bedding materials available",
"Do households have bedding materials available (tarps, plastic mats, blankets)?")),
Field("clothing_sets_available", "boolean",
**rat_label_and_tooltip(
"Appropriate clothing available",
"Do people have at least 2 full sets of clothing (shirts, pants/sarong, underwear)?")),
Field("nfi_assistance_available", "boolean",
**rat_label_and_tooltip(
"Shelter/NFI assistance received/expected",
"Have households received any shelter/NFI assistance or is assistance expected in the coming days?")),
Field("kits_hygiene_received", "boolean",
label = T("Hygiene kits received")),
Field("kits_hygiene_source",
label = T("Hygiene kits, source")),
Field("kits_household_received", "boolean",
label = T("Household kits received")),
Field("kits_household_source",
label = T("Household kits, source")),
Field("kits_dwelling_received", "boolean",
label = T("Family tarpaulins received")), # @ToDo: Better label, perhaps? A tarp isn't a dwelling.
Field("kits_dwelling_source",
label = T("Family tarpaulins, source")),
s3_comments(),
*s3_meta_fields())
# CRUD strings
s3.crud_strings[tablename] = rat_section_crud_strings
s3mgr.model.add_component(table,
assess_rat=dict(joinby="assessment_id",
multiple=False))
s3mgr.configure(tablename, deletable=False)
# Section 4 - Water and Sanitation ----------------------------------------
rat_water_source_types = {
1: T("PDAM"),
2: T("Dug Well"),
3: T("Spring"),
4: T("River"),
5: T("Other Faucet/Piped Water"),
99: T("Other (describe)"),
999: NOT_APPLICABLE
}
rat_water_coll_person_opts = {
1: T("Child"),
2: T("Adult male"),
3: T("Adult female"),
4: T("Older person (>60 yrs)"),
999: NOT_APPLICABLE
}
rat_defec_place_types = {
1: T("open defecation"),
2: T("pit"),
3: T("latrines"),
4: T("river"),
99: T("other")
}
rat_defec_place_animals_opts = {
1: T("enclosed area"),
2: T("within human habitat"),
999: NOT_APPLICABLE
}
rat_latrine_types = {
1: T("flush latrine with septic tank"),
2: T("pit latrine"),
999: NOT_APPLICABLE
}
resourcename = "section4"
tablename = "%s_%s" % (module, resourcename)
table = db.define_table(
tablename,
assessment_id(),
Field("water_source_pre_disaster_type", "integer",
label = T("Type of water source before the disaster"),
requires = IS_EMPTY_OR(IS_IN_SET(rat_water_source_types,
zero=None)),
represent = lambda opt: rat_water_source_types.get(opt,
UNKNOWN_OPT)),
Field("water_source_pre_disaster_description",
label = T("Description of water source before the disaster")),
Field("dwater_source_type", "integer",
requires = IS_EMPTY_OR(IS_IN_SET(rat_water_source_types,
zero=None)),
represent = lambda opt: rat_water_source_types.get(opt,
UNKNOWN_OPT),
**rat_label_and_tooltip(
"Current type of source for drinking water",
"What is your major source of drinking water?")),
Field("dwater_source_description",
label = T("Description of drinking water source")),
Field("dwater_reserve",
**rat_label_and_tooltip(
"How long will this water resource last?",
"Specify the minimum sustainability in weeks or days.")),
Field("swater_source_type", "integer",
requires = IS_EMPTY_OR(IS_IN_SET(rat_water_source_types,
zero=None)),
represent = lambda opt: rat_water_source_types.get(opt,
UNKNOWN_OPT),
**rat_label_and_tooltip(
"Current type of source for sanitary water",
"What is your major source of clean water for daily use (ex: washing, cooking, bathing)?")),
Field("swater_source_description",
label = T("Description of sanitary water source")),
Field("swater_reserve",
**rat_label_and_tooltip(
"How long will this water resource last?",
"Specify the minimum sustainability in weeks or days.")),
Field("water_coll_time", "integer",
requires = IS_EMPTY_OR(IS_IN_SET(rat_walking_time_opts,
zero=None)),
represent = lambda opt: rat_walking_time_opts.get(opt,
UNKNOWN_OPT),
**rat_label_and_tooltip(
"Time needed to collect water",
"How long does it take you to reach the available water resources? Specify the time required to go there and back, including queuing time, by foot.")),
Field("water_coll_safe", "boolean",
label = T("Is it safe to collect water?"),
default = True),
Field("water_coll_safety_problems",
label = T("If no, specify why")),
Field("water_coll_person", "integer",
label = T("Who usually collects water for the family?"),
requires = IS_EMPTY_OR(IS_IN_SET(rat_water_coll_person_opts,
zero=None)),
represent = lambda opt: rat_water_coll_person_opts.get(opt,
UNKNOWN_OPT)),
Field("defec_place_type",
requires = IS_EMPTY_OR(IS_IN_SET(rat_defec_place_types,
zero=None,
multiple=True)),
represent = lambda opt: rat_defec_place_types.get(opt,
UNKNOWN_OPT),
**rat_label_and_tooltip(
"Type of place for defecation",
"Where do the majority of people defecate?",
multiple=True)),
Field("defec_place_description",
label = T("Description of defecation area")),
Field("defec_place_distance", "integer",
label = T("Distance between defecation area and water source"),
comment = T("meters")),
Field("defec_place_animals", "integer",
label = T("Defecation area for animals"),
requires = IS_EMPTY_OR(IS_IN_SET(rat_defec_place_animals_opts,
zero = None)),
represent = lambda opt: rat_defec_place_animals_opts.get(opt,
UNKNOWN_OPT)),
Field("close_industry", "boolean",
**rat_label_and_tooltip(
"Industry close to village/camp",
"Is there any industrial or agro-chemical production close to the affected area/village?")),
Field("waste_disposal",
**rat_label_and_tooltip(
"Place for solid waste disposal",
"Where is solid waste disposed in the village/camp?")),
Field("latrines_number", "integer",
requires = IS_EMPTY_OR(IS_INT_IN_RANGE(0, 999999)),
**rat_label_and_tooltip(
"Number of latrines",
"How many latrines are available in the village/IDP centre/Camp?")),
Field("latrines_type", "integer",
requires = IS_EMPTY_OR(IS_IN_SET(rat_latrine_types,
zero=None)),
represent = lambda opt: rat_latrine_types.get(opt,
UNKNOWN_OPT),
**rat_label_and_tooltip(
"Type of latrines",
"What type of latrines are available in the village/IDP centre/Camp?")),
Field("latrines_separation", "boolean",
**rat_label_and_tooltip(
"Separate latrines for women and men",
"Are there separate latrines for women and men available?")),
Field("latrines_distance", "integer",
**rat_label_and_tooltip(
"Distance between shelter and latrines",
"Distance between latrines and temporary shelter in meters")),
s3_comments(),
*s3_meta_fields())
# CRUD strings
s3.crud_strings[tablename] = rat_section_crud_strings
s3mgr.model.add_component(table,
assess_rat=dict(joinby="assessment_id",
multiple=False))
s3mgr.configure(tablename, deletable=False)
# Section 5 - Health ------------------------------------------------------
rat_health_services_types = {
1: T("Community Health Center"),
2: T("Hospital")
}
rat_health_problems_opts = {
1: T("Respiratory Infections"),
2: T("Diarrhea"),
3: T("Dehydration"),
99: T("Other (specify)")
}
rat_infant_nutrition_alternative_opts = {
1: T("Porridge"),
2: T("Banana"),
3: T("Instant Porridge"),
4: T("Air tajin"),
99: T("Other (specify)")
}
resourcename = "section5"
tablename = "%s_%s" % (module, resourcename)
table = db.define_table(
tablename,
assessment_id(),
Field("health_services_pre_disaster", "boolean",
**rat_label_and_tooltip(
"Health services functioning prior to disaster",
"Were there health services functioning for the community prior to the disaster?")),
Field("medical_supplies_pre_disaster", "boolean",
**rat_label_and_tooltip(
"Basic medical supplies available prior to disaster",
"Were basic medical supplies available for health services prior to the disaster?")),
Field("health_services_post_disaster", "boolean",
**rat_label_and_tooltip(
"Health services functioning since disaster",
"Are there health services functioning for the community since the disaster?")),
Field("medical_supplies_post_disaster", "boolean",
**rat_label_and_tooltip(
"Basic medical supplies available since disaster",
"Are basic medical supplies available for health services since the disaster?")),
Field("medical_supplies_reserve", "integer",
label = T("How many days will the supplies last?")),
Field("health_services_available_types", "list:integer",
requires = IS_EMPTY_OR(IS_IN_SET(rat_health_services_types,
zero=None, multiple=True)),
represent = lambda opt: \
rat_represent_multiple(rat_health_services_types, opt),
**rat_label_and_tooltip(
"Types of health services available",
"What types of health services are still functioning in the affected area?",
multiple=True)),
Field("staff_number_doctors", "integer",
requires = IS_EMPTY_OR(IS_INT_IN_RANGE(0, 999999)),
**rat_label_and_tooltip(
"Number of doctors actively working",
"How many doctors in the health centers are still actively working?")),
Field("staff_number_nurses", "integer",
requires = IS_EMPTY_OR(IS_INT_IN_RANGE(0, 999999)),
**rat_label_and_tooltip(
"Number of nurses actively working",
"How many nurses in the health centers are still actively working?")),
Field("staff_number_midwives", "integer",
requires = IS_EMPTY_OR(IS_INT_IN_RANGE(0, 999999)),