quick intro and instructions used by github
[openemr.git] / library / pnotes.inc
blob2c3dcad013a11e9c3edd13d2a82019dd0cfcfc74
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   if ($docid) {
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";
25   }
26   else {
27     $sql = "SELECT $cols FROM pnotes AS p " .
28       "WHERE date LIKE '%$date%' AND pid LIKE '$pid'";
29   }
30   $sql .= " AND deleted != 1"; // exclude ALL deleted notes
31   if ($activity != "all")
32     $sql .= " AND activity = '$activity'";
33   if ($username)
34     $sql .= " AND assigned_to LIKE '$username'";
35   if ($status)
36     $sql .= " AND message_status IN ('".str_replace(",", "','", $status)."')";
37   $sql .= " ORDER BY date DESC";
38   if($limit != "all")
39     $sql .= " LIMIT $start, $limit";
41   $res = sqlStatement($sql);
43   for ($iter = 0;$row = sqlFetchArray($res);$iter++)
44     $all[$iter] = $row;
45   return $all;
48 function getPnotesByPid ($pid, $activity = "1", $cols = "*", $limit=10, $start=0)
50   $res = sqlStatement("SELECT $cols FROM pnotes WHERE pid LIKE '$pid' " .
51     "AND activity = '$activity' ".
52     " AND deleted != 1 ".
53     " ORDER BY date DESC LIMIT $start,$limit");
54   for ($iter = 0; $row = sqlFetchArray($res); $iter++)
55     $all[$iter] = $row;
56   return $all;
59 function addPnote($pid, $newtext, $authorized = '0', $activity = '1',
60   $title='Unassigned', $assigned_to = '', $datetime = '')
62   if (empty($datetime)) $datetime = date('Y-m-d H:i:s');
64   $body = date('Y-m-d H:i') . ' (' . $_SESSION['authUser'];
65   if ($assigned_to) $body .= " to $assigned_to";
66   $body = addslashes($body . ') ' . $newtext);
68   return sqlInsert("INSERT INTO pnotes (date, body, pid, user, groupname, " .
69     "authorized, activity, title, assigned_to) VALUES ('$datetime', '$body', '$pid', '" .
70     $_SESSION['authUser'] . "', '". $_SESSION['authProvider'] .
71     "', '$authorized', '$activity', '$title', '$assigned_to')");
74 function updatePnote($id, $newtext, $title, $assigned_to)
76   $row = getPnoteById($id);
77   if (! $row) die("updatePnote() did not find id '$id'");
78   $activity = $assigned_to ? '1' : '0';
80   $body = $row['body'] . "\n" . date('Y-m-d H:i') .
81     ' (' . $_SESSION['authUser'];
82   if ($assigned_to) $body .= " to $assigned_to";
83   $body = addslashes($body . ') ' . $newtext);
85   sqlStatement("UPDATE pnotes SET " .
86     "body = '$body', activity = '$activity', title='$title', " .
87     "assigned_to = '$assigned_to' WHERE id = '$id'");
90 function authorizePnote($id, $authorized = "1")
92   sqlQuery("UPDATE pnotes SET authorized = '$authorized' WHERE id = '$id'");
95 function disappearPnote($id)
97   sqlStatement("UPDATE pnotes SET activity = '0' WHERE id='$id'");
98   return true;
101 function reappearPnote ($id)
103   sqlStatement("UPDATE pnotes SET activity = '1' WHERE id='$id'");
104   return true;
107 function deletePnote($id)
109   sqlStatement("UPDATE pnotes SET deleted = '1' WHERE id='$id'");
110   return true;