|
9 | 9 |
|
10 | 10 | type CohortDataI interface {
|
11 | 11 | RetrieveDataBySourceIdAndCohortIdAndConceptIdsOrderedByPersonId(sourceId int, cohortDefinitionId int, conceptIds []int64) ([]*PersonConceptAndValue, error)
|
12 |
| - RetrieveCohortOverlapStats(sourceId int, caseCohortId int, controlCohortId int, filterConceptId int64, filterConceptValue int64, otherFilterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) (CohortOverlapStats, error) |
13 | 12 | RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(sourceId int, caseCohortId int, controlCohortId int, otherFilterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) (CohortOverlapStats, error)
|
14 | 13 | RetrieveDataByOriginalCohortAndNewCohort(sourceId int, originalCohortDefinitionId int, cohortDefinitionId int) ([]*PersonIdAndCohort, error)
|
15 | 14 | RetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(sourceId int, cohortDefinitionId int, histogramConceptId int64, filterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) ([]*PersonConceptAndValue, error)
|
@@ -79,97 +78,44 @@ func (h CohortData) RetrieveDataBySourceIdAndCohortIdAndConceptIdsOrderedByPerso
|
79 | 78 | }
|
80 | 79 |
|
81 | 80 | func (h CohortData) RetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(sourceId int, cohortDefinitionId int, histogramConceptId int64, filterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) ([]*PersonConceptAndValue, error) {
|
82 |
| - log.Printf(">> Using inner join impl. for large cohorts") |
83 | 81 | var dataSourceModel = new(Source)
|
84 | 82 | omopDataSource := dataSourceModel.GetDataSource(sourceId, Omop)
|
85 | 83 |
|
86 | 84 | resultsDataSource := dataSourceModel.GetDataSource(sourceId, Results)
|
87 | 85 |
|
88 | 86 | // get the observations for the subjects and the concepts, to build up the data rows to return:
|
89 | 87 | var cohortData []*PersonConceptAndValue
|
90 |
| - query := omopDataSource.Db.Table(omopDataSource.Schema+".observation_continuous as observation"+omopDataSource.GetViewDirective()). |
| 88 | + query := QueryFilterByCohortPairsHelper(filterCohortPairs, resultsDataSource, cohortDefinitionId, "unionAndIntersect"). |
91 | 89 | Select("distinct(observation.person_id), observation.observation_concept_id as concept_id, observation.value_as_number as concept_value_as_number").
|
92 |
| - Joins("INNER JOIN "+resultsDataSource.Schema+".cohort as cohort ON cohort.subject_id = observation.person_id"). |
93 |
| - Where("cohort.cohort_definition_id = ?", cohortDefinitionId). |
| 90 | + Joins("INNER JOIN "+omopDataSource.Schema+".observation_continuous as observation"+omopDataSource.GetViewDirective()+" ON unionAndIntersect.subject_id = observation.person_id"). |
94 | 91 | Where("observation.observation_concept_id = ?", histogramConceptId).
|
95 | 92 | Where("observation.value_as_number is not null")
|
96 | 93 |
|
97 |
| - query = QueryFilterByConceptIdsAndCohortPairsHelper(query, sourceId, filterConceptIds, filterCohortPairs, omopDataSource, resultsDataSource.Schema, "observation") |
| 94 | + query = QueryFilterByConceptIdsHelper(query, sourceId, filterConceptIds, omopDataSource, resultsDataSource.Schema, "observation") |
98 | 95 |
|
99 | 96 | meta_result := query.Scan(&cohortData)
|
100 | 97 | return cohortData, meta_result.Error
|
101 | 98 | }
|
102 | 99 |
|
103 |
| -// Assesses the overlap between case and control cohorts. It does this after filtering the cohorts and keeping only |
104 |
| -// the persons that have data for each of the selected conceptIds and match the filterConceptId/filterConceptValue criteria. |
105 |
| -func (h CohortData) RetrieveCohortOverlapStats(sourceId int, caseCohortId int, controlCohortId int, |
106 |
| - filterConceptId int64, filterConceptValue int64, otherFilterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) (CohortOverlapStats, error) { |
107 |
| - |
108 |
| - var dataSourceModel = new(Source) |
109 |
| - omopDataSource := dataSourceModel.GetDataSource(sourceId, Omop) |
110 |
| - resultsDataSource := dataSourceModel.GetDataSource(sourceId, Results) |
111 |
| - |
112 |
| - // count persons that are in the intersection of both case and control cohorts, filtering on filterConceptValue: |
113 |
| - var cohortOverlapStats CohortOverlapStats |
114 |
| - query := omopDataSource.Db.Table(omopDataSource.Schema+".observation_continuous as observation"+omopDataSource.GetViewDirective()). |
115 |
| - Select("count(distinct(observation.person_id)) as case_control_overlap"). |
116 |
| - Joins("INNER JOIN "+resultsDataSource.Schema+".cohort as case_cohort ON case_cohort.subject_id = observation.person_id"). |
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 |
118 |
| - Where("case_cohort.cohort_definition_id = ?", caseCohortId). |
119 |
| - Where("control_cohort.cohort_definition_id = ?", controlCohortId). |
120 |
| - Where("observation.observation_concept_id = ?", filterConceptId). |
121 |
| - Where("observation.value_as_concept_id = ?", filterConceptValue) |
122 |
| - |
123 |
| - query = QueryFilterByConceptIdsAndCohortPairsHelper(query, sourceId, otherFilterConceptIds, filterCohortPairs, omopDataSource, resultsDataSource.Schema, "observation") |
124 |
| - |
125 |
| - meta_result := query.Scan(&cohortOverlapStats) |
126 |
| - return cohortOverlapStats, meta_result.Error |
127 |
| -} |
128 |
| - |
129 | 100 | // Basically the same as the method above, but without the extra filtering on filterConceptId and filterConceptValue:
|
130 | 101 | func (h CohortData) RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(sourceId int, caseCohortId int, controlCohortId int,
|
131 | 102 | otherFilterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) (CohortOverlapStats, error) {
|
132 | 103 |
|
133 |
| - // special case for when filter lists are empty: |
134 |
| - if len(otherFilterConceptIds) == 0 && len(filterCohortPairs) == 0 { |
135 |
| - // call the faster version of overlap check: |
136 |
| - return h.RetrieveCohortOverlapStatsWithoutFiltering(sourceId, caseCohortId, controlCohortId) |
137 |
| - } |
138 |
| - |
139 |
| - var dataSourceModel = new(Source) |
140 |
| - omopDataSource := dataSourceModel.GetDataSource(sourceId, Omop) |
141 |
| - resultsDataSource := dataSourceModel.GetDataSource(sourceId, Results) |
142 |
| - |
143 |
| - // count persons that are in the intersection of both case and control cohorts, filtering on filterConceptValue: |
144 |
| - var cohortOverlapStats CohortOverlapStats |
145 |
| - query := omopDataSource.Db.Table(omopDataSource.Schema+".observation_continuous as observation"+omopDataSource.GetViewDirective()). |
146 |
| - Select("count(distinct(observation.person_id)) as case_control_overlap"). |
147 |
| - Joins("INNER JOIN "+resultsDataSource.Schema+".cohort as case_cohort ON case_cohort.subject_id = observation.person_id"). |
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 |
149 |
| - Where("case_cohort.cohort_definition_id = ?", caseCohortId). |
150 |
| - Where("control_cohort.cohort_definition_id = ?", controlCohortId) |
151 |
| - |
152 |
| - query = QueryFilterByConceptIdsAndCohortPairsHelper(query, sourceId, otherFilterConceptIds, filterCohortPairs, omopDataSource, resultsDataSource.Schema, "observation") |
153 |
| - |
154 |
| - meta_result := query.Scan(&cohortOverlapStats) |
155 |
| - return cohortOverlapStats, meta_result.Error |
156 |
| -} |
157 |
| - |
158 |
| -// Basically the same as the method above, but without any filtering on any concepts or on any CustomDichotomousVariableDef: |
159 |
| -func (h CohortData) RetrieveCohortOverlapStatsWithoutFiltering(sourceId int, caseCohortId int, controlCohortId int) (CohortOverlapStats, error) { |
160 |
| - |
161 | 104 | var dataSourceModel = new(Source)
|
162 | 105 | omopDataSource := dataSourceModel.GetDataSource(sourceId, Omop)
|
163 | 106 | resultsDataSource := dataSourceModel.GetDataSource(sourceId, Results)
|
164 | 107 |
|
165 | 108 | // count persons that are in the intersection of both case and control cohorts, filtering on filterConceptValue:
|
166 | 109 | var cohortOverlapStats CohortOverlapStats
|
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 |
170 |
| - Where("case_cohort.cohort_definition_id = ?", caseCohortId). |
171 |
| - Where("control_cohort.cohort_definition_id = ?", controlCohortId) |
| 110 | + query := QueryFilterByCohortPairsHelper(filterCohortPairs, resultsDataSource, caseCohortId, "case_cohort_unionedAndIntersectedWithFilters"). |
| 111 | + Select("count(distinct(case_cohort_unionedAndIntersectedWithFilters.subject_id)) as case_control_overlap"). |
| 112 | + Joins("INNER JOIN " + resultsDataSource.Schema + ".cohort as control_cohort ON control_cohort.subject_id = case_cohort_unionedAndIntersectedWithFilters.subject_id") // this one allows for the intersection between case and control and the assessment of the overlap |
172 | 113 |
|
| 114 | + if len(otherFilterConceptIds) > 0 { |
| 115 | + query = query.Joins("INNER JOIN " + omopDataSource.Schema + ".observation_continuous as observation" + omopDataSource.GetViewDirective() + " ON control_cohort.subject_id = observation.person_id") |
| 116 | + query = QueryFilterByConceptIdsHelper(query, sourceId, otherFilterConceptIds, omopDataSource, resultsDataSource.Schema, "observation") |
| 117 | + } |
| 118 | + query = query.Where("control_cohort.cohort_definition_id = ?", controlCohortId) |
173 | 119 | meta_result := query.Scan(&cohortOverlapStats)
|
174 | 120 | return cohortOverlapStats, meta_result.Error
|
175 | 121 | }
|
|
0 commit comments