You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// get the observations for the subjects and the concepts, to build up the data rows to return:
70
70
varcohortData []*PersonConceptAndValue
71
-
meta_result:=omopDataSource.Db.Table(omopDataSource.Schema+".observation_continuous as observation").
71
+
meta_result:=omopDataSource.Db.Table(omopDataSource.Schema+".observation_continuous as observation"+omopDataSource.GetViewDirective()).
72
72
Select("observation.person_id, observation.observation_concept_id as concept_id, observation.value_as_string as concept_value_as_string, observation.value_as_number as concept_value_as_number, observation.value_as_concept_id as concept_value_as_concept_id").
73
73
Joins("INNER JOIN "+resultsDataSource.Schema+".cohort as cohort ON cohort.subject_id = observation.person_id").
// count persons that are in the intersection of both case and control cohorts, filtering on filterConceptValue:
113
113
varcohortOverlapStatsCohortOverlapStats
114
-
query:=omopDataSource.Db.Table(omopDataSource.Schema+".observation_continuous as observation").
114
+
query:=omopDataSource.Db.Table(omopDataSource.Schema+".observation_continuous as observation"+omopDataSource.GetViewDirective()).
115
115
Select("count(distinct(observation.person_id)) as case_control_overlap").
116
116
Joins("INNER JOIN "+resultsDataSource.Schema+".cohort as case_cohort ON case_cohort.subject_id = observation.person_id").
117
117
Joins("INNER JOIN "+resultsDataSource.Schema+".cohort as control_cohort ON control_cohort.subject_id = case_cohort.subject_id"). // this one allows for the intersection between case and control and the assessment of the overlap
// count persons that are in the intersection of both case and control cohorts, filtering on filterConceptValue:
138
144
varcohortOverlapStatsCohortOverlapStats
139
-
query:=omopDataSource.Db.Table(omopDataSource.Schema+".observation_continuous as observation").
145
+
query:=omopDataSource.Db.Table(omopDataSource.Schema+".observation_continuous as observation"+omopDataSource.GetViewDirective()).
140
146
Select("count(distinct(observation.person_id)) as case_control_overlap").
141
147
Joins("INNER JOIN "+resultsDataSource.Schema+".cohort as case_cohort ON case_cohort.subject_id = observation.person_id").
142
148
Joins("INNER JOIN "+resultsDataSource.Schema+".cohort as control_cohort ON control_cohort.subject_id = case_cohort.subject_id"). // this one allows for the intersection between case and control and the assessment of the overlap
// count persons that are in the intersection of both case and control cohorts, filtering on filterConceptValue:
166
+
varcohortOverlapStatsCohortOverlapStats
167
+
query:=omopDataSource.Db.Table(resultsDataSource.Schema+".cohort as case_cohort").
168
+
Select("count(distinct(case_cohort.subject_id)) as case_control_overlap").
169
+
Joins("INNER JOIN "+resultsDataSource.Schema+".cohort as control_cohort ON control_cohort.subject_id = case_cohort.subject_id"). // this one allows for the intersection between case and control and the assessment of the overlap
Joins("INNER JOIN "+omopDataSource.Schema+".observation_continuous as observation"+omopDataSource.GetViewDirective()+" ON unionAndIntersect.subject_id = observation.person_id").
Where(breakdownValueFieldName+" is not null"). // this one seems like a bit of a random constraint...but was a request from the business side: skip records where this field is null
229
228
Where("observation.value_as_concept_id is not null"). // this is assuming that the breakdownConceptId has its values nicely stored as concepts as well and correctly used in observation table...
// note: here we pass empty []utils.CustomDichotomousVariableDef{} instead of filterCohortPairs, since we already use the SQL generated by QueryFilterByCohortPairsHelper above,
232
+
// which is a better performing SQL in this particular scenario:
// Validate assumption of a table or view aliased as "observation":
18
-
ifquery.Statement.Table!="observation" {
19
-
panic("Error: this QueryFilterByConceptIdsAndCohortPairsHelper is meant for adding extra filters to a query on a table or view with the alias name `observation`")
log.Printf("Adding extra INNER JOIN with alias %s", observationTableAlias)
27
-
query=query.Joins("INNER JOIN "+omopSchemaName+".observation_continuous as "+observationTableAlias+" ON "+observationTableAlias+".person_id = observation.person_id").// assumption: there is a table or view named or aliased as "observation"
23
+
query=query.Joins("INNER JOIN "+omopDataSource.Schema+".observation_continuous as "+observationTableAlias+omopDataSource.GetViewDirective()+" ON "+observationTableAlias+".person_id = "+mainObservationTableAlias+".person_id").
Where("("+observationTableAlias+".value_as_string is not null or "+observationTableAlias+".value_as_number is not null)") // TODO - improve performance by only filtering on type according to getConceptValueType()
" EXCEPT "+//now use EXCEPT to exclude the part where both cohorts INTERSECT
44
40
" Select "+cohortTableAlias2+".subject_id FROM "+resultSchemaName+".cohort as "+cohortTableAlias2+
45
41
" INNER JOIN "+resultSchemaName+".cohort as "+cohortTableAlias3+" ON "+cohortTableAlias3+".subject_id = "+cohortTableAlias2+".subject_id "+
46
-
" where "+cohortTableAlias2+".cohort_definition_id = ? AND "+cohortTableAlias3+".cohort_definition_id =? ) AS "+unionExceptAlias+" ON "+unionExceptAlias+".subject_id = observation.person_id",// assumption: there is a table or view named or aliased as "observation"
42
+
" where "+cohortTableAlias2+".cohort_definition_id = ? AND "+cohortTableAlias3+".cohort_definition_id =? ) AS "+unionExceptAlias+" ON "+unionExceptAlias+".subject_id = "+mainObservationTableAlias+".person_id",
0 commit comments