System not creating new encounter properly

The system is creating the encounter but it is not assigning the encounter a number so when the system tries to load the encounter, it shows a blank encounter with the date of 1970-01-01. I have checked the database table form and form_encounter and the encounter column is 0.

Just started happening today. Has anyone had this happen before. I have seen it before but forgot what fixed it.

Windows 2012 server
Apache 2.4.9 -
PHP 7.0.3
MySQL 5.6.17

What version of OpenEMR is this?

Version Number: v5.0.0 (3).
Even if I put an appointment on the calendar and arrive the patient it does the same thing.
There are no errors in the error log. Also, the popup that displays the encounter created is not showing up.

after digging through the code this function is not working in the sql.inc

/**

  • @todo document use of the generate_id function
    */
    function generate_id () {
    $database = $GLOBALS[‘adodb’][‘db’];
    return $database->GenID(“sequences”);
    }

I swapped out the line 56 in the save.php and put in a static number and everything worked. So the
generate_id() is not returning an ID to insert into the table.

Now how to fix it?

This is the workaround that I came up with because the system is incrementing the table but the data is not being retrieved. So, I am just making a simple call to the table to get the data that is not being returned.

function generate_id () {
$database = $GLOBALS[‘adodb’][‘db’];
//return $database->GenID(“sequences”);
$database->GenID(“sequences”);
$sql = “SELECT id FROM sequences”;
$g = sqlQuery($sql);
return $g[‘id’];
}

G for Gaddis.

I guess what is really perplexing is why this just started happening today on your OpenEMR instance. How high is the sequence number up to?
-brady

also, why don’t you just make it:
$gaddis_was_here = sqlQuery($sql);
:slight_smile:

The sequence if very low 1200+. And I was just slapping stuff together to and I was just doing the first thing that came to mind. While I was posting the result I thought someone would wonder why I used $g.

I am going to try and figure out why the code stopped working. I just need to patch it enough for the doc to work. I suspect there is something wrong with the database table. That is the only thing that makes sense since the code did not change.

Developers log final entry, stardate 2017-15-06:
After investigating the database table, I noticed that the Rows column of the sequences table stayed 0 even though there was data in the table. So, I dropped and restored the table. Re-entered the last number and drop the patch and the system is now working as it did before. The sequences table had become corrupt. That is why the system could not issue new encounter numbers. So anyone reading this thread, drop the sequences table and build a fresh table. That may solve this problem if it occurs in your system.

1 Like