1
- import { gen3Api , GEN3_API } from '@gen3/core' ;
1
+ import { gen3Api , GEN3_API } from '@gen3/core' ;
2
2
3
3
const TAGS = 'GWASApp' ;
4
4
export const GEN3_COHORT_MIDDLEWARE_API = `${ GEN3_API } /cohort-middleware` ;
@@ -16,6 +16,19 @@ interface CohortDefinitionQueryParams {
16
16
selectedTeamProject : string ;
17
17
}
18
18
19
+ interface CovariateQueryParams {
20
+ sourceId : number ;
21
+ cohortDefinitionId : string ;
22
+ selectedCovariateIds : Array < string > ;
23
+ }
24
+
25
+ interface ConceptStatsByHareSubset {
26
+ sourceId : number ;
27
+ cohortDefinitionId : string ;
28
+ subsetCovariates : string ;
29
+ outcome : Array < string > ;
30
+ }
31
+
19
32
export interface GWASCohortDefinition {
20
33
cohort_definition_id : number ;
21
34
cohort_name : string ;
@@ -27,18 +40,29 @@ export interface GWASCohortDefinitionResponse {
27
40
}
28
41
29
42
interface SourcesResponse {
30
- sources : Array < { source_id : string , source_name : string } >
43
+ sources : Array < { source_id : string ; source_name : string } > ;
31
44
}
32
45
33
- export const gwasCohortApi = gwasCohortApiTags . injectEndpoints ( {
34
- endpoints : ( builder ) => ( {
46
+ interface CovariateInformation {
47
+ concept_id : number ;
48
+ prefixed_concept_id : string ;
49
+ concept_code : string ;
50
+ concept_name : string ;
51
+ concept_type : string ;
52
+ }
35
53
54
+ interface CovariateResponse {
55
+ covariates : Array < CovariateInformation > ;
56
+ }
36
57
37
- getCohortDefinitions : builder . query < GWASCohortDefinitionResponse , CohortDefinitionQueryParams > ( {
38
- query : ( {
39
- sourceId,
40
- selectedTeamProject
41
- } ) => `${ GEN3_COHORT_MIDDLEWARE_API } /cohortdefinition-stats/by-source-id/${ sourceId } /by-team-project?team-project=${ selectedTeamProject } ` ,
58
+ export const gwasCohortApi = gwasCohortApiTags . injectEndpoints ( {
59
+ endpoints : ( builder ) => ( {
60
+ getCohortDefinitions : builder . query <
61
+ GWASCohortDefinitionResponse ,
62
+ CohortDefinitionQueryParams
63
+ > ( {
64
+ query : ( { sourceId, selectedTeamProject } ) =>
65
+ `${ GEN3_COHORT_MIDDLEWARE_API } /cohortdefinition-stats/by-source-id/${ sourceId } /by-team-project?team-project=${ selectedTeamProject } ` ,
42
66
transformResponse : ( response : Record < string , never > ) => {
43
67
// confirm data is valid
44
68
if ( ! response || typeof response !== 'object' ) {
@@ -47,13 +71,15 @@ export const gwasCohortApi = gwasCohortApiTags.injectEndpoints({
47
71
if ( ! ( 'cohort_definitions_and_stats' in response ) ) {
48
72
throw new Error ( 'Missing field cohort_definitions_and_stats' ) ;
49
73
}
50
- return { cohort_definitions_and_stats : response . cohort_definitions_and_stats } ;
74
+ return {
75
+ cohort_definitions_and_stats : response . cohort_definitions_and_stats ,
76
+ } ;
51
77
} ,
52
78
} ) ,
53
- getSources : builder . query < SourcesResponse , void > ( {
79
+ getSources : builder . query < SourcesResponse , void > ( {
54
80
query : ( ) => `${ GEN3_COHORT_MIDDLEWARE_API } /sources` ,
55
81
} ) ,
56
- getSourceId : builder . query < string , void > ( {
82
+ getSourceId : builder . query < string , void > ( {
57
83
query : ( ) => `${ GEN3_COHORT_MIDDLEWARE_API } /sources` ,
58
84
transformResponse : ( response : SourcesResponse ) => {
59
85
if ( Array . isArray ( response ?. sources ) && response . sources . length === 1 ) {
@@ -63,14 +89,48 @@ export const gwasCohortApi = gwasCohortApiTags.injectEndpoints({
63
89
${ JSON . stringify ( response ?. sources ) } ` ;
64
90
throw new Error ( message ) ;
65
91
}
66
- }
67
- } )
92
+ } ,
93
+ } ) ,
94
+ getCovariates : builder . query < CovariateResponse , string > ( {
95
+ query : ( sourceId : string ) => ( {
96
+ url : `${ GEN3_COHORT_MIDDLEWARE_API } /concept/by-source-id/${ sourceId } /by-type` ,
97
+ method : 'POST' ,
98
+ body : JSON . stringify ( {
99
+ ConceptTypes : [ 'MVP Continuous' ] ,
100
+ } ) ,
101
+ } ) ,
102
+ } ) ,
103
+ 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 } ` ,
106
+ method : 'POST' ,
107
+ body : JSON . stringify ( {
108
+ ConceptIds : params . selectedCovariateIds ,
109
+ } ) ,
110
+ } ) ,
111
+ } ) ,
112
+ getConceptStatsByHareSubset : builder . query <
113
+ string ,
114
+ ConceptStatsByHareSubset
115
+ > ( {
116
+ query : ( params : ConceptStatsByHareSubset ) => {
117
+ const variablesPayload = {
118
+ variables : [ params . outcome , ...params . subsetCovariates ] ,
119
+ } ;
120
+ 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 } ` ,
122
+ method : 'POST' ,
123
+ body : JSON . stringify ( variablesPayload ) ,
124
+ } ;
125
+ } ,
126
+ } ) ,
68
127
} ) ,
69
128
} ) ;
70
129
71
-
72
130
export const {
73
131
useGetCohortDefinitionsQuery,
74
132
useGetSourcesQuery,
75
133
useGetSourceIdQuery,
134
+ useGetCovariatesQuery,
135
+ useGetCovariateStatsQuery,
76
136
} = gwasCohortApi ;
0 commit comments