Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / library / api.inc
blobc4fc585c49d5c0bb9fbd1b4187221050709eeae0
1 <?php
2 //our api for 3rd party developers
3 require_once(dirname(__FILE__) . "/../interface/globals.php");
5 use OpenEMR\Billing\BillingUtilities;
7 $GLOBALS['form_exit_url'] = "javascript:parent.closeTab(window.name, false)";
9 function formHeader($title = "My Form")
11     ?>
12     <html>
13     <head>
14     <link rel=stylesheet href="<?php echo $GLOBALS['css_header']?>" type="text/css">
15     <title><?php echo text($title); ?></title>
16     </head>
17     <body background="<?php echo $GLOBALS['backpic']?>" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
18     <?php
21 function formFooter()
23     ?>
24     </body>
25     </html>
26     <?php
29 function formSubmit($tableName, $values, $id, $authorized = "0")
31     global $attendant_type;
33     $sqlBindingArray = [$_SESSION['pid'], $_SESSION['authProvider'], $_SESSION['authUser'], $authorized];
34     $sql = "insert into " . escape_table_name($tableName) . " set " .  escape_sql_column_name($attendant_type, array($tableName)) . "=?, groupname=?, user=?, authorized=?, activity=1, date = NOW(),";
35     foreach ($values as $key => $value) {
36         if ($key == "csrf_token_form") {
37             continue;
38         }
39         if (strpos($key, "openemr_net_cpt") === 0) {
40             //code to auto add cpt code
41             if (!empty($value)) {
42                 $code_array = explode(" ", $value, 2);
44                 BillingUtilities::addBilling(date("Ymd"), 'CPT4', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
45             }
46         } //case where key looks like "[a-zA-Z]*diagnosis[0-9]" which is special, it is used to auto add ICD codes
48         elseif (strpos($key, "diagnosis") == (strlen($key) -10) && !(strpos($key, "diagnosis")=== false )) {
49             //icd auto add ICD9-CM
50             if (!empty($value)) {
51                 $code_array = explode(" ", $value, 2);
52                 BillingUtilities::addBilling(date("Ymd"), 'ICD9-M', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
53             }
54         } else {
55             $sql .= " " . escape_sql_column_name($key, array($tableName)) . " = ?,";
56             $sqlBindingArray[] = $value;
57         }
58     }
60     $sql = substr($sql, 0, -1);
61     return sqlInsert($sql, $sqlBindingArray);
65 function formUpdate($tableName, $values, $id, $authorized = "0")
67     $sqlBindingArray = [$_SESSION['pid'], $_SESSION['authProvider'], $_SESSION['authUser'], $authorized];
68     $sql = "update " . escape_table_name($tableName) . " set pid =?, groupname=?, user=? ,authorized=?, activity=1, date = NOW(),";
69     foreach ($values as $key => $value) {
70         if ($key == "csrf_token_form") {
71             continue;
72         }
73         $sql .= " " . escape_sql_column_name($key, array($tableName)) . " = ?,";
74         $sqlBindingArray[] = $value;
75     }
77     $sql = substr($sql, 0, -1);
78     $sql .= " where id=?";
79     $sqlBindingArray[] = $id;
81     return sqlInsert($sql, $sqlBindingArray);
84 function formJump($address = '')
86     echo "<script>\n";
87     if ($address) {
88         echo "top.restoreSession();\n";
89         echo "location.href = " . js_escape($address) . ";\n";
90     } else {
91         echo "parent.closeTab(window.name, true);\n";
92     }
93     echo "</script>\n";
94     // TBD: Exit seems wrong here, but that's how it has been forever.
95     exit;
98 function formFetch($tableName, $id, $cols = "*", $activity = "1")
100         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
101     return sqlQuery("select " . escape_sql_column_name(process_cols_escape($cols), array($tableName)) . " from `" . escape_table_name($tableName) . "` where id=? and pid = ? and activity like ? order by date DESC LIMIT 0,1", array($id,$GLOBALS['pid'],$activity)) ;
105 function formDisappear($tableName, $id)
107         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
108     if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '0' where id=? and pid=?", [$id, $pid])) {
109         return true;
110     }
112     return false;
115 function formReappear($tableName, $id)
117         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
118     if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '1' where id=? and pid=?", [$id, $pid])) {
119         return true;
120     }
122     return false;