Skip to content

Commit

Permalink
feat: invert fallback insert code
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlukasse committed Oct 4, 2024
1 parent a65b5ea commit 5e159ea
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/data_generator/datagenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,43 +293,43 @@ func AddObservationForPerson(conceptId int64, concept Concept, personId int64) {
result := tests.ExecSQLString(
fmt.Sprintf(
"INSERT into %s.observation "+
"(observation_id,person_id,observation_concept_id,value_as_concept_id,value_as_number,observation_date,observation_datetime,observation_type_concept_id) "+
"(person_id,observation_concept_id,value_as_concept_id,value_as_number,observation_date,observation_datetime,observation_type_concept_id) "+
"values "+
"(%d,%d,%d,%s,%s,'2000-01-01','2000-01-01 00:00:00',0)",
"(%d,%d,%s,%s,'2000-01-01','2000-01-01 00:00:00',0)",
tests.GetOmopDataSourceForSourceId(sourceId).Schema,
lastObservationId+1, personId, conceptId, valueAsConceptId, valueAsNumber),
personId, conceptId, valueAsConceptId, valueAsNumber),
sourceId)
if result.Error != nil {
// fallback, try simpler record without explicitly setting observation_id:
tests.ExecSQLStringOrFail(fmt.Sprintf(
"INSERT into %s.observation "+
"(person_id,observation_concept_id,value_as_concept_id,value_as_number,observation_date,observation_datetime,observation_type_concept_id) "+
"(observation_id,person_id,observation_concept_id,value_as_concept_id,value_as_number,observation_date,observation_datetime,observation_type_concept_id) "+
"values "+
"(%d,%d,%s,%s,'2000-01-01','2000-01-01 00:00:00',0)",
"(%d,%d,%d,%s,%s,'2000-01-01','2000-01-01 00:00:00',0)",
tests.GetOmopDataSourceForSourceId(sourceId).Schema,
personId, conceptId, valueAsConceptId, valueAsNumber),
lastObservationId+1, personId, conceptId, valueAsConceptId, valueAsNumber),
sourceId)
}

// add observation period as well:
result = tests.ExecSQLString(
fmt.Sprintf(
"INSERT into %s.observation_period "+
"(observation_period_id,person_id,observation_period_start_date,observation_period_end_date,period_type_concept_id) "+
"(person_id,observation_period_start_date,observation_period_end_date,period_type_concept_id) "+
"values "+
"(%d,%d,'1999-01-01','2099-01-01',0)",
"(%d,'1999-01-01','2099-01-01',0)",
tests.GetOmopDataSourceForSourceId(sourceId).Schema,
lastObservationId+1, personId),
personId),
sourceId)
if result.Error != nil {
// fallback, try simpler record without explicitly setting observation_id:
tests.ExecSQLStringOrFail(fmt.Sprintf(
"INSERT into %s.observation_period "+
"(person_id,observation_period_start_date,observation_period_end_date,period_type_concept_id) "+
"(observation_period_id,person_id,observation_period_start_date,observation_period_end_date,period_type_concept_id) "+
"values "+
"(%d,'1999-01-01','2099-01-01',0)",
"(%d,%d,'1999-01-01','2099-01-01',0)",
tests.GetOmopDataSourceForSourceId(sourceId).Schema,
personId),
lastObservationId+1, personId),
sourceId)
}
lastObservationId++
Expand Down

0 comments on commit 5e159ea

Please sign in to comment.