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='$id' " .
14 " AND deleted != 1 ". // exclude ALL deleted notes
15 "order by date DESC limit 0,1");
18 function getPnotesByDate($date, $activity = "1", $cols = "*", $pid = "%",
19 $limit = "all", $start = 0, $username = '', $docid = 0)
22 $sql = "SELECT $cols FROM pnotes AS p, gprelations AS r " .
23 "WHERE p.date LIKE '%$date%' AND r.type1 = 1 AND " .
24 "r.id1 = '$docid' AND r.type2 = 6 AND p.id = r.id2";
27 $sql = "SELECT $cols FROM pnotes AS p " .
28 "WHERE date LIKE '%$date%' AND pid LIKE '$pid'";
30 $sql .= " AND deleted != 1"; // exclude ALL deleted notes
31 if ($activity != "all")
32 $sql .= " AND activity = '$activity'";
34 $sql .= " AND assigned_to LIKE '$username'";
35 $sql .= " ORDER BY date DESC";
37 $sql .= " LIMIT $start, $limit";
39 $res = sqlStatement($sql);
41 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
46 function getPnotesByPid ($pid, $activity = "1", $cols = "*", $limit=10, $start=0)
48 $res = sqlStatement("SELECT $cols FROM pnotes WHERE pid LIKE '$pid' " .
49 "AND activity = '$activity' ".
51 " ORDER BY date DESC LIMIT $start,$limit");
52 for ($iter = 0; $row = sqlFetchArray($res); $iter++)
57 function addPnote($pid, $newtext, $authorized = '0', $activity = '1',
58 $title='Unassigned', $assigned_to = '')
60 $body = date('Y-m-d H:i') . ' (' . $_SESSION['authUser'];
61 if ($assigned_to) $body .= " to $assigned_to";
62 $body = addslashes($body . ') ' . $newtext);
64 return sqlInsert("INSERT INTO pnotes (date, body, pid, user, groupname, " .
65 "authorized, activity, title, assigned_to) VALUES (NOW(), '$body', '$pid', '" .
66 $_SESSION['authUser'] . "', '". $_SESSION['authProvider'] .
67 "', '$authorized', '$activity', '$title', '$assigned_to')");
70 function updatePnote($id, $newtext, $title, $assigned_to)
72 $row = getPnoteById($id);
73 if (! $row) die("updatePnote() did not find id '$id'");
74 $activity = $assigned_to ? '1' : '0';
76 $body = $row['body'] . "\n" . date('Y-m-d H:i') .
77 ' (' . $_SESSION['authUser'];
78 if ($assigned_to) $body .= " to $assigned_to";
79 $body = addslashes($body . ') ' . $newtext);
81 sqlStatement("UPDATE pnotes SET " .
82 "body = '$body', activity = '$activity', title='$title', " .
83 "assigned_to = '$assigned_to' WHERE id = '$id'");
86 function authorizePnote($id, $authorized = "1")
88 sqlQuery("UPDATE pnotes SET authorized = '$authorized' WHERE id = '$id'");
91 function disappearPnote($id)
93 sqlStatement("UPDATE pnotes SET activity = '0' WHERE id='$id'");
97 function reappearPnote ($id)
99 sqlStatement("UPDATE pnotes SET activity = '1' WHERE id='$id'");
103 function deletePnote($id)
105 sqlStatement("UPDATE pnotes SET deleted = '1' WHERE id='$id'");