Skip to content

Commit 7e4c2fb

Browse files
committed
fix: update RetrieveCohortOverlapStats method name
1 parent 4963bce commit 7e4c2fb

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

controllers/cohortdata.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func populateConceptValue(row []string, cohortItem models.PersonConceptAndValue,
241241
return row
242242
}
243243

244-
func (u CohortDataController) RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(c *gin.Context) {
244+
func (u CohortDataController) RetrieveCohortOverlapStats(c *gin.Context) {
245245
errors := make([]error, 4)
246246
var sourceId, caseCohortId, controlCohortId int
247247
var conceptIds []int64
@@ -264,7 +264,7 @@ func (u CohortDataController) RetrieveCohortOverlapStatsWithoutFilteringOnConcep
264264
c.Abort()
265265
return
266266
}
267-
overlapStats, err := u.cohortDataModel.RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(sourceId, caseCohortId,
267+
overlapStats, err := u.cohortDataModel.RetrieveCohortOverlapStats(sourceId, caseCohortId,
268268
controlCohortId, conceptIds, cohortPairs)
269269
if err != nil {
270270
c.JSON(http.StatusInternalServerError, gin.H{"message": "Error retrieving stats", "error": err.Error()})

models/cohortdata.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type CohortDataI interface {
1111
RetrieveDataBySourceIdAndCohortIdAndConceptIdsOrderedByPersonId(sourceId int, cohortDefinitionId int, conceptIds []int64) ([]*PersonConceptAndValue, error)
12-
RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(sourceId int, caseCohortId int, controlCohortId int, otherFilterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) (CohortOverlapStats, error)
12+
RetrieveCohortOverlapStats(sourceId int, caseCohortId int, controlCohortId int, otherFilterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) (CohortOverlapStats, error)
1313
RetrieveDataByOriginalCohortAndNewCohort(sourceId int, originalCohortDefinitionId int, cohortDefinitionId int) ([]*PersonIdAndCohort, error)
1414
RetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(sourceId int, cohortDefinitionId int, histogramConceptId int64, filterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) ([]*PersonConceptAndValue, error)
1515
}
@@ -110,21 +110,20 @@ func (h CohortData) RetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCo
110110
}
111111

112112
// Basically the same as the method above, but without the extra filtering on filterConceptId and filterConceptValue:
113-
func (h CohortData) RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(sourceId int, caseCohortId int, controlCohortId int,
114-
otherFilterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) (CohortOverlapStats, error) {
113+
func (h CohortData) RetrieveCohortOverlapStats(sourceId int, caseCohortId int, controlCohortId int,
114+
filterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) (CohortOverlapStats, error) {
115115

116116
var dataSourceModel = new(Source)
117117
omopDataSource := dataSourceModel.GetDataSource(sourceId, Omop)
118118
resultsDataSource := dataSourceModel.GetDataSource(sourceId, Results)
119119

120-
// count persons that are in the intersection of both case and control cohorts, filtering on filterConceptValue:
121120
var cohortOverlapStats CohortOverlapStats
122121
query := QueryFilterByCohortPairsHelper(filterCohortPairs, resultsDataSource, caseCohortId, "case_cohort_unionedAndIntersectedWithFilters").
123122
Select("count(distinct(case_cohort_unionedAndIntersectedWithFilters.subject_id)) as case_control_overlap").
124123
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
125124

126-
if len(otherFilterConceptIds) > 0 {
127-
query = QueryFilterByConceptIdsHelper2(query, sourceId, otherFilterConceptIds, omopDataSource, resultsDataSource.Schema, "control_cohort.subject_id")
125+
if len(filterConceptIds) > 0 {
126+
query = QueryFilterByConceptIdsHelper2(query, sourceId, filterConceptIds, omopDataSource, resultsDataSource.Schema, "control_cohort.subject_id")
128127
}
129128
query = query.Where("control_cohort.cohort_definition_id = ?", controlCohortId)
130129
query, cancel := utils.AddTimeoutToQuery(query)

server/router.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewRouter() *gin.Engine {
4848
// cohort stats and checks:
4949
cohortData := controllers.NewCohortDataController(*new(models.CohortData), middlewares.NewTeamProjectAuthz(*new(models.CohortDefinition), &http.Client{}))
5050
// :casecohortid/:controlcohortid are just labels here and have no special meaning. Could also just be :cohortAId/:cohortBId here:
51-
authorized.POST("/cohort-stats/check-overlap/by-source-id/:sourceid/by-cohort-definition-ids/:casecohortid/:controlcohortid", cohortData.RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue)
51+
authorized.POST("/cohort-stats/check-overlap/by-source-id/:sourceid/by-cohort-definition-ids/:casecohortid/:controlcohortid", cohortData.RetrieveCohortOverlapStats)
5252

5353
// full data endpoints:
5454
authorized.POST("/cohort-data/by-source-id/:sourceid/by-cohort-definition-id/:cohortid", cohortData.RetrieveDataBySourceIdAndCohortIdAndVariables)

tests/controllers_tests/controllers_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (h dummyCohortDataModel) RetrieveHistogramDataBySourceIdAndCohortIdAndConce
7676
return cohortData, nil
7777
}
7878

79-
func (h dummyCohortDataModel) RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(sourceId int, caseCohortId int, controlCohortId int,
79+
func (h dummyCohortDataModel) RetrieveCohortOverlapStats(sourceId int, caseCohortId int, controlCohortId int,
8080
otherFilterConceptIds []int64, filterCohortPairs []utils.CustomDichotomousVariableDef) (models.CohortOverlapStats, error) {
8181
var zeroOverlap models.CohortOverlapStats
8282
return zeroOverlap, nil
@@ -335,7 +335,7 @@ func TestRetrieveDataBySourceIdAndCohortIdAndVariablesCorrectParams(t *testing.T
335335
}
336336
}
337337

338-
func TestRetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(t *testing.T) {
338+
func TestRetrieveCohortOverlapStats(t *testing.T) {
339339
setUp(t)
340340
requestContext := new(gin.Context)
341341
requestContext.Params = append(requestContext.Params, gin.Param{Key: "sourceid", Value: strconv.Itoa(tests.GetTestSourceId())})
@@ -346,7 +346,7 @@ func TestRetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(t *testing.T)
346346
requestBody := "{\"variables\":[{\"variable_type\": \"concept\", \"concept_id\": 2000000324},{\"variable_type\": \"concept\", \"concept_id\": 2000006885}]}"
347347
requestContext.Request.Body = io.NopCloser(strings.NewReader(requestBody))
348348

349-
cohortDataController.RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(requestContext)
349+
cohortDataController.RetrieveCohortOverlapStats(requestContext)
350350
// Params above are correct, so request should NOT abort:
351351
if requestContext.IsAborted() {
352352
t.Errorf("Did not expect this request to abort")
@@ -358,7 +358,7 @@ func TestRetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(t *testing.T)
358358

359359
// the same request should fail if the teamProject authorization fails:
360360
requestContext.Request.Body = io.NopCloser(strings.NewReader(requestBody))
361-
cohortDataControllerWithFailingTeamProjectAuthz.RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(requestContext)
361+
cohortDataControllerWithFailingTeamProjectAuthz.RetrieveCohortOverlapStats(requestContext)
362362
result = requestContext.Writer.(*tests.CustomResponseWriter)
363363
// expect error:
364364
if !strings.Contains(result.CustomResponseWriterOut, "access denied") {
@@ -369,13 +369,13 @@ func TestRetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(t *testing.T)
369369
}
370370
}
371371

372-
func TestRetrieveCohortOverlapStatsWithoutFilteringOnConceptValueBadRequest(t *testing.T) {
372+
func TestRetrieveCohortOverlapStatsBadRequest(t *testing.T) {
373373
setUp(t)
374374
requestContext := new(gin.Context)
375375
requestContext.Params = append(requestContext.Params, gin.Param{Key: "sourceid", Value: strconv.Itoa(tests.GetTestSourceId())})
376376
requestContext.Writer = new(tests.CustomResponseWriter)
377377

378-
cohortDataController.RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(requestContext)
378+
cohortDataController.RetrieveCohortOverlapStats(requestContext)
379379
// Params above are incorrect, so request should abort:
380380
if !requestContext.IsAborted() {
381381
t.Errorf("Expected this request to abort")

tests/models_tests/models_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -850,14 +850,14 @@ func TestErrorForRetrieveDataBySourceIdAndCohortIdAndConceptIdsOrderedByPersonId
850850
tests.FixSomething(models.Results, "cohort", "cohort_definition_id")
851851
}
852852

853-
func TestRetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(t *testing.T) {
853+
func TestRetrieveCohortOverlapStats(t *testing.T) {
854854
// Tests if we get the expected overlap
855855
setUp(t)
856856
caseCohortId := secondLargestCohort.Id
857857
controlCohortId := secondLargestCohort.Id // to ensure we get some overlap, just repeat the same here...
858858
otherFilterConceptIds := []int64{}
859859
filterCohortPairs := []utils.CustomDichotomousVariableDef{}
860-
stats, _ := cohortDataModel.RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(testSourceId, caseCohortId, controlCohortId,
860+
stats, _ := cohortDataModel.RetrieveCohortOverlapStats(testSourceId, caseCohortId, controlCohortId,
861861
otherFilterConceptIds, filterCohortPairs)
862862
// basic test:
863863
if stats.CaseControlOverlap != int64(secondLargestCohort.CohortSize) {
@@ -874,7 +874,7 @@ func TestRetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(t *testing.T)
874874
ProvidedName: "test"},
875875
}
876876
// then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort:
877-
stats, _ = cohortDataModel.RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(testSourceId, caseCohortId, controlCohortId,
877+
stats, _ = cohortDataModel.RetrieveCohortOverlapStats(testSourceId, caseCohortId, controlCohortId,
878878
otherFilterConceptIds, filterCohortPairs)
879879
if stats.CaseControlOverlap != 5 {
880880
t.Errorf("Expected nr persons to be %d, found %d", 5, stats.CaseControlOverlap)
@@ -887,7 +887,7 @@ func TestRetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(t *testing.T)
887887
otherFilterConceptIds = []int64{histogramConceptId} // extra filter, to cover this part of the code...
888888
// then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort (the filter on histogramConceptId should not matter
889889
// since all in largestCohort have an observation for this concept id):
890-
stats2, _ := cohortDataModel.RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(testSourceId, caseCohortId, controlCohortId,
890+
stats2, _ := cohortDataModel.RetrieveCohortOverlapStats(testSourceId, caseCohortId, controlCohortId,
891891
otherFilterConceptIds, filterCohortPairs)
892892
if stats2.CaseControlOverlap != stats.CaseControlOverlap {
893893
t.Errorf("Expected nr persons to be %d, found %d", stats.CaseControlOverlap, stats2.CaseControlOverlap)
@@ -898,7 +898,7 @@ func TestRetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(t *testing.T)
898898
otherFilterConceptIds = []int64{histogramConceptId, dummyContinuousConceptId}
899899
// all other arguments are the same as test above, and we expect overlap of 0, showing the otherFilterConceptIds
900900
// had the expected effect:
901-
stats3, _ := cohortDataModel.RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(testSourceId, caseCohortId, controlCohortId,
901+
stats3, _ := cohortDataModel.RetrieveCohortOverlapStats(testSourceId, caseCohortId, controlCohortId,
902902
otherFilterConceptIds, filterCohortPairs)
903903
if stats3.CaseControlOverlap != 0 {
904904
t.Errorf("Expected nr persons to be 0, found %d", stats3.CaseControlOverlap)

0 commit comments

Comments
 (0)