quick minor path updates (#1968)
[openemr.git] / library / api.inc
blob0bd444bf5a457aa0b32bf32eec1f38e6e9c81fab
1 <?php
2 //our api for 3rd party developers
3 require_once(dirname(__FILE__) . "/../interface/globals.php");
4 require_once("{$GLOBALS['srcdir']}/billing.inc");
6 $GLOBALS['form_exit_url'] = "javascript:parent.closeTab(window.name, false)";
8 function formHeader($title = "My Form")
10     ?>
11     <html>
12     <head>
13 <?php html_header_show();?>
14     <link rel=stylesheet href="<?php echo $GLOBALS['css_header']?>" type="text/css">
15     <title><?php echo $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     $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(),";
34     foreach ($values as $key => $value) {
35         if (strpos($key, "openemr_net_cpt") === 0) {
36             //code to auto add cpt code
37             if (!empty($value)) {
38                 $code_array = explode(" ", $value, 2);
40                 addBilling(date("Ymd"), 'CPT4', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
41             }
42         } //case where key looks like "[a-zA-Z]*diagnosis[0-9]" which is special, it is used to auto add ICD codes
44         elseif (strpos($key, "diagnosis") == (strlen($key) -10) && !(strpos($key, "diagnosis")=== false )) {
45             //icd auto add ICD9-CM
46             if (!empty($value)) {
47                 $code_array = explode(" ", $value, 2);
48                 addBilling(date("Ymd"), 'ICD9-M', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
49             }
50         } else {
51             $sql .= " " . escape_sql_column_name($key, array($tableName)) . " = '" . add_escape_custom($value) . "',";
52         }
53     }
55     $sql = substr($sql, 0, -1);
56     return sqlInsert($sql);
60 function formUpdate($tableName, $values, $id, $authorized = "0")
62     $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(),";
63     foreach ($values as $key => $value) {
64         $sql .= " " . escape_sql_column_name($key, array($tableName)) . " = '" . add_escape_custom($value) . "',";
65     }
67     $sql = substr($sql, 0, -1);
68     $sql .= " where id='".add_escape_custom($id)."'";
70     return sqlInsert($sql);
73 function formJump($address = '')
75     echo "<script>\n";
76     if ($address) {
77         echo "top.restoreSession();\n";
78         echo "location.href = '" . addslashes($address) . "';\n";
79     } else {
80         echo "parent.closeTab(window.name, true);\n";
81     }
82     echo "</script>\n";
83     // TBD: Exit seems wrong here, but that's how it has been forever.
84     exit;
87 function formFetch($tableName, $id, $cols = "*", $activity = "1")
89         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
90     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)) ;
93 function formGetIds($tableName, $cols = "*", $limit = 'all', $start = 0, $activity = "1")
95     if ($limit == "all") {
96                 // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
97                 $sql = "select $cols from `" . escape_table_name($tableName) . "` where pid like '$pid' ";
98         if ($activity != "all") {
99                 $sql .= "and activity like '$activity' ";
100         }
102                 $sql .= "order by date DESC";
103     } else {
104         $sql = "select $cols from pnotes where pid like '$pid' ";
105         $sql .= " AND deleted != 1 "; // exclude ALL deleted notes
106         if ($activity != "all") {
107                 $sql .= "and activity like '$activity' ";
108         }
110         $sql .= "order by date DESC LIMIT $start, $limit";
111     }
113         $res = sqlStatement($sql);
115     for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
116             $all[$iter] = $row;
117     }
119         return $all;
122 function formDisappear($tableName, $id)
124         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
125     if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '0' where id='$id' and pid='$pid'")) {
126         return true;
127     }
129     return false;
132 function formReappear($tableName, $id)
134         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
135     if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '1' where id='$id' and pid='$pid'")) {
136         return true;
137     }
139     return false;