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 " . escape_table_name($tableName) . " set pid ='".add_escape_custom($_SESSION['pid'])."',groupname='".add_escape_custom($_SESSION['authProvider'])."',user='".add_escape_custom($_SESSION['authUser'])."',authorized='".add_escape_custom($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 = explode(" ",$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 = explode(" ",$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 .= " " . escape_sql_column_name($key,array($tableName)) . " = '" . 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 // Bring in $sanitize_all_escapes variable, which will decide
79 // the variable escaping method.
80 global $sanitize_all_escapes;
82 $sql = "update " . escape_table_name($tableName) . " set pid ='".add_escape_custom($_SESSION['pid'])."',groupname='".add_escape_custom($_SESSION['authProvider'])."',user='".add_escape_custom($_SESSION['authUser'])."',authorized='".add_escape_custom($authorized)."',activity=1, date = NOW(),";
83 foreach ($values as $key => $value)
84 if (isset($sanitize_all_escapes) && $sanitize_all_escapes) {
85 // using new security method, so escape the key and values here
86 $sql .= " " . escape_sql_column_name($key,array($tableName)) . " = '" . add_escape_custom($value) . "',";
89 // original method (rely on code to escape values before using this function)
90 $sql .= " $key = '$value',";
92 $sql = substr($sql, 0, -1);
93 $sql .= " where id='".add_escape_custom($id)."'";
95 return sqlInsert($sql);
99 function formJump ($address = "0")
101 $returnurl = $GLOBALS['concurrent_layout'] ? 'encounter_top.php' : 'patient_encounter.php';
103 $address = "{$GLOBALS['rootdir']}/patient_file/encounter/$returnurl";
104 echo "\n<script language='Javascript'>top.restoreSession();window.location='$address';</script>\n";
108 function formFetch ($tableName, $id, $cols="*", $activity="1")
110 // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
111 return sqlQuery ( "select $cols from `" . escape_table_name($tableName) . "` where id=? and pid = ? and activity like ? order by date DESC LIMIT 0,1", array($id,$GLOBALS['pid'],$activity) ) ;
114 function formGetIds ($tableName, $cols = "*", $limit='all', $start=0, $activity = "1")
118 // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
119 $sql = "select $cols from `" . escape_table_name($tableName) . "` where pid like '$pid' ";
120 if ($activity != "all")
121 $sql .= "and activity like '$activity' ";
122 $sql .= "order by date DESC";
126 $sql = "select $cols from pnotes where pid like '$pid' ";
127 $sql .= " AND deleted != 1 "; // exclude ALL deleted notes
128 if ($activity != "all")
129 $sql .= "and activity like '$activity' ";
130 $sql .= "order by date DESC LIMIT $start, $limit";
133 $res = sqlStatement($sql);
135 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
140 function formDisappear ($tableName, $id)
142 // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
143 if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '0' where id='$id' and pid='$pid'")) return true;
147 function formReappear ($tableName, $id)
149 // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
150 if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '1' where id='$id' and pid='$pid'")) return true;