fix for attendance form
[openemr.git] / library / api.inc
blob0ab663eea8e83c3967bf1889756c7cb3f7235710
1 <?php
2 //our api for 3rd party developers
3 include_once("../../globals.php");
4 include_once("{$GLOBALS['srcdir']}/billing.inc");
6 $GLOBALS['form_exit_url'] = "$rootdir/patient_file/encounter/encounter_top.php";
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                         }
43                 }
44                 //case where key looks like "[a-zA-Z]*diagnosis[0-9]" which is special, it is used to auto add ICD codes
46                 elseif (strpos($key,"diagnosis") == (strlen($key) -10) && !(strpos($key,"diagnosis")=== false )) {
47                         //icd auto add ICD9-CM
48                         if (!empty($value)) {
49                                 $code_array = explode(" ",$value,2);
50                                 addBilling(date("Ymd"), 'ICD9-M', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
51                         }
52                 }
53                 else {
54             $sql .= " " . escape_sql_column_name($key,array($tableName)) . " = '" . add_escape_custom($value) . "',";
55                 }
56         $sql = substr($sql, 0, -1);
57         return sqlInsert($sql);
61 function formUpdate ($tableName, $values, $id, $authorized = "0")
63         $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(),";
64         foreach ($values as $key => $value)
65         $sql .= " " . escape_sql_column_name($key,array($tableName)) . " = '" . add_escape_custom($value) . "',";
67         $sql = substr($sql, 0, -1);
68         $sql .= " where id='".add_escape_custom($id)."'";
70         return sqlInsert($sql);
74 function formJump ($address = "0")
76         $returnurl = 'encounter_top.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         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
86         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) ) ;
89 function formGetIds ($tableName, $cols = "*", $limit='all', $start=0, $activity = "1")
91         if($limit == "all")
92         {
93                 // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
94                 $sql = "select $cols from `" . escape_table_name($tableName) . "` where pid like '$pid' ";
95                 if ($activity != "all")
96                         $sql .= "and activity like '$activity' ";
97                 $sql .= "order by date DESC";
98         }
99         else
100         {
101                 $sql = "select $cols from pnotes where pid like '$pid' ";
102                 $sql .= " AND deleted != 1 "; // exclude ALL deleted notes
103                 if ($activity != "all")
104                         $sql .= "and activity like '$activity' ";
105                 $sql .= "order by date DESC LIMIT $start, $limit";
106         }
108         $res = sqlStatement($sql);
110         for ($iter = 0;$row = sqlFetchArray($res);$iter++)
111                 $all[$iter] = $row;
112         return $all;
115 function formDisappear ($tableName, $id)
117         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
118         if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '0' where id='$id' and pid='$pid'")) return true;
119         return false;
122 function formReappear ($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 = '1' where id='$id' and pid='$pid'")) return true;
126         return false;