4 * This file contains functions for handling on-site portal notes attached to patient files.
7 * @link https://www.open-emr.org
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @copyright Copyright (c) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("$srcdir/pnotes.inc");
15 function addPortalMailboxPnote(
20 $title = 'Unassigned',
23 $message_status = "New",
27 if (empty($datetime)) {
28 $datetime = date('Y-m-d H:i:s');
31 // make inactive if set as Done
32 if ($message_status == "Done") {
36 $user = $_SESSION['authUser'] ? $_SESSION['authUser'] : $pid;
37 $pname = $_SESSION['ptName'] ? $_SESSION['ptName'] : $user;
39 /* $body = " ($pname";
40 if ($assigned_to) $body .= " to $assigned_to";
41 $body = $body . ') ' . $newtext; */
46 "INSERT INTO pnotes (date, body, pid, user, groupname, " .
47 "authorized, activity, title, assigned_to, message_status, portal_relation) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
48 array($datetime, $body, $pid, $user, 'Default', $authorized, $activity, $title, $assigned_to, $message_status,$master_note)
52 function getPortalPatientNotes($pid = '', $limit = '', $offset = 0, $search = '')
55 $limit = "LIMIT " . escape_limit($offset) . ", " . escape_limit($limit);
67 CONCAT(pd.fname, ' ', pd.lname)
74 LEFT JOIN patient_data AS pd
76 WHERE assigned_to = '-patient-'
83 $res = sqlStatement($sql, array($pid));
84 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
91 function getPortalPatientNotifications($pid = '', $limit = '', $offset = 0, $search = '')
94 $limit = "LIMIT " . escape_limit($offset) . ", " . escape_limit($limit);
100 date_created AS `date`,
101 'Patient Reminders' AS `user`,
103 CONCAT(lo.title, ':', lo2.title) AS body,
104 '' as message_status,
105 'Notification' as `type`
107 patient_reminders AS pr
108 LEFT JOIN list_options AS lo
109 ON lo.option_id = pr.category
110 AND lo.list_id = 'rule_action_category'
111 LEFT JOIN list_options AS lo2
112 ON lo2.option_id = pr.item
113 AND lo2.list_id = 'rule_action'
116 AND date_created > DATE_SUB(NOW(), INTERVAL 1 MONTH)
121 $res = sqlStatement($sql, array($pid));
122 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
129 function getPortalPatientSentNotes($pid = '', $limit = '', $offset = 0, $search = '')
132 $limit = "LIMIT " . escape_limit($offset) . ", " . escape_limit($limit);
144 CONCAT(pd.fname, ' ', pd.lname)
152 LEFT JOIN patient_data AS pd
157 AND p.message_status != 'Done'
162 $res = sqlStatement($sql, array($pid,$pid));
163 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
169 function updatePortalPnoteMessageStatus($id, $message_status)
171 if ($message_status == "Done") {
172 sqlStatement("update pnotes set message_status = ?, activity = '0' where id = ?", array($message_status, $id));
174 sqlStatement("update pnotes set message_status = ?, activity = '1' where id = ?", array($message_status, $id));
177 function getMails($pid, $dotype, $nsrch, $nfsrch)
181 if ($dotype == "inbox") {
182 if ($nsrch && $nfsrch) {
183 $result_notes = getPortalPatientNotes($pid, '', '0', $nsrch);
184 $result_notifications = getPortalPatientNotifications($pid, '', '0', $nfsrch);
185 $result = array_merge((array)$result_notes, (array)$result_notifications);
187 $result_notes = getPortalPatientNotes($pid);
188 $result_notifications = getPortalPatientNotifications($pid);
189 $result = array_merge((array)$result_notes, (array)$result_notifications);
193 } elseif ($dotype == "sent") {
195 $result_sent_notes = getPortalPatientSentNotes($pid, '', '0', $nsrch);
197 $result_sent_notes = getPortalPatientSentNotes($pid);
200 return $result_sent_notes;
207 function getMailDetails($id)
210 $result = getPnoteById($id);
211 if ($result['assigned_to'] == '-patient-' && $result['message_status'] == 'New') {
212 updatePortalPnoteMessageStatus($id, 'Read');
221 function sendMail($pid, $note, string $title = null, $to, $noteid)
224 $title = 'Unassigned';
227 addPortalMailboxPnote($pid, $note, '1', '1', $title, $to, '', 'New', $noteid);
235 function updateStatus($id, $status)
238 updatePortalPnoteMessageStatus($id, $status);