Label changes as discussed in forums on sourceforge
[openemr.git] / library / pnotes.inc
blob3a302b37dd096832f39203abdf7cf7d0bfc00243
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='$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, $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 = '$activity'";
36   if ($username) {
37     $sql .= " AND assigned_to LIKE ?";
38     array_push($sqlParameterArray, $username);
39   }
40   if ($status)
41     $sql .= " AND message_status IN ('".str_replace(",", "','", $status)."')";
42   $sql .= " ORDER BY date DESC";
43   if($limit != "all")
44     $sql .= " LIMIT $start, $limit";
46   $res = sqlStatement($sql, $sqlParameterArray);
48   for ($iter = 0;$row = sqlFetchArray($res);$iter++)
49     $all[$iter] = $row;
50   return $all;
53 function getPnotesByPid ($pid, $activity = "1", $cols = "*", $limit=10, $start=0)
55   $res = sqlStatement("SELECT $cols FROM pnotes WHERE pid LIKE '$pid' " .
56     "AND activity = '$activity' ".
57     " AND deleted != 1 ".
58     " ORDER BY date DESC LIMIT $start,$limit");
59   for ($iter = 0; $row = sqlFetchArray($res); $iter++)
60     $all[$iter] = $row;
61   return $all;
64 function addPnote($pid, $newtext, $authorized = '0', $activity = '1',
65   $title='Unassigned', $assigned_to = '', $datetime = '')
67   if (empty($datetime)) $datetime = date('Y-m-d H:i:s');
69   $body = date('Y-m-d H:i') . ' (' . $_SESSION['authUser'];
70   if ($assigned_to) $body .= " to $assigned_to";
71   $body = addslashes($body . ') ' . $newtext);
73   return sqlInsert("INSERT INTO pnotes (date, body, pid, user, groupname, " .
74     "authorized, activity, title, assigned_to) VALUES ('$datetime', '$body', '$pid', '" .
75     $_SESSION['authUser'] . "', '". $_SESSION['authProvider'] .
76     "', '$authorized', '$activity', '$title', '$assigned_to')");
79 function updatePnote($id, $newtext, $title, $assigned_to)
81   $row = getPnoteById($id);
82   if (! $row) die("updatePnote() did not find id '$id'");
83   $activity = $assigned_to ? '1' : '0';
85   $body = $row['body'] . "\n" . date('Y-m-d H:i') .
86     ' (' . $_SESSION['authUser'];
87   if ($assigned_to) $body .= " to $assigned_to";
88   $body = addslashes($body . ') ' . $newtext);
90   sqlStatement("UPDATE pnotes SET " .
91     "body = '$body', activity = '$activity', title='$title', " .
92     "assigned_to = '$assigned_to' WHERE id = '$id'");
95 function authorizePnote($id, $authorized = "1")
97   sqlQuery("UPDATE pnotes SET authorized = '$authorized' WHERE id = '$id'");
100 function disappearPnote($id)
102   sqlStatement("UPDATE pnotes SET activity = '0' WHERE id='$id'");
103   return true;
106 function reappearPnote ($id)
108   sqlStatement("UPDATE pnotes SET activity = '1' WHERE id='$id'");
109   return true;
112 function deletePnote($id)
114   sqlStatement("UPDATE pnotes SET deleted = '1' WHERE id='$id'");
115   return true;