Auto Increment Bug?

mike-h30 wrote on Monday, January 28, 2008:

I loaded 247 records from a text file into tables "forms", "form_encounter", and "form_soap".  I verified that the data was loaded properly and tested it by viewing them via clicking on the "Encounter" button for corresponding patient and clicking through the documents.  However, I ran into a problem when entering a new encounter via the "New Encounter" form.  The auto increment is working correctly on the "ID" field (form_encounter.id), however it does not seem to be working correctly on the field form_encounter.encounter and forms.encounter

Here is sample output from the table "form_encounter" where I added my new entry via the "New Encounter" form. 

"id";"date";"reason";"facility";"facility_id";"pid";"encounter";"onset_date";"sensitivity"
"247";"2007-07-10 18:14:19";"TEST";NULL;"4";"1042";"247";"2007-07-10 18:14:19";
"248";"2008-01-28 00:00:00";"TEST";NULL;"4";"1010";"62";"2008-01-28 00:00:00";

I noticed that the field "encounter" did not increment from number in the last record ("247").  I was expecting "248" not "62".

Please advise as there is already an encounter "62" that was imported from my text file.

Regards,

-Mike

sunsetsystems wrote on Monday, January 28, 2008:

The encounter number is not an auto_increment column.  You have to generate it by incrementing the value in the "sequences" table.

Rod
www.sunsetsystems.com

mike-h30 wrote on Monday, January 28, 2008:

Thanks Rod! 

So after I import my data, should I set it to the number of my last encounter + 1 ( in my case 248 ), since I am importing 247 records?
Are there other critical values that I need to keep an eye out for?

The only data that I am importing is patient demographics and the recent encounters.  From there all new records will be created via the OpenEMR interface.

Mike

sunsetsystems wrote on Monday, January 28, 2008:

I think what you want to do is get your *first* encounter number as sequences.id + 1, and then when done set sequences.id to your last encounter number.

I believe the sequences table is shared for some other IDs also (which is dumb, oh well)… that might be something to watch out for, but perhaps doesn’t matter for what you are doing.

Rod
www.sunsetsystems.com

mike-h30 wrote on Tuesday, January 29, 2008:

Thanks Rod.  I was a little concerned about that “sequences” table.  I just hope that it doesn’t cause an issue going forward.  So far this was the only instance I came across.