Skip to content

Commit faed7c2

Browse files
committed
feat: improve variable name to reflect its real nature
...which is cohort_definition_id...there is no such thing as "cohort id"
1 parent e783f33 commit faed7c2

File tree

6 files changed

+91
-91
lines changed

6 files changed

+91
-91
lines changed

controllers/cohortdata.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func generateCohortPairsHeaders(cohortPairs []utils.CustomDichotomousVariableDef
111111
cohortPairsHeaders := []string{}
112112

113113
for _, cohortPair := range cohortPairs {
114-
cohortPairsHeaders = append(cohortPairsHeaders, utils.GetCohortPairKey(cohortPair.CohortId1, cohortPair.CohortId2))
114+
cohortPairsHeaders = append(cohortPairsHeaders, utils.GetCohortPairKey(cohortPair.CohortDefinitionId1, cohortPair.CohortDefinitionId2))
115115
}
116116

117117
return cohortPairsHeaders
@@ -298,8 +298,8 @@ func (u CohortDataController) RetrievePeopleIdAndCohort(sourceId int, cohortId i
298298
*/
299299
personIdToCSVValues := make(map[int64]map[string]string)
300300
for _, cohortPair := range cohortPairs {
301-
firstCohortDefinitionId := cohortPair.CohortId1
302-
secondCohortDefinitionId := cohortPair.CohortId2
301+
firstCohortDefinitionId := cohortPair.CohortDefinitionId1
302+
secondCohortDefinitionId := cohortPair.CohortDefinitionId2
303303
cohortPairKey := utils.GetCohortPairKey(firstCohortDefinitionId, secondCohortDefinitionId)
304304

305305
firstCohortPeopleData, err1 := u.cohortDataModel.RetrieveDataByOriginalCohortAndNewCohort(sourceId, cohortId, firstCohortDefinitionId)

models/helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func QueryFilterByCohortPairsHelper(filterCohortPairs []utils.CustomDichotomousV
4444
"UNION " +
4545
"SELECT subject_id FROM " + resultsDataSource.Schema + ".cohort WHERE cohort_definition_id=? " +
4646
")"
47-
idsList = append(idsList, filterCohortPair.CohortId1, filterCohortPair.CohortId2)
47+
idsList = append(idsList, filterCohortPair.CohortDefinitionId1, filterCohortPair.CohortDefinitionId2)
4848
}
4949
// EXCEPTs section:
5050
for _, filterCohortPair := range filterCohortPairs {
@@ -54,7 +54,7 @@ func QueryFilterByCohortPairsHelper(filterCohortPairs []utils.CustomDichotomousV
5454
"INTERSECT " +
5555
"SELECT subject_id FROM " + resultsDataSource.Schema + ".cohort WHERE cohort_definition_id=? " +
5656
")"
57-
idsList = append(idsList, filterCohortPair.CohortId1, filterCohortPair.CohortId2)
57+
idsList = append(idsList, filterCohortPair.CohortDefinitionId1, filterCohortPair.CohortDefinitionId2)
5858
}
5959
}
6060
unionAndIntersectSQL = unionAndIntersectSQL +

tests/controllers_tests/controllers_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -717,14 +717,14 @@ func TestGetAttritionRowForConceptIdsAndCohortPairs(t *testing.T) {
717717
int64(1234),
718718
int64(5678),
719719
utils.CustomDichotomousVariableDef{
720-
CohortId1: 1,
721-
CohortId2: 2,
722-
ProvidedName: "testA12"},
720+
CohortDefinitionId1: 1,
721+
CohortDefinitionId2: 2,
722+
ProvidedName: "testA12"},
723723
int64(2090006880),
724724
utils.CustomDichotomousVariableDef{
725-
CohortId1: 3,
726-
CohortId2: 4,
727-
ProvidedName: "testB34"},
725+
CohortDefinitionId1: 3,
726+
CohortDefinitionId2: 4,
727+
ProvidedName: "testB34"},
728728
}
729729

730730
result, _ := conceptController.GetAttritionRowForConceptIdsAndCohortPairs(sourceId, cohortId, conceptIdsAndCohortPairs, breakdownConceptId, sortedConceptValues)
@@ -771,9 +771,9 @@ func TestGenerateCompleteCSV(t *testing.T) {
771771

772772
cohortPairs := []utils.CustomDichotomousVariableDef{
773773
{
774-
CohortId1: 2,
775-
CohortId2: 3,
776-
ProvidedName: "test"},
774+
CohortDefinitionId1: 2,
775+
CohortDefinitionId2: 3,
776+
ProvidedName: "test"},
777777
}
778778

779779
b := controllers.GenerateCompleteCSV(partialCsv, personIdToCSVValues, cohortPairs)
@@ -798,9 +798,9 @@ func TestRetrievePeopleIdAndCohort(t *testing.T) {
798798
cohortId := 1
799799
cohortPairs := []utils.CustomDichotomousVariableDef{
800800
{
801-
CohortId1: 2,
802-
CohortId2: 3,
803-
ProvidedName: "test"},
801+
CohortDefinitionId1: 2,
802+
CohortDefinitionId2: 3,
803+
ProvidedName: "test"},
804804
}
805805

806806
cohortData := []*models.PersonConceptAndValue{
@@ -839,9 +839,9 @@ func TestRetrievePeopleIdAndCohortNonExistingCohortPair(t *testing.T) {
839839
cohortId := 1
840840
cohortPairs := []utils.CustomDichotomousVariableDef{
841841
{
842-
CohortId1: 4,
843-
CohortId2: 5,
844-
ProvidedName: "test"},
842+
CohortDefinitionId1: 4,
843+
CohortDefinitionId2: 5,
844+
ProvidedName: "test"},
845845
}
846846

847847
cohortData := []*models.PersonConceptAndValue{
@@ -880,9 +880,9 @@ func TestRetrievePeopleIdAndCohortOverlappingCohortPair(t *testing.T) {
880880
cohortId := 1
881881
cohortPairs := []utils.CustomDichotomousVariableDef{
882882
{
883-
CohortId1: 1,
884-
CohortId2: 1,
885-
ProvidedName: "test"},
883+
CohortDefinitionId1: 1,
884+
CohortDefinitionId2: 1,
885+
ProvidedName: "test"},
886886
}
887887

888888
cohortData := []*models.PersonConceptAndValue{

tests/models_tests/models_test.go

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
249249
// smallestCohort and largestCohort do not overlap...
250250
filterCohortPairs := []utils.CustomDichotomousVariableDef{
251251
{
252-
CohortId1: smallestCohort.Id,
253-
CohortId2: largestCohort.Id,
254-
ProvidedName: "test"},
252+
CohortDefinitionId1: smallestCohort.Id,
253+
CohortDefinitionId2: largestCohort.Id,
254+
ProvidedName: "test"},
255255
}
256256
resultsDataSource := tests.GetResultsDataSource()
257257
var subjectIds []*SubjectId
@@ -267,13 +267,13 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
267267
// now add a pair that overlaps with largestCohort:
268268
filterCohortPairs = []utils.CustomDichotomousVariableDef{
269269
{
270-
CohortId1: smallestCohort.Id,
271-
CohortId2: largestCohort.Id,
272-
ProvidedName: "test"},
270+
CohortDefinitionId1: smallestCohort.Id,
271+
CohortDefinitionId2: largestCohort.Id,
272+
ProvidedName: "test"},
273273
{
274-
CohortId1: extendedCopyOfSecondLargestCohort.Id,
275-
CohortId2: largestCohort.Id,
276-
ProvidedName: "test"},
274+
CohortDefinitionId1: extendedCopyOfSecondLargestCohort.Id,
275+
CohortDefinitionId2: largestCohort.Id,
276+
ProvidedName: "test"},
277277
}
278278
subjectIds = []*SubjectId{}
279279
population = largestCohort
@@ -289,13 +289,13 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
289289
// order doesn't matter:
290290
filterCohortPairs = []utils.CustomDichotomousVariableDef{
291291
{
292-
CohortId1: extendedCopyOfSecondLargestCohort.Id,
293-
CohortId2: largestCohort.Id,
294-
ProvidedName: "test"},
292+
CohortDefinitionId1: extendedCopyOfSecondLargestCohort.Id,
293+
CohortDefinitionId2: largestCohort.Id,
294+
ProvidedName: "test"},
295295
{
296-
CohortId1: smallestCohort.Id,
297-
CohortId2: largestCohort.Id,
298-
ProvidedName: "test"},
296+
CohortDefinitionId1: smallestCohort.Id,
297+
CohortDefinitionId2: largestCohort.Id,
298+
ProvidedName: "test"},
299299
}
300300
subjectIds = []*SubjectId{}
301301
population = largestCohort
@@ -311,9 +311,9 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
311311
// now test with two other cohorts that overlap:
312312
filterCohortPairs = []utils.CustomDichotomousVariableDef{
313313
{
314-
CohortId1: secondLargestCohort.Id,
315-
CohortId2: extendedCopyOfSecondLargestCohort.Id,
316-
ProvidedName: "test"},
314+
CohortDefinitionId1: secondLargestCohort.Id,
315+
CohortDefinitionId2: extendedCopyOfSecondLargestCohort.Id,
316+
ProvidedName: "test"},
317317
}
318318
subjectIds = []*SubjectId{}
319319
population = extendedCopyOfSecondLargestCohort
@@ -329,13 +329,13 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
329329
// now add in the largestCohort as a pair of extendedCopyOfSecondLargestCohort to the mix above:
330330
filterCohortPairs = []utils.CustomDichotomousVariableDef{
331331
{
332-
CohortId1: secondLargestCohort.Id,
333-
CohortId2: extendedCopyOfSecondLargestCohort.Id,
334-
ProvidedName: "test"},
332+
CohortDefinitionId1: secondLargestCohort.Id,
333+
CohortDefinitionId2: extendedCopyOfSecondLargestCohort.Id,
334+
ProvidedName: "test"},
335335
{
336-
CohortId1: largestCohort.Id,
337-
CohortId2: extendedCopyOfSecondLargestCohort.Id,
338-
ProvidedName: "test"},
336+
CohortDefinitionId1: largestCohort.Id,
337+
CohortDefinitionId2: extendedCopyOfSecondLargestCohort.Id,
338+
ProvidedName: "test"},
339339
}
340340
subjectIds = []*SubjectId{}
341341
population = extendedCopyOfSecondLargestCohort
@@ -376,27 +376,27 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
376376
// should return 0:
377377
filterCohortPairs = []utils.CustomDichotomousVariableDef{
378378
{
379-
CohortId1: largestCohort.Id,
380-
CohortId2: largestCohort.Id,
381-
ProvidedName: "test"},
379+
CohortDefinitionId1: largestCohort.Id,
380+
CohortDefinitionId2: largestCohort.Id,
381+
ProvidedName: "test"},
382382
}
383383
subjectIds = []*SubjectId{}
384384
population = largestCohort
385385
resultsDataSource = tests.GetResultsDataSource()
386386
query = models.QueryFilterByCohortPairsHelper(filterCohortPairs, resultsDataSource, population.Id, "unionAndIntersect").
387387
Select("subject_id")
388388
_ = query.Scan(&subjectIds)
389-
// in this case we expect overlap the size to be 0, since the pair is composed of the same cohort in CohortId1 and CohortId2 and their overlap is excluded:
389+
// in this case we expect overlap the size to be 0, since the pair is composed of the same cohort in CohortDefinitionId1 and CohortDefinitionId2 and their overlap is excluded:
390390
if len(subjectIds) != 0 {
391391
t.Errorf("Expected 0 overlap, found %d", len(subjectIds))
392392
}
393393

394394
// should return 0:
395395
filterCohortPairs = []utils.CustomDichotomousVariableDef{
396396
{
397-
CohortId1: thirdLargestCohort.Id,
398-
CohortId2: largestCohort.Id,
399-
ProvidedName: "test"},
397+
CohortDefinitionId1: thirdLargestCohort.Id,
398+
CohortDefinitionId2: largestCohort.Id,
399+
ProvidedName: "test"},
400400
}
401401
subjectIds = []*SubjectId{}
402402
population = smallestCohort
@@ -417,9 +417,9 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndTwoCohortPai
417417
// setting the largest and smallest cohorts here as a pair:
418418
filterCohortPairs := []utils.CustomDichotomousVariableDef{
419419
{
420-
CohortId1: smallestCohort.Id,
421-
CohortId2: largestCohort.Id,
422-
ProvidedName: "test"},
420+
CohortDefinitionId1: smallestCohort.Id,
421+
CohortDefinitionId2: largestCohort.Id,
422+
ProvidedName: "test"},
423423
}
424424
breakdownConceptId := hareConceptId // not normally the case...but we'll use the same here just for the test...
425425
stats, _ := conceptModel.RetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(testSourceId,
@@ -439,13 +439,13 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndTwoCohortPai
439439
// and because of an overlaping person found in the two cohorts of the new pair.
440440
filterCohortPairs = []utils.CustomDichotomousVariableDef{
441441
{
442-
CohortId1: smallestCohort.Id,
443-
CohortId2: largestCohort.Id,
444-
ProvidedName: "test"},
442+
CohortDefinitionId1: smallestCohort.Id,
443+
CohortDefinitionId2: largestCohort.Id,
444+
ProvidedName: "test"},
445445
{
446-
CohortId1: secondLargestCohort.Id,
447-
CohortId2: extendedCopyOfSecondLargestCohort.Id,
448-
ProvidedName: "test2"},
446+
CohortDefinitionId1: secondLargestCohort.Id,
447+
CohortDefinitionId2: extendedCopyOfSecondLargestCohort.Id,
448+
ProvidedName: "test2"},
449449
}
450450
stats, _ = conceptModel.RetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(testSourceId,
451451
populationCohort.Id, filterIds, filterCohortPairs, breakdownConceptId)
@@ -464,9 +464,9 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairsW
464464
// setting the same cohort id here (artificial...but just to check if that returns the same value as when this filter is not there):
465465
filterCohortPairs := []utils.CustomDichotomousVariableDef{
466466
{
467-
CohortId1: secondLargestCohort.Id,
468-
CohortId2: extendedCopyOfSecondLargestCohort.Id,
469-
ProvidedName: "test"},
467+
CohortDefinitionId1: secondLargestCohort.Id,
468+
CohortDefinitionId2: extendedCopyOfSecondLargestCohort.Id,
469+
ProvidedName: "test"},
470470
}
471471
breakdownConceptId := hareConceptId // not normally the case...but we'll use the same here just for the test...
472472
stats, _ := conceptModel.RetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(testSourceId,
@@ -499,9 +499,9 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairsW
499499
// setting the same cohort id here (artificial...normally it should be two different ids):
500500
filterCohortPairs = []utils.CustomDichotomousVariableDef{
501501
{
502-
CohortId1: smallestCohort.Id,
503-
CohortId2: largestCohort.Id,
504-
ProvidedName: "test"},
502+
CohortDefinitionId1: smallestCohort.Id,
503+
CohortDefinitionId2: largestCohort.Id,
504+
ProvidedName: "test"},
505505
}
506506
stats3, _ := conceptModel.RetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(testSourceId,
507507
secondLargestCohort.Id, filterIds, filterCohortPairs, breakdownConceptId)
@@ -569,9 +569,9 @@ func TestGetTeamProjectsThatMatchAllCohortDefinitionIdsOnlyDefaultMatch(t *testi
569569
cohortDefinitionId := 2
570570
filterCohortPairs := []utils.CustomDichotomousVariableDef{
571571
{
572-
CohortId1: smallestCohort.Id,
573-
CohortId2: largestCohort.Id,
574-
ProvidedName: "test"},
572+
CohortDefinitionId1: smallestCohort.Id,
573+
CohortDefinitionId2: largestCohort.Id,
574+
ProvidedName: "test"},
575575
}
576576
uniqueCohortDefinitionIdsList := utils.GetUniqueCohortDefinitionIdsListFromRequest(cohortDefinitionId, filterCohortPairs)
577577
teamProjects, _ := cohortDefinitionModel.GetTeamProjectsThatMatchAllCohortDefinitionIds(uniqueCohortDefinitionIdsList)
@@ -585,9 +585,9 @@ func TestGetTeamProjectsThatMatchAllCohortDefinitionIds(t *testing.T) {
585585
cohortDefinitionId := 2
586586
filterCohortPairs := []utils.CustomDichotomousVariableDef{
587587
{
588-
CohortId1: 2,
589-
CohortId2: 2,
590-
ProvidedName: "test"},
588+
CohortDefinitionId1: 2,
589+
CohortDefinitionId2: 2,
590+
ProvidedName: "test"},
591591
}
592592
uniqueCohortDefinitionIdsList := utils.GetUniqueCohortDefinitionIdsListFromRequest(cohortDefinitionId, filterCohortPairs)
593593
teamProjects, _ := cohortDefinitionModel.GetTeamProjectsThatMatchAllCohortDefinitionIds(uniqueCohortDefinitionIdsList)
@@ -710,9 +710,9 @@ func TestRetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(t
710710
// now filter on the extendedCopyOfSecondLargestCohort
711711
filterCohortPairs = []utils.CustomDichotomousVariableDef{
712712
{
713-
CohortId1: smallestCohort.Id,
714-
CohortId2: extendedCopyOfSecondLargestCohort.Id,
715-
ProvidedName: "test"},
713+
CohortDefinitionId1: smallestCohort.Id,
714+
CohortDefinitionId2: extendedCopyOfSecondLargestCohort.Id,
715+
ProvidedName: "test"},
716716
}
717717
// then we expect histogram data for the overlapping population only (which is 5 for extendedCopyOfSecondLargestCohort and largestCohort):
718718
data, _ = cohortDataModel.RetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(testSourceId, largestCohort.Id, histogramConceptId, filterConceptIds, filterCohortPairs)
@@ -840,9 +840,9 @@ func TestRetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(t *testing.T)
840840
controlCohortId = largestCohort.Id // to ensure we get largestCohort as initial overlap, just repeat the same here...
841841
filterCohortPairs = []utils.CustomDichotomousVariableDef{
842842
{
843-
CohortId1: smallestCohort.Id,
844-
CohortId2: extendedCopyOfSecondLargestCohort.Id,
845-
ProvidedName: "test"},
843+
CohortDefinitionId1: smallestCohort.Id,
844+
CohortDefinitionId2: extendedCopyOfSecondLargestCohort.Id,
845+
ProvidedName: "test"},
846846
}
847847
// then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort:
848848
stats, _ = cohortDataModel.RetrieveCohortOverlapStatsWithoutFilteringOnConceptValue(testSourceId, caseCohortId, controlCohortId,

tests/utils_tests/utils_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func TestParsePrefixedConceptIdsAndDichotomousIds(t *testing.T) {
6666

6767
expectedCohortPairs := []utils.CustomDichotomousVariableDef{
6868
{
69-
CohortId1: 1,
70-
CohortId2: 3,
71-
ProvidedName: "test"},
69+
CohortDefinitionId1: 1,
70+
CohortDefinitionId2: 3,
71+
ProvidedName: "test"},
7272
}
7373

7474
for i, cohortPair := range cohortPairs {

utils/parsing.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ type ConceptTypes struct {
9494

9595
// fields that define a custom dichotomous variable:
9696
type CustomDichotomousVariableDef struct {
97-
CohortId1 int
98-
CohortId2 int
99-
ProvidedName string
97+
CohortDefinitionId1 int
98+
CohortDefinitionId2 int
99+
ProvidedName string
100100
}
101101

102102
func GetCohortPairKey(firstCohortDefinitionId int, secondCohortDefinitionId int) string {
@@ -144,9 +144,9 @@ func ParseConceptIdsAndDichotomousDefsAsSingleList(c *gin.Context) ([]interface{
144144
providedName = variable["provided_name"].(string)
145145
}
146146
customDichotomousVariableDef := CustomDichotomousVariableDef{
147-
CohortId1: cohortPair[0],
148-
CohortId2: cohortPair[1],
149-
ProvidedName: providedName,
147+
CohortDefinitionId1: cohortPair[0],
148+
CohortDefinitionId2: cohortPair[1],
149+
ProvidedName: providedName,
150150
}
151151
conceptIdsAndCohortPairs = append(conceptIdsAndCohortPairs, customDichotomousVariableDef)
152152
}
@@ -294,7 +294,7 @@ func GetUniqueCohortDefinitionIdsListFromRequest(cohortDefinitionId int, filterC
294294
idsList = append(idsList, cohortDefinitionId)
295295
if len(filterCohortPairs) > 0 {
296296
for _, filterCohortPair := range filterCohortPairs {
297-
idsList = append(idsList, filterCohortPair.CohortId1, filterCohortPair.CohortId2) // TODO - rename CohortId1/2 here to cohortDefinition1/2
297+
idsList = append(idsList, filterCohortPair.CohortDefinitionId1, filterCohortPair.CohortDefinitionId2)
298298
}
299299
}
300300
uniqueIdsList := MakeUnique(idsList)

0 commit comments

Comments
 (0)