@@ -38,11 +38,7 @@ func (u CohortDataController) RetrieveHistogramForCohortIdAndConceptId(c *gin.Co
38
38
39
39
// parse cohortPairs separately as well, so we can validate permissions
40
40
_ , cohortPairs := utils .GetConceptDefsAndValuesAndCohortPairsAsSeparateLists (conceptIdsAndCohortPairs )
41
- if err != nil {
42
- c .JSON (http .StatusInternalServerError , gin.H {"message" : "Error parsing request body for prefixed concept ids" , "error" : err .Error ()})
43
- c .Abort ()
44
- return
45
- }
41
+
46
42
validAccessRequest := u .teamProjectAuthz .TeamProjectValidation (c , []int {cohortId }, cohortPairs )
47
43
if ! validAccessRequest {
48
44
log .Printf ("Error: invalid request" )
@@ -69,22 +65,15 @@ func (u CohortDataController) RetrieveHistogramForCohortIdAndConceptId(c *gin.Co
69
65
}
70
66
71
67
func (u CohortDataController ) RetrieveStatsForCohortIdAndConceptId (c * gin.Context ) {
72
- sourceIdStr := c .Param ("sourceid" )
73
- log .Printf ("Querying source: %s" , sourceIdStr )
74
- cohortIdStr := c .Param ("cohortid" )
75
- log .Printf ("Querying cohort for cohort definition id: %s" , cohortIdStr )
76
- conceptIdStr := c .Param ("conceptid" )
77
- if sourceIdStr == "" || cohortIdStr == "" || conceptIdStr == "" {
78
- c .JSON (http .StatusBadRequest , gin.H {"message" : "bad request" })
68
+ sourceId , cohortId , conceptIdsAndCohortPairs , err := utils .ParseSourceIdAndCohortIdAndVariablesAsSingleList (c )
69
+ if err != nil {
70
+ c .JSON (http .StatusBadRequest , gin.H {"message" : "bad request" , "error" : err .Error ()})
79
71
c .Abort ()
80
72
return
81
73
}
82
74
83
- filterConceptIdsAndValues , cohortPairs , _ := utils .ParseConceptDefsAndDichotomousDefs (c )
84
-
85
- sourceId , _ := strconv .Atoi (sourceIdStr )
86
- cohortId , _ := strconv .Atoi (cohortIdStr )
87
- conceptId , _ := strconv .ParseInt (conceptIdStr , 10 , 64 )
75
+ // parse cohortPairs separately as well, so we can validate permissions
76
+ _ , cohortPairs := utils .GetConceptDefsAndValuesAndCohortPairsAsSeparateLists (conceptIdsAndCohortPairs )
88
77
89
78
validAccessRequest := u .teamProjectAuthz .TeamProjectValidation (c , []int {cohortId }, cohortPairs )
90
79
if ! validAccessRequest {
@@ -94,7 +83,7 @@ func (u CohortDataController) RetrieveStatsForCohortIdAndConceptId(c *gin.Contex
94
83
return
95
84
}
96
85
97
- cohortData , err := u .cohortDataModel .RetrieveHistogramDataBySourceIdAndCohortIdAndConceptDefsAndCohortPairs (sourceId , cohortId , conceptId , filterConceptIdsAndValues , cohortPairs )
86
+ cohortData , err := u .cohortDataModel .RetrieveHistogramDataBySourceIdAndCohortIdAndConceptDefsPlusCohortPairs (sourceId , cohortId , conceptIdsAndCohortPairs )
98
87
if err != nil {
99
88
c .JSON (http .StatusInternalServerError , gin.H {"message" : "Error retrieving concept details" , "error" : err .Error ()})
100
89
c .Abort ()
@@ -105,37 +94,30 @@ func (u CohortDataController) RetrieveStatsForCohortIdAndConceptId(c *gin.Contex
105
94
for _ , personData := range cohortData {
106
95
conceptValues = append (conceptValues , float64 (* personData .ConceptValueAsNumber ))
107
96
}
97
+ conceptToStat , errGetLast := utils .CheckAndGetLastCustomConceptVariableDef (conceptIdsAndCohortPairs )
98
+ if errGetLast != nil {
99
+ c .JSON (http .StatusInternalServerError , gin.H {"message" : "Error: last variable should be of numeric type" , "error" : errGetLast .Error ()})
100
+ c .Abort ()
101
+ return
102
+ }
108
103
109
- statsData := utils .GenerateStatsData (cohortId , conceptId , conceptValues )
104
+ statsData := utils .GenerateStatsData (cohortId , conceptToStat . ConceptId , conceptValues )
110
105
111
106
c .JSON (http .StatusOK , gin.H {"statsData" : statsData })
112
107
}
113
108
114
109
func (u CohortDataController ) RetrieveDataBySourceIdAndCohortIdAndVariables (c * gin.Context ) {
115
110
// TODO - add some validation to ensure that only calls from Argo are allowed through since it outputs FULL data?
116
-
117
- // parse and validate all parameters:
118
- sourceIdStr := c .Param ("sourceid" )
119
- log .Printf ("Querying source: %s" , sourceIdStr )
120
- cohortIdStr := c .Param ("cohortid" )
121
- log .Printf ("Querying cohort for cohort definition id: %s" , cohortIdStr )
122
- if sourceIdStr == "" || cohortIdStr == "" {
123
- c .JSON (http .StatusBadRequest , gin.H {"message" : "bad request" })
124
- c .Abort ()
125
- return
126
- }
127
-
128
- conceptIdsAndValues , cohortPairs , err := utils .ParseConceptDefsAndDichotomousDefs (c )
129
- conceptIds := utils .ExtractConceptIdsFromCustomConceptVariablesDef (conceptIdsAndValues )
130
-
111
+ // -> this concern is considered to be addressed by https://github.com/uc-cdis/cloud-automation/pull/1884
112
+ sourceId , cohortId , conceptDefsAndCohortPairs , err := utils .ParseSourceIdAndCohortIdAndVariablesAsSingleList (c )
131
113
if err != nil {
132
- c .JSON (http .StatusInternalServerError , gin.H {"message" : "Error parsing request body for prefixed concept ids and dichotomous Ids " , "error" : err .Error ()})
114
+ c .JSON (http .StatusBadRequest , gin.H {"message" : "bad request" , "error" : err .Error ()})
133
115
c .Abort ()
134
116
return
135
117
}
136
118
137
- sourceId , _ := strconv . Atoi ( sourceIdStr )
138
- cohortId , _ := strconv . Atoi ( cohortIdStr )
119
+ // parse cohortPairs separately as well, so we can validate permissions
120
+ conceptDefs , cohortPairs := utils . GetConceptDefsAndValuesAndCohortPairsAsSeparateLists ( conceptDefsAndCohortPairs )
139
121
140
122
validAccessRequest := u .teamProjectAuthz .TeamProjectValidation (c , []int {cohortId }, cohortPairs )
141
123
if ! validAccessRequest {
@@ -145,17 +127,32 @@ func (u CohortDataController) RetrieveDataBySourceIdAndCohortIdAndVariables(c *g
145
127
return
146
128
}
147
129
148
- // call model method:
149
- cohortData , err := u .cohortDataModel .RetrieveDataBySourceIdAndCohortIdAndConceptIdsOrderedByPersonId (sourceId , cohortId , conceptIds )
150
- if err != nil {
151
- c .JSON (http .StatusInternalServerError , gin.H {"message" : "Error retrieving concept details" , "error" : err .Error ()})
152
- c .Abort ()
153
- return
130
+ // Iterate over conceptDefsAndCohortPairs and collect the concept values for each person:
131
+ // {PersonId:1, ConceptId:1, ConceptValue: "A value with, comma!"},
132
+ // {PersonId:1, ConceptId:2, ConceptValue: B},
133
+ // {PersonId:2, ConceptId:1, ConceptValue: C},
134
+ var variablesToQuery []interface {}
135
+ var finalConceptDataset []* models.PersonConceptAndValue
136
+ for _ , item := range conceptDefsAndCohortPairs {
137
+ variablesToQuery = append (variablesToQuery , item )
138
+ // if item is of type CustomConceptVariableDef, get the data:
139
+ if _ , ok := item .(utils.CustomConceptVariableDef ); ok {
140
+ // use variablesToQuery to query an increasingly tight set (simulating the attrition table that generated this query)
141
+ cohortData , err := u .cohortDataModel .RetrieveHistogramDataBySourceIdAndCohortIdAndConceptDefsPlusCohortPairs (sourceId , cohortId , variablesToQuery )
142
+ if err != nil {
143
+ c .JSON (http .StatusInternalServerError , gin.H {"message" : "Error retrieving concept details" , "error" : err .Error ()})
144
+ c .Abort ()
145
+ return
146
+ }
147
+ // add to final concept data set:
148
+ finalConceptDataset = append (finalConceptDataset , cohortData ... )
149
+ }
154
150
}
155
151
156
- partialCSV := GeneratePartialCSV (sourceId , cohortData , conceptIds )
152
+ conceptIds := utils .ExtractConceptIdsFromCustomConceptVariablesDef (conceptDefs )
153
+ partialCSV := GeneratePartialCSV (sourceId , finalConceptDataset , conceptIds ) // use conceptdefs to improve column description? nah...no person is reading this table....just needs to be unique
157
154
158
- personIdToCSVValues , err := u .RetrievePeopleIdAndCohort (sourceId , cohortId , cohortPairs , cohortData )
155
+ personIdToCSVValues , err := u .RetrievePeopleIdAndCohort (sourceId , cohortId , cohortPairs , finalConceptDataset )
159
156
if err != nil {
160
157
c .JSON (http .StatusInternalServerError , gin.H {"message" : "Error retrieving people ID to csv value map" , "error" : err .Error ()})
161
158
c .Abort ()
@@ -287,13 +284,12 @@ func populateConceptValue(row []string, cohortItem models.PersonConceptAndValue,
287
284
func (u CohortDataController ) RetrieveCohortOverlapStats (c * gin.Context ) {
288
285
errors := make ([]error , 4 )
289
286
var sourceId , caseCohortId , controlCohortId int
290
- var conceptIdsAndValues []utils.CustomConceptVariableDef
291
- var cohortPairs []utils.CustomDichotomousVariableDef
287
+ var conceptDefsAndCohortPairs []interface {}
292
288
sourceId , errors [0 ] = utils .ParseNumericArg (c , "sourceid" )
293
289
caseCohortId , errors [1 ] = utils .ParseNumericArg (c , "casecohortid" )
294
290
controlCohortId , errors [2 ] = utils .ParseNumericArg (c , "controlcohortid" )
295
- conceptIdsAndValues , cohortPairs , errors [3 ] = utils .ParseConceptDefsAndDichotomousDefs (c )
296
- conceptIds := utils .ExtractConceptIdsFromCustomConceptVariablesDef ( conceptIdsAndValues )
291
+ conceptDefsAndCohortPairs , errors [3 ] = utils .ParseConceptDefsAndDichotomousDefsAsSingleList (c )
292
+ _ , cohortPairs := utils .GetConceptDefsAndValuesAndCohortPairsAsSeparateLists ( conceptDefsAndCohortPairs )
297
293
298
294
validAccessRequest := u .teamProjectAuthz .TeamProjectValidation (c , []int {caseCohortId , controlCohortId }, cohortPairs )
299
295
if ! validAccessRequest {
@@ -309,7 +305,7 @@ func (u CohortDataController) RetrieveCohortOverlapStats(c *gin.Context) {
309
305
return
310
306
}
311
307
overlapStats , err := u .cohortDataModel .RetrieveCohortOverlapStats (sourceId , caseCohortId ,
312
- controlCohortId , conceptIds , cohortPairs )
308
+ controlCohortId , conceptDefsAndCohortPairs )
313
309
if err != nil {
314
310
c .JSON (http .StatusInternalServerError , gin.H {"message" : "Error retrieving stats" , "error" : err .Error ()})
315
311
c .Abort ()
0 commit comments