@@ -70,24 +70,24 @@ func QueryFilterByConceptDefHelper(query *gorm.DB, sourceId int, filterConceptDe
70
70
simpleFilterConceptDef := utils.CustomConceptVariableDef {ConceptId : filterConceptDef .ConceptId }
71
71
query .Select (fmt .Sprintf ("%s.person_id, %s.observation_concept_id, %s.value_as_number " ,
72
72
observationTableAlias + "_a" , observationTableAlias + "_a" , observationTableAlias + "_a" ))
73
- query := QueryFilterByConceptDefHelper2 (query , sourceId , simpleFilterConceptDef ,
74
- omopDataSource , "" , personIdFieldForObservationJoin , "observation_continuous" , observationTableAlias + "_a" )
73
+ query := queryJoinAndFilterByConceptDef (query , sourceId , simpleFilterConceptDef ,
74
+ omopDataSource , personIdFieldForObservationJoin , "observation_continuous" , observationTableAlias + "_a" )
75
75
tmpTransformedTable , err := TransformDataIntoTempTable (omopDataSource , query , filterConceptDef )
76
- // TODO - the resulting query should actually be Select * from temptable.... as this collapses all underlying queries. TODO2 - ensure the transform method also filters....
77
- query = QueryFilterByConceptDefHelper2 (query , sourceId , filterConceptDef , //TODO - turn around
78
- omopDataSource , "" , personIdFieldForObservationJoin , tmpTransformedTable , observationTableAlias + "_b" )
76
+ // TODO - the resulting query should actually be Select * from temptable.... as this collapses all underlying queries.
77
+ query = queryJoinAndFilterByConceptDef (query , sourceId , filterConceptDef ,
78
+ omopDataSource , personIdFieldForObservationJoin , tmpTransformedTable , observationTableAlias + "_b" )
79
79
return query , observationTableAlias + "_b" , err
80
80
81
81
} else {
82
82
// simple filterConceptDef with no transformation
83
- query := QueryFilterByConceptDefHelper2 (query , sourceId , filterConceptDef ,
84
- omopDataSource , "" , personIdFieldForObservationJoin , "observation_continuous" , observationTableAlias )
83
+ query := queryJoinAndFilterByConceptDef (query , sourceId , filterConceptDef ,
84
+ omopDataSource , personIdFieldForObservationJoin , "observation_continuous" , observationTableAlias )
85
85
return query , "" , nil
86
86
}
87
87
}
88
88
89
- func QueryFilterByConceptDefHelper2 (query * gorm.DB , sourceId int , filterConceptDef utils.CustomConceptVariableDef ,
90
- omopDataSource * utils.DbAndSchema , resultSchemaName string , personIdFieldForObservationJoin string , observationDataSource string , observationTableAlias string ) * gorm.DB {
89
+ func queryJoinAndFilterByConceptDef (query * gorm.DB , sourceId int , filterConceptDef utils.CustomConceptVariableDef ,
90
+ omopDataSource * utils.DbAndSchema , personIdFieldForObservationJoin string , observationDataSource string , observationTableAlias string ) * gorm.DB {
91
91
log .Printf ("Adding extra INNER JOIN with alias %s" , observationTableAlias )
92
92
aliasedObservationDataSource := omopDataSource .Schema + "." + observationDataSource + " as " + observationTableAlias + omopDataSource .GetViewDirective ()
93
93
// for temp table, the alias is slightly different:
@@ -131,7 +131,7 @@ func TransformDataIntoTempTable(omopDataSource *utils.DbAndSchema, query *gorm.D
131
131
// Generate a unique hash key based on the query and transformation
132
132
querySQL := utils .ToSQL (query )
133
133
queryKey := fmt .Sprintf ("%s|%s" , querySQL , filterConceptDef .Transformation )
134
- cacheKey := utils .GenerateHash (queryKey ) // TODO - review
134
+ cacheKey := utils .GenerateHash (queryKey )
135
135
136
136
// Check if the temporary table already exists in the cache
137
137
if cachedTableName , exists := utils .TempTableCache .Get (cacheKey ); exists {
@@ -192,7 +192,7 @@ func CreateAndFillTempTable(omopDataSource *utils.DbAndSchema, query *gorm.DB, t
192
192
case "box_cox" :
193
193
// Placeholder: implement Box-Cox transformation logic as per requirements
194
194
log .Printf ("box_cox transformation logic needs to be implemented" )
195
- return ""
195
+ panic ( "error" )
196
196
default :
197
197
log .Fatalf ("Unsupported transformation type: %s" , filterConceptDef .Transformation )
198
198
panic ("error" )
@@ -212,7 +212,7 @@ func TempTableSQLAndFinalName(omopDataSource *utils.DbAndSchema, tempTableName s
212
212
tempTableName , selectStatement , fromSQL , extraWhereSQL ,
213
213
)
214
214
if omopDataSource .Vendor == "sqlserver" {
215
- finalTempTableName = "##" + tempTableName // Global temp table for MSSQL
215
+ finalTempTableName = "##" + tempTableName
216
216
tempTableSQL = fmt .Sprintf (
217
217
"SELECT %s INTO %s FROM (%s) T WHERE %s" ,
218
218
selectStatement , finalTempTableName , fromSQL , extraWhereSQL ,
@@ -231,6 +231,7 @@ func QueryFilterByConceptDefsHelper(query *gorm.DB, sourceId int, filterConceptD
231
231
return query
232
232
}
233
233
234
+ // DEPRECATED - use QueryFilterByConceptDefsPlusCohortPairsHelper instead
234
235
// Helper function that adds extra filter clauses to the query, for the given filterCohortPairs, intersecting on the
235
236
// right set of tables, excluding data where necessary, etc.
236
237
// It basically iterates over the list of filterCohortPairs, adding relevant INTERSECT and EXCEPT clauses, so that the resulting set is the
@@ -247,7 +248,6 @@ func QueryFilterByCohortPairsHelper(filterCohortPairs []utils.CustomDichotomousV
247
248
return query
248
249
}
249
250
250
- // TODO - remove code duplication above
251
251
func QueryFilterByCohortPairHelper (query * gorm.DB , filterCohortPair utils.CustomDichotomousVariableDef , resultsDataSource * utils.DbAndSchema , cohortDefinitionId int , personIdFieldForObservationJoin string , unionAndIntersectSQLAlias string ) * gorm.DB {
252
252
unionAndIntersectSQL := "(" +
253
253
"SELECT subject_id FROM " + resultsDataSource .Schema + ".cohort WHERE cohort_definition_id=? "
0 commit comments