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();
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 AND p.pid != p.user";
26 array_push($sqlParameterArray, '%'.$date.'%', $docid);
29 $sql = "SELECT $cols FROM pnotes AS p " .
30 "WHERE date LIKE ? AND pid LIKE ? AND p.pid != p.user";
31 array_push($sqlParameterArray, '%'.$date.'%', $pid);
33 $sql .= " AND deleted != 1"; // exclude ALL deleted notes
34 if ($activity != "all") {
35 $sql .= " AND activity = ?";
36 array_push($sqlParameterArray, $activity);
39 $sql .= " AND assigned_to LIKE ?";
40 array_push($sqlParameterArray, $username);
43 $sql .= " AND message_status IN ('".str_replace(",", "','", $status)."')";
44 $sql .= " ORDER BY date DESC";
46 $sql .= " LIMIT $start, $limit";
48 $res = sqlStatement($sql, $sqlParameterArray);
51 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
56 function getSentPnotesByDate($date, $activity = "1", $cols = "*", $pid = "%",
57 $limit = "all", $start = 0, $username = '', $docid = 0, $status = "")
59 $sqlParameterArray = array();
61 $sql = "SELECT $cols FROM pnotes AS p, gprelations AS r " .
62 "WHERE p.date LIKE ? AND r.type1 = 1 AND " .
63 "r.id1 = ? AND r.type2 = 6 AND p.id = r.id2 AND p.pid = p.user";
64 array_push($sqlParameterArray, '%'.$date.'%', $docid);
67 $sql = "SELECT $cols FROM pnotes AS p " .
68 "WHERE date LIKE ? AND pid LIKE ? AND p.pid = p.user";
69 array_push($sqlParameterArray, '%'.$date.'%', $pid);
71 $sql .= " AND deleted != 1"; // exclude ALL deleted notes
72 if ($activity != "all") {
73 $sql .= " AND activity = ?";
74 array_push($sqlParameterArray, $activity);
77 $sql .= " AND assigned_to LIKE ?";
78 array_push($sqlParameterArray, $username);
81 $sql .= " AND message_status IN ('".str_replace(",", "','", $status)."')";
82 $sql .= " ORDER BY date DESC";
84 $sql .= " LIMIT $start, $limit";
86 $res = sqlStatement($sql, $sqlParameterArray);
89 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
94 function getPatientNotes($pid = '', $limit = '', $offset = 0, $search = '')
97 $limit = "LIMIT $offset, $limit";
108 CONCAT(pd.fname, ' ', pd.lname)
114 LEFT JOIN patient_data AS pd
116 WHERE assigned_to = '-patient-'
123 $res = sqlStatement($sql, array($pid));
124 for($iter = 0;$row = sqlFetchArray($res);$iter++){
130 function getPatientNotifications($pid = '', $limit = '', $offset = 0, $search = '')
133 $limit = "LIMIT $offset, $limit";
138 date_created AS `date`,
139 'Patient Reminders' AS `user`,
141 CONCAT(lo.title, ':', lo2.title) AS body,
142 '' as message_status,
143 'Notification' as `type`
145 patient_reminders AS pr
146 LEFT JOIN list_options AS lo
147 ON lo.option_id = pr.category
148 AND lo.list_id = 'rule_action_category'
149 LEFT JOIN list_options AS lo2
150 ON lo2.option_id = pr.item
151 AND lo2.list_id = 'rule_action'
154 AND date_created > DATE_SUB(NOW(), INTERVAL 1 MONTH)
159 $res = sqlStatement($sql, array($pid));
160 for($iter = 0;$row = sqlFetchArray($res);$iter++){
166 function getPatientSentNotes($pid = '', $limit = '', $offset = 0, $search = '')
169 $limit = "LIMIT $offset, $limit";
180 CONCAT(pd.lname, ' ', pd.fname)
187 LEFT JOIN patient_data AS pd
196 $res = sqlStatement($sql, array($pid,$pid));
197 for($iter = 0;$row = sqlFetchArray($res);$iter++){
203 function getPnotesByPid ($pid, $activity = "1", $cols = "*", $limit=10, $start=0)
205 $res = sqlStatement("SELECT $cols FROM pnotes WHERE pid LIKE '$pid' " .
206 "AND activity = '$activity' ".
207 " AND deleted != 1 ".
208 " ORDER BY date DESC LIMIT $start,$limit");
209 for ($iter = 0; $row = sqlFetchArray($res); $iter++)
214 function addPnote($pid, $newtext, $authorized = '0', $activity = '1',
215 $title='Unassigned', $assigned_to = '', $datetime = '', $message_status = "New")
217 if (empty($datetime)) $datetime = date('Y-m-d H:i:s');
219 $body = date('Y-m-d H:i') . ' (' . $_SESSION['authUser'];
220 if ($assigned_to) $body .= " to $assigned_to";
221 $body = $body . ') ' . $newtext;
223 return sqlInsert("INSERT INTO pnotes (date, body, pid, user, groupname, " .
224 "authorized, activity, title, assigned_to, message_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
225 array($datetime, $body, $pid, $_SESSION['authUser'], $_SESSION['authProvider'], $authorized, $activity, $title, $assigned_to, $message_status) );
228 function addMailboxPnote($pid, $newtext, $authorized = '0', $activity = '1',
229 $title='Unassigned', $assigned_to = '', $datetime = '', $message_status = "New")
231 if (empty($datetime)) $datetime = date('Y-m-d H:i:s');
233 $body = date('Y-m-d H:i') . ' (' . $pid;
234 if ($assigned_to) $body .= " to $assigned_to";
235 $body = $body . ') ' . $newtext;
237 return sqlInsert("INSERT INTO pnotes (date, body, pid, user, groupname, " .
238 "authorized, activity, title, assigned_to, message_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
239 array($datetime, $body, $pid, $pid, 'Default', $authorized, $activity, $title, $assigned_to, $message_status) );
242 function updatePnote($id, $newtext, $title, $assigned_to, $message_status = "")
244 $row = getPnoteById($id);
245 if (! $row) die("updatePnote() did not find id '$id'");
246 $activity = $assigned_to ? '1' : '0';
248 $body = $row['body'] . "\n" . date('Y-m-d H:i') .
249 ' (' . $_SESSION['authUser'];
250 if ($assigned_to) $body .= " to $assigned_to";
251 $body = $body . ') ' . $newtext;
253 if ($message_status) {
254 sqlStatement("UPDATE pnotes SET " .
255 "body = ?, activity = ?, title= ?, " .
256 "assigned_to = ?, message_status = ? WHERE id = ?",
257 array($body, $activity, $title, $assigned_to, $message_status, $id) );
260 sqlStatement("UPDATE pnotes SET " .
261 "body = ?, activity = ?, title= ?, " .
262 "assigned_to = ? WHERE id = ?",
263 array($body, $activity, $title, $assigned_to, $id) );
267 function updatePnoteMessageStatus($id, $message_status)
269 sqlStatement("update pnotes set message_status = ? where id = ?", array($message_status, $id) );
272 function authorizePnote($id, $authorized = "1")
274 sqlQuery("UPDATE pnotes SET authorized = '$authorized' WHERE id = '$id'");
277 function disappearPnote($id)
279 sqlStatement("UPDATE pnotes SET activity = '0' WHERE id=?", array($id) );
283 function reappearPnote ($id)
285 sqlStatement("UPDATE pnotes SET activity = '1' WHERE id=?", array($id) );
289 function deletePnote($id)
291 sqlStatement("UPDATE pnotes SET deleted = '1' WHERE id=?", array($id) );