Date picker for exams

cbezuidenhout wrote on Wednesday, January 25, 2012:

Hi all, a very small feature, added a date picker to the patient->exams section.

Let me know if you are interested and I will commit to GIT.

view it here :
http://www.tajemo.co.za/demoSystem/
username : dem_doctor
password : pass

open a patient
on the right hand column of the dashboard, under exams (second from the top) click edit

see the date pickers along the right (you should select the date first, then type any other Notes required, as the date clears the field) .

  - Craig
    Tajemo Enterprises

yehster wrote on Wednesday, January 25, 2012:

Craig,
I looked at this, and I think it’s a useful feature.  I’m guessing it was also a pretty simple code change.
There’s no rush for you to commit to git, but when you do I suggest that you make a new/separate branch from your dated reminder stuff  and commit just this change.
-Kevin

bradymiller wrote on Wednesday, January 25, 2012:

Hi,
Agree it’s a nice quick thing to do. But it does bring the following issue to surface. Why are we combining a date field with a note field(note if you add a date, it will erase the note if it’s there)? Having a combo field like this will make incorporating things here (of which, there are many things like mammogram, etc. which should be tracked) like this into the CDR engine very difficult (if not impossible). I suggest we add another separate field for date to these entries in library/options.inc.php .
-brady

yehster wrote on Thursday, January 26, 2012:

Brady,
The fundamental problem is the way that history_data is stored.
The “Exam” data is stored in the exam column as pipe and colon delimited fields. 
brs:1:Today|cec:0:|ecg:0:|gyn:0:|mam:0:|phy:0:|pro:0:|rec:0:|sic:0:|ret:0:|flu:0:|pne:0:|ldl:0:|hem:0:|psa:0:

bradymiller wrote on Thursday, January 26, 2012:

Hi,

But with a little coding that can be the same as:
brs:1:Today:|cec:0::|ecg:0::|gyn:0::|mam:0::|phy:0::|pro:0::|rec:0::|sic:0::|ret:0::|flu:0::|pne:0::|ldl:0::|hem:0::|psa:0::

Would basically make a new datatype in library/options.inc.php (simply clone the current one) that is flexible and will work with the one above or the original one:
name:toggle:date/note
name:toggle:note:date

Then just change to the new datatype of the entry in database.sql and the upgrade script.

-brady

cbezuidenhout wrote on Thursday, January 26, 2012:

I agree with Brady, that the benefits of storing the date separately out-way the cons of the work involved

It makes more sense to be able to separate the two pieces of information, the only consideration is where else will this cause issues, I would suggest using a pipe or any other chosen character to slit date an note, that way for scripts still using the old format there is no issue

name:toggle:note|date
name:toggle:note~date

if other scripts are splitting by colon, then the count will be off if we split the date and notes with a colon

  - Craig
    Tajemo Enterprises

bradymiller wrote on Thursday, January 26, 2012:

Hi,

This is one of the gems of Rod’s layout engine. The parsing and entering of this data to and from the database is centralized in the library/options.inc.php library.

The above code uses data_type 23:

  // a set of exam results; 3 radio buttons and a text field:
  else if ($data_type == 23) {
    $tmp = explode('|', $currvalue);
    $avalue = array();
    foreach ($tmp as $value) {
      if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
        $avalue[$matches[1]] = $matches[2];
      }
    }
    $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
    $fldlength = empty($frow['fld_length']) ?  20 : $frow['fld_length'];
    $lres = sqlStatement("SELECT * FROM list_options " .
      "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
    echo "<table cellpadding='0' cellspacing='0'>";
    echo "<tr><td>&nbsp;</td><td class='bold'>" .
      htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
      "&nbsp;</td><td class='bold'>" .
      htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
      "<td class='bold'>" .
      htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
      htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
    while ($lrow = sqlFetchArray($lres)) {
      $option_id = $lrow['option_id'];
      $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
      $restype = substr($avalue[$option_id], 0, 1);
      $resnote = substr($avalue[$option_id], 2);
	
      // Added 5-09 by BM - Translate label if applicable
      echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
	
      for ($i = 0; $i < 3; ++$i) {
	$inputValue = htmlspecialchars( $i, ENT_QUOTES);
        echo "<td><input type='radio'" .
          " name='radio_{$field_id_esc}[$option_id_esc]'" .
          " id='radio_{$field_id_esc}[$option_id_esc]'" .
          " value='$inputValue'";
        if ($restype === "$i") echo " checked";
        echo " /></td>";
      }
      $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
      $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
      $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
      echo "<td><input type='text'" .
        " name='form_{$field_id_esc}[$option_id_esc]'" .
        " id='form_{$field_id_esc}[$option_id_esc]'" .
        " size='$fldlength'" .
        " maxlength='$maxlength'" .
        " value='$resnote' /></td>";
      echo "</tr>";
    }
    echo "</table>";
  }





  // a set of exam results; 3 radio buttons and a text field:
  else if ($data_type == 23) {
    $tmp = explode('|', $currvalue);
    $avalue = array();
    foreach ($tmp as $value) {
      if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
        $avalue[$matches[1]] = $matches[2];
      }
    }
    $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
    $fldlength = empty($frow['fld_length']) ?  20 : $frow['fld_length'];
    $lres = sqlStatement("SELECT * FROM list_options " .
      "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
    echo "<table cellpadding='0' cellspacing='0'>";
    echo "<tr><td>&nbsp;</td><td class='bold'>" .
      htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
      "&nbsp;</td><td class='bold'>" .
      htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
      "<td class='bold'>" .
      htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
      htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
    while ($lrow = sqlFetchArray($lres)) {
      $option_id = $lrow['option_id'];
      $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
      $restype = substr($avalue[$option_id], 0, 1);
      $resnote = substr($avalue[$option_id], 2);
	
      // Added 5-09 by BM - Translate label if applicable
      echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
	
      for ($i = 0; $i < 3; ++$i) {
	$inputValue = htmlspecialchars( $i, ENT_QUOTES);
        echo "<td><input type='radio'" .
          " name='radio_{$field_id_esc}[$option_id_esc]'" .
          " id='radio_{$field_id_esc}[$option_id_esc]'" .
          " value='$inputValue'";
        if ($restype === "$i") echo " checked";
        echo " /></td>";
      }
      $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
      $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
      $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
      echo "<td><input type='text'" .
        " name='form_{$field_id_esc}[$option_id_esc]'" .
        " id='form_{$field_id_esc}[$option_id_esc]'" .
        " size='$fldlength'" .
        " maxlength='$maxlength'" .
        " value='$resnote' /></td>";
      echo "</tr>";
    }
    echo "</table>";
  }





  // a set of exam results; 3 radio buttons and a text field:
  else if ($data_type == 23) {
    $tmp = explode('|', $currvalue);
    $avalue = array();
    foreach ($tmp as $value) {
      if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
        $avalue[$matches[1]] = $matches[2];
      }
    }
    $lres = sqlStatement("SELECT * FROM list_options " .
      "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
    $s .= "<table cellpadding='0' cellspacing='0'>";
    while ($lrow = sqlFetchArray($lres)) {
      $option_id = $lrow['option_id'];
      $restype = substr($avalue[$option_id], 0, 1);
      $resnote = substr($avalue[$option_id], 2);
      if (empty($restype) && empty($resnote)) continue;
	
      // Added 5-09 by BM - Translate label if applicable
      $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
	
      $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
      // $s .= "<td class='text' valign='top'>$restype</td></tr>";
      // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
      $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
      $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
      $s .= "</tr>";
    }
    $s .= "</table>";
  }





    else if ($data_type == 23) {
      // $_POST["form_$field_id"] is an array of text fields with companion
      // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
      foreach ($_POST["form_$field_id"] as $key => $val) {
        $restype = $_POST["radio_{$field_id}"][$key];
        if (empty($restype)) $restype = '0';
        $val = str_replace('|', ' ', $val);
        if (strlen($value)) $value .= '|';
        $value .= "$key:$restype:$val";
      }
    }

My thoughts are that it makes sense to make another data type (basically clone the elements above) that has 3 radio buttons, text field, and date field. And will have it flexible, so it can read either:
name:toggle:note
name:toggle:note:date
but only write:
name:toggle:note:date

This should only take some minor mods to the above code along with a couple other mods in other places:
change the data type for this field in layouts within database.sql and the upgrade file
enter the new datatype in the layouts configuration gui (one line to do this)

-brady

cbezuidenhout wrote on Thursday, January 26, 2012:

this is the file I edited to add the date picker, just edited type 23

cbezuidenhout wrote on Thursday, January 26, 2012:

else if ($data_type == 23) {
$tmp = explode(’|’, $currvalue);
$avalue = array();
foreach ($tmp as $value) {
if (preg_match(’/^([^:]+):(.*)$/’, $value, $matches)) {
$avalue[$matches[1]] = $matches[2];
}
}
$maxlength = empty($frow[‘max_length’]) ? 255 : $frow[‘max_length’];
$fldlength = empty($frow[‘fld_length’]) ? 20 : $frow[‘fld_length’];
$lres = sqlStatement("SELECT * FROM list_options " .
“WHERE list_id = ? ORDER BY seq, title”, array($list_id) );
echo “

”;
echo "" .
“”;
while ($lrow = sqlFetchArray($lres)) {
$option_id = $lrow[‘option_id’];
$option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
$restype = substr($avalue[$option_id], 0, 1);
$resnote = substr($avalue[$option_id], 2);
      // Added 5-09 by BM - Translate label if applicable
      echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
	
      for ($i = 0; $i < 3; ++$i) {
	$inputValue = htmlspecialchars( $i, ENT_QUOTES);
        echo "<td><input type='radio'" .
          " name='radio_{$field_id_esc}[$option_id_esc]'" .
          " id='radio_{$field_id_esc}[$option_id_esc]'" .
          " value='$inputValue'";
        if ($restype === "$i") echo " checked";
        echo " /></td>";
      }
      $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
      $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
      $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
      
      // TajEmo Work by CB 2012/01/25 09:36:29 AM added a date picker to exams
      echo "<td><input type='text'" .
        " name='form_{$field_id_esc}[$option_id_esc]'" .
        " id='form_{$field_id_esc}[$option_id_esc]'" .
        " size='$fldlength'" .
        " maxlength='$maxlength'" .
        " value='$resnote' />" .
        "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
      " id='img_{$field_id_esc}[$option_id_esc]' border='0' alt='[?]' style='cursor:pointer'" .
      " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />&nbsp;</td>";
    $date_init .= " Calendar.setup({inputField:'form_{$field_id_esc}[$option_id_esc]', ifFormat:'%Y-%m-%d', button:'img_{$field_id_esc}[$option_id_esc]'});\n"; 
        "</td>";
      echo "</tr>";
    }
    echo "</table>";
  }

  - Craig
    Tajemo Enterprises

  " .
htmlspecialchars( xl(‘N/A’), ENT_NOQUOTES) .
" .
htmlspecialchars( xl(‘Nor’), ENT_NOQUOTES) . " 
” .
htmlspecialchars( xl(‘Abn’), ENT_NOQUOTES) . " 
" .
htmlspecialchars( xl(‘Date/Notes’), ENT_NOQUOTES) . “