Where does the encounter number come from

michael_barnett wrote on Tuesday, June 20, 2006:

i know i know under a leaf in the garden…

seriously though

looking at the encounter.inc
i assume this is where the encounter is made…
but it looks to me like $enc is a date function  $enc = date("Ymd");

I had assumed my encounter would therefore be a date yet its just an incrementing integer by looks of the database.
how does it become an integer when it started out as $enc = date("Ymd");

$encounter=$enc;

function setencounter($enc) {
   
    $return_val = 1;
    global $encounter;
    global $pid;
   
    if ($enc == “” ) {
        $enc = date(“Ymd”);
        if (getFormByEncounter($pid,$enc)) {
            //there is an encounter enterred for today
        } else {
            //addForm($enc, “New Patient Encounter”, 0, $pid, 1);
            $return_val = 0;
        }
    }
   
    $_SESSION[‘encounter’]=$enc;
    $encounter=$enc;
   
   
    //returns 1 on successful global set, or 0 if there was no
    //current encounter, signifying that the interface should load
    //the screen for a new encounter
    return $return_val;
}

michael_barnett wrote on Tuesday, June 20, 2006:

in the encounter_title.php

there is a line that says

<span class="title_bar_top">Encounter: <?echo $encounter_date?></span><br>

probably another reason i thought the encounter was a date/timestamp

still cannot find where the encounter number is incremented

markleeds wrote on Tuesday, June 20, 2006:

check this out from openemr/interface/forms/newpatient/save.php
which is where new encounters are created…

if ($mode == ‘new’)
{
  $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’, " .
      "pid = ‘$pid’, " .
      “encounter = ‘$encounter’”),
    “newpatient”, $pid, $userauthorized, $date);
}
else if ($mode == ‘update’)
{
  $id = $_REQUEST[‘id’];
  $result = sqlQuery(“SELECT encounter FROM form_encounter WHERE id = ‘$id’”);
  $encounter = $result[‘encounter’];
  // See view.php to allow or disallow updates of the encounter date.
  // $datepart = $_POST[“day”] ? "date = ‘$date’, " : “”;
  $datepart = acl_check(‘encounters’, ‘date_a’) ? "date = ‘$date’, " : “”;
  $id = $_POST[“id”];
  sqlStatement("update form_encounter set " .
    $datepart .
    "onset_date = ‘$onset_date’, " .
    "reason = ‘$reason’, " .
    "facility = ‘$facility’ " .
    “where id = ‘$id’”);
}

setencounter($encounter);

*****************************************

I did not track down what

  $encounter = $conn->GenID("sequences");

does, but it looks like that’s where the number comes from.  Note in the code you quoted above, if setencounter gets an argument, it does not set $encounter to the date.

Are you using grep to track stuff down?  using it with the -irn options is very helpful.

michael_barnett wrote on Tuesday, June 20, 2006:

lol no i am using textpad 4.7

it will look in every file and subdirectory and report back the filename and line number of the match. the out put looks like this

Searching for: set_encounter
interface\billing\billing_report.php(380): $lhtml .= “&nbsp;&nbsp;&nbsp;<a class=&quot;link_submit&quot; href=&quot;” . $GLOBALS[‘webroot’] ."/interface/patient_file/encounter/patient_encounter.php?set_encounter=" . $iter[‘encounter’] . “&pid=” . $iter[‘pid’] . “&quot;>[To&nbsp;Encounter]</a>”;
interface\patient_file\encounter\encounter_title.php(19): if (!empty($_GET[“set_encounter”])) {
interface\patient_file\encounter\encounter_title.php(20): setencounter($_GET[“set_encounter”]);
interface\patient_file\encounter\patient_encounter.php(34): if (isset($_GET[“set_encounter”])) {
interface\patient_file\encounter\patient_encounter.php(35): setencounter($_GET[“set_encounter”]);
interface\patient_file\history\encounters.php(38): top.Title.location.href = ‘…/encounter/encounter_title.php?set_encounter=’   + enc;
interface\patient_file\history\encounters.php(39): top.Main.location.href  = ‘…/encounter/patient_encounter.php?set_encounter=’ + enc;
interface\patient_file\history\encounters_full.php(35): top.Title.location.href = ‘…/encounter/encounter_title.php?set_encounter=’   + enc;
interface\patient_file\history\encounters_full.php(36): top.Main.location.href  = ‘…/encounter/patient_encounter.php?set_encounter=’ + enc;
interface\patient_file\report\report_title.php(7): //if (isset($_GET[“set_encounter”])) {
interface\patient_file\report\report_title.php(8): //    $_SESSION[“encounter”] = $_GET[“set_encounter”];
interface\patient_file\report\report_title.php(13): //setencounter($_GET[“set_encounter”]);
Found 12 occurrence(s) in 6 file(s)

michael_barnett wrote on Tuesday, June 20, 2006:

you were right the genid() is a function of the database connection driver.

/interface/main/calendar/pnadodb/docs-adodb.htm

GenID($seqName = ‘adodbseq’,$startID=1)

Generate a sequence number . Works for interbase, mysql, postgresql, oci8, oci8po, mssql, ODBC based (access,vfp,db2,etc) drivers currently. Uses $seqName as the name of the sequence. GenID() will automatically create the sequence for you if it does not exist (provided the userid has permission to do so). Otherwise you will have to create the sequence yourself.

If your database driver emulates sequences, the name of the table is the sequence name. The table has one column, "id" which should be of type integer, or if you need something larger - numeric(16).

For ODBC and databases that do not support sequences natively (eg mssql, mysql), we create a table for each sequence. If the sequence has not been defined earlier, it is created with the starting value set in $startID.

Note that the mssql driver’s GenID() before 1.90 used to generate 16 byte GUID’s.

markleeds wrote on Tuesday, June 20, 2006:

We don’t support those other databases, do we?  oh well, it works.

I use unix tools because my server is locked in a closet with no terminal, keyboard, or mouse connected to it.  I have to do everything via ssh.