4 * This file contains functions for handling on-site portal notes attached to patient files.
6 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
8 * LICENSE: This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * @author Jerry Padgett <sjpadgett@gmail.com>
23 * @link http://www.open-emr.org
26 require_once("$srcdir/pnotes.inc");
28 function addPortalMailboxPnote(
33 $title = 'Unassigned',
36 $message_status = "New",
40 if (empty($datetime)) {
41 $datetime = date('Y-m-d H:i:s');
44 // make inactive if set as Done
45 if ($message_status == "Done") {
49 $user = $_SESSION['authUser']?$_SESSION['authUser']:$pid;
50 $pname = $_SESSION['ptName']?$_SESSION['ptName']:$user;
52 /* $body = " ($pname";
53 if ($assigned_to) $body .= " to $assigned_to";
54 $body = $body . ') ' . $newtext; */
59 "INSERT INTO pnotes (date, body, pid, user, groupname, " .
60 "authorized, activity, title, assigned_to, message_status, portal_relation) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
61 array($datetime, $body, $pid, $user, 'Default', $authorized, $activity, $title, $assigned_to, $message_status,$master_note)
65 function getPortalPatientNotes($pid = '', $limit = '', $offset = 0, $search = '')
68 $limit = "LIMIT ".escape_limit($offset).", ".escape_limit($limit);
80 CONCAT(pd.fname, ' ', pd.lname)
87 LEFT JOIN patient_data AS pd
89 WHERE assigned_to = '-patient-'
96 $res = sqlStatement($sql, array($pid));
97 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
104 function getPortalPatientNotifications($pid = '', $limit = '', $offset = 0, $search = '')
107 $limit = "LIMIT ".escape_limit($offset).", ".escape_limit($limit);
113 date_created AS `date`,
114 'Patient Reminders' AS `user`,
116 CONCAT(lo.title, ':', lo2.title) AS body,
117 '' as message_status,
118 'Notification' as `type`
120 patient_reminders AS pr
121 LEFT JOIN list_options AS lo
122 ON lo.option_id = pr.category
123 AND lo.list_id = 'rule_action_category'
124 LEFT JOIN list_options AS lo2
125 ON lo2.option_id = pr.item
126 AND lo2.list_id = 'rule_action'
129 AND date_created > DATE_SUB(NOW(), INTERVAL 1 MONTH)
134 $res = sqlStatement($sql, array($pid));
135 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
142 function getPortalPatientSentNotes($pid = '', $limit = '', $offset = 0, $search = '')
145 $limit = "LIMIT ".escape_limit($offset).", ".escape_limit($limit);
157 CONCAT(pd.fname, ' ', pd.lname)
165 LEFT JOIN patient_data AS pd
170 AND p.message_status != 'Done'
175 $res = sqlStatement($sql, array($pid,$pid));
176 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
182 function updatePortalPnoteMessageStatus($id, $message_status)
184 if ($message_status == "Done") {
185 sqlStatement("update pnotes set message_status = ?, activity = '0' where id = ?", array($message_status, $id));
187 sqlStatement("update pnotes set message_status = ?, activity = '1' where id = ?", array($message_status, $id));
190 function getMails($pid, $dotype, $nsrch, $nfsrch)
194 if ($dotype == "inbox") {
195 if ($nsrch && $nfsrch) {
196 $result_notes = getPortalPatientNotes($pid, '', '0', $nsrch);
197 $result_notifications = getPortalPatientNotifications($pid, '', '0', $nfsrch);
198 $result = array_merge((array)$result_notes, (array)$result_notifications);
200 $result_notes = getPortalPatientNotes($pid);
201 $result_notifications = getPortalPatientNotifications($pid);
202 $result = array_merge((array)$result_notes, (array)$result_notifications);
206 } elseif ($dotype == "sent") {
208 $result_sent_notes = getPortalPatientSentNotes($pid, '', '0', $nsrch);
210 $result_sent_notes = getPortalPatientSentNotes($pid);
213 return $result_sent_notes;
220 function getMailDetails($id)
223 $result = getPnoteById($id);
224 if ($result['assigned_to'] == '-patient-' && $result['message_status'] == 'New') {
225 updatePortalPnoteMessageStatus($id, 'Read');
234 function sendMail($pid, $note, $title = 'Unassigned', $to, $noteid)
237 addPortalMailboxPnote($pid, $note, '1', '1', $title, $to, '', 'New', $noteid);
245 function updateStatus($id, $status)
248 updatePortalPnoteMessageStatus($id, $status);