2 //our api for 3rd party developers
3 include_once("../../globals.php");
4 include_once("{$GLOBALS['srcdir']}/billing.inc");
6 $GLOBALS['form_exit_url'] = "$rootdir/patient_file/encounter/encounter_top.php";
8 function formHeader ($title = "My Form")
13 <?php html_header_show();?>
14 <link rel=stylesheet href="<?php echo $GLOBALS['css_header']?>" type="text/css">
15 <title><?php echo $title?></title>
17 <body background="<?php echo $GLOBALS['backpic']?>" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
21 function formFooter ()
29 // This function will escape the $values when using the new security method (ie. $sanitize_all_escapes is TRUE).
30 // Otherwise, this function expects the $values to already be escaped(original and legacy behavior).
31 function formSubmit ($tableName, $values, $id, $authorized = "0")
33 // Bring in $sanitize_all_escapes variable, which will decide
34 // the variable escaping method.
35 global $sanitize_all_escapes;
36 global $attendant_type;
38 $sql = "insert into " . escape_table_name($tableName) . " set " . $attendant_type . "='".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(),";
39 foreach ($values as $key => $value)
40 if (strpos($key,"openemr_net_cpt") === 0) {
41 //code to auto add cpt code
43 $code_array = explode(" ",$value,2);
45 addBilling(date("Ymd"), 'CPT4', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
49 //case where key looks like "[a-zA-Z]*diagnosis[0-9]" which is special, it is used to auto add ICD codes
51 elseif (strpos($key,"diagnosis") == (strlen($key) -10) && !(strpos($key,"diagnosis")=== false )) {
52 //icd auto add ICD9-CM
54 $code_array = explode(" ",$value,2);
55 addBilling(date("Ymd"), 'ICD9-M', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
59 if (isset($sanitize_all_escapes) && $sanitize_all_escapes) {
60 // using new security method, so escape the key and values here
61 $sql .= " " . escape_sql_column_name($key,array($tableName)) . " = '" . add_escape_custom($value) . "',";
64 // original method (rely on code to escape values before using this function)
65 $sql .= " $key = '$value',";
68 $sql = substr($sql, 0, -1);
69 return sqlInsert($sql);
73 function formUpdate ($tableName, $values, $id, $authorized = "0")
75 // Bring in $sanitize_all_escapes variable, which will decide
76 // the variable escaping method.
77 global $sanitize_all_escapes;
79 $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(),";
80 foreach ($values as $key => $value)
81 if (isset($sanitize_all_escapes) && $sanitize_all_escapes) {
82 // using new security method, so escape the key and values here
83 $sql .= " " . escape_sql_column_name($key,array($tableName)) . " = '" . add_escape_custom($value) . "',";
86 // original method (rely on code to escape values before using this function)
87 $sql .= " $key = '$value',";
89 $sql = substr($sql, 0, -1);
90 $sql .= " where id='".add_escape_custom($id)."'";
92 return sqlInsert($sql);
96 function formJump ($address = "0")
98 $returnurl = 'encounter_top.php';
100 $address = "{$GLOBALS['rootdir']}/patient_file/encounter/$returnurl";
101 echo "\n<script language='Javascript'>top.restoreSession();window.location='$address';</script>\n";
105 function formFetch ($tableName, $id, $cols="*", $activity="1")
107 // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
108 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) ) ;
111 function formGetIds ($tableName, $cols = "*", $limit='all', $start=0, $activity = "1")
115 // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
116 $sql = "select $cols from `" . escape_table_name($tableName) . "` where pid like '$pid' ";
117 if ($activity != "all")
118 $sql .= "and activity like '$activity' ";
119 $sql .= "order by date DESC";
123 $sql = "select $cols from pnotes where pid like '$pid' ";
124 $sql .= " AND deleted != 1 "; // exclude ALL deleted notes
125 if ($activity != "all")
126 $sql .= "and activity like '$activity' ";
127 $sql .= "order by date DESC LIMIT $start, $limit";
130 $res = sqlStatement($sql);
132 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
137 function formDisappear ($tableName, $id)
139 // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
140 if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '0' where id='$id' and pid='$pid'")) return true;
144 function formReappear ($tableName, $id)
146 // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
147 if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '1' where id='$id' and pid='$pid'")) return true;