diff --git a/tests/controllers_tests/controllers_test.go b/tests/controllers_tests/controllers_test.go index e7e4f2a..1381f79 100644 --- a/tests/controllers_tests/controllers_test.go +++ b/tests/controllers_tests/controllers_test.go @@ -81,6 +81,11 @@ func (h dummyCohortDataModel) RetrieveHistogramDataBySourceIdAndCohortIdAndConce return cohortData, nil } +func (h dummyCohortDataModel) RetrieveHistogramDataBySourceIdAndCohortIdAndConceptDefsPlusCohortPairs(sourceId int, cohortDefinitionId int, histogramConceptId int64, filterConceptDefsAndCohortPairs []interface{}) ([]*models.PersonConceptAndValue, error) { + cohortData := []*models.PersonConceptAndValue{} + return cohortData, nil +} + func (h dummyCohortDataModel) RetrieveHistogramDataBySourceIdAndConceptId(sourceId int, histogramConceptId int64) ([]*models.PersonConceptAndValue, error) { cohortData := []*models.PersonConceptAndValue{} @@ -907,13 +912,13 @@ func TestGetAttritionRowForConceptIdsAndCohortPairs(t *testing.T) { // mix of concept ids and CustomDichotomousVariableDef items: conceptIdsAndCohortPairs := []interface{}{ - utils.CustomConceptVariableDef{ConceptId: int64(1234), ConceptValues: []int64{}}, - utils.CustomConceptVariableDef{ConceptId: int64(5678), ConceptValues: []int64{}}, + utils.CustomConceptVariableDef{ConceptId: int64(1234)}, + utils.CustomConceptVariableDef{ConceptId: int64(5678)}, utils.CustomDichotomousVariableDef{ CohortDefinitionId1: 1, CohortDefinitionId2: 2, ProvidedName: "testA12"}, - utils.CustomConceptVariableDef{ConceptId: int64(2090006880), ConceptValues: []int64{}}, + utils.CustomConceptVariableDef{ConceptId: int64(2090006880)}, utils.CustomDichotomousVariableDef{ CohortDefinitionId1: 3, CohortDefinitionId2: 4, diff --git a/tests/utils_tests/utils_test.go b/tests/utils_tests/utils_test.go index 72ea77b..8384066 100644 --- a/tests/utils_tests/utils_test.go +++ b/tests/utils_tests/utils_test.go @@ -51,7 +51,7 @@ func TestParsePrefixedConceptIdsAndDichotomousIds(t *testing.T) { requestContext.Writer = new(tests.CustomResponseWriter) requestContext.Request = new(http.Request) requestBody := "{\"variables\":[{\"variable_type\": \"concept\", \"concept_id\": 2000000324}," + - "{\"variable_type\": \"concept\", \"concept_id\": 2000000123, \"values\": [2000000237, 2000000238]}," + + "{\"variable_type\": \"concept\", \"concept_id\": 2000000123, \"filters\": [{\"type\": \"in\", \"values_as_concept_ids\": [2000000237, 2000000238]}]}," + "{\"variable_type\": \"custom_dichotomous\", \"provided_name\": \"test\", \"cohort_ids\": [1, 3]}]}" requestContext.Request.Body = io.NopCloser(strings.NewReader(requestBody)) @@ -60,9 +60,20 @@ func TestParsePrefixedConceptIdsAndDichotomousIds(t *testing.T) { t.Errorf("Did not expect this request to abort") } - expectedPrefixedConceptDefs := []utils.CustomConceptVariableDef{{ConceptId: 2000000324, ConceptValues: []int64{}}, {ConceptId: 2000000123, ConceptValues: []int64{2000000237, 2000000238}}} + expectedPrefixedConceptDefs := []utils.CustomConceptVariableDef{ + {ConceptId: 2000000324}, + {ConceptId: 2000000123, + Filters: []utils.Filter{ + { + Type: "in", + ValuesAsConceptIds: []int64{2000000237, 2000000238}, + }, + }, + }, + } + if !reflect.DeepEqual(conceptDefs, expectedPrefixedConceptDefs) { - t.Errorf("Expected %d but found %d", expectedPrefixedConceptDefs, conceptDefs) + t.Errorf("Expected %v but found %v", expectedPrefixedConceptDefs, conceptDefs) } expectedCohortPairs := []utils.CustomDichotomousVariableDef{ @@ -336,7 +347,7 @@ func TestGenerateStatsData(t *testing.T) { func TestConvertConceptIdToCustomConceptVariablesDef(t *testing.T) { setUp(t) - expectedResult := []utils.CustomConceptVariableDef{{ConceptId: 1234, ConceptValues: []int64{}}, {ConceptId: 5678, ConceptValues: []int64{}}} + expectedResult := []utils.CustomConceptVariableDef{{ConceptId: 1234}, {ConceptId: 5678}} conceptIds := []int64{1234, 5678} result := utils.ConvertConceptIdToCustomConceptVariablesDef(conceptIds) @@ -348,7 +359,17 @@ func TestConvertConceptIdToCustomConceptVariablesDef(t *testing.T) { func TestExtractConceptIdsFromCustomConceptVariablesDef(t *testing.T) { setUp(t) - var testData = []utils.CustomConceptVariableDef{{ConceptId: 1234, ConceptValues: []int64{7890}}, {ConceptId: 5678, ConceptValues: []int64{}}} + var testData = []utils.CustomConceptVariableDef{ + {ConceptId: 1234, + Filters: []utils.Filter{ + { + Type: "in", + ValuesAsConceptIds: []int64{7890}, + }, + }, + }, + {ConceptId: 5678}, + } expectedResult := []int64{1234, 5678} result := utils.ExtractConceptIdsFromCustomConceptVariablesDef(testData) if !reflect.DeepEqual(expectedResult, result) { diff --git a/utils/parsing.go b/utils/parsing.go index f7a389a..12f8a92 100644 --- a/utils/parsing.go +++ b/utils/parsing.go @@ -117,7 +117,7 @@ type Filter struct { Value *float64 `json:"value,omitempty"` Values []float64 `json:"values,omitempty"` ValueAsConceptId *int64 `json:"value_as_concept_id,omitempty"` - ValuesAsConceptIds []int64 `json:"values_as_concept_id,omitempty"` + ValuesAsConceptIds []int64 `json:"values_as_concept_ids,omitempty"` } // fields that define a custom dichotomous variable: