Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: SKFP-1208 add ethnicity in statistics endpoint #190

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading