2 require_once("{$GLOBALS['srcdir']}/sql.inc");
4 // 06-2009, BM migrated the patient_note_types array to the list_options table
6 function getPnoteById($id, $cols = "*")
8 return sqlQuery("SELECT $cols FROM pnotes WHERE id='$id' " .
9 " AND deleted != 1 ". // exclude ALL deleted notes
10 "order by date DESC limit 0,1");
13 function getPnotesByDate($date, $activity = "1", $cols = "*", $pid = "%",
14 $limit = "all", $start = 0, $username = '')
16 $sql = "SELECT $cols FROM pnotes WHERE date LIKE '%$date%' " .
17 "AND pid LIKE '$pid' ";
18 $sql .= " AND deleted != 1 "; // exclude ALL deleted notes
19 if ($activity != "all")
20 $sql .= "AND activity = '$activity' ";
22 $sql .= "AND assigned_to LIKE '$username' ";
23 $sql .= "ORDER BY date DESC";
25 $sql .= " LIMIT $start, $limit";
27 $res = sqlStatement($sql);
29 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
34 function getPnotesByPid ($pid, $activity = "1", $cols = "*", $limit=10, $start=0)
36 $res = sqlStatement("SELECT $cols FROM pnotes WHERE pid LIKE '$pid' " .
37 "AND activity = '$activity' ".
39 " ORDER BY date DESC LIMIT $start,$limit");
40 for ($iter = 0; $row = sqlFetchArray($res); $iter++)
45 function addPnote($pid, $newtext, $authorized = '0', $activity = '1',
46 $title='Unassigned', $assigned_to = '')
48 $body = date('Y-m-d H:i') . ' (' . $_SESSION['authUser'];
49 if ($assigned_to) $body .= " to $assigned_to";
50 $body = addslashes($body . ') ' . $newtext);
52 return sqlInsert("INSERT INTO pnotes (date, body, pid, user, groupname, " .
53 "authorized, activity, title, assigned_to) VALUES (NOW(), '$body', '$pid', '" .
54 $_SESSION['authUser'] . "', '". $_SESSION['authProvider'] .
55 "', '$authorized', '$activity', '$title', '$assigned_to')");
58 function updatePnote($id, $newtext, $title, $assigned_to)
60 $row = getPnoteById($id);
61 if (! $row) die("updatePnote() did not find id '$id'");
62 $activity = $assigned_to ? '1' : '0';
64 $body = $row['body'] . "\n" . date('Y-m-d H:i') .
65 ' (' . $_SESSION['authUser'];
66 if ($assigned_to) $body .= " to $assigned_to";
67 $body = addslashes($body . ') ' . $newtext);
69 sqlStatement("UPDATE pnotes SET " .
70 "body = '$body', activity = '$activity', title='$title', " .
71 "assigned_to = '$assigned_to' WHERE id = '$id'");
74 function authorizePnote($id, $authorized = "1")
76 sqlQuery("UPDATE pnotes SET authorized = '$authorized' WHERE id = '$id'");
79 function disappearPnote($id)
81 sqlStatement("UPDATE pnotes SET activity = '0' WHERE id='$id'");
85 function reappearPnote ($id)
87 sqlStatement("UPDATE pnotes SET activity = '1' WHERE id='$id'");
91 function deletePnote($id)
93 sqlStatement("UPDATE pnotes SET deleted = '1' WHERE id='$id'");