diff --git a/pkg/datasource/explore_query.go b/pkg/datasource/explore_query.go index c22d928..d157feb 100644 --- a/pkg/datasource/explore_query.go +++ b/pkg/datasource/explore_query.go @@ -55,6 +55,7 @@ func (ds I2b2DataSource) ExploreQueryHandler(userID string, jsonParameters []byt { OutputName: outputNameExploreQueryCount, SharedID: outputDataObjectsSharedIDs[outputNameExploreQueryCount], + Columns: []string{"count"}, IntValue: &count, }, { OutputName: outputNameExploreQueryPatientList, diff --git a/pkg/datasource/statistics_query.go b/pkg/datasource/statistics_query.go index 24958c2..bc74926 100644 --- a/pkg/datasource/statistics_query.go +++ b/pkg/datasource/statistics_query.go @@ -42,9 +42,12 @@ func (ds I2b2DataSource) StatisticsQueryHandler( valueVector := []int64{} columns := []string{} - for _, bucket := range statResult.Buckets { + // these are needed to correctly sort the columns during the aggregation + labels := generateColumnsLabels(len(statResult.Buckets)) + + for i, bucket := range statResult.Buckets { valueVector = append(valueVector, bucket.Count) - columns = append(columns, "["+fmt.Sprintf("%f", bucket.LowerBound)+", "+fmt.Sprintf("%f", bucket.HigherBound)+"]") + columns = append(columns, "[\""+labels[i]+"\", "+fmt.Sprintf("%f", bucket.LowerBound)+", "+fmt.Sprintf("%f", bucket.HigherBound)+"]") } values = append(values, valueVector) diff --git a/pkg/datasource/survival_query.go b/pkg/datasource/survival_query.go index a9336ac..fea8cf4 100644 --- a/pkg/datasource/survival_query.go +++ b/pkg/datasource/survival_query.go @@ -43,6 +43,7 @@ func (ds I2b2DataSource) SurvivalQueryHandler(userID string, jsonParameters []by { OutputName: outputNameSurvivalQueryResult, SharedID: outputDataObjectsSharedIDs[outputNameSurvivalQueryResult], + Columns: generateColumnsLabels(len(survivalQueryResult)), IntVector: survivalQueryResult, }, } diff --git a/pkg/datasource/utils.go b/pkg/datasource/utils.go new file mode 100644 index 0000000..8878b8e --- /dev/null +++ b/pkg/datasource/utils.go @@ -0,0 +1,20 @@ +package datasource + +import ( + "fmt" + "math" +) + +// generateColumnsLabels generates a list containing the string representations of the numbers from 0 to n-1, with the right number of leading 0s. +// e.g., for n=16 -> ["00", "01, ..., "15"], for n=106 -> ["000", "001", ..., "115"] +func generateColumnsLabels(n int) []string { + + labels := make([]string, n) + figures := int(math.Ceil(math.Log10(float64(n)))) + + for i := 0; i < n; i++ { + labels[i] = fmt.Sprintf(fmt.Sprintf("%%0%dd", figures), i) + } + + return labels +}