Fix the dated reminders script headers.
[openemr.git] / library / api.inc
blobc1752000f89c83e100bb742d9a25d39cc58c71ce
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'] = $GLOBALS['concurrent_layout'] ?
8         "$rootdir/patient_file/encounter/encounter_top.php" :
9         "$rootdir/patient_file/encounter/patient_encounter.php";
11 function formHeader ($title = "My Form")
13         ?>
14         <html>
15         <head>
16 <?php html_header_show();?>
17         <link rel=stylesheet href="<?php echo $GLOBALS['css_header']?>" type="text/css">
18         <title><?php echo $title?></title>
19         </head>
20         <body background="<?php echo $GLOBALS['backpic']?>" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
21         <?php
24 function formFooter ()
26         ?>
27         </body>
28         </html>
29         <?php
32 function formSubmit ($tableName, $values, $id, $authorized = "0")
34         $sql = "insert into $tableName set pid = {$_SESSION['pid']},groupname='".$_SESSION['authProvider']."',user='".$_SESSION['authUser']."',authorized=$authorized,activity=1, date = NOW(),";
35         foreach ($values as $key => $value)
36                 if (strpos($key,"openemr_net_cpt") === 0) {
37                         //code to auto add cpt code
38                         if (!empty($value)) {
39                                 $code_array = split(" ",$value,2);
40                                 
41                                 addBilling(date("Ymd"), 'CPT4', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
42                         }
43                                         
44                 }
45                 //case where key looks like "[a-zA-Z]*diagnosis[0-9]" which is special, it is used to auto add ICD codes
46                 
47                 elseif (strpos($key,"diagnosis") == (strlen($key) -10) && !(strpos($key,"diagnosis")=== false )) {
48                         //icd auto add ICD9-CM
49                         if (!empty($value)) {
50                                 $code_array = split(" ",$value,2);
51                                 addBilling(date("Ymd"), 'ICD9-M', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
52                         }
53                 }
54                 else {
55                         $sql .= " $key = '$value',";
56                 }
57         $sql = substr($sql, 0, -1);
58         return sqlInsert($sql);
62 function formUpdate ($tableName, $values, $id, $authorized = "0")
64         $sql = "update $tableName set pid = {$_SESSION['pid']},groupname='".$_SESSION['authProvider']."',user='".$_SESSION['authUser']."',authorized=$authorized,activity=1, date = NOW(),";
65         foreach ($values as $key => $value)
66                 $sql .= " $key = '$value',";
67         $sql = substr($sql, 0, -1);
68         $sql .= " where id=$id";
69         
70         return sqlInsert($sql);
74 function formJump ($address = "0")
76         $returnurl = $GLOBALS['concurrent_layout'] ? 'encounter_top.php' : 'patient_encounter.php';
77         if ($address == "0")
78                 $address = "{$GLOBALS['rootdir']}/patient_file/encounter/$returnurl";
79         echo "\n<script language='Javascript'>top.restoreSession();window.location='$address';</script>\n";
80         exit;
83 function formFetch ($tableName, $id, $cols="*", $activity="1")
85         return sqlQuery ( "select $cols from `$tableName` where id='$id' and pid = '{$GLOBALS['pid']}' and activity like '$activity' order by date DESC LIMIT 0,1" ) ;
88 function formGetIds ($tableName, $cols = "*", $limit='all', $start=0, $activity = "1")
90         if($limit == "all")
91         {
93                 $sql = "select $cols from `$tableName` where pid like '$pid' ";
94                 if ($activity != "all")
95                         $sql .= "and activity like '$activity' ";
96                 $sql .= "order by date DESC";
97         }
98         else
99         {
100                 $sql = "select $cols from pnotes where pid like '$pid' ";
101                 $sql .= " AND deleted != 1 "; // exclude ALL deleted notes
102                 if ($activity != "all")
103                         $sql .= "and activity like '$activity' ";
104                 $sql .= "order by date DESC LIMIT $start, $limit";
105         }
107         $res = sqlStatement($sql);
108         
109         for ($iter = 0;$row = sqlFetchArray($res);$iter++)
110                 $all[$iter] = $row;
111         return $all;
114 function formDisappear ($tableName, $id)
116         if (sqlStatement("update `$tableName` set activity = '0' where id='$id' and pid='$pid'")) return true;
117         return false;
120 function formReappear ($tableName, $id)
122         if (sqlStatement("update `$tableName` set activity = '1' where id='$id' and pid='$pid'")) return true;
123         return false;