Percent-based price levels (#2577)
[openemr.git] / library / api.inc
blob2e6e3dd97af529e668254403e9959d4e6fa1bbfb
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         } elseif (strpos($key, "diagnosis") == (strlen($key) -10) && !(strpos($key, "diagnosis")=== false )) {
47             //case where key looks like "[a-zA-Z]*diagnosis[0-9]" which is special, it is used to auto add ICD codes
48             //icd auto add ICD9-CM
49             if (!empty($value)) {
50                 $code_array = explode(" ", $value, 2);
51                 BillingUtilities::addBilling(date("Ymd"), 'ICD9-M', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
52             }
53         } else {
54             $sql .= " " . escape_sql_column_name($key, array($tableName)) . " = ?,";
55             $sqlBindingArray[] = $value;
56         }
57     }
59     $sql = substr($sql, 0, -1);
60     return sqlInsert($sql, $sqlBindingArray);
64 function formUpdate($tableName, $values, $id, $authorized = "0")
66     $sqlBindingArray = [$_SESSION['pid'], $_SESSION['authProvider'], $_SESSION['authUser'], $authorized];
67     $sql = "update " . escape_table_name($tableName) . " set pid =?, groupname=?, user=? ,authorized=?, activity=1, date = NOW(),";
68     foreach ($values as $key => $value) {
69         if ($key == "csrf_token_form") {
70             continue;
71         }
72         $sql .= " " . escape_sql_column_name($key, array($tableName)) . " = ?,";
73         $sqlBindingArray[] = $value;
74     }
76     $sql = substr($sql, 0, -1);
77     $sql .= " where id=?";
78     $sqlBindingArray[] = $id;
80     return sqlInsert($sql, $sqlBindingArray);
83 function formJump($address = '')
85     echo "<script>\n";
86     if ($address) {
87         echo "top.restoreSession();\n";
88         echo "location.href = " . js_escape($address) . ";\n";
89     } else {
90         echo "parent.closeTab(window.name, true);\n";
91     }
92     echo "</script>\n";
93     // TBD: Exit seems wrong here, but that's how it has been forever.
94     exit;
97 function formFetch($tableName, $id, $cols = "*", $activity = "1")
99         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
100     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)) ;
104 function formDisappear($tableName, $id)
106         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
107     if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '0' where id=? and pid=?", [$id, $pid])) {
108         return true;
109     }
111     return false;
114 function formReappear($tableName, $id)
116         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
117     if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '1' where id=? and pid=?", [$id, $pid])) {
118         return true;
119     }
121     return false;