Skip to content

Commit

Permalink
feat(case-aggregations): add case severity and stage facets
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMaruchu committed Jun 9, 2020
1 parent ef0a8a0 commit 353172b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
65 changes: 62 additions & 3 deletions src/aggregations/case.aggregations.js
Expand Up @@ -234,6 +234,56 @@ export const CASE_FACET_NATIONALITIES = {
],
};

/**
* @constant
* @name CASE_FACET_STAGES
* @description Case stages facet
*
* @author Benson Maruchu<benmaruchu@gmail.com>
* @license MIT
* @since 0.9.0
* @version 0.1.0
*/
export const CASE_FACET_STAGES = {
stages: [
{
$group: {
_id: '$stage._id',
total: { $sum: 1 },
namespace: { $first: '$stage.namespace' },
name: { $first: '$stage.strings.name' },
weight: { $first: '$stage.numbers.weight' },
color: { $first: '$stage.strings.color' },
},
},
],
};

/**
* @constant
* @name CASE_FACET_SEVERITIES
* @description Case severities facet
*
* @author Benson Maruchu<benmaruchu@gmail.com>
* @license MIT
* @since 0.9.0
* @version 0.1.0
*/
export const CASE_FACET_SEVERITIES = {
severities: [
{
$group: {
_id: '$severity._id',
total: { $sum: 1 },
namespace: { $first: '$severity.namespace' },
name: { $first: '$severity.strings.name' },
weight: { $first: '$severity.numbers.weight' },
color: { $first: '$severity.strings.color' },
},
},
],
};

// start: aggregations
// order: base to specific

Expand Down Expand Up @@ -314,6 +364,8 @@ export const getEventCaseAnalysis = (criteria, done) => {
...CASE_FACET_AGE_GROUPS,
...CASE_FACET_OCCUPATIONS,
...CASE_FACET_NATIONALITIES,
...CASE_FACET_SEVERITIES,
...CASE_FACET_STAGES,
};

base.facet(facets);
Expand All @@ -322,9 +374,14 @@ export const getEventCaseAnalysis = (criteria, done) => {

// Normalize data
const normalize = (result, next) => {
const { gender, ageGroups, occupations, nationalities } = safeMergeObjects(
...result
);
const {
gender,
ageGroups,
occupations,
nationalities,
severities,
stages,
} = safeMergeObjects(...result);

// add upper boundary for returned age groups
const normalizedResultsAgeGroups = map(ageGroups, (group) => ({
Expand All @@ -347,6 +404,8 @@ export const getEventCaseAnalysis = (criteria, done) => {
ageGroups: normalizedAgeGroups,
occupations,
nationalities,
severities,
stages,
},
});

Expand Down
2 changes: 2 additions & 0 deletions test/integration/case.aggregations.spec.js
Expand Up @@ -23,6 +23,8 @@ describe('EventCase Aggregations', () => {
expect(report.data.overall.ageGroups).to.exist.and.be.an('array');
expect(report.data.overall.occupations).to.exist.and.be.an('array');
expect(report.data.overall.nationalities).to.exist.and.be.an('array');
expect(report.data.overall.severities).to.exist.and.be.an('array');
expect(report.data.overall.stages).to.exist.and.be.an('array');
expect(report.data.overall.ageGroups).to.have.lengthOf(16);
done(error, report);
});
Expand Down

0 comments on commit 353172b

Please sign in to comment.