Skip to content

Commit

Permalink
fix: fix Last* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlukasse committed Oct 4, 2024
1 parent 5e159ea commit c8149cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions tests/data_generator/datagenerator_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"os"
"testing"
Expand Down Expand Up @@ -80,6 +81,16 @@ func TestRunDataGeneration(t *testing.T) {
if countPersons != 18 {
t.Errorf("Expected 18 persons, found %d", countPersons)
}
lastConceptId := tests.GetLastConceptId(tests.GetTestSourceId())
if lastConceptId <= 2000007031 {
t.Errorf("Expected larger concept_id, found %d", lastConceptId)
}
totalObservationsLastConcept := tests.GetCountWhere(tests.GetOmopDataSourceForSourceId(tests.GetTestSourceId()), "observation",
fmt.Sprintf("observation_concept_id = %d", lastConceptId))
if totalObservationsLastConcept != 4 {
t.Errorf("Expected 4 observations, found %d", totalObservationsLastConcept)
}

// the name cohort is confusing...but it is one row per person x cohort_definition:
// totalCohortSize := tests.GetCount(tests.GetResultsDataSourceForSourceId(tests.GetTestSourceId()), "cohort")
// if totalCohortSize != 32 {
Expand Down
8 changes: 4 additions & 4 deletions tests/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func EmptyTable(dataSource *utils.DbAndSchema, tableName string) {
func GetLastCohortId() int {
dataSource := db.GetAtlasDB()
var lastCohortDefinition models.CohortDefinition
dataSource.Db.Order("id DESC").First(&lastCohortDefinition)
dataSource.Db.Select("id").Order("id DESC").First(&lastCohortDefinition)
return lastCohortDefinition.Id
}

Expand All @@ -124,7 +124,7 @@ func GetNextCohortId() int {
func GetLastConceptId(sourceId int) int64 {
dataSource := GetOmopDataSourceForSourceId(sourceId)
var lastConcept models.Concept
dataSource.Db.Order("concept_id DESC").First(&lastConcept)
dataSource.Db.Select("concept_id").Order("concept_id DESC").First(&lastConcept)
log.Printf("Last concept id found %d",
lastConcept.ConceptId)
return lastConcept.ConceptId
Expand All @@ -133,14 +133,14 @@ func GetLastConceptId(sourceId int) int64 {
func GetLastObservationId(sourceId int) int64 {
dataSource := GetOmopDataSourceForSourceId(sourceId)
var lastObservation models.Observation
dataSource.Db.Order("observation_id DESC").First(&lastObservation)
dataSource.Db.Select("observation_id").Order("observation_id DESC").First(&lastObservation)
return lastObservation.ObservationId
}

func GetLastPersonId(sourceId int) int64 {
dataSource := GetOmopDataSourceForSourceId(sourceId)
var lastPerson models.Person
dataSource.Db.Order("person_id DESC").First(&lastPerson)
dataSource.Db.Select("person_id").Order("person_id DESC").First(&lastPerson)
return lastPerson.PersonId
}

Expand Down

0 comments on commit c8149cb

Please sign in to comment.