Skip to content

Commit

Permalink
fix: using ORM methods instead of raw query
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlukasse committed Jan 16, 2025
1 parent d2ce4cf commit 835006e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions models/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ func QueryFilterByConceptDefsPlusCohortPairsHelper(sourceId int, mainCohortDefin
// Caching of temporary tables: for optimal performance, a temporary table dictionary / cache is updated, keeping a mapping
// of existing temporary table names vs underlying subsets of items in filterConceptDefsAndCohortPairs that gave rise to these
// tables.
finalSQL := "(SELECT subject_id FROM " + resultsDataSource.Schema + ".cohort WHERE cohort_definition_id=? )" + " as " + finalSetAlias + " "
query := resultsDataSource.Db.Table(finalSQL, mainCohortDefinitionId)
query := resultsDataSource.Db.Table(resultsDataSource.Schema+".cohort as "+finalSetAlias).
Select("*").
Where("cohort_definition_id=?", mainCohortDefinitionId)

tmpTableName := ""
for i, item := range filterConceptDefsAndCohortPairs {
tableAlias := fmt.Sprintf("filter_%d", i)
Expand Down
2 changes: 1 addition & 1 deletion tests/models_tests/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ func TestRetrieveHistogramDataBySourceIdAndCohortIdAndConceptDefsPlusCohortPairs
}
// everyone in the largestCohort has the histogramConceptId, but one person has NULL in the value_as_number:
if len(data) != largestCohort.CohortSize-1 {
t.Errorf("expected %d histogram data but got %d", largestCohort.CohortSize, len(data))
t.Errorf("expected %d histogram data but got %d", largestCohort.CohortSize-1, len(data))
}

// now filter on the extendedCopyOfSecondLargestCohort
Expand Down

0 comments on commit 835006e

Please sign in to comment.