2 //our api for 3rd party developers
3 include_once("../../globals.php");
4 include_once("{$GLOBALS['srcdir']}/sql.inc");
5 include_once("{$GLOBALS['srcdir']}/billing.inc");
6 include_once("{$GLOBALS['srcdir']}/formdata.inc.php");
8 $GLOBALS['form_exit_url'] = $GLOBALS['concurrent_layout'] ?
9 "$rootdir/patient_file/encounter/encounter_top.php" :
10 "$rootdir/patient_file/encounter/patient_encounter.php";
12 function formHeader ($title = "My Form")
17 <?php html_header_show();?>
18 <link rel=stylesheet href="<?php echo $GLOBALS['css_header']?>" type="text/css">
19 <title><?php echo $title?></title>
21 <body background="<?php echo $GLOBALS['backpic']?>" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
25 function formFooter ()
33 // This function will escape the $values when using the new security method (ie. $sanitize_all_escapes is TRUE).
34 // Otherwise, this function expects the $values to already be escaped(original and legacy behavior).
35 function formSubmit ($tableName, $values, $id, $authorized = "0")
37 // Bring in $sanitize_all_escapes variable, which will decide
38 // the variable escaping method.
39 global $sanitize_all_escapes;
41 $sql = "insert into $tableName set pid = {$_SESSION['pid']},groupname='".$_SESSION['authProvider']."',user='".$_SESSION['authUser']."',authorized=$authorized,activity=1, date = NOW(),";
42 foreach ($values as $key => $value)
43 if (strpos($key,"openemr_net_cpt") === 0) {
44 //code to auto add cpt code
46 $code_array = split(" ",$value,2);
48 addBilling(date("Ymd"), 'CPT4', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
52 //case where key looks like "[a-zA-Z]*diagnosis[0-9]" which is special, it is used to auto add ICD codes
54 elseif (strpos($key,"diagnosis") == (strlen($key) -10) && !(strpos($key,"diagnosis")=== false )) {
55 //icd auto add ICD9-CM
57 $code_array = split(" ",$value,2);
58 addBilling(date("Ymd"), 'ICD9-M', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
62 if (isset($sanitize_all_escapes) && $sanitize_all_escapes) {
63 // using new security method, so escape the key and values here
64 $sql .= " " . add_escape_custom($key) . " = '" . add_escape_custom($value) . "',";
67 // original method (rely on code to escape values before using this function)
68 $sql .= " $key = '$value',";
71 $sql = substr($sql, 0, -1);
72 return sqlInsert($sql);
76 function formUpdate ($tableName, $values, $id, $authorized = "0")
78 $sql = "update $tableName set pid = {$_SESSION['pid']},groupname='".$_SESSION['authProvider']."',user='".$_SESSION['authUser']."',authorized=$authorized,activity=1, date = NOW(),";
79 foreach ($values as $key => $value)
80 $sql .= " $key = '$value',";
81 $sql = substr($sql, 0, -1);
82 $sql .= " where id=$id";
84 return sqlInsert($sql);
88 function formJump ($address = "0")
90 $returnurl = $GLOBALS['concurrent_layout'] ? 'encounter_top.php' : 'patient_encounter.php';
92 $address = "{$GLOBALS['rootdir']}/patient_file/encounter/$returnurl";
93 echo "\n<script language='Javascript'>top.restoreSession();window.location='$address';</script>\n";
97 function formFetch ($tableName, $id, $cols="*", $activity="1")
99 return sqlQuery ( "select $cols from `$tableName` where id='$id' and pid = '{$GLOBALS['pid']}' and activity like '$activity' order by date DESC LIMIT 0,1" ) ;
102 function formGetIds ($tableName, $cols = "*", $limit='all', $start=0, $activity = "1")
107 $sql = "select $cols from `$tableName` where pid like '$pid' ";
108 if ($activity != "all")
109 $sql .= "and activity like '$activity' ";
110 $sql .= "order by date DESC";
114 $sql = "select $cols from pnotes where pid like '$pid' ";
115 $sql .= " AND deleted != 1 "; // exclude ALL deleted notes
116 if ($activity != "all")
117 $sql .= "and activity like '$activity' ";
118 $sql .= "order by date DESC LIMIT $start, $limit";
121 $res = sqlStatement($sql);
123 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
128 function formDisappear ($tableName, $id)
130 if (sqlStatement("update `$tableName` set activity = '0' where id='$id' and pid='$pid'")) return true;
134 function formReappear ($tableName, $id)
136 if (sqlStatement("update `$tableName` set activity = '1' where id='$id' and pid='$pid'")) return true;