Skip to content

Commit

Permalink
feat: SKFP-1208 add ethnicity in statistics endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
celinepelletier committed Aug 30, 2024
1 parent d38cee5 commit cd56afb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ describe('Express app (without Arranger)', () => {
'Native Hawaiian or Other Pacific Islander': 8,
'not available': 3,
},
ethnicity: {
'Not Hispanic or Latino': 20460,
NoInformation: 6263,
'Hispanic or Latino': 4107,
'not available': 1419,
unknown: 775,
},
diagnosis: [
{
mondo_id: 'speech disorder (MONDO:0004730)',
Expand Down
11 changes: 10 additions & 1 deletion src/endpoints/statistics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type Statistics = {
sex: Record<string, number>;
downSyndromeStatus: Record<string, number>;
race: Record<string, number>;
ethnicity: Record<string, number>;
diagnosis: Diagnosis[];
};

Expand Down Expand Up @@ -224,6 +225,8 @@ export const fetchDemographicsStats = async (client: Client): Promise<Record<str
{ size: 0, aggs: { down_syndrome_status: { terms: { field: 'down_syndrome_status', size: 10 } } } },
{ index: esParticipantIndex },
{ size: 0, aggs: { race: { terms: { field: 'race', size: 20 } } } },
{ index: esParticipantIndex },
{ size: 0, aggs: { ethnicity: { terms: { field: 'ethnicity', size: 20 } } } },
],
});

Expand All @@ -243,7 +246,12 @@ export const fetchDemographicsStats = async (client: Client): Promise<Record<str
return acc;
}, {});

return [sex, downSyndromeStatus, race];
const ethnicity = response.body.responses[3].aggregations.ethnicity.buckets.reduce((acc, curr) => {
acc[curr.key] = curr.doc_count;
return acc;
}, {});

return [sex, downSyndromeStatus, race, ethnicity];
};

export const fetchTopDiagnosis = async (client: Client): Promise<Diagnosis[]> => {
Expand Down Expand Up @@ -322,6 +330,7 @@ export const getStatistics = async (): Promise<Statistics> => {
sex: results[9][0],
downSyndromeStatus: results[9][1],
race: results[9][2],
ethnicity: results[9][3],
diagnosis,
};
};
Expand Down

0 comments on commit cd56afb

Please sign in to comment.