\n";
} else { // if it is done
switch ($action) {
case "add": case "addform":
$ptdtadd = $cur_date; // current date of add...
$ptdtmod = $cur_date; // current date for mod as well
// next of kin prepare blob field
$ptnextofkin = addslashes ($ptnextofkin);
// assemble phone numbers
$pthphone = fm_phone_assemble ("pthphone");
$ptwphone = fm_phone_assemble ("ptwphone");
$ptfax = fm_phone_assemble ("ptfax");
// assemble dates
$ptdob = fm_date_assemble("ptdob");
// knock state to upper case
$ptstate = strtoupper ($ptstate);
// assemble email
if ((strlen($ptemail1)>0) AND (strlen($ptemail2)>3))
$ptemail = $ptemail1 . "@" . $ptemail2;
// collapse the TEXT variables...
//reset($t_vars);while ($i=next($t_vars))
// $$i = fm_join_from_array($$i);
$query = $sql->insert_query (
"patient",
array (
"ptarchive" => '0',
"ptdtadd" => date("Y-m-d"),
"ptdob" => fm_date_assemble ("ptdob"),
"ptbal",
"ptbalfwd",
"ptunapp",
"ptrefdoc",
"ptpcp",
"ptphy1",
"ptphy2",
"ptphy3",
"ptphy4",
"ptbilltype",
"ptbudg",
"ptdoc",
"ptlname",
"ptfname",
"ptmname",
"ptaddr1",
"ptaddr2",
"ptcity",
"ptstate" => strtoupper ($ptstate),
"ptzip",
"ptcountry",
"pthphone" => fm_phone_assemble ("pthphone"),
"ptwphone" => fm_phone_assemble ("ptwphone"),
"ptfax" => fm_phone_assemble ("ptfax"),
"ptemail",
"ptsex",
"ptssn",
"ptdmv",
"ptdtlpay",
"ptamtlpay" => $ptpaytype,
"ptstatus",
"ptytdchg",
"ptar",
"ptextinf",
"ptdisc",
"ptdiag1",
"ptdiag2",
"ptdiag3",
"ptdiag4",
"ptid",
"pthistbal",
"ptmarital",
"ptempl",
"ptemp1",
"ptemp2",
"ptguar",
"ptguarstart",
"ptguarend",
"ptrelguar",
"ptins",
"ptinsno",
"ptinsgrp",
"ptinsstart",
"ptinsend",
"ptnextofkin",
"ptblood",
"ptpharmacy",
"pttimestamp" => '',
"ptemriversion" => '1',
"iso" => $__ISO_SET__
) );
break; // end add
case "mod": case "modform":
// collapse the TEXT variables...
//reset($t_vars);while ($i=next($t_vars))
// if (is_array($$i)) $$i = implode(':', $$i);
//$ptins{start,end} already fm_date_assemble'd
// reassemble email
if ((strlen($ptemail1)>1) AND (strlen($ptemail2)>3))
$ptemail = $ptemail1 . "@" . $ptemail2;
$query = $sql->update_query (
"patient",
array (
"ptdtmod" => date("Y-m-d"),
"ptdob" => fm_date_assemble ("ptdob"),
"ptbal",
"ptbalfwd",
"ptunapp",
"ptrefdoc",
"ptpcp",
"ptphy1",
"ptphy2",
"ptphy3",
"ptphy4",
"ptbilltype",
"ptbudg",
"ptdoc",
"ptlname",
"ptfname",
"ptmname",
"ptaddr1",
"ptaddr2",
"ptcity",
"ptstate" => strtoupper ($ptstate),
"ptzip",
"ptcountry",
"pthphone" => fm_phone_assemble ("pthphone"),
"ptwphone" => fm_phone_assemble ("ptwphone"),
"ptfax" => fm_phone_assemble ("ptfax"),
"ptemail",
"ptsex",
"ptssn",
"ptdmv",
"ptdtlpay",
"ptamtlpay" => $ptpaytype,
"ptstatus",
"ptytdchg",
"ptar",
"ptextinf",
"ptdisc",
"ptdiag1",
"ptdiag2",
"ptdiag3",
"ptdiag4",
"ptid",
"pthistbal",
"ptmarital",
"ptempl",
"ptemp1",
"ptemp2",
"ptguar",
"ptguarstart",
"ptguarend",
"ptrelguar",
"ptins",
"ptinsno",
"ptinsgrp",
"ptinsstart",
"ptinsend",
"ptnextofkin",
"ptblood",
"ptpharmacy",
"pttimestamp" => '',
"iso"
), array ( "id" => $id )
);
break; // end mod
} // end switch for action (done .. actual action)
$display_buffer .= "
".( (($action=="mod") OR ($action=="modform")) ?
__("Modifying") : __("Adding") )." ... ";
$result = $sql->query($query);
if ($result) $display_buffer .= __("Done");
else $display_buffer .= __("Error");
$display_buffer .= " \n";
if ( ($result) AND ($action=="addform") AND (empty($ptid)) )
{
$display_buffer .= "".__("Adding Patient ID")." ... ";
$pid = $sql->last_record($result);
$patid = PATID_PREFIX.$pid;
$result = $sql->query("UPDATE patient SET ptid='".addslashes($patid)."' ".
"WHERE id='".addslashes($pid)."'");
if ($result) $display_buffer .= __("Done");
else $display_buffer .= __("Error");
$display_buffer .= " \n";
} elseif (($action=="addform") and (!empty($ptid))) {
// Be sure to calculate PID if ptid is already calculated
$pid = $sql->last_record($result);
}
// If we're dealing with a call-in ...
if (($_REQUEST['ci'] > 0) and ($action == 'addform')) {
// Just in case ...
if (($pid+0) < 1) { $pid = $sql->last_record($result); }
// Move all appointments to proper patient
$display_buffer .= "".__("Reassigning appointments")." ... ";
$result = $sql->query("UPDATE scheduler SET ".
"caltype = 'pat', calpatient = '".addslashes($pid)."' ".
"WHERE caltype = 'temp' AND calpatient = '".
addslashes($_REQUEST['ci'])."'");
if ($result) $display_buffer .= __("Done");
else $display_buffer .= __("Error");
$display_buffer .= " \n";
// Remove the call-in appointment entirely
$display_buffer .= "".__("Removing old temporary patient account")." ... ";
$result = $sql->query("DELETE FROM callin ".
"WHERE id = '".addslashes($_REQUEST['ci'])."'");
if ($result) $display_buffer .= __("Done");
else $display_buffer .= __("Error");
$display_buffer .= " \n";
}
// Set automatic page refresh to management screen
$refresh = "manage.php?id=".( $action=="addform" ? $pid : $id );
$display_buffer .= "
".__("Manage This Patient")."
";
} // end checking if done
break; // end action add/mod
case "delete":
case "del":
$page_title = __("Archiving Patient");
$display_buffer .= "
".__("Archiving")." ... ";
//$query = "DELETE FROM patient WHERE id='".addslashes($id)."'";
$query = $sql->update_query(
'patient',
array( 'ptarchive' => '1' ),
array( 'id' => $id )
);
$result = $sql->query ($query);
if ($result) { $display_buffer .= __("done")."."; }
else { $display_buffer .= __("ERROR"); }
// Take care of scheduler entries
//$query = "DELETE FROM scheduler WHERE calpatient='".addslashes($id)."'";
//$result = $sql->query ($query);
$display_buffer .= "
";
// TODO: Go through EVERY associated record and delete all things having
// to do with the patient!
// Return to patient selection after deleting a patient
$refresh = "patient.php";
break; // end action delete
case "find":
switch ($criteria) {
case "letter":
$query = "SELECT ptlname,ptfname,ptdob,ptid,id FROM patient ".
"WHERE (UCASE(ptlname) LIKE '".addslashes(strtoupper($f1))."%') ".
" AND ptarchive+0 != '1' ".
freemed::itemlist_conditions(false).
"ORDER BY ptlname, ptfname, ptdob";
$_crit = __("Last Names")." (".prepare($f1).")";
break;
case "contains":
$query = "SELECT ptlname,ptfname,ptdob,ptid,id FROM patient ".
"WHERE (UCASE(".addslashes($f1).") LIKE '%".addslashes(strtoupper($f2))."%') ".
" AND ptarchive+0 != '1' ".
freemed::itemlist_conditions(false).
"ORDER BY ptlname, ptfname, ptdob";
$_crit = __("Searching for")." \"".prepare($f2)."\"";
break;
case "soundex":
$query = "SELECT ptlname,ptfname,ptdob,ptid,id FROM patient ".
"WHERE (soundex(".addslashes($f1).") = soundex('".addslashes($f2)."')) ".
" AND ptarchive+0 != '1' ".
freemed::itemlist_conditions(false).
"ORDER BY ptlname, ptfname, ptdob";
$_crit = "Sounds Like \"".prepare($f2)."\"";
break;
case "smart":
// decide if we're last, first or first last
if (!(strpos($_REQUEST['f1'], ',')===false)) {
// last, first
list ($last, $first) = explode(',', $_REQUEST['f1']);
$last = trim($last);
$first = trim($first);
} else {
// first last
list ($first, $last) = explode(' ', $_REQUEST['f1']);
}
$query = "SELECT ptlname,ptfname,ptdob,ptid,id FROM patient ".
"WHERE (UCASE(ptlname) LIKE '".addslashes(strtoupper($last))."%') ".
" AND (UCASE(ptfname) LIKE '".addslashes(strtoupper($first))."%') ".
" AND ptarchive+0 != '1' ".
freemed::itemlist_conditions(false).
" ORDER BY ptlname, ptfname, ptdob";
$_crit = __("Patient Name")." \"".prepare($_REQUEST['f1'])."\"";
break;
case "all":
$query = "SELECT ptlname,ptfname,ptdob,ptid,id FROM patient ".
" WHERE ptarchive+0 != '1' ".
freemed::itemlist_conditions(false).
"ORDER BY ptlname, ptfname, ptdob";
$_crit = "\"".__("All Patients")."\"";
break;
default:
$_crit = "";
break;
} // end criteria search
$result = $sql->query($query);
// Check to see if there's only one result, and jump to them
// if it's found
if ($result and ($sql->num_rows($result)==1)) {
// Go to beginning
$sql->data_seek($result, 0);
// Grab the data
$_r = $sql->fetch_array($result);
// Form refresh string to pass to template
$refresh = "manage.php?id=".urlencode($_r['id']);
// Reset data so that the display works (in case of no refresh)
$sql->data_seek($result, 0);
} // end checking for single patient jump
$page_title = __("Patients Meeting Criteria")." ".$_crit;
if (strlen($_ref)<5) {
$_ref="main.php";
} // if no ref, then return to home page...
$display_buffer .= freemed_display_itemlist(
$result,
$page_name,
array (
__("Last Name") => "ptlname",
__("First Name") => "ptfname",
__("Date of Birth") => "ptdob",
__("Practice ID") => "ptid"
),
array ("","",""),
"", "", "",
ITEMLIST_MOD|ITEMLIST_VIEW|ITEMLIST_DEL
);
$display_buffer .= "\n";
break; // end action find
case "display":
case "view":
// KludgE AlerTx0r!
header("Location:".ereg_replace("patient.php",
"manage.php", basename($_ENV['REQUEST_URI'])));
break;
default: // default action
// Set page title
$page_title = __("Patients");
// Push onto stack
page_push();
if ($_COOKIE['current_patient'] > 0) {
$this_patient = CreateObject('FreeMED.Patient', $_COOKIE['current_patient']);
$display_buffer .= freemed::patient_box ($this_patient);
}
//----- Load template with patient menu
if (file_exists("./lib/template/".$template."/patient.php")) {
include_once ("./lib/template/".$template."/patient.php");
} else {
include_once ("./lib/template/default/patient.php");
}
break; // end default action
} // end action
//----- Display the template
template_display();
?>