@@ -241,9 +241,7 @@ func AddConceptAndMaybeAddObservations(nextConceptId int64, concept Concept) {
241
241
}
242
242
vocabularyId := 124 // just use "OMOP Vocabulary" for now...
243
243
// If concept id was already added in this session before, skip inserting it:
244
- if utils .Pos (conceptId , conceptIds ) == - 1 {
245
- // just in case, remove it if it already exists in DB:
246
- tests .RemoveConcept (models .Omop , conceptId )
244
+ if utils .Pos (conceptId , conceptIds ) == - 1 && ! tests .ConceptExists (models .Omop , conceptId ) {
247
245
// add:
248
246
tests .ExecSQLStringOrFail (
249
247
fmt .Sprintf (
@@ -292,7 +290,7 @@ func AddObservationForPerson(conceptId int64, concept Concept, personId int64) {
292
290
}
293
291
valueAsConceptId = concept .PossibleValues [randIndex ]
294
292
}
295
- tests .ExecSQLStringOrFail (
293
+ result := tests .ExecSQLString (
296
294
fmt .Sprintf (
297
295
"INSERT into %s.observation " +
298
296
"(observation_id,person_id,observation_concept_id,value_as_concept_id,value_as_number,observation_date,observation_datetime,observation_type_concept_id) " +
@@ -301,9 +299,20 @@ func AddObservationForPerson(conceptId int64, concept Concept, personId int64) {
301
299
tests .GetOmopDataSourceForSourceId (sourceId ).Schema ,
302
300
lastObservationId + 1 , personId , conceptId , valueAsConceptId , valueAsNumber ),
303
301
sourceId )
302
+ if result .Error != nil {
303
+ // fallback, try simpler record without explicitly setting observation_id:
304
+ tests .ExecSQLStringOrFail (fmt .Sprintf (
305
+ "INSERT into %s.observation " +
306
+ "(person_id,observation_concept_id,value_as_concept_id,value_as_number,observation_date,observation_datetime,observation_type_concept_id) " +
307
+ "values " +
308
+ "(%d,%d,%s,%s,'2000-01-01','2000-01-01 00:00:00',0)" ,
309
+ tests .GetOmopDataSourceForSourceId (sourceId ).Schema ,
310
+ personId , conceptId , valueAsConceptId , valueAsNumber ),
311
+ sourceId )
312
+ }
304
313
305
314
// add observation period as well:
306
- tests .ExecSQLStringOrFail (
315
+ result = tests .ExecSQLString (
307
316
fmt .Sprintf (
308
317
"INSERT into %s.observation_period " +
309
318
"(observation_period_id,person_id,observation_period_start_date,observation_period_end_date,period_type_concept_id) " +
@@ -312,7 +321,17 @@ func AddObservationForPerson(conceptId int64, concept Concept, personId int64) {
312
321
tests .GetOmopDataSourceForSourceId (sourceId ).Schema ,
313
322
lastObservationId + 1 , personId ),
314
323
sourceId )
315
-
324
+ if result .Error != nil {
325
+ // fallback, try simpler record without explicitly setting observation_id:
326
+ tests .ExecSQLStringOrFail (fmt .Sprintf (
327
+ "INSERT into %s.observation_period " +
328
+ "(person_id,observation_period_start_date,observation_period_end_date,period_type_concept_id) " +
329
+ "values " +
330
+ "(%d,'1999-01-01','2099-01-01',0)" ,
331
+ tests .GetOmopDataSourceForSourceId (sourceId ).Schema ,
332
+ personId ),
333
+ sourceId )
334
+ }
316
335
lastObservationId ++
317
336
countObservations ++
318
337
}
0 commit comments