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($pid, $newtext, $authorized = '0', $activity = '1',
29 $title='Unassigned', $assigned_to = '', $datetime = '', $message_status = "New",$master_note = '0')
31 if (empty($datetime)) $datetime = date('Y-m-d H:i:s');
33 // make inactive if set as Done
34 if ($message_status == "Done") $activity = 0;
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; */
45 return sqlInsert("INSERT INTO pnotes (date, body, pid, user, groupname, " .
46 "authorized, activity, title, assigned_to, message_status, portal_relation) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
47 array($datetime, $body, $pid, $user, 'Default', $authorized, $activity, $title, $assigned_to, $message_status,$master_note) );
50 function getPortalPatientNotes($pid = '', $limit = '', $offset = 0, $search = '')
53 $limit = "LIMIT ".escape_limit($offset).", ".escape_limit($limit);
64 CONCAT(pd.fname, ' ', pd.lname)
71 LEFT JOIN patient_data AS pd
73 WHERE assigned_to = '-patient-'
80 $res = sqlStatement($sql, array($pid));
81 for($iter = 0;$row = sqlFetchArray($res);$iter++){
87 function getPortalPatientNotifications($pid = '', $limit = '', $offset = 0, $search = '')
90 $limit = "LIMIT ".escape_limit($offset).", ".escape_limit($limit);
95 date_created AS `date`,
96 'Patient Reminders' AS `user`,
98 CONCAT(lo.title, ':', lo2.title) AS body,
100 'Notification' as `type`
102 patient_reminders AS pr
103 LEFT JOIN list_options AS lo
104 ON lo.option_id = pr.category
105 AND lo.list_id = 'rule_action_category'
106 LEFT JOIN list_options AS lo2
107 ON lo2.option_id = pr.item
108 AND lo2.list_id = 'rule_action'
111 AND date_created > DATE_SUB(NOW(), INTERVAL 1 MONTH)
116 $res = sqlStatement($sql, array($pid));
117 for($iter = 0;$row = sqlFetchArray($res);$iter++){
123 function getPortalPatientSentNotes($pid = '', $limit = '', $offset = 0, $search = '')
126 $limit = "LIMIT ".escape_limit($offset).", ".escape_limit($limit);
137 CONCAT(pd.fname, ' ', pd.lname)
145 LEFT JOIN patient_data AS pd
150 AND p.message_status != 'Done'
155 $res = sqlStatement($sql, array($pid,$pid));
156 for($iter = 0;$row = sqlFetchArray($res);$iter++){
161 function updatePortalPnoteMessageStatus($id, $message_status)
163 if ($message_status == "Done") {
164 sqlStatement("update pnotes set message_status = ?, activity = '0' where id = ?", array($message_status, $id) );
167 sqlStatement("update pnotes set message_status = ?, activity = '1' where id = ?", array($message_status, $id) );
170 function getMails($pid,$dotype,$nsrch,$nfsrch){
173 if($dotype == "inbox"){
174 if($nsrch && $nfsrch){
175 $result_notes = getPortalPatientNotes($pid,'','0',$nsrch);
176 $result_notifications = getPortalPatientNotifications($pid,'','0',$nfsrch);
177 $result = array_merge((array)$result_notes,(array)$result_notifications);
179 $result_notes = getPortalPatientNotes($pid);
180 $result_notifications = getPortalPatientNotifications($pid);
181 $result = array_merge((array)$result_notes,(array)$result_notifications);
184 }elseif($dotype == "sent"){
186 $result_sent_notes = getPortalPatientSentNotes($pid,'','0',$nsrch);
188 $result_sent_notes = getPortalPatientSentNotes($pid);
190 return $result_sent_notes;
197 function getMailDetails($id){
199 $result = getPnoteById($id);
200 if($result['assigned_to'] == '-patient-' && $result['message_status'] == 'New'){
201 updatePortalPnoteMessageStatus($id,'Read');
209 function sendMail($pid,$note,$title='Unassigned',$to, $noteid){
211 addPortalMailboxPnote($pid,$note,'1','1',$title,$to,'','New',$noteid);
219 function updateStatus($id,$status){
221 updatePortalPnoteMessageStatus($id,$status);