CDR Module: Fixed email reminders.
[openemr.git] / interface / patient_file / reminder / patient_reminders.php
blob4e0ff49316f310fa7ad4577a7fabe6878027a417
1 <?php
2 // Copyright (C) 2011 by following authors:
3 // -Brady Miller <brady@sparmy.com>
4 // -Ensofttek, LLC
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 //SANITIZE ALL ESCAPES
12 $sanitize_all_escapes=true;
14 //STOP FAKE REGISTER GLOBALS
15 $fake_register_globals=false;
17 require_once("../../globals.php");
18 require_once("$srcdir/options.inc.php");
19 require_once("$srcdir/formdata.inc.php");
20 require_once("$srcdir/reminders.php");
21 require_once("$srcdir/clinical_rules.php");
24 <html>
25 <head>
26 <?php html_header_show();?>
27 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
29 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
30 <script type="text/javascript" src="../../../library/dialog.js"></script>
31 <script type="text/javascript" src="../../../library/textformat.js"></script>
32 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
33 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
34 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
35 <script type="text/javascript" src="../../../library/js/common.js"></script>
36 <script type="text/javascript" src="../../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
37 <link rel="stylesheet" type="text/css" href="../../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
38 <script type="text/javascript" src="../../../library/js/jquery.1.3.2.js"></script>
40 <script LANGUAGE="JavaScript">
41 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
42 </script>
44 </head>
46 <?php
47 $patient_id = ($_GET['patient_id']) ? $_GET['patient_id'] : "";
48 $mode = ($_GET['mode']) ? $_GET['mode'] : "simple";
49 $sortby = $_GET['sortby'];
50 $sortorder = $_GET['sortorder'];
51 $begin = $_GET['begin'];
53 // Update the reminders and show debugging data
54 $update_rem_log = update_reminders('', $patient_id);
56 if ($mode == "simple") {
57 // Collect the rules for the per patient rules selection tab
58 $rules_default = resolve_rules_sql('','0',TRUE);
63 <script language="javascript">
64 // This is for callback by the find-patient popup.
65 function setpatient(pid, lname, fname, dob) {
66 var f = document.forms[0];
67 f.form_patient.value = lname + ', ' + fname;
68 f.patient_id.value = pid;
71 // This invokes the find-patient popup.
72 function sel_patient() {
73 dlgopen('../../main/calendar/find_patient_popup.php', '_blank', 500, 400);
75 </script>
77 <body class='body_top'>
78 <div>
79 <span class='title'><?php echo htmlspecialchars( xl('Patient Reminders'), ENT_NOQUOTES); ?></span>
80 </div>
81 <?php if ($mode == "simple") { ?>
82 <div style='float:left;margin-right:10px'>
83 <?php echo htmlspecialchars( xl('for'), ENT_NOQUOTES);?>&nbsp;
84 <span class="title">
85 <a href="../summary/demographics.php" onclick="top.restoreSession()"><?php echo htmlspecialchars( getPatientName($pid), ENT_NOQUOTES); ?></a>
86 </span>
87 </div>
88 <div>
89 <a href="../summary/demographics.php" <?php if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?> class="css_button" onclick="top.restoreSession()">
90 <span><?php echo htmlspecialchars( xl('Back To Patient'), ENT_NOQUOTES);?></span>
91 </a>
92 </div>
93 <?php } ?>
94 <div>
95 &nbsp;
96 </div>
98 <?php
99 // This is for sorting the records.
100 $sort = array("category, item", "lname, fname", "due_status", "date_created", "hipaa_allowemail", "hipaa_allowsms", "date_sent", "voice_status", "email_status", "sms_status", "mail_status");
101 if($sortby == "") {
102 $sortby = $sort[0];
104 if($sortorder == "") {
105 $sortorder = "asc";
107 for($i = 0; $i < count($sort); $i++) {
108 $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sort[$i]&sortorder=asc\" onclick=\"top.restoreSession()\">" .
109 "<img src=\"../../../images/sortdown.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Up'), ENT_QUOTES)."\"></a>";
111 for($i = 0; $i < count($sort); $i++) {
112 if($sortby == $sort[$i]) {
113 switch($sortorder) {
114 case "asc" : $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=desc\" onclick=\"top.restoreSession()\">" .
115 "<img src=\"../../../images/sortup.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Up'), ENT_QUOTES)."\"></a>";
116 break;
117 case "desc" : $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=asc\" onclick=\"top.restoreSession()\">" .
118 "<img src=\"../../../images/sortdown.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Down'), ENT_QUOTES)."\"></a>";
119 break;
120 } break;
123 // This is for managing page numbering and display beneath the Patient Reminders table.
124 $listnumber = 25;
125 $sqlBindArray = array();
126 if (!empty($patient_id)) {
127 $add_sql = "AND a.pid=? ";
128 array_push($sqlBindArray,$patient_id);
130 $sql = "SELECT a.id, a.due_status, a.category, a.item, a.date_created, a.date_sent, b.fname, b.lname " .
131 "FROM `patient_reminders` as a, `patient_data` as b " .
132 "WHERE a.active='1' AND a.pid=b.pid ".$add_sql;
133 $result = sqlStatement($sql, $sqlBindArray);
134 if(sqlNumRows($result) != 0) {
135 $total = sqlNumRows($result);
137 else {
138 $total = 0;
140 if($begin == "" or $begin == 0) {
141 $begin = 0;
143 $prev = $begin - $listnumber;
144 $next = $begin + $listnumber;
145 $start = $begin + 1;
146 $end = $listnumber + $start - 1;
147 if($end >= $total) {
148 $end = $total;
150 if($end < $start) {
151 $start = 0;
153 if($prev >= 0) {
154 $prevlink = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=$sortorder&begin=$prev\" onclick=\"top.restoreSession()\"><<</a>";
156 else {
157 $prevlink = "<<";
160 if($next < $total) {
161 $nextlink = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=$sortorder&begin=$next\" onclick=\"top.restoreSession()\">>></a>";
163 else {
164 $nextlink = ">>";
169 <br>
170 <br>
172 <?php if ($mode == "simple") { // show the per patient rule setting option ?>
173 <ul class="tabNav">
174 <li class='current'><a href='/play/javascript-tabbed-navigation/'><?php echo htmlspecialchars( xl('Main'), ENT_NOQUOTES); ?></a></li>
175 <li ><a href='/play/javascript-tabbed-navigation/'><?php echo htmlspecialchars( xl('Rules'), ENT_NOQUOTES); ?></a></li>
176 </ul>
177 <div class="tabContainer">
178 <div class="tab current" style="height:auto;width:97%;">
179 <?php } ?>
181 <div id='report_parameters'>
182 <table>
183 <tr>
184 <td width='410px'>
185 <div style='float:left'>
186 <table class='text'>
187 <tr>
188 <td class='label'>
189 <?php echo " "; ?>
190 </td>
191 </tr>
192 </table>
193 </div>
194 </td>
195 <td align='left' valign='middle' height="100%">
196 <table style='border-left:1px solid; width:100%; height:100%' >
197 <tr>
198 <td>
199 <div style='margin-left:15px'>
200 <?php if ($mode == "admin") { ?>
201 <a href='#' class='css_button' onclick='return ReminderBatch()'>
202 <span><?php echo htmlspecialchars( xl('Send Reminders Batch'), ENT_NOQUOTES); ?></span>
203 </a>
204 <?php } ?>
205 <a href='patient_reminders.php?patient_id=<?php echo $patient_id; ?>&mode=<?php echo $mode; ?>' class='css_button' onclick='top.restoreSession()'>
206 <span><?php echo htmlspecialchars( xl('Refresh'), ENT_NOQUOTES); ?></span>
207 </a>
208 </div>
209 </td>
210 <td align=right class='text'><?php echo $prevlink." ".$end." of ".$total." ".$nextlink; ?></td>
211 </tr>
212 </table>
213 </td>
214 </tr>
215 </table>
216 </div>
218 <div id='report_results'>
219 <table>
220 <thead>
221 <th><?php echo htmlspecialchars( xl('Item'), ENT_NOQUOTES) . " " . $sortlink[0]; ?></th>
222 <th><?php echo htmlspecialchars( xl('Patient'), ENT_NOQUOTES) . " " . $sortlink[1]; ?></th>
223 <th><?php echo htmlspecialchars( xl('Due Status'), ENT_NOQUOTES) . " " . $sortlink[2]; ?></th>
224 <th><?php echo htmlspecialchars( xl('Date Created'), ENT_NOQUOTES) . " " . $sortlink[3]; ?></th>
225 <th><?php echo htmlspecialchars( xl('Email Auth'), ENT_NOQUOTES) . " " . $sortlink[4]; ?></th>
226 <th><?php echo htmlspecialchars( xl('SMS Auth'), ENT_NOQUOTES) . " " . $sortlink[5]; ?></th>
227 <th><?php echo htmlspecialchars( xl('Date Sent'), ENT_NOQUOTES) . " " . $sortlink[6]; ?></th>
228 <th><?php echo htmlspecialchars( xl('Voice Sent'), ENT_NOQUOTES) . " " . $sortlink[7]; ?></th>
229 <th><?php echo htmlspecialchars( xl('Email Sent'), ENT_NOQUOTES) . " " . $sortlink[8]; ?></th>
230 <th><?php echo htmlspecialchars( xl('SMS Sent'), ENT_NOQUOTES) . " " . $sortlink[9]; ?></th>
231 <th><?php echo htmlspecialchars( xl('Mail Sent'), ENT_NOQUOTES) . " " . $sortlink[10]; ?></th>
232 </thead>
233 <tbody>
234 <?php
235 $sql = "SELECT a.id, a.due_status, a.category, a.item, a.date_created, a.date_sent, a.voice_status, " .
236 "a.sms_status, a.email_status, a.mail_status, b.fname, b.lname, b.hipaa_allowemail, b.hipaa_allowsms " .
237 "FROM `patient_reminders` as a, `patient_data` as b " .
238 "WHERE a.active='1' AND a.pid=b.pid " . $add_sql .
239 "ORDER BY " . add_escape_custom($sortby) . " " .
240 add_escape_custom($sortorder) . " " .
241 "LIMIT " . add_escape_custom($begin) . ", " .
242 add_escape_custom($listnumber);
243 $result = sqlStatement($sql,$sqlBindArray);
244 while ($myrow = sqlFetchArray($result)) { ?>
245 <tr>
246 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'),$myrow['category']) . " : " .
247 generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'),$myrow['item']); ?></td>
248 <td><?php echo htmlspecialchars($myrow['lname'].", ".$myrow['fname'], ENT_NOQUOTES); ?></td>
249 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_reminder_due_opt'),$myrow['due_status']); ?></td>
250 <td><?php echo ($myrow['date_created']) ? htmlspecialchars($myrow['date_created'], ENT_NOQUOTES) : " "; ?></td>
251 <td><?php echo ($myrow['hipaa_allowemail']=='YES') ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
252 <td><?php echo ($myrow['hipaa_allowsms']=='YES') ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
253 <td><?php echo ($myrow['date_sent']) ? htmlspecialchars($myrow['date_sent'], ENT_NOQUOTES) : htmlspecialchars( xl("Not Sent Yet") , ENT_NOQUOTES); ?></td>
254 <td><?php echo ($myrow['voice_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
255 <td><?php echo ($myrow['email_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
256 <td><?php echo ($myrow['sms_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
257 <td><?php echo ($myrow['mail_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
258 </tr>
259 <?php } ?>
260 </tbody>
261 </table>
262 </div>
264 <?php if ($mode == "simple") { // show the per patient rule setting option ?>
265 </div>
266 <div class="tab" style="height:auto;width:97%;">
267 <div id='report_results'>
268 <table>
269 <tr>
270 <th rowspan="2"><?php echo htmlspecialchars( xl('Rule'), ENT_NOQUOTES); ?></th>
271 <th colspan="2"><?php echo htmlspecialchars( xl('Patient Reminder'), ENT_NOQUOTES); ?></th>
272 </tr>
273 <tr>
274 <th><?php echo htmlspecialchars( xl('Patient Setting'), ENT_NOQUOTES); ?></th>
275 <th style="left-margin:1em;"><?php echo htmlspecialchars( xl('Practice Default Setting'), ENT_NOQUOTES); ?></th>
276 </tr>
277 <?php foreach ($rules_default as $rule) { ?>
278 <tr>
279 <td style="border-right:1px solid black;"><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $rule['id']); ?></td>
280 <td align="center">
281 <?php
282 $patient_rule = collect_rule($rule['id'],$patient_id);
283 // Set the patient specific setting for gui
284 if (empty($patient_rule)) {
285 $select = "default";
287 else {
288 if ($patient_rule['patient_reminder_flag'] == "1") {
289 $select = "on";
291 else if ($patient_rule['patient_reminder_flag'] == "0"){
292 $select = "off";
294 else { // $patient_rule['patient_reminder_flag'] == NULL
295 $select = "default";
297 } ?>
298 <select class="patient_reminder" name="<?php echo htmlspecialchars( $rule['id'], ENT_NOQUOTES); ?>">
299 <option value="default" <?php if ($select == "default") echo "selected"; ?>><?php echo htmlspecialchars( xl('Default'), ENT_NOQUOTES); ?></option>
300 <option value="on" <?php if ($select == "on") echo "selected"; ?>><?php echo htmlspecialchars( xl('On'), ENT_NOQUOTES); ?></option>
301 <option value="off" <?php if ($select == "off") echo "selected"; ?>><?php echo htmlspecialchars( xl('Off'), ENT_NOQUOTES); ?></option>
302 </select>
303 </td>
304 <td align="center" style="border-right:1px solid black;">
305 <?php if ($rule['patient_reminder_flag'] == "1") {
306 echo htmlspecialchars( xl('On'), ENT_NOQUOTES);
308 else {
309 echo htmlspecialchars( xl('Off'), ENT_NOQUOTES);
310 } ?>
311 </td>
312 </tr>
313 <?php } ?>
314 </table>
315 </div>
316 </div>
317 </div>
318 <?php } ?>
320 <script language="javascript">
322 $(document).ready(function(){
324 tabbify();
326 $(".patient_reminder").change(function() {
327 top.restoreSession();
328 $.post( "../../../library/ajax/rule_setting.php", {
329 rule: this.name,
330 type: 'patient_reminder',
331 setting: this.value,
332 patient_id: '<?php echo htmlspecialchars($patient_id, ENT_QUOTES); ?>'
338 // Show a template popup of patient reminders batch sending tool.
339 function ReminderBatch() {
340 top.restoreSession();
341 dlgopen('../../batchcom/batch_reminders.php', '_blank', 600, 500);
342 return false;
344 </script>
345 </body>
346 </html>