migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / library / api.inc
blobce99ca1dafb5a0dafb63fb105a52e88e0f656cd0
1 <?php
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");
7 $GLOBALS['form_exit_url'] = "$rootdir/patient_file/encounter/encounter_top.php";
9 function formHeader ($title = "My Form")
11         ?>
12         <html>
13         <head>
14 <?php html_header_show();?>
15         <link rel=stylesheet href="<?php echo $GLOBALS['css_header']?>" type="text/css">
16         <title><?php echo $title?></title>
17         </head>
18         <body background="<?php echo $GLOBALS['backpic']?>" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
19         <?php
22 function formFooter ()
24         ?>
25         </body>
26         </html>
27         <?php
30 // This function will escape the $values when using the new security method (ie. $sanitize_all_escapes is TRUE).
31 //   Otherwise, this function expects the $values to already be escaped(original and legacy behavior).
32 function formSubmit ($tableName, $values, $id, $authorized = "0")
34         // Bring in $sanitize_all_escapes variable, which will decide
35         // the variable escaping method.
36         global $sanitize_all_escapes;
38         $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(),";
39         foreach ($values as $key => $value)
40                 if (strpos($key,"openemr_net_cpt") === 0) {
41                         //code to auto add cpt code
42                         if (!empty($value)) {
43                                 $code_array = explode(" ",$value,2);
44                                 
45                                 addBilling(date("Ymd"), 'CPT4', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
46                         }
47                                         
48                 }
49                 //case where key looks like "[a-zA-Z]*diagnosis[0-9]" which is special, it is used to auto add ICD codes
50                 
51                 elseif (strpos($key,"diagnosis") == (strlen($key) -10) && !(strpos($key,"diagnosis")=== false )) {
52                         //icd auto add ICD9-CM
53                         if (!empty($value)) {
54                                 $code_array = explode(" ",$value,2);
55                                 addBilling(date("Ymd"), 'ICD9-M', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
56                         }
57                 }
58                 else {
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) . "',";
62                         }
63                         else {
64                                 // original method (rely on code to escape values before using this function)
65                                 $sql .= " $key = '$value',";
66                         }
67                 }
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) . "',";
84                 }
85                 else {
86                         // original method (rely on code to escape values before using this function)
87                         $sql .= " $key = '$value',";
88                 }
89         $sql = substr($sql, 0, -1);
90         $sql .= " where id='".add_escape_custom($id)."'";
91         
92         return sqlInsert($sql);
96 function formJump ($address = "0")
98         $returnurl = 'encounter_top.php';
99         if ($address == "0")
100                 $address = "{$GLOBALS['rootdir']}/patient_file/encounter/$returnurl";
101         echo "\n<script language='Javascript'>top.restoreSession();window.location='$address';</script>\n";
102         exit;
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")
113         if($limit == "all")
114         {
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";
120         }
121         else
122         {
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";
128         }
130         $res = sqlStatement($sql);
131         
132         for ($iter = 0;$row = sqlFetchArray($res);$iter++)
133                 $all[$iter] = $row;
134         return $all;
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;
141         return false;
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;
148         return false;