\n";
//----- Master action switch
switch ($action) {
case __("Search"):
// Perform query
// if ( empty($last_name) and empty($first_name) and
// empty(html_form::combo_assemble("city")) ) break;
unset ( $wheres );
if (!empty($last_name))
$wheres[] = "LCASE(ptlname) LIKE '".addslashes(
strtolower($last_name))."%'";
if (!empty($first_name))
$wheres[] = "LCASE(ptfname) LIKE '".addslashes(
strtolower($first_name))."%'";
if (!empty($city))
$wheres[] = "ptcity = '".addslashes(
html_form::combo_assemble("city"))."'";
// smart query
if (!empty($smart)) {
// decide if we're last, first or first last
if (!(strpos($_REQUEST['smart'], ',')===false)) {
// last, first
list ($last, $first) = explode(',', $_REQUEST['smart']);
$last = trim($last);
$first = trim($first);
} else {
// first last
list ($first, $last) = explode(' ', $_REQUEST['smart']);
}
unset($wheres);
$wheres[] = "ptfname LIKE '".addslashes($first)."%'";
$wheres[] = "ptlname LIKE '".addslashes($last)."%'";
}
$wheres[] = "ptarchive != 1";
$query = "SELECT * FROM patient WHERE ".implode(" AND ", $wheres)." ".
"ORDER BY ptlname, ptfname, ptcity";
if ($_REQUEST['id'] > 0) {
$query = "SELECT * FROM patient ".
"WHERE id='".addslashes($_REQUEST['id'])."' ".
"ORDER BY ptlname, ptfname, ptcity";
}
$result = $sql->query($query);
// If no results, die right here
if (!$sql->results($result)) {
$display_buffer .= __("No patients found with that criteria!").
"
\n".
"".__("Back")."\n";
break;
}
// Handle immediate passing and closing
if ($sql->num_rows($result)==1) {
$r = $sql->fetch_array($result);
$display_buffer .= "
We should be '".$r['ptfname'].' '.$r['ptlname']."'.
";
// Add to pick list
$pick_list[(stripslashes($r['ptlname'].", ".
$r['ptfname']." [".
$r['ptdob']."] (".
$r['ptcity'].", ".
$r['ptstate'].")"))] = $r['id'];
} else { // end handling only one result
unset($pick_list);
// Display pick list of results
while ($r = $sql->fetch_array($result)) {
$pick_list[(stripslashes($r['ptlname'].", ".
$r['ptfname']." [".
$r['ptdob']."] (".
$r['ptcity'].", ".
$r['ptstate'].")"))] = $r['id'];
} // end looping through results
}
$display_buffer .= "
".__("Select a patient from the following list:")."
".html_form::select_widget(
"list", $pick_list
)." ".__("Back")."
";
// Make sure that it uses the smart search for focus
$GLOBALS['__freemed']['on_load'] = 'changeFocus';
$display_buffer .= "
";
break;
} // end switch
//----- End of form
$display_buffer .= "\n";
//----- Display template
$GLOBALS['__freemed']['no_template_display'] = true;
template_display();
?>