Internationalization: some more documentation fixes
[openemr.git] / library / pnotes.inc
blob286734b82fa1781ed83cc835337f55f75b45a079
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 require_once("{$GLOBALS['srcdir']}/sql.inc");
9 // 06-2009, BM migrated the patient_note_types array to the list_options table
11 function getPnoteById($id, $cols = "*")
13   return sqlQuery("SELECT $cols FROM pnotes WHERE id=? " .
14     " AND deleted != 1 ". // exclude ALL deleted notes
15     "order by date DESC limit 0,1", array($id) );
18 function getPnotesByDate($date, $activity = "1", $cols = "*", $pid = "%",
19   $limit = "all", $start = 0, $username = '', $docid = 0, $status = "")
21 $sqlParameterArray = array();
22   if ($docid) {
23     $sql = "SELECT $cols FROM pnotes AS p, gprelations AS r " .
24     "WHERE p.date LIKE ? AND r.type1 = 1 AND " .
25     "r.id1 = ? AND r.type2 = 6 AND p.id = r.id2";
26     array_push($sqlParameterArray, '%'.$date.'%', $docid);
27   }
28   else {
29     $sql = "SELECT $cols FROM pnotes AS p " .
30       "WHERE date LIKE ? AND pid LIKE ?";
31     array_push($sqlParameterArray, '%'.$date.'%', $pid);
32   }
33   $sql .= " AND deleted != 1"; // exclude ALL deleted notes
34   if ($activity != "all") {
35     $sql .= " AND activity = ?";
36     array_push($sqlParameterArray, $activity);
37   }
38   if ($username) {
39     $sql .= " AND assigned_to LIKE ?";
40     array_push($sqlParameterArray, $username);
41   }
42   if ($status)
43     $sql .= " AND message_status IN ('".str_replace(",", "','", $status)."')";
44   $sql .= " ORDER BY date DESC";
45   if($limit != "all")
46     $sql .= " LIMIT $start, $limit";
48   $res = sqlStatement($sql, $sqlParameterArray);
50   for ($iter = 0;$row = sqlFetchArray($res);$iter++)
51     $all[$iter] = $row;
52   return $all;
55 function getPnotesByPid ($pid, $activity = "1", $cols = "*", $limit=10, $start=0)
57   $res = sqlStatement("SELECT $cols FROM pnotes WHERE pid LIKE '$pid' " .
58     "AND activity = '$activity' ".
59     " AND deleted != 1 ".
60     " ORDER BY date DESC LIMIT $start,$limit");
61   for ($iter = 0; $row = sqlFetchArray($res); $iter++)
62     $all[$iter] = $row;
63   return $all;
66 function addPnote($pid, $newtext, $authorized = '0', $activity = '1',
67   $title='Unassigned', $assigned_to = '', $datetime = '', $message_status = "New")
69   if (empty($datetime)) $datetime = date('Y-m-d H:i:s');
71   $body = date('Y-m-d H:i') . ' (' . $_SESSION['authUser'];
72   if ($assigned_to) $body .= " to $assigned_to";
73   $body = $body . ') ' . $newtext;
75   return sqlInsert("INSERT INTO pnotes (date, body, pid, user, groupname, " .
76     "authorized, activity, title, assigned_to, message_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
77     array($datetime, $body, $pid, $_SESSION['authUser'], $_SESSION['authProvider'], $authorized, $activity, $title, $assigned_to, $message_status) );
80 function updatePnote($id, $newtext, $title, $assigned_to, $message_status = "")
82   $row = getPnoteById($id);
83   if (! $row) die("updatePnote() did not find id '$id'");
84   $activity = $assigned_to ? '1' : '0';
86   $body = $row['body'] . "\n" . date('Y-m-d H:i') .
87     ' (' . $_SESSION['authUser'];
88   if ($assigned_to) $body .= " to $assigned_to";
89   $body = $body . ') ' . $newtext;
91   if ($message_status) {
92     sqlStatement("UPDATE pnotes SET " .
93       "body = ?, activity = ?, title= ?, " .
94       "assigned_to = ?, message_status = ? WHERE id = ?",
95       array($body, $activity, $title, $assigned_to, $message_status, $id) );
96   }
97   else {
98     sqlStatement("UPDATE pnotes SET " .
99       "body = ?, activity = ?, title= ?, " .
100       "assigned_to = ? WHERE id = ?",
101       array($body, $activity, $title, $assigned_to, $id) );
102   }
105 function updatePnoteMessageStatus($id, $message_status)
107   sqlStatement("update pnotes set message_status = ? where id = ?", array($message_status, $id) );
110 function authorizePnote($id, $authorized = "1")
112   sqlQuery("UPDATE pnotes SET authorized = '$authorized' WHERE id = '$id'");
115 function disappearPnote($id)
117   sqlStatement("UPDATE pnotes SET activity = '0' WHERE id=?", array($id) );
118   return true;
121 function reappearPnote ($id)
123   sqlStatement("UPDATE pnotes SET activity = '1' WHERE id=?", array($id) );
124   return true;
127 function deletePnote($id)
129   sqlStatement("UPDATE pnotes SET deleted = '1' WHERE id=?", array($id) );
130   return true;