1
- import { COLLECTION_NAME_CASE , POPULATION_MAX_DEPTH , PREDEFINE_NAMESPACE_ADMINISTRATIVEAREA , PREDEFINE_NAMESPACE_PARTYGENDER , PREDEFINE_NAMESPACE_PARTYOCCUPATION , PREDEFINE_NAMESPACE_PARTYNATIONALITY , MODEL_NAME_CASE } from '@codetanzania/ewea-internals' ;
1
+ import { COLLECTION_NAME_CASE , POPULATION_MAX_DEPTH , PREDEFINE_NAMESPACE_CASESTAGE , PREDEFINE_NAMESPACE_CASESEVERITY , PREDEFINE_NAMESPACE_ADMINISTRATIVEAREA , PREDEFINE_NAMESPACE_PARTYGENDER , PREDEFINE_NAMESPACE_PARTYOCCUPATION , PREDEFINE_NAMESPACE_PARTYNATIONALITY , MODEL_NAME_CASE , DEFAULT_SEEDS as DEFAULT_SEEDS$1 } from '@codetanzania/ewea-internals' ;
2
2
import { compact , mergeObjects , idOf , pkg } from '@lykmapipo/common' ;
3
3
import { getString , apiVersion as apiVersion$1 } from '@lykmapipo/env' ;
4
4
import { ObjectId , createSubSchema , Mixed , model , createSchema , copyInstance , connect } from '@lykmapipo/mongoose-common' ;
5
5
import { mount } from '@lykmapipo/express-common' ;
6
6
import { Router , getFor , schemaFor , downloadFor , postFor , getByIdFor , patchFor , putFor , deleteFor , start as start$1 } from '@lykmapipo/express-rest-actions' ;
7
7
import { createModels } from '@lykmapipo/file' ;
8
- import { get , pick } from 'lodash' ;
8
+ import { get , set , pick } from 'lodash' ;
9
9
import '@lykmapipo/mongoose-sequenceable' ;
10
10
import actions from 'mongoose-rest-actions' ;
11
11
import exportable from '@lykmapipo/mongoose-exportable' ;
12
+ import { DEFAULT_SEEDS , caseSeverityFor } from '@codetanzania/ewea-common' ;
12
13
import moment from 'moment' ;
13
14
import { Predefine } from '@lykmapipo/predefine' ;
14
- import { DEFAULT_SEEDS } from '@codetanzania/ewea-common' ;
15
15
import { Event } from '@codetanzania/ewea-event' ;
16
16
import 'mongoose-geojson-schemas' ;
17
17
import { Party } from '@codetanzania/emis-stakeholder' ;
@@ -236,7 +236,7 @@ const stage = {
236
236
format : ( v ) => get ( v , 'strings.name.en' ) ,
237
237
default : 'NA' ,
238
238
} ,
239
- default : DEFAULT_SEEDS . CaseStage ,
239
+ default : DEFAULT_SEEDS [ PREDEFINE_NAMESPACE_CASESTAGE ] ,
240
240
} ;
241
241
242
242
/**
@@ -280,7 +280,7 @@ const severity = {
280
280
format : ( v ) => get ( v , 'strings.name.en' ) ,
281
281
default : 'NA' ,
282
282
} ,
283
- default : DEFAULT_SEEDS . CaseSeverity ,
283
+ default : DEFAULT_SEEDS [ PREDEFINE_NAMESPACE_CASESEVERITY ] ,
284
284
} ;
285
285
286
286
/**
@@ -749,7 +749,7 @@ const age = {
749
749
type : Number ,
750
750
index : true ,
751
751
exportable : true ,
752
- fake : ( f ) => f . random . number ( ) ,
752
+ fake : ( f ) => f . random . number ( { min : 1 , max : 100 } ) ,
753
753
} ;
754
754
755
755
/**
@@ -773,7 +773,32 @@ const weight = {
773
773
type : Number ,
774
774
index : true ,
775
775
exportable : true ,
776
- fake : ( f ) => f . random . number ( ) ,
776
+ fake : ( f ) => f . random . number ( { min : 1 , max : 250 } ) ,
777
+ } ;
778
+
779
+ /**
780
+ * @name score
781
+ * @description Current score of the case followup.
782
+ *
783
+ * It used to derive case severity.
784
+ *
785
+ * @property {object } type - schema(data) type
786
+ * @property {boolean } trim - force trimming
787
+ * @property {boolean } index - ensure database index
788
+ * @property {object } fake - fake data generator options
789
+ *
790
+ * @author lally elias <lallyelias87@gmail.com>
791
+ * @since 0.1.0
792
+ * @version 0.1.0
793
+ * @instance
794
+ * @example
795
+ * 4
796
+ */
797
+ const score = {
798
+ type : Number ,
799
+ index : true ,
800
+ exportable : true ,
801
+ fake : ( f ) => f . random . number ( { min : 0 , max : 5 } ) ,
777
802
} ;
778
803
779
804
/**
@@ -1213,6 +1238,7 @@ const followup = createSubSchema({
1213
1238
follower,
1214
1239
followedAt,
1215
1240
symptoms : properties ,
1241
+ score,
1216
1242
outcome,
1217
1243
remarks,
1218
1244
} ) ;
@@ -1294,17 +1320,47 @@ CaseSchema.pre('validate', function onPreValidate(done) {
1294
1320
* @instance
1295
1321
*/
1296
1322
CaseSchema . methods . preValidate = function preValidate ( done ) {
1297
- // ensure started(or reported) date
1298
- // TODO: drop reported date & use createdAt
1323
+ // ensure reported date
1299
1324
this . reportedAt = this . reportedAt || this . createdAt || new Date ( ) ;
1300
1325
1301
- // TODO: ensure victim default gender
1302
- // TODO: ensure victim default occupation
1326
+ // ensure case stage
1327
+ if ( ! get ( this , 'stage' ) ) {
1328
+ const staje = DEFAULT_SEEDS$1 [ PREDEFINE_NAMESPACE_CASESTAGE ] ;
1329
+ set ( this , 'stage' , staje ) ;
1330
+ }
1303
1331
1304
- // TODO: ensure event group and type
1332
+ // TODO: compute score
1333
+ // TODO: move score to case base schema
1334
+ // always: ensure case severity from followup score
1335
+ const score = get ( this , 'followup.score' ) ;
1336
+ this . severity = caseSeverityFor ( { score } ) ;
1305
1337
1306
- // TODO: ensure default values
1338
+ // ensure victim gender
1339
+ if ( ! get ( this , 'victim.gender' ) ) {
1340
+ const gender = DEFAULT_SEEDS$1 [ PREDEFINE_NAMESPACE_PARTYGENDER ] ;
1341
+ set ( this , 'victim.gender' , gender ) ;
1342
+ }
1307
1343
1344
+ // ensure victim default occupation
1345
+ if ( ! get ( this , 'victim.occupation' ) ) {
1346
+ const occupation = DEFAULT_SEEDS$1 [ PREDEFINE_NAMESPACE_PARTYOCCUPATION ] ;
1347
+ set ( this , 'victim.occupation' , occupation ) ;
1348
+ }
1349
+
1350
+ // ensure victim default nationality
1351
+ if ( ! get ( this , 'victim.nationality' ) ) {
1352
+ const nationality = DEFAULT_SEEDS$1 [ PREDEFINE_NAMESPACE_PARTYNATIONALITY ] ;
1353
+ set ( this , 'victim.nationality' , nationality ) ;
1354
+ }
1355
+
1356
+ // ensure victim default area
1357
+ if ( ! get ( this , 'victim.area' ) ) {
1358
+ const area = DEFAULT_SEEDS$1 [ PREDEFINE_NAMESPACE_ADMINISTRATIVEAREA ] ;
1359
+ set ( this , 'victim.area' , area ) ;
1360
+ }
1361
+
1362
+ // TODO: ensure event group and type
1363
+ // TODO: ensure default values
1308
1364
// TODO: ensure case status
1309
1365
1310
1366
// return
0 commit comments