@@ -11,38 +11,29 @@ export const gwasCohortApiTags = gen3Api.enhanceEndpoints({
11
11
12
12
// Types for API calls
13
13
14
- interface ConceptOutcome {
15
- size : number ,
16
- variable_type : string ,
17
- concept_id : number ,
18
- concept_name : string ,
19
- }
20
-
21
- interface CohortDefinitionQueryParams {
22
- sourceId : string ;
23
- selectedTeamProject : string ;
14
+ interface CohortOverlap {
15
+ cohort_overlap : {
16
+ case_control_overlap : number ;
17
+ } ;
24
18
}
25
19
26
- interface CovariateQueryParams {
27
- sourceId : number ;
28
- cohortDefinitionId : string ;
29
- selectedCovariateIds : Array < string > ;
20
+ interface ConceptOutcome {
21
+ size : number ;
22
+ variable_type : string ;
23
+ concept_id : number ;
24
+ concept_name : string ;
30
25
}
31
26
32
27
interface Covariates {
33
28
variable_type : string ;
34
- provided_name : string ,
35
- cohort_sizes : [ number , number ] ,
36
- cohort_names : [ string , string ] ,
37
- cohort_ids : [ number , number ] ,
29
+ provided_name : string ;
30
+ cohort_ids : [ number , number ] ;
38
31
}
39
32
40
- interface HistogramQueryParams {
41
- sourceId : number ,
42
- cohortId : number ,
43
- selectedCovariates : Array < Covariates > ,
44
- outcome : ConceptOutcome ,
45
- selectedConceptId : number ,
33
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
+ interface CovariateStats extends Covariates {
35
+ cohort_sizes : [ number , number ] ;
36
+ cohort_names : [ string , string ] ;
46
37
}
47
38
48
39
interface ConceptStatsByHareSubset {
@@ -52,22 +43,12 @@ interface ConceptStatsByHareSubset {
52
43
outcome : Array < ConceptOutcome > ;
53
44
}
54
45
55
-
56
-
57
46
export interface GWASCohortDefinition {
58
47
cohort_definition_id : number ;
59
48
cohort_name : string ;
60
49
size : number ;
61
50
}
62
51
63
- export interface GWASCohortDefinitionResponse {
64
- cohort_definitions_and_stats : Array < GWASCohortDefinition > ;
65
- }
66
-
67
- interface SourcesResponse {
68
- sources : Array < { source_id : string ; source_name : string } > ;
69
- }
70
-
71
52
interface CovariateConceptTypeAndId {
72
53
concept_type : string ;
73
54
concept_id : number ;
@@ -79,11 +60,53 @@ interface CovariateInformation extends CovariateConceptTypeAndId {
79
60
concept_name : string ;
80
61
}
81
62
63
+ /**
64
+ * Query Parameters for the rtkQueries below
65
+ */
66
+
67
+ interface CohortDefinitionQueryParams {
68
+ sourceId : string ;
69
+ selectedTeamProject : string ;
70
+ }
71
+
72
+ interface CovariateQueryParams {
73
+ sourceId : number ;
74
+ cohortDefinitionId : string ;
75
+ selectedCovariateIds : Array < string > ;
76
+ }
77
+
78
+ interface HistogramQueryParams {
79
+ sourceId : number ;
80
+ cohortId : number ;
81
+ selectedCovariates : Array < Covariates > ;
82
+ outcome : ConceptOutcome ;
83
+ selectedConceptId : number ;
84
+ }
85
+
86
+ interface OverlapQueryParams {
87
+ sourceId : number ;
88
+ cohortAId : number ;
89
+ cohortBId : number ;
90
+ selectedCovariates : Array < Covariates > ;
91
+ outcome : ConceptOutcome ;
92
+ }
93
+
94
+ /**
95
+ * Responses from queries below
96
+ */
97
+ export interface GWASCohortDefinitionResponse {
98
+ cohort_definitions_and_stats : Array < GWASCohortDefinition > ;
99
+ }
100
+
101
+ interface SourcesResponse {
102
+ sources : Array < { source_id : string ; source_name : string } > ;
103
+ }
104
+
82
105
interface CovariateResponse {
83
106
covariates : Array < CovariateInformation > ;
84
107
}
85
108
86
- export interface GWASHistogramBin {
109
+ export interface GWASHistogramBin {
87
110
start : number ;
88
111
end : number ;
89
112
personCount : number ;
@@ -93,12 +116,16 @@ export interface GWASHistogramResponse {
93
116
bins : Array < GWASHistogramBin > ;
94
117
}
95
118
96
- export const addCDFilter = ( cohortId : number , otherCohortId : number , covariateArray : Array < CovariateInformation > ) => {
119
+ export const addCDFilter = (
120
+ cohortId : number ,
121
+ otherCohortId : number ,
122
+ covariateArray : Array < Covariates > ,
123
+ ) => {
97
124
// adding an extra filter on top of the given covariateArr
98
125
// to ensure that any person that belongs to _both_ cohorts
99
126
// [cohortId, otherCohortId] also gets filtered out:
100
127
const covariateRequest = [ ...covariateArray ] ;
101
- const cdFilter = {
128
+ const cdFilter : Covariates = {
102
129
variable_type : 'custom_dichotomous' ,
103
130
cohort_ids : [ cohortId , otherCohortId ] ,
104
131
provided_name :
@@ -108,7 +135,6 @@ export const addCDFilter = (cohortId: number, otherCohortId: number, covariateAr
108
135
return covariateRequest ;
109
136
} ;
110
137
111
-
112
138
export const gwasCohortApi = gwasCohortApiTags . injectEndpoints ( {
113
139
endpoints : ( builder ) => ( {
114
140
getCohortDefinitions : builder . query <
@@ -167,9 +193,9 @@ export const gwasCohortApi = gwasCohortApiTags.injectEndpoints({
167
193
string ,
168
194
ConceptStatsByHareSubset
169
195
> ( {
170
- query : ( { outcome, cohortDefinitionId, subsetCovariates, sourceId } ) => {
196
+ query : ( { outcome, cohortDefinitionId, subsetCovariates, sourceId } ) => {
171
197
const variablesPayload = {
172
- variables : [ . outcome , ...subsetCovariates ] ,
198
+ variables : [ outcome , ...subsetCovariates ] ,
173
199
} ;
174
200
return {
175
201
url : `${ GEN3_COHORT_MIDDLEWARE_API } /concept-stats/by-source-id/${ sourceId } /by-cohort-definition-id/${ cohortDefinitionId } /breakdown-by-concept-id/${ hareConceptId } ` ,
@@ -209,6 +235,34 @@ export const gwasCohortApi = gwasCohortApiTags.injectEndpoints({
209
235
} ;
210
236
} ,
211
237
} ) ,
238
+ getSimpleOverlapInfo : builder . query < CohortOverlap , OverlapQueryParams > ( {
239
+ query : ( {
240
+ sourceId,
241
+ cohortAId,
242
+ cohortBId,
243
+ selectedCovariates,
244
+ outcome,
245
+ } ) => {
246
+ const variablesPayload = {
247
+ variables : [
248
+ ...selectedCovariates ,
249
+ outcome ,
250
+ // add extra filter to make sure we only count persons that have a HARE group as well:
251
+ {
252
+ variable_type : 'concept' ,
253
+ concept_id : hareConceptId ,
254
+ } ,
255
+ ] . filter ( Boolean ) , // filter out any undefined or null items (e.g. in some
256
+ // scenarios "outcome" and "selectedCovariates" are still null and/or empty)
257
+ } ;
258
+
259
+ return {
260
+ url : `${ GEN3_COHORT_MIDDLEWARE_API } /cohort-stats/check-overlap/by-source-id/${ sourceId } /by-cohort-definition-ids/${ cohortAId } /${ cohortBId } ` ,
261
+ method : 'POST' ,
262
+ body : JSON . stringify ( variablesPayload ) ,
263
+ } ;
264
+ } ,
265
+ } ) ,
212
266
} ) ,
213
267
} ) ;
214
268
@@ -219,4 +273,6 @@ export const {
219
273
useGetCovariatesQuery,
220
274
useGetCovariateStatsQuery,
221
275
useGetConceptStatsByHareSubsetQuery,
276
+ useGetHistogramInfoQuery,
277
+ useGetSimpleOverlapInfoQuery,
222
278
} = gwasCohortApi ;
0 commit comments