Skip to content

Commit c8149cb

Browse files
committed
fix: fix Last* methods
1 parent 5e159ea commit c8149cb

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

tests/data_generator/datagenerator_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"log"
56
"os"
67
"testing"
@@ -80,6 +81,16 @@ func TestRunDataGeneration(t *testing.T) {
8081
if countPersons != 18 {
8182
t.Errorf("Expected 18 persons, found %d", countPersons)
8283
}
84+
lastConceptId := tests.GetLastConceptId(tests.GetTestSourceId())
85+
if lastConceptId <= 2000007031 {
86+
t.Errorf("Expected larger concept_id, found %d", lastConceptId)
87+
}
88+
totalObservationsLastConcept := tests.GetCountWhere(tests.GetOmopDataSourceForSourceId(tests.GetTestSourceId()), "observation",
89+
fmt.Sprintf("observation_concept_id = %d", lastConceptId))
90+
if totalObservationsLastConcept != 4 {
91+
t.Errorf("Expected 4 observations, found %d", totalObservationsLastConcept)
92+
}
93+
8394
// the name cohort is confusing...but it is one row per person x cohort_definition:
8495
// totalCohortSize := tests.GetCount(tests.GetResultsDataSourceForSourceId(tests.GetTestSourceId()), "cohort")
8596
// if totalCohortSize != 32 {

tests/testutils.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func EmptyTable(dataSource *utils.DbAndSchema, tableName string) {
109109
func GetLastCohortId() int {
110110
dataSource := db.GetAtlasDB()
111111
var lastCohortDefinition models.CohortDefinition
112-
dataSource.Db.Order("id DESC").First(&lastCohortDefinition)
112+
dataSource.Db.Select("id").Order("id DESC").First(&lastCohortDefinition)
113113
return lastCohortDefinition.Id
114114
}
115115

@@ -124,7 +124,7 @@ func GetNextCohortId() int {
124124
func GetLastConceptId(sourceId int) int64 {
125125
dataSource := GetOmopDataSourceForSourceId(sourceId)
126126
var lastConcept models.Concept
127-
dataSource.Db.Order("concept_id DESC").First(&lastConcept)
127+
dataSource.Db.Select("concept_id").Order("concept_id DESC").First(&lastConcept)
128128
log.Printf("Last concept id found %d",
129129
lastConcept.ConceptId)
130130
return lastConcept.ConceptId
@@ -133,14 +133,14 @@ func GetLastConceptId(sourceId int) int64 {
133133
func GetLastObservationId(sourceId int) int64 {
134134
dataSource := GetOmopDataSourceForSourceId(sourceId)
135135
var lastObservation models.Observation
136-
dataSource.Db.Order("observation_id DESC").First(&lastObservation)
136+
dataSource.Db.Select("observation_id").Order("observation_id DESC").First(&lastObservation)
137137
return lastObservation.ObservationId
138138
}
139139

140140
func GetLastPersonId(sourceId int) int64 {
141141
dataSource := GetOmopDataSourceForSourceId(sourceId)
142142
var lastPerson models.Person
143-
dataSource.Db.Order("person_id DESC").First(&lastPerson)
143+
dataSource.Db.Select("person_id").Order("person_id DESC").First(&lastPerson)
144144
return lastPerson.PersonId
145145
}
146146

0 commit comments

Comments
 (0)