@@ -280,8 +280,8 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
280
280
query = models .QueryFilterByCohortPairsHelper (filterCohortPairs , resultsDataSource , population .Id , "unionAndIntersect" ).
281
281
Select ("subject_id" )
282
282
_ = query .Scan (& subjectIds )
283
- // in this case we expect overlap the size of the largestCohort-5 :
284
- if len (subjectIds ) != (largestCohort .CohortSize - 5 ) {
283
+ // in this case we expect overlap the size of the largestCohort-6 (where 6 is the size of the overlap between extendedCopyOfSecondLargestCohort and largestCohort) :
284
+ if len (subjectIds ) != (largestCohort .CohortSize - 6 ) {
285
285
t .Errorf ("Expected %d overlap, found %d" , largestCohort .CohortSize - 5 , len (subjectIds ))
286
286
}
287
287
@@ -303,7 +303,7 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
303
303
Select ("subject_id" )
304
304
_ = query .Scan (& subjectIds )
305
305
// in this case we expect same as previous test above:
306
- if len (subjectIds ) != (largestCohort .CohortSize - 5 ) {
306
+ if len (subjectIds ) != (largestCohort .CohortSize - 6 ) {
307
307
t .Errorf ("Expected %d overlap, found %d" , largestCohort .CohortSize - 5 , len (subjectIds ))
308
308
}
309
309
@@ -494,8 +494,10 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairsW
494
494
if len (stats ) > len (stats2 ) {
495
495
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 ))
496
496
}
497
- // test filtering with smallest cohort, lenght should be 1, since that's the size of the smallest cohort:
498
- // setting the same cohort id here (artificial...normally it should be two different ids):
497
+
498
+ // test filtering with secondLargestCohort, smallest and largestCohort.
499
+ // Lenght of result set should be 2 persons (one HIS, one ASN), since there is a overlap of 1 between secondLargestCohort and smallest cohort,
500
+ // and overlap of 2 between secondLargestCohort and largestCohort, BUT only 1 has a HARE value:
499
501
filterCohortPairs = []utils.CustomDichotomousVariableDef {
500
502
{
501
503
CohortId1 : smallestCohort .Id ,
@@ -505,7 +507,14 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairsW
505
507
stats3 , _ := conceptModel .RetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairs (testSourceId ,
506
508
secondLargestCohort .Id , filterIds , filterCohortPairs , breakdownConceptId )
507
509
if len (stats3 ) != 2 {
508
- t .Errorf ("Expected only two items in resultset, found %d" , len (stats ))
510
+ t .Errorf ("Expected only two items in resultset, found %d" , len (stats3 ))
511
+ }
512
+ countPersons := 0
513
+ for _ , stat := range stats3 {
514
+ countPersons = countPersons + stat .NpersonsInCohortWithValue
515
+ }
516
+ if countPersons != 2 {
517
+ t .Errorf ("Expected only two persons in resultset, found %d" , countPersons )
509
518
}
510
519
}
511
520
@@ -633,9 +642,9 @@ func TestRetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(t
633
642
filterConceptIds := []int64 {}
634
643
filterCohortPairs := []utils.CustomDichotomousVariableDef {}
635
644
data , _ := cohortDataModel .RetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs (testSourceId , largestCohort .Id , histogramConceptId , filterConceptIds , filterCohortPairs )
636
- // everyone in the largestCohort has the histogramConceptId:
637
- if len (data ) != largestCohort .CohortSize {
638
- t .Errorf ("expected 10 or more histogram data but got %d" , len (data ))
645
+ // everyone in the largestCohort has the histogramConceptId, but one person has NULL in the value_as_number :
646
+ if len (data ) != largestCohort .CohortSize - 1 {
647
+ t .Errorf ("expected %d histogram data but got %d" , largestCohort . CohortSize , len (data ))
639
648
}
640
649
641
650
// now filter on the extendedCopyOfSecondLargestCohort
@@ -775,11 +784,11 @@ func TestRetrieveCohortOverlapStats(t *testing.T) {
775
784
CohortId2 : extendedCopyOfSecondLargestCohort .Id ,
776
785
ProvidedName : "test" },
777
786
}
778
- // then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort:
787
+ // then we expect overlap of 6 for extendedCopyOfSecondLargestCohort and largestCohort:
779
788
stats , _ = cohortDataModel .RetrieveCohortOverlapStats (testSourceId , caseCohortId , controlCohortId ,
780
789
otherFilterConceptIds , filterCohortPairs )
781
- if stats .CaseControlOverlap != 5 {
782
- t .Errorf ("Expected nr persons to be %d, found %d" , 5 , stats .CaseControlOverlap )
790
+ if stats .CaseControlOverlap != 6 {
791
+ t .Errorf ("Expected nr persons to be %d, found %d" , 6 , stats .CaseControlOverlap )
783
792
}
784
793
785
794
// extra test: different parameters that should return the same as above ^:
@@ -788,10 +797,10 @@ func TestRetrieveCohortOverlapStats(t *testing.T) {
788
797
filterCohortPairs = []utils.CustomDichotomousVariableDef {}
789
798
otherFilterConceptIds = []int64 {histogramConceptId } // extra filter, to cover this part of the code...
790
799
// then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort (the filter on histogramConceptId should not matter
791
- // since all in largestCohort have an observation for this concept id):
800
+ // since all in largestCohort have an observation for this concept id except one person who has it but has value_as_number as NULL ):
792
801
stats2 , _ := cohortDataModel .RetrieveCohortOverlapStats (testSourceId , caseCohortId , controlCohortId ,
793
802
otherFilterConceptIds , filterCohortPairs )
794
- if stats2 .CaseControlOverlap != stats .CaseControlOverlap {
803
+ if stats2 .CaseControlOverlap != stats .CaseControlOverlap - 1 {
795
804
t .Errorf ("Expected nr persons to be %d, found %d" , stats .CaseControlOverlap , stats2 .CaseControlOverlap )
796
805
}
797
806
0 commit comments