Skip to content

Commit

Permalink
fix: SJIP-625 extract in function
Browse files Browse the repository at this point in the history
  • Loading branch information
celinepelletier committed Oct 26, 2023
1 parent 0ec9d47 commit 0440e57
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/reports/biospecimen-request/biospecimenRequestStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const biospecimenRequestStats = async (req: Request, res: Response): Promise<voi
biospecimenDatasByStudy.push({
study_code: biospecimen.study.study_code,
study_name: biospecimen.study.study_name,
nb_participants: new Set(biospecimenForStudy.map(b => b.participant_fhir_id)).size,
nb_available_samples: new Set(biospecimenForStudy.map(b => b.sample_id)).size,
nb_containers: new Set(biospecimenForStudy.map(b => b.container_id).filter(c => c)).size,
nb_participants: countDistinct(biospecimenForStudy.map(b => b.participant_fhir_id)),
nb_available_samples: countDistinct(biospecimenForStudy.map(b => b.sample_id)),
nb_containers: countDistinct(biospecimenForStudy.map(b => b.container_id).filter(c => c)),
});
}
}
Expand All @@ -59,4 +59,6 @@ const biospecimenRequestStats = async (req: Request, res: Response): Promise<voi
console.timeEnd('biospecimenRequestStats');
};

const countDistinct = (array: string[]) => new Set(array).size;

export default biospecimenRequestStats;

0 comments on commit 0440e57

Please sign in to comment.