@@ -281,8 +281,8 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
281
281
query = models .QueryFilterByCohortPairsHelper (filterCohortPairs , resultsDataSource , population .Id , "unionAndIntersect" ).
282
282
Select ("subject_id" )
283
283
_ = query .Scan (& subjectIds )
284
- // in this case we expect overlap the size of the largestCohort-5 :
285
- if len (subjectIds ) != (largestCohort .CohortSize - 5 ) {
284
+ // in this case we expect overlap the size of the largestCohort-6 (where 6 is the size of the overlap between extendedCopyOfSecondLargestCohort and largestCohort) :
285
+ if len (subjectIds ) != (largestCohort .CohortSize - 6 ) {
286
286
t .Errorf ("Expected %d overlap, found %d" , largestCohort .CohortSize - 5 , len (subjectIds ))
287
287
}
288
288
@@ -304,7 +304,7 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
304
304
Select ("subject_id" )
305
305
_ = query .Scan (& subjectIds )
306
306
// in this case we expect same as previous test above:
307
- if len (subjectIds ) != (largestCohort .CohortSize - 5 ) {
307
+ if len (subjectIds ) != (largestCohort .CohortSize - 6 ) {
308
308
t .Errorf ("Expected %d overlap, found %d" , largestCohort .CohortSize - 5 , len (subjectIds ))
309
309
}
310
310
@@ -495,8 +495,10 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairsW
495
495
if len (stats ) > len (stats2 ) {
496
496
t .Errorf ("First query is more restrictive, so its stats should not be larger than stats2 of second query. Got %d and %d" , len (stats ), len (stats2 ))
497
497
}
498
- // test filtering with smallest cohort, lenght should be 1, since that's the size of the smallest cohort:
499
- // setting the same cohort id here (artificial...normally it should be two different ids):
498
+
499
+ // test filtering with secondLargestCohort, smallest and largestCohort.
500
+ // Lenght of result set should be 2 persons (one HIS, one ASN), since there is a overlap of 1 between secondLargestCohort and smallest cohort,
501
+ // and overlap of 2 between secondLargestCohort and largestCohort, BUT only 1 has a HARE value:
500
502
filterCohortPairs = []utils.CustomDichotomousVariableDef {
501
503
{
502
504
CohortDefinitionId1 : smallestCohort .Id ,
@@ -506,7 +508,14 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairsW
506
508
stats3 , _ := conceptModel .RetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairs (testSourceId ,
507
509
secondLargestCohort .Id , filterIds , filterCohortPairs , breakdownConceptId )
508
510
if len (stats3 ) != 2 {
509
- t .Errorf ("Expected only two items in resultset, found %d" , len (stats ))
511
+ t .Errorf ("Expected only two items in resultset, found %d" , len (stats3 ))
512
+ }
513
+ countPersons := 0
514
+ for _ , stat := range stats3 {
515
+ countPersons = countPersons + stat .NpersonsInCohortWithValue
516
+ }
517
+ if countPersons != 2 {
518
+ t .Errorf ("Expected only two persons in resultset, found %d" , countPersons )
510
519
}
511
520
}
512
521
@@ -731,9 +740,9 @@ func TestRetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(t
731
740
filterConceptIds := []int64 {}
732
741
filterCohortPairs := []utils.CustomDichotomousVariableDef {}
733
742
data , _ := cohortDataModel .RetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs (testSourceId , largestCohort .Id , histogramConceptId , filterConceptIds , filterCohortPairs )
734
- // everyone in the largestCohort has the histogramConceptId:
735
- if len (data ) != largestCohort .CohortSize {
736
- t .Errorf ("expected 10 or more histogram data but got %d" , len (data ))
743
+ // everyone in the largestCohort has the histogramConceptId, but one person has NULL in the value_as_number :
744
+ if len (data ) != largestCohort .CohortSize - 1 {
745
+ t .Errorf ("expected %d histogram data but got %d" , largestCohort . CohortSize , len (data ))
737
746
}
738
747
739
748
// now filter on the extendedCopyOfSecondLargestCohort
@@ -873,11 +882,11 @@ func TestRetrieveCohortOverlapStats(t *testing.T) {
873
882
CohortDefinitionId2 : extendedCopyOfSecondLargestCohort .Id ,
874
883
ProvidedName : "test" },
875
884
}
876
- // then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort:
885
+ // then we expect overlap of 6 for extendedCopyOfSecondLargestCohort and largestCohort:
877
886
stats , _ = cohortDataModel .RetrieveCohortOverlapStats (testSourceId , caseCohortId , controlCohortId ,
878
887
otherFilterConceptIds , filterCohortPairs )
879
- if stats .CaseControlOverlap != 5 {
880
- t .Errorf ("Expected nr persons to be %d, found %d" , 5 , stats .CaseControlOverlap )
888
+ if stats .CaseControlOverlap != 6 {
889
+ t .Errorf ("Expected nr persons to be %d, found %d" , 6 , stats .CaseControlOverlap )
881
890
}
882
891
883
892
// extra test: different parameters that should return the same as above ^:
@@ -886,10 +895,10 @@ func TestRetrieveCohortOverlapStats(t *testing.T) {
886
895
filterCohortPairs = []utils.CustomDichotomousVariableDef {}
887
896
otherFilterConceptIds = []int64 {histogramConceptId } // extra filter, to cover this part of the code...
888
897
// then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort (the filter on histogramConceptId should not matter
889
- // since all in largestCohort have an observation for this concept id):
898
+ // since all in largestCohort have an observation for this concept id except one person who has it but has value_as_number as NULL ):
890
899
stats2 , _ := cohortDataModel .RetrieveCohortOverlapStats (testSourceId , caseCohortId , controlCohortId ,
891
900
otherFilterConceptIds , filterCohortPairs )
892
- if stats2 .CaseControlOverlap != stats .CaseControlOverlap {
901
+ if stats2 .CaseControlOverlap != stats .CaseControlOverlap - 1 {
893
902
t .Errorf ("Expected nr persons to be %d, found %d" , stats .CaseControlOverlap , stats2 .CaseControlOverlap )
894
903
}
895
904
0 commit comments