added appointments-encounters report
[openemr.git] / library / api.inc
blob8545547d7cdd76fd40eb904377bcee1a527c660f
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");
6 function formHeader ($title = "My Form")
8         ?>
9         <html>
10         <head>
11         <link rel=stylesheet href="<?=$GLOBALS['css_header']?>" type="text/css">
12         <title><?=$title?></title>
13         </head>
14         <body background="<?=$GLOBALS['backpic']?>" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
15         <?php
18 function formFooter ()
20         ?>
21         </body>
22         </form>
23         <?php
26 function formSubmit ($tableName, $values, $id, $authorized = "0")
28         $sql = "insert into $tableName set pid = {$_SESSION['pid']},groupname='".$_SESSION['authProvider']."',user='".$_SESSION['authUser']."',authorized=$authorized,activity=1, date = NOW(),";
29         while(list($key, $value) = each($values))
30                 if (strpos($key,"openemr_net_cpt") === 0) {
31                         //code to auto add cpt code
32                         if (!empty($value)) {
33                                 $code_array = split(" ",$value,2);
34                                 
35                                 addBilling(date("Ymd"), 'CPT4', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
36                         }
37                                         
38                 }
39                 //case where key looks like "[a-zA-Z]*diagnosis[0-9]" which is special, it is used to auto add ICD codes
40                 
41                 elseif (strpos($key,"diagnosis") == (strlen($key) -10) && !(strpos($key,"diagnosis")=== false )) {
42                         //icd auto add ICD9-CM
43                         if (!empty($value)) {
44                                 $code_array = split(" ",$value,2);
45                                 addBilling(date("Ymd"), 'ICD9-M', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
46                         }
47                 }
48                 else {
49                         $sql .= " $key = '$value',";
50                 }
51         $sql = substr($sql, 0, -1);
52         return sqlInsert($sql);
56 function formUpdate ($tableName, $values, $id, $authorized = "0")
58         $sql = "update $tableName set pid = {$_SESSION['pid']},groupname='".$_SESSION['authProvider']."',user='".$_SESSION['authUser']."',authorized=$authorized,activity=1, date = NOW(),";
59         while(list($key, $value) = each($values))
60                 $sql .= " $key = '$value',";
61         $sql = substr($sql, 0, -1);
62         $sql .= " where id=$id";
63         
64         return sqlInsert($sql);
68 function formJump ($address = "0")
70         if ($address == "0")
71                 $address = "{$GLOBALS['rootdir']}/patient_file/encounter/patient_encounter.php";
72 //      echo $address;
73         echo "\n<script language='Javascript'>window.location='$address';</script>\n";
74         exit;
77 function formFetch ($tableName, $id, $cols="*", $activity="1")
79         return sqlQuery ( "select $cols from `$tableName` where id='$id' and pid = '{$GLOBALS['pid']}' and activity like '$activity' order by date DESC LIMIT 0,1" ) ;
82 function formGetIds ($tableName, $cols = "*", $limit='all', $start=0, $activity = "1")
84         if($limit == "all")
85         {
87                 $sql = "select $cols from `$tableName` where pid like '$pid' ";
88                 if ($activity != "all")
89                         $sql .= "and activity like '$activity' ";
90                 $sql .= "order by date DESC";
91         }
92         else
93         {
94                 $sql = "select $cols from pnotes where pid like '$pid' ";
95                 if ($activity != "all")
96                         $sql .= "and activity like '$activity' ";
97                 $sql .= "order by date DESC LIMIT $start, $limit";
98         }
100         $res = sqlStatement($sql);
101         
102         for ($iter = 0;$row = sqlFetchArray($res);$iter++)
103                 $all[$iter] = $row;
104         return $all;
107 function formDisappear ($tableName, $id)
109         if (sqlStatement("update `$tableName` set activity = '0' where id='$id' and pid='$pid'")) return true;
110         return false;
113 function formReappear ($tableName, $id)
115         if (sqlStatement("update `$tableName` set activity = '1' where id='$id' and pid='$pid'")) return true;
116         return false;