Facility Name not showing in Encounters

light_coder wrote on Friday, September 10, 2010:

I have noticed (for a while now) that after an encounter/visit has been saved, the “Facility” name,  under “Reason” always shows blank.

I have also noticed that the reason for that is that the “facility” field in the form_encounter table does not get updated.

To fix this I made some changes in the interface/forms/newpatient/save.php file which updates the form_encounter table. My changes are as followed:

$facilityresult = sqlQuery(“select name FROM facility WHERE id = $facility_id”);  
$facility = $facilityresult; // This line and the one above it were added by me just to grab the facility name

if ($GLOBALS)
  $normalurl = “$rootdir/patient_file/encounter/encounter_top.php”;
else
  $normalurl = “$rootdir/patient_file/encounter/patient_encounter.php”;

$nexturl = $normalurl;

if ($mode == ‘new’)
{
  $provider_id = $userauthorized ? $_SESSION : 0;
  $encounter = $conn->GenID(“sequences”);
  addForm($encounter, “New Patient Encounter”,
    sqlInsert("INSERT INTO form_encounter SET " .
      "date = ‘$date’, " .
      "onset_date = ‘$onset_date’, " .
      "reason = ‘$reason’, " .
      "facility = ‘$facility’, " .  // Added by me to set the facility name in the form_encounter table
      "pc_catid = ‘$pc_catid’, " .
      "facility_id = ‘$facility_id’, " .
      "sensitivity = ‘$sensitivity’, " .
      "pid = ‘$pid’, " .
      "encounter = ‘$encounter’, " .
      “provider_id = ‘$provider_id’”),
    “newpatient”, $pid, $userauthorized, $date);
}
else if ($mode == ‘update’)
{
  $id = $_POST;
  $result = sqlQuery(“SELECT encounter, sensitivity FROM form_encounter WHERE id = ‘$id’”);
  if ($result && !acl_check(‘sensitivities’, $result)) {
   die(“You are not authorized to see this encounter.”);
  }
  $encounter = $result;
  // See view.php to allow or disallow updates of the encounter date.
  // $datepart = $_POST ? "date = ‘$date’, " : “”;
  $datepart = acl_check(‘encounters’, ‘date_a’) ? "date = ‘$date’, " : “”;
  sqlStatement("UPDATE form_encounter SET " .
    $datepart .
    "onset_date = ‘$onset_date’, " .
    "reason = ‘$reason’, " .
    "facility = ‘$facility’, " .  // Added by me to set the facility name in the form_encounter table
    "pc_catid = ‘$pc_catid’, " .
    "facility_id = ‘$facility_id’, " .
    "sensitivity = ‘$sensitivity’ " .
    “WHERE id = ‘$id’”);
      ……………
      ……………

I have added comments (above) wherever I made changes.
I am no database expert, but that’s how I was able to fix this. There may be more efficient or secure ways to do this. You guys can look into it and let us know.

Thanks

Jude

sunsetsystems wrote on Friday, September 10, 2010:

Which OpenEMR version is that?  Doesn’t sound like a recent one.

Rod
www.sunsetsystems.com

light_coder wrote on Friday, September 10, 2010:

Latest 4.0.

Jude

sunsetsystems wrote on Friday, September 10, 2010:

You’re right, the facility displays as blank when you go to an encounter.  You do see it when you edit the information.

Even more curious, trying the development demo:

http://www.openmedsoftware.org/wiki/Development_Demo

I’m not even able to add a second facility, or change the current one!  “Save” just fails silently.  This does not happen in my local installation of 4.0, though that is a couple of weeks old.

Rod
www.sunsetsystems.com

light_coder wrote on Friday, September 10, 2010:

In my local 4.0 installation which is the latest, I am able to edit the current facility and add new one.

My little change works perfectly, except for old encounters as the facility name has not been saved for them. For old encounters, one would have to write a little sql query to update the db table using the facility_id.  For new encounters, the Facility name now displays correctly in view mode.

Jude