@@ -57,8 +57,6 @@ var cohortDefinitionControllerNeedsDb = controllers.NewCohortDefinitionControlle
57
57
// instance of the controller that talks to a mock implementation of the model:
58
58
var cohortDefinitionController = controllers .NewCohortDefinitionController (* new (dummyCohortDefinitionDataModel ))
59
59
60
- var conceptController = controllers .NewConceptController (* new (dummyConceptDataModel ), * new (dummyCohortDefinitionDataModel ))
61
-
62
60
type dummyCohortDataModel struct {}
63
61
64
62
func (h dummyCohortDataModel ) RetrieveDataBySourceIdAndCohortIdAndConceptIdsOrderedByPersonId (sourceId int , cohortDefinitionId int , conceptIds []int64 ) ([]* models.PersonConceptAndValue , error ) {
@@ -129,11 +127,28 @@ func (h dummyCohortDefinitionDataModel) GetAllCohortDefinitions() ([]*models.Coh
129
127
return nil , nil
130
128
}
131
129
130
+ var conceptController = controllers .NewConceptController (* new (dummyConceptDataModel ), * new (dummyCohortDefinitionDataModel ))
131
+
132
132
type dummyConceptDataModel struct {}
133
133
134
134
func (h dummyConceptDataModel ) RetriveAllBySourceId (sourceId int ) ([]* models.Concept , error ) {
135
135
return nil , nil
136
136
}
137
+
138
+ func (h dummyConceptDataModel ) RetrieveInfoBySourceIdAndConceptId (sourceId int , conceptId int64 ) (* models.ConceptSimple , error ) {
139
+ conceptSimpleItems := []* models.ConceptSimple {
140
+ {ConceptId : 1234 , ConceptName : "Concept A" },
141
+ {ConceptId : 5678 , ConceptName : "Concept B" },
142
+ {ConceptId : 2090006880 , ConceptName : "Concept C" },
143
+ }
144
+ for _ , conceptSimple := range conceptSimpleItems {
145
+ if conceptSimple .ConceptId == conceptId {
146
+ return conceptSimple , nil
147
+ }
148
+ }
149
+ return nil , fmt .Errorf ("concept id %d not found in mock data" , conceptId )
150
+ }
151
+
137
152
func (h dummyConceptDataModel ) RetrieveInfoBySourceIdAndConceptIds (sourceId int , conceptIds []int64 ) ([]* models.ConceptSimple , error ) {
138
153
// dummy data with _some_ of the relevant fields:
139
154
conceptSimple := []* models.ConceptSimple {
@@ -169,8 +184,8 @@ func (h dummyConceptDataModel) RetrieveBreakdownStatsBySourceIdAndCohortId(sourc
169
184
}
170
185
func (h dummyConceptDataModel ) RetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairs (sourceId int , cohortDefinitionId int , filterConceptIds []int64 , filterCohortPairs []utils.CustomDichotomousVariableDef , breakdownConceptId int64 ) ([]* models.ConceptBreakdown , error ) {
171
186
conceptBreakdown := []* models.ConceptBreakdown {
172
- {ConceptValue : "value1" , NpersonsInCohortWithValue : 4 },
173
- {ConceptValue : "value2" , NpersonsInCohortWithValue : 7 },
187
+ {ConceptValue : "value1" , NpersonsInCohortWithValue : 4 - len ( filterCohortPairs )}, // simulate decreasing numbers as filter increases - the use of filterCohortPairs instead of filterConceptIds is otherwise meaningless here...
188
+ {ConceptValue : "value2" , NpersonsInCohortWithValue : 7 - len ( filterConceptIds )}, // simulate decreasing numbers as filter increases- the use of filterConceptIds instead of filterCohortPairs is otherwise meaningless here...
174
189
}
175
190
if dummyModelReturnError {
176
191
return nil , fmt .Errorf ("error!" )
@@ -603,75 +618,49 @@ func TestGenerateHeaderAndNonFilterRow(t *testing.T) {
603
618
}
604
619
}
605
620
606
- func TestGetConceptVariablesAttritionRows (t * testing.T ) {
621
+ func TestGetAttritionRowForConceptIdsAndCohortPairs (t * testing.T ) {
607
622
setUp (t )
608
623
sourceId := 1
609
624
cohortId := 1
610
625
var breakdownConceptId int64 = 1
611
- conceptIds := []int64 {1234 , 5678 , 2090006880 }
612
- sortedConceptValues := []string {"value1" , "value2" }
613
-
614
- result , _ := conceptController .GetConceptVariablesAttritionRows (sourceId , cohortId , conceptIds , breakdownConceptId , sortedConceptValues )
615
- if len (result ) != 3 {
616
- t .Errorf ("Expected 3 data lines, found %d lines in total" ,
617
- len (result ))
618
- t .Errorf ("Lines: %s" , result )
619
- }
620
-
621
- expectedLines := [][]string {
622
- {"Concept A" , "11" , "4" , "7" },
623
- {"Concept B" , "11" , "4" , "7" },
624
- {"Concept C" , "11" , "4" , "7" },
625
- }
626
-
627
- i := 0
628
- for _ , expectedLine := range expectedLines {
629
- if ! reflect .DeepEqual (expectedLine , result [i ]) {
630
- t .Errorf ("header or non filter row line not as expected. \n Expected: \n %s \n Found: \n %s" ,
631
- expectedLine , result [i ])
632
- }
633
- i ++
634
- }
635
- }
626
+ sortedConceptValues := []string {"value1" , "value2" , "value3" }
636
627
637
- func TestGetCustomDichotomousVariablesAttritionRows (t * testing.T ) {
638
- setUp (t )
639
- sourceId := 1
640
- cohortId := 1
641
- var breakdownConceptId int64 = 1
642
- conceptIds := []int64 {1234 , 5678 , 2090006880 }
643
- cohortPairs := []utils.CustomDichotomousVariableDef {
644
- {
628
+ // mix of concept ids and CustomDichotomousVariableDef items:
629
+ conceptIdsAndCohortPairs := []interface {}{
630
+ int64 (1234 ),
631
+ int64 (5678 ),
632
+ utils.CustomDichotomousVariableDef {
645
633
CohortId1 : 1 ,
646
634
CohortId2 : 2 ,
647
635
ProvidedName : "testA12" },
648
- {
636
+ int64 (2090006880 ),
637
+ utils.CustomDichotomousVariableDef {
649
638
CohortId1 : 3 ,
650
639
CohortId2 : 4 ,
651
640
ProvidedName : "testB34" },
652
641
}
653
642
654
- sortedConceptValues := []string {"value1" , "value2" , "value3" }
655
-
656
- result , _ := conceptController .GetCustomDichotomousVariablesAttritionRows (sourceId , cohortId , conceptIds , cohortPairs , breakdownConceptId , sortedConceptValues )
657
- if len (result ) != 2 {
658
- t .Errorf ("Expected 3 data lines, found %d lines in total" ,
643
+ result , _ := conceptController .GetAttritionRowForConceptIdsAndCohortPairs (sourceId , cohortId , conceptIdsAndCohortPairs , breakdownConceptId , sortedConceptValues )
644
+ if len (result ) != len (conceptIdsAndCohortPairs ) {
645
+ t .Errorf ("Expected %d data lines, found %d lines in total" ,
646
+ len (conceptIdsAndCohortPairs ),
659
647
len (result ))
660
648
t .Errorf ("Lines: %s" , result )
661
649
}
662
650
663
651
expectedLines := [][]string {
664
- {"testA12" , "11" , "4" , "7" , "0" },
665
- {"testB34" , "11" , "4" , "7" , "0" },
652
+ {"Concept A" , "10" , "4" , "6" , "0" },
653
+ {"Concept B" , "9" , "4" , "5" , "0" },
654
+ {"testA12" , "8" , "3" , "5" , "0" },
655
+ {"Concept C" , "7" , "3" , "4" , "0" },
656
+ {"testB34" , "6" , "2" , "4" , "0" },
666
657
}
667
658
668
- i := 0
669
- for _ , expectedLine := range expectedLines {
659
+ for i , expectedLine := range expectedLines {
670
660
if ! reflect .DeepEqual (expectedLine , result [i ]) {
671
661
t .Errorf ("header or non filter row line not as expected. \n Expected: \n %s \n Found: \n %s" ,
672
662
expectedLine , result [i ])
673
663
}
674
- i ++
675
664
}
676
665
}
677
666
@@ -849,8 +838,8 @@ func TestRetrieveAttritionTable(t *testing.T) {
849
838
requestContext .Params = append (requestContext .Params , gin.Param {Key : "breakdownconceptid" , Value : "2" })
850
839
requestContext .Writer = new (tests.CustomResponseWriter )
851
840
requestContext .Request = new (http.Request )
852
- requestBody := "{\" variables\" :[{\" variable_type\" : \" concept \" , \" concept_id \" : 2090006880 }," +
853
- "{\" variable_type\" : \" custom_dichotomous \" , \" provided_name \" : \" testABC \" , \" cohort_ids \" : [1, 3] }," +
841
+ requestBody := "{\" variables\" :[{\" variable_type\" : \" custom_dichotomous \" , \" provided_name \" : \" testABC \" , \" cohort_ids \" : [1, 3] }," +
842
+ "{\" variable_type\" : \" concept \" , \" concept_id \" : 2090006880 }," +
854
843
"{\" variable_type\" : \" custom_dichotomous\" , \" cohort_ids\" : [4, 5]}]}" // this one with no provided name (to test auto generated one)
855
844
requestContext .Request .Body = io .NopCloser (strings .NewReader (requestBody ))
856
845
requestContext .Writer = new (tests.CustomResponseWriter )
@@ -862,9 +851,9 @@ func TestRetrieveAttritionTable(t *testing.T) {
862
851
expectedLines := []string {
863
852
"Cohort,Size,value1_name,value2_name" ,
864
853
"dummy cohort name,13,5,8" ,
865
- "Concept C,11,4 ,7" ,
866
- "testABC,11,4,7 " ,
867
- "ID_4_5,11,4,7 " ,
854
+ "testABC,10,3 ,7" ,
855
+ "Concept C,9,3,6 " ,
856
+ "ID_4_5,8,2,6 " ,
868
857
}
869
858
i := 0
870
859
for _ , expectedLine := range expectedLines {
0 commit comments