@@ -11,6 +11,13 @@ 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
+
14
21
interface CohortDefinitionQueryParams {
15
22
sourceId : string ;
16
23
selectedTeamProject : string ;
@@ -22,13 +29,31 @@ interface CovariateQueryParams {
22
29
selectedCovariateIds : Array < string > ;
23
30
}
24
31
32
+ interface Covariates {
33
+ variable_type : string ;
34
+ provided_name : string ,
35
+ cohort_sizes : [ number , number ] ,
36
+ cohort_names : [ string , string ] ,
37
+ cohort_ids : [ number , number ] ,
38
+ }
39
+
40
+ interface HistogramQueryParams {
41
+ sourceId : number ,
42
+ cohortId : number ,
43
+ selectedCovariates : Array < Covariates > ,
44
+ outcome : ConceptOutcome ,
45
+ selectedConceptId : number ,
46
+ }
47
+
25
48
interface ConceptStatsByHareSubset {
26
49
sourceId : number ;
27
- cohortDefinitionId : string ;
50
+ cohortDefinitionId : number ;
28
51
subsetCovariates : string ;
29
- outcome : Array < string > ;
52
+ outcome : Array < ConceptOutcome > ;
30
53
}
31
54
55
+
56
+
32
57
export interface GWASCohortDefinition {
33
58
cohort_definition_id : number ;
34
59
cohort_name : string ;
@@ -43,18 +68,47 @@ interface SourcesResponse {
43
68
sources : Array < { source_id : string ; source_name : string } > ;
44
69
}
45
70
46
- interface CovariateInformation {
71
+ interface CovariateConceptTypeAndId {
72
+ concept_type : string ;
47
73
concept_id : number ;
74
+ }
75
+
76
+ interface CovariateInformation extends CovariateConceptTypeAndId {
48
77
prefixed_concept_id : string ;
49
78
concept_code : string ;
50
79
concept_name : string ;
51
- concept_type : string ;
52
80
}
53
81
54
82
interface CovariateResponse {
55
83
covariates : Array < CovariateInformation > ;
56
84
}
57
85
86
+ export interface GWASHistogramBin {
87
+ start : number ;
88
+ end : number ;
89
+ personCount : number ;
90
+ }
91
+
92
+ export interface GWASHistogramResponse {
93
+ bins : Array < GWASHistogramBin > ;
94
+ }
95
+
96
+ export const addCDFilter = ( cohortId : number , otherCohortId : number , covariateArray : Array < CovariateInformation > ) => {
97
+ // adding an extra filter on top of the given covariateArr
98
+ // to ensure that any person that belongs to _both_ cohorts
99
+ // [cohortId, otherCohortId] also gets filtered out:
100
+ const covariateRequest = [ ...covariateArray ] ;
101
+ const cdFilter = {
102
+ variable_type : 'custom_dichotomous' ,
103
+ cohort_ids : [ cohortId , otherCohortId ] ,
104
+ provided_name :
105
+ 'auto_generated_extra_item_to_filter_out_case_control_overlap' ,
106
+ } ;
107
+ covariateRequest . push ( cdFilter ) ;
108
+ return covariateRequest ;
109
+ } ;
110
+
111
+
58
112
export const gwasCohortApi = gwasCohortApiTags . injectEndpoints ( {
59
113
endpoints : ( builder ) => ( {
60
114
getCohortDefinitions : builder . query <
@@ -101,24 +155,55 @@ export const gwasCohortApi = gwasCohortApiTags.injectEndpoints({
101
155
} ) ,
102
156
} ) ,
103
157
getCovariateStats : builder . query < string , CovariateQueryParams > ( {
104
- query : ( params : CovariateQueryParams ) => ( {
105
- url : `${ GEN3_COHORT_MIDDLEWARE_API } /concept-stats/by-source-id/${ params . sourceId } /by-cohort-definition-id/${ params . cohortDefinitionId } ` ,
158
+ query : ( { sourceId , cohortDefinitionId , selectedCovariateIds } ) => ( {
159
+ url : `${ GEN3_COHORT_MIDDLEWARE_API } /concept-stats/by-source-id/${ sourceId } /by-cohort-definition-id/${ cohortDefinitionId } ` ,
106
160
method : 'POST' ,
107
161
body : JSON . stringify ( {
108
- ConceptIds : params . selectedCovariateIds ,
162
+ ConceptIds : selectedCovariateIds ,
109
163
} ) ,
110
164
} ) ,
111
165
} ) ,
112
166
getConceptStatsByHareSubset : builder . query <
113
167
string ,
114
168
ConceptStatsByHareSubset
115
169
> ( {
116
- query : ( params : ConceptStatsByHareSubset ) => {
170
+ query : ( { outcome, cohortDefinitionId, subsetCovariates, sourceId } ) => {
171
+ const variablesPayload = {
172
+ variables : [ . outcome , ...subsetCovariates ] ,
173
+ } ;
174
+ return {
175
+ url : `${ GEN3_COHORT_MIDDLEWARE_API } /concept-stats/by-source-id/${ sourceId } /by-cohort-definition-id/${ cohortDefinitionId } /breakdown-by-concept-id/${ hareConceptId } ` ,
176
+ method : 'POST' ,
177
+ body : JSON . stringify ( variablesPayload ) ,
178
+ } ;
179
+ } ,
180
+ } ) ,
181
+ getHistogramInfo : builder . query <
182
+ GWASHistogramResponse ,
183
+ HistogramQueryParams
184
+ > ( {
185
+ query : ( {
186
+ sourceId,
187
+ cohortId,
188
+ selectedCovariates,
189
+ outcome,
190
+ selectedConceptId,
191
+ } ) => {
117
192
const variablesPayload = {
118
- variables : [ params . outcome , ...params . subsetCovariates ] ,
193
+ variables : [
194
+ ...selectedCovariates ,
195
+ outcome ,
196
+ // add extra filter to make sure we only count persons that have a HARE group as well:
197
+ {
198
+ variable_type : 'concept' ,
199
+ concept_id : hareConceptId ,
200
+ } ,
201
+ ] . filter ( Boolean ) , // filter out any undefined or null items (e.g. in some
202
+ // scenarios "outcome" and "selectedCovariates" are still null and/or empty)
119
203
} ;
204
+
120
205
return {
121
- url : `${ GEN3_COHORT_MIDDLEWARE_API } /concept-stats /by-source-id/${ params . sourceId } /by-cohort-definition-id/${ params . cohortDefinitionId } /breakdown- by-concept-id/${ hareConceptId } ` ,
206
+ url : `${ GEN3_COHORT_MIDDLEWARE_API } /histogram /by-source-id/${ sourceId } /by-cohort-definition-id/${ cohortId } / by-histogram- concept-id/${ selectedConceptId } ` ,
122
207
method : 'POST' ,
123
208
body : JSON . stringify ( variablesPayload ) ,
124
209
} ;
@@ -133,4 +218,5 @@ export const {
133
218
useGetSourceIdQuery,
134
219
useGetCovariatesQuery,
135
220
useGetCovariateStatsQuery,
221
+ useGetConceptStatsByHareSubsetQuery,
136
222
} = gwasCohortApi ;
0 commit comments