Skip to content

Commit 7813153

Browse files
authored
Merge pull request #3370 from OpenNeuroOrg/update/nihbi-participant-count
adding participant count for brain initiative
2 parents 6564ab5 + c124c42 commit 7813153

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

packages/openneuro-app/src/scripts/pages/front-page/aggregate-queries/aggregate-counts-container.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ const AggregateCountsContainer: React.FC<AggregateCountsContainerProps> = ({
2929
else {
3030
return (
3131
<>
32-
{participantData.participantCount > 0 && (
33-
<AggregateCount
34-
type="participants"
35-
count={participantData.participantCount}
36-
/>
37-
)}
32+
<AggregateCount
33+
type="participants"
34+
count={participantData.participantCount}
35+
/>
36+
3837
<AggregateCount
3938
type="publicDataset"
4039
count={publicDatasetsData.datasets?.pageInfo?.count ||

packages/openneuro-server/src/graphql/resolvers/snapshots.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,28 +136,43 @@ export const undoDeprecateSnapshot = async (
136136
}
137137

138138
export const participantCount = (obj, { modality }) => {
139+
const cacheKey = modality === "NIH" ? "NIH" : modality || "all"
139140
const cache = new CacheItem(
140141
redis,
141142
CacheType.participantCount,
142-
[modality || "all"],
143+
[cacheKey],
143144
3600,
144145
)
146+
145147
return cache.get(async () => {
146148
const queryHasSubjects = {
147-
"summary.subjects": {
148-
$exists: true,
149-
},
149+
"summary.subjects": { $exists: true },
150150
}
151-
const matchQuery = modality
152-
? {
151+
152+
let matchQuery: Record<string, unknown> = queryHasSubjects
153+
154+
if (modality && modality !== "NIH") {
155+
matchQuery = {
153156
$and: [
154157
queryHasSubjects,
155158
{
156159
"summary.modalities": modality,
157160
},
158161
],
159162
}
160-
: queryHasSubjects
163+
} else if (modality === "NIH") {
164+
// When modality is 'NIH', we don't filter by a specific modality.
165+
// Instead, we query for datasets that have any modality within the NIH portal
166+
matchQuery = {
167+
$and: [
168+
queryHasSubjects,
169+
{
170+
"summary.modalities": { $exists: true },
171+
},
172+
],
173+
}
174+
}
175+
161176
const aggregateResult = await DatasetModel.aggregate([
162177
{
163178
$match: {
@@ -198,8 +213,12 @@ export const participantCount = (obj, { modality }) => {
198213
},
199214
},
200215
]).exec()
201-
if (aggregateResult.length) return aggregateResult[0].participantCount
202-
else return 0
216+
217+
if (aggregateResult.length) {
218+
return aggregateResult[0].participantCount
219+
} else {
220+
return 0
221+
}
203222
})
204223
}
205224

0 commit comments

Comments
 (0)