Incorrect Encounter IDs when logging is on

rnagul wrote on Monday, March 21, 2011:

Hi there,

I am having an issue with encounters when logging is turned on. It looks like there was a fix put in place in log.inc by VicarePlus to store the last_insert_id  so the correct ID is returned but as of last week’s (3/14/2011) build it looks like the issue exists. The $GLOBALS value is not retained.

The stack is as follows.

log.inc - auditSQLEvent call after the execute function completes the insert
adodb.inc.php - Execute($statement, $binds) call
sql.inc (sqlInsert(…) call)
save.php

My environment is: PHP 5.3.0/Apache 2.2.11/MySQL 5.1.36

Anyone encountered something similar?

Thanks!

Ramesh

visolveemr wrote on Tuesday, March 22, 2011:

Hi Ramesh,

We have verified for the previously reported auditlog issues in the current code base and we don’t find any issues.  If you could share specific info on the issue you have faced while the audit log is enable, we’ll able to isolate the issue, if any.

Thanks
ViCarePlus Team
www.vicareplus.com
services@vicareplus.com

rnagul wrote on Tuesday, March 22, 2011:

It looks like the code in log.inc is not retaining its value for some reason. I have tried it a few different times. Possibly you need to turn logging off, create some encounters and then turn logging back on again.

Here is your code in log.inc
// Fix:
// The task of assigning LAST_INSERT_ID  to a global variable $GLOBALS  is moved from sql.inc to this file.
// Following code will get executed, when (a) when audit is enabled (b) When break glass is invoked.
// Retrieve LAST_INSERT_ID and assign it to a global variable and eventually it can be used by other functions.
    $lastid=mysql_insert_id($GLOBALS);
    $GLOBALS=$lastid;
// ViCarePlus : Audit fix - ends here :: Sep 24,2010

When getSQLLastId is called in sql.inc after the insert is complete, (code below for your reference) the if statement always evaluates to false and the else is executed, Not sure where the value is being reset.

// Function that will safely return the last
//   ID inserted, and accounts for
//   the audit engine.
function getSqlLastID() {
  if ($GLOBALS >0) {
    return $GLOBALS;
  }
  else {
    return $GLOBALS->Insert_ID();
  }
}

Ramesh

visolveemr wrote on Wednesday, March 23, 2011:

Hi,

The if statement of getSQLLastId() will be evaluated to true, if the audit logging is enabled.  Have you verified for the issue  in the OpenEMR demo?  To analyze more into this issue, it would be better if you could share the steps to reproduce the problem or a screenshot to get a clear picture on the issue.

Thanks
ViCareplus Team
www.vicareplus.com