added ending dates of service
[openemr.git] / library / pnotes.inc
blobaa197ceb6b8ad1f4a182b049957abd8ae238452b
1 <?php
2 require_once("{$GLOBALS['srcdir']}/sql.inc");
4 $patient_note_types = array(
5   'Unassigned',
6   'Chart Note',
7   'Insurance',
8   'New Document',
9   'Pharmacy',
10   'Prior Auth',
11   'Referral',
12   'Test Scheduling',
13   'Bill/Collect',
14   'Other');
16 function getPnoteById($id, $cols = "*")
18   return sqlQuery("SELECT $cols FROM pnotes WHERE id='$id' " .
19     "order by date DESC limit 0,1");
22 function getPnotesByDate($date, $activity = "1", $cols = "*", $pid = "%",
23   $limit = "all", $start = 0, $username = '')
25   $sql = "SELECT $cols FROM pnotes WHERE date LIKE '%$date%' " .
26     "AND pid LIKE '$pid' ";
27   if ($activity != "all")
28     $sql .= "AND activity = '$activity' ";
29   if ($username)
30     $sql .= "AND assigned_to = '$username' ";
31   $sql .= "ORDER BY date DESC";
32   if($limit != "all")
33     $sql .= " LIMIT $start, $limit";
35   $res = sqlStatement($sql);
37   for ($iter = 0;$row = sqlFetchArray($res);$iter++)
38     $all[$iter] = $row;
39   return $all;
42 function getPnotesByPid ($pid, $activity = "1", $cols = "*", $limit=10, $start=0)
44   $res = sqlStatement("SELECT $cols FROM pnotes WHERE pid LIKE '$pid' " .
45     "AND activity = '$activity' ORDER BY date DESC LIMIT $start,$limit");
46   for ($iter = 0; $row = sqlFetchArray($res); $iter++)
47     $all[$iter] = $row;
48   return $all;
51 function addPnote($pid, $newtext, $authorized = '0', $activity = '1',
52   $title='Unassigned', $assigned_to = '')
54   $body = date('Y-m-d H:i') . ' (' . $_SESSION['authUser'];
55   if ($assigned_to) $body .= " to $assigned_to";
56   $body = addslashes($body . ') ' . $newtext);
58   return sqlInsert("INSERT INTO pnotes (date, body, pid, user, groupname, " .
59     "authorized, activity, title, assigned_to) VALUES (NOW(), '$body', '$pid', '" .
60     $_SESSION['authUser'] . "', '". $_SESSION['authProvider'] .
61     "', '$authorized', '$activity', '$title', '$assigned_to')");
64 function updatePnote($id, $newtext, $title, $assigned_to)
66   $row = getPnoteById($id);
67   if (! $row) die("updatePnote() did not find id '$id'");
68   $activity = $assigned_to ? '1' : '0';
70   $body = $row['body'] . "\n" . date('Y-m-d H:i') .
71     ' (' . $_SESSION['authUser'];
72   if ($assigned_to) $body .= " to $assigned_to";
73   $body = addslashes($body . ') ' . $newtext);
75   sqlStatement("UPDATE pnotes SET " .
76     "body = '$body', activity = '$activity', title='$title', " .
77     "assigned_to = '$assigned_to' WHERE id = '$id'");
80 function authorizePnote($id, $authorized = "1")
82   sqlQuery("UPDATE pnotes SET authorized = '$authorized' WHERE id = '$id'");
85 function disappearPnote($id)
87   sqlStatement("UPDATE pnotes SET activity = '0' WHERE id='$id'");
88   return true;
91 function reappearPnote ($id)
93   sqlStatement("UPDATE pnotes SET activity = '1' WHERE id='$id'");
94   return true;