Skip to content

Commit 098a394

Browse files
committed
add sample data to nextJS API routes
1 parent 61689e9 commit 098a394

File tree

10 files changed

+570
-257
lines changed
  • src
    • lib/AnalysisApps/GWAS/Utils
    • pages/api
      • cohort-stats/check-overlap/by-source-id/[sourceId]/by-cohort-definition-ids/[cohortAId]/[cohortBId]
      • cohortdefinition-stats/by-source-id/[sourceId]/by-team-project
      • concept-stats/by-source-id/[sourceId]/by-cohort-definition-id/[cohortDefinitionId]
      • concept/by-spurce-id/[sourceId]/by-type
      • histogram/by-source-id/[sourceId]/by-cohort-definition-id/[cohortDefinitionId]/by-histogram-concept-id/[selectedConceptId]

10 files changed

+570
-257
lines changed

src/lib/AnalysisApps/GWAS/Utils/cohortApi.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { gen3Api, GEN3_API } from '@gen3/core';
22

33
const TAGS = 'GWASApp';
4-
export const GEN3_COHORT_MIDDLEWARE_API = `${GEN3_API}/cohort-middleware`;
4+
export const GEN3_COHORT_MIDDLEWARE_API = process.env.NEXT_PUBLIC_GEN3_COHORT_MIDDLEWARE_API || `${GEN3_API}/cohort-middleware`;
55

66
const hareConceptId = 2000007027;
77

@@ -11,7 +11,7 @@ export const gwasCohortApiTags = gen3Api.enhanceEndpoints({
1111

1212
// Types for API calls
1313

14-
interface CohortOverlap {
14+
export interface CohortOverlap {
1515
cohort_overlap: {
1616
case_control_overlap: number;
1717
};
@@ -116,6 +116,18 @@ export interface GWASHistogramResponse {
116116
bins: Array<GWASHistogramBin>;
117117
}
118118

119+
/**
120+
* Adds a filter to the given covariate array to exclude individuals
121+
* who are members of both specified cohorts from analysis. This ensures that
122+
* overlapping members in the two cohorts are filtered out based on a
123+
* custom dichotomous variable.
124+
*
125+
* @param {number} cohortId - The identifier for the first cohort.
126+
* @param {number} otherCohortId - The identifier for the second cohort.
127+
* @param {Array<Covariates>} covariateArray - An array of covariate objects to which
128+
* the new filter will be added.
129+
* @returns {Array<Covariates>} A new array of covariate objects with the added filter.
130+
*/
119131
export const addCDFilter = (
120132
cohortId: number,
121133
otherCohortId: number,
@@ -135,6 +147,22 @@ export const addCDFilter = (
135147
return covariateRequest;
136148
};
137149

150+
/**
151+
* gwasCohortApi is a configuration object used to interact with the GWAS Cohort API.
152+
* It provides endpoints to query and transform data related to cohort definitions, sources,
153+
* covariates, histogram data, and cohort overlaps. Each endpoint is implemented as a query using
154+
* RTK Query `builder.query` and supports fetching and transforming of data for specific use cases.
155+
*
156+
* Endpoints included:
157+
* - getCohortDefinitions: Fetches cohort definitions and statistics by source ID and team project.
158+
* - getSources: Retrieves available data sources from the middleware API.
159+
* - getSourceId: Extracts the single source ID if only one source is available.
160+
* - getCovariates: Fetches covariates based on source ID and predefined concept types.
161+
* - getCovariateStats: Retrieves statistics for selected covariates for a given cohort definition.
162+
* - getConceptStatsByHareSubset: Fetches concept statistics for a subset of covariates broken down by HARE concept.
163+
* - getHistogramInfo: Retrieves histogram data for selected covariates, outcomes, and cohorts.
164+
* - getSimpleOverlapInfo: Checks the overlap between two cohorts for selected covariates and outcomes.
165+
*/
138166
export const gwasCohortApi = gwasCohortApiTags.injectEndpoints({
139167
endpoints: (builder) => ({
140168
getCohortDefinitions: builder.query<

src/lib/AnalysisApps/GWAS/Utils/data/histogram.js

Lines changed: 0 additions & 254 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { NextApiRequest, NextApiResponse } from 'next';
2+
import { CohortOverlap } from '@/lib/AnalysisApps/GWAS/Utils/cohortApi';
3+
4+
interface PathParameters {
5+
sourceId: string;
6+
cohortAId: string;
7+
cohortBId: string;
8+
}
9+
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
10+
// Get the sourceId from the slug in the path
11+
const { query } = req;
12+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
13+
const { sourceId, cohortAId, cohortBId } = query as unknown as PathParameters; // messy but this is for development
14+
15+
const data: Record<string, Record<string, CohortOverlap>> = {
16+
'1537': {
17+
'446': { cohort_overlap: { case_control_overlap: 236021 } },
18+
'2356': { cohort_overlap: { case_control_overlap: 236021 } },
19+
},
20+
'446': {
21+
'2356': { cohort_overlap: { case_control_overlap: 648242 } },
22+
},
23+
};
24+
25+
if (data[cohortAId] && data[cohortAId][cohortBId]) {
26+
return res.status(200).json(data[cohortAId][cohortBId]);
27+
}
28+
if (data[cohortBId] && data[cohortBId][cohortAId]) {
29+
return res.status(200).json(data[cohortBId][cohortAId]);
30+
}
31+
return res.status(200).json({ cohort_overlap: { case_control_overlap: 648242 }});
32+
33+
};
34+
export default handler;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { NextApiRequest, NextApiResponse } from 'next';
2+
3+
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
4+
5+
// Get the sourceId from the slug in the path
6+
// const { query } = req;
7+
// const { sourceId } = query;
8+
return res.status(200).json({
9+
cohort_definitions_and_stats: [
10+
{
11+
cohort_definition_id: 573,
12+
cohort_name: 'team2 - test new cohort - catch all',
13+
size: 70240,
14+
},
15+
{
16+
cohort_definition_id: 559,
17+
cohort_name: 'test new cohort - catch all',
18+
size: 70240,
19+
},
20+
{
21+
cohort_definition_id: 574,
22+
cohort_name: 'team2 - test new cohort - medium + large',
23+
size: 23800,
24+
},
25+
{
26+
cohort_definition_id: 575,
27+
cohort_name: 'team2 - test new cohort - small',
28+
size: 80,
29+
},
30+
],
31+
});
32+
};
33+
export default handler;

0 commit comments

Comments
 (0)