Skip to content

Commit 0a9b6db

Browse files
committed
feat(case): add followup schema
1 parent b816296 commit 0a9b6db

File tree

6 files changed

+205
-2
lines changed

6 files changed

+205
-2
lines changed

src/case.model.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from './internals';
1717

1818
import { number, description, remarks } from './schema/base.schema';
19-
import { victim } from './schema/common.schema';
19+
import { victim, followup } from './schema/common.schema';
2020
import { reporter, resolver } from './schema/parties.schema';
2121
import { reportedAt, resolvedAt } from './schema/dates.schema';
2222

@@ -26,6 +26,7 @@ const SCHEMA = mergeObjects(
2626
{ description },
2727
{ reportedAt, reporter },
2828
{ resolvedAt, resolver },
29+
{ followup },
2930
{ remarks }
3031
);
3132

src/schema/base.schema.js

+33
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,36 @@ export const remarks = {
263263
type: 'sentence',
264264
},
265265
};
266+
267+
/**
268+
* @name outcome
269+
* @description An outcome of about a case followup.
270+
*
271+
* @memberof Case
272+
*
273+
* @type {object}
274+
* @property {object} type - schema(data) type
275+
* @property {boolean} trim - force trimming
276+
* @property {boolean} index - ensure database index
277+
* @property {boolean} searchable - allow for searching
278+
* @property {boolean} exportable - allow field use for exporting
279+
* @property {object} fake - fake data generator options
280+
*
281+
* @author lally elias <lallyelias87@gmail.com>
282+
* @since 0.1.0
283+
* @version 0.1.0
284+
* @instance
285+
* @example
286+
* Home
287+
*/
288+
export const outcome = {
289+
type: String,
290+
trim: true,
291+
index: true,
292+
searchable: true,
293+
exportable: true,
294+
fake: {
295+
generator: 'lorem',
296+
type: 'sentence',
297+
},
298+
};

src/schema/common.schema.js

+68-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,44 @@ import {
77
import { DEFAULT_SEEDS } from '@codetanzania/ewea-common';
88
import { compact } from '@lykmapipo/common';
99
import { Point } from 'mongoose-geojson-schemas';
10-
import { ObjectId, createSubSchema } from '@lykmapipo/mongoose-common';
10+
import { ObjectId, Mixed, createSubSchema } from '@lykmapipo/mongoose-common';
1111
import { Predefine } from '@lykmapipo/predefine';
1212

1313
import {
1414
AUTOPOPULATE_OPTION_PREDEFINE,
1515
AUTOPOPULATE_OPTION_AREA,
1616
} from '../internals';
1717

18+
import { follower } from './parties.schema';
19+
import { followedAt } from './dates.schema';
20+
import { outcome, remarks } from './base.schema';
21+
22+
/**
23+
* @name properties
24+
* @description A map of key value pairs to allow to associate
25+
* other meaningful information to a case.
26+
*
27+
* @type {object}
28+
* @property {object} type - schema(data) type
29+
* @property {object} fake - fake data generator options
30+
*
31+
* @since 0.2.0
32+
* @version 0.1.0
33+
* @instance
34+
* @example
35+
* {
36+
* "population": {
37+
* "male": 1700000,
38+
* "female": 2700000
39+
* }
40+
* }
41+
*/
42+
export const properties = {
43+
type: Map,
44+
of: Mixed,
45+
fake: (f) => f.helpers.createTransaction(),
46+
};
47+
1848
/**
1949
* @name name
2050
* @description Full name name of the party(i.e individual).
@@ -521,3 +551,40 @@ export const victim = createSubSchema({
521551
area,
522552
nextOfKin,
523553
});
554+
555+
/**
556+
* @name victim
557+
* @description A party(i.e patient or victim) whom a case is for.
558+
*
559+
* @type {object}
560+
* @property {string} referral - Valid referral number
561+
* @property {string} pcr - Valid patient care number
562+
* @property {string} name - Full name of the victim
563+
* @property {string} mobile - Mobile phone number of the victim
564+
* @property {object} gender - Gender of the victim
565+
* @property {number} age - Age of the victim
566+
* @property {number} weight - Weight of the victim
567+
* @property {object} occupation - Occupation of the victim
568+
* @property {object} nationality - Nationality of the victim
569+
* @property {string} address - Address of the victim
570+
*
571+
* @author lally elias <lallyelias87@gmail.com>
572+
* @since 0.1.0
573+
* @version 0.2.0
574+
* @instance
575+
* @example
576+
* {
577+
* follower: {_id: "5bcda2c073dd0700048fb846", name: "Jane Doe" }
578+
* followedAt: '2018-10-19T07:55:32.831Z',
579+
* symptoms: { cough: 5 },
580+
* outcome: 'Hospital',
581+
* remarks: 'Handled'
582+
* }
583+
*/
584+
export const followup = createSubSchema({
585+
follower,
586+
followedAt,
587+
symptoms: properties,
588+
outcome,
589+
remarks,
590+
});

src/schema/dates.schema.js

+28
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,31 @@ export const resolvedAt = {
5555
type: 'recent',
5656
},
5757
};
58+
59+
/**
60+
* @name followedAt
61+
* @description Latest date when a case followed up after discharged.
62+
*
63+
* @memberof Case
64+
*
65+
* @type {object}
66+
* @property {object} type - schema(data) type
67+
* @property {boolean} index - ensure database index
68+
* @property {object} fake - fake data generator options
69+
*
70+
* @author lally elias <lallyelias87@gmail.com>
71+
* @since 0.3.0
72+
* @version 0.1.0
73+
* @instance
74+
* @example
75+
* 2018-10-19T07:55:32.831Z
76+
*/
77+
export const followedAt = {
78+
type: Date,
79+
index: true,
80+
exportable: true,
81+
fake: {
82+
generator: 'date',
83+
type: 'recent',
84+
},
85+
};

src/schema/parties.schema.js

+47
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,50 @@ export const resolver = {
9797
aggregatable: { unwind: true },
9898
default: undefined,
9999
};
100+
101+
/**
102+
* @name follower
103+
* @description A party(i.e call center or EOC operator) who
104+
* made a latest follow-up on a case.
105+
*
106+
* @memberof Case
107+
*
108+
* @type {object}
109+
* @property {object} type - schema(data) type
110+
* @property {boolean} required - mark required
111+
* @property {boolean} index - ensure database index
112+
* @property {boolean} exists - ensure ref exists before save
113+
* @property {object} autopopulate - auto populate(eager loading) options
114+
* @property {boolean} taggable - allow field use for tagging
115+
* @property {boolean} exportable - allow field use for exporting
116+
* @property {boolean} aggregatable - allow field use for aggregation
117+
* @property {boolean} default - default value set when none provided
118+
* @property {object} fake - fake data generator options
119+
*
120+
* @author lally elias <lallyelias87@gmail.com>
121+
* @since 0.1.0
122+
* @version 0.1.0
123+
* @instance
124+
* @example
125+
* {
126+
* _id: "5bcda2c073dd0700048fb846",
127+
* name: "Jane Doe",
128+
* mobile: "+255715463739",
129+
* email: "jane.doe@example.com",
130+
* }
131+
*/
132+
export const follower = {
133+
type: ObjectId,
134+
ref: Party.MODEL_NAME,
135+
// required: true,
136+
index: true,
137+
exists: true,
138+
autopopulate: AUTOPOPULATE_OPTION_PARTY,
139+
taggable: true,
140+
exportable: {
141+
format: (v) => get(v, 'name'),
142+
default: 'NA',
143+
},
144+
aggregatable: { unwind: true },
145+
default: undefined,
146+
};

test/unit/case.schema.spec.js

+27
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,31 @@ describe('Case Schema', () => {
252252
expect(remarks.options.exportable).to.be.true;
253253
expect(remarks.options.fake).to.exist;
254254
});
255+
256+
it('should have followup field', () => {
257+
const followup = Case.path('followup');
258+
const follower = Case.path('followup.follower');
259+
const followedAt = Case.path('followup.followedAt');
260+
const symptoms = Case.path('followup.symptoms');
261+
const outcome = Case.path('followup.outcome');
262+
const remarks = Case.path('followup.remarks');
263+
264+
expect(followup).to.exist;
265+
expect(followup).to.be.an.instanceof(SchemaTypes.Embedded);
266+
267+
expect(follower).to.exist;
268+
expect(follower).to.be.instanceof(SchemaTypes.ObjectId);
269+
270+
expect(followedAt).to.exist;
271+
expect(followedAt).to.be.instanceof(SchemaTypes.Date);
272+
273+
expect(symptoms).to.exist;
274+
expect(symptoms).to.be.instanceof(SchemaTypes.Map);
275+
276+
expect(outcome).to.exist;
277+
expect(outcome).to.be.instanceof(SchemaTypes.String);
278+
279+
expect(remarks).to.exist;
280+
expect(remarks).to.be.instanceof(SchemaTypes.String);
281+
});
255282
});

0 commit comments

Comments
 (0)