Improved performance and memory management of CDR engine.
[openemr.git] / interface / patient_file / reminder / patient_reminders.php
blob6efd4feec6c460afecd38345448f30cf1939f447
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");
23 //To improve performance and not freeze the session when running this
24 // report, turn off session writing. Note that php session variables
25 // can not be modified after the line below. So, if need to do any php
26 // session work in the future, then will need to remove this line.
27 session_write_close();
29 //Remove time limit, since script can take many minutes
30 set_time_limit(0);
33 <html>
34 <head>
35 <?php html_header_show();?>
36 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
38 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
39 <script type="text/javascript" src="../../../library/dialog.js"></script>
40 <script type="text/javascript" src="../../../library/textformat.js"></script>
41 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
42 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
43 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
44 <script type="text/javascript" src="../../../library/js/common.js"></script>
45 <script type="text/javascript" src="../../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
46 <link rel="stylesheet" type="text/css" href="../../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
47 <script type="text/javascript" src="../../../library/js/jquery.1.3.2.js"></script>
49 <script LANGUAGE="JavaScript">
50 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
51 </script>
53 </head>
55 <?php
56 $patient_id = ($_GET['patient_id']) ? $_GET['patient_id'] : "";
57 $mode = ($_GET['mode']) ? $_GET['mode'] : "simple";
58 $sortby = $_GET['sortby'];
59 $sortorder = $_GET['sortorder'];
60 $begin = $_GET['begin'];
62 // Update the reminders and show debugging data
63 if (empty($patient_id)) {
64 //Update all patients
65 $update_rem_log = update_reminders_batch_method();
67 else {
68 //Only update one patient
69 $update_rem_log = update_reminders('', $patient_id);
72 if ($mode == "simple") {
73 // Collect the rules for the per patient rules selection tab
74 $rules_default = resolve_rules_sql('','0',TRUE);
79 <script language="javascript">
80 // This is for callback by the find-patient popup.
81 function setpatient(pid, lname, fname, dob) {
82 var f = document.forms[0];
83 f.form_patient.value = lname + ', ' + fname;
84 f.patient_id.value = pid;
87 // This invokes the find-patient popup.
88 function sel_patient() {
89 dlgopen('../../main/calendar/find_patient_popup.php', '_blank', 500, 400);
91 </script>
93 <body class='body_top'>
94 <div>
95 <span class='title'><?php echo htmlspecialchars( xl('Patient Reminders'), ENT_NOQUOTES); ?></span>
96 </div>
97 <?php if ($mode == "simple") { ?>
98 <div style='float:left;margin-right:10px'>
99 <?php echo htmlspecialchars( xl('for'), ENT_NOQUOTES);?>&nbsp;
100 <span class="title">
101 <a href="../summary/demographics.php" onclick="top.restoreSession()"><?php echo htmlspecialchars( getPatientName($pid), ENT_NOQUOTES); ?></a>
102 </span>
103 </div>
104 <div>
105 <a href="../summary/demographics.php" <?php if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?> class="css_button" onclick="top.restoreSession()">
106 <span><?php echo htmlspecialchars( xl('Back To Patient'), ENT_NOQUOTES);?></span>
107 </a>
108 </div>
109 <?php } ?>
110 <div>
111 &nbsp;
112 </div>
114 <?php
115 // This is for sorting the records.
116 $sort = array("category, item", "lname, fname", "due_status", "date_created", "hipaa_allowemail", "hipaa_allowsms", "date_sent", "voice_status", "email_status", "sms_status", "mail_status");
117 if($sortby == "") {
118 $sortby = $sort[0];
120 if($sortorder == "") {
121 $sortorder = "asc";
123 for($i = 0; $i < count($sort); $i++) {
124 $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sort[$i]&sortorder=asc\" onclick=\"top.restoreSession()\">" .
125 "<img src=\"../../../images/sortdown.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Up'), ENT_QUOTES)."\"></a>";
127 for($i = 0; $i < count($sort); $i++) {
128 if($sortby == $sort[$i]) {
129 switch($sortorder) {
130 case "asc" : $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=desc\" onclick=\"top.restoreSession()\">" .
131 "<img src=\"../../../images/sortup.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Up'), ENT_QUOTES)."\"></a>";
132 break;
133 case "desc" : $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=asc\" onclick=\"top.restoreSession()\">" .
134 "<img src=\"../../../images/sortdown.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Down'), ENT_QUOTES)."\"></a>";
135 break;
136 } break;
139 // This is for managing page numbering and display beneath the Patient Reminders table.
140 $listnumber = 25;
141 $sqlBindArray = array();
142 if (!empty($patient_id)) {
143 $add_sql = "AND a.pid=? ";
144 array_push($sqlBindArray,$patient_id);
146 $sql = "SELECT a.id, a.due_status, a.category, a.item, a.date_created, a.date_sent, b.fname, b.lname " .
147 "FROM `patient_reminders` as a, `patient_data` as b " .
148 "WHERE a.active='1' AND a.pid=b.pid ".$add_sql;
149 $result = sqlStatement($sql, $sqlBindArray);
150 if(sqlNumRows($result) != 0) {
151 $total = sqlNumRows($result);
153 else {
154 $total = 0;
156 if($begin == "" or $begin == 0) {
157 $begin = 0;
159 $prev = $begin - $listnumber;
160 $next = $begin + $listnumber;
161 $start = $begin + 1;
162 $end = $listnumber + $start - 1;
163 if($end >= $total) {
164 $end = $total;
166 if($end < $start) {
167 $start = 0;
169 if($prev >= 0) {
170 $prevlink = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=$sortorder&begin=$prev\" onclick=\"top.restoreSession()\"><<</a>";
172 else {
173 $prevlink = "<<";
176 if($next < $total) {
177 $nextlink = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=$sortorder&begin=$next\" onclick=\"top.restoreSession()\">>></a>";
179 else {
180 $nextlink = ">>";
185 <br>
186 <br>
188 <?php if ($mode == "simple") { // show the per patient rule setting option ?>
189 <ul class="tabNav">
190 <li class='current'><a href='/play/javascript-tabbed-navigation/'><?php echo htmlspecialchars( xl('Main'), ENT_NOQUOTES); ?></a></li>
191 <li ><a href='/play/javascript-tabbed-navigation/' onclick='top.restoreSession()'><?php echo htmlspecialchars( xl('Rules'), ENT_NOQUOTES); ?></a></li>
192 </ul>
193 <div class="tabContainer">
194 <div class="tab current" style="height:auto;width:97%;">
195 <?php } ?>
197 <div id='report_parameters'>
198 <table>
199 <tr>
200 <td width='410px'>
201 <div style='float:left'>
202 <table class='text'>
203 <tr>
204 <td class='label'>
205 <?php echo " "; ?>
206 </td>
207 </tr>
208 </table>
209 </div>
210 </td>
211 <td align='left' valign='middle' height="100%">
212 <table style='border-left:1px solid; width:100%; height:100%' >
213 <tr>
214 <td>
215 <div style='margin-left:15px'>
216 <?php if ($mode == "admin") { ?>
217 <a href='#' class='css_button' onclick='return ReminderBatch()'>
218 <span><?php echo htmlspecialchars( xl('Send Reminders Batch'), ENT_NOQUOTES); ?></span>
219 </a>
220 <?php } ?>
221 <a href='patient_reminders.php?patient_id=<?php echo $patient_id; ?>&mode=<?php echo $mode; ?>' class='css_button' onclick='top.restoreSession()'>
222 <span><?php echo htmlspecialchars( xl('Refresh'), ENT_NOQUOTES); ?></span>
223 </a>
224 </div>
225 </td>
226 <td align=right class='text'><?php echo $prevlink." ".$end." of ".$total." ".$nextlink; ?></td>
227 </tr>
228 </table>
229 </td>
230 </tr>
231 </table>
232 </div>
234 <div id='report_results'>
235 <table>
236 <thead>
237 <th><?php echo htmlspecialchars( xl('Item'), ENT_NOQUOTES) . " " . $sortlink[0]; ?></th>
238 <th><?php echo htmlspecialchars( xl('Patient'), ENT_NOQUOTES) . " " . $sortlink[1]; ?></th>
239 <th><?php echo htmlspecialchars( xl('Due Status'), ENT_NOQUOTES) . " " . $sortlink[2]; ?></th>
240 <th><?php echo htmlspecialchars( xl('Date Created'), ENT_NOQUOTES) . " " . $sortlink[3]; ?></th>
241 <th><?php echo htmlspecialchars( xl('Email Auth'), ENT_NOQUOTES) . " " . $sortlink[4]; ?></th>
242 <th><?php echo htmlspecialchars( xl('SMS Auth'), ENT_NOQUOTES) . " " . $sortlink[5]; ?></th>
243 <th><?php echo htmlspecialchars( xl('Date Sent'), ENT_NOQUOTES) . " " . $sortlink[6]; ?></th>
244 <th><?php echo htmlspecialchars( xl('Voice Sent'), ENT_NOQUOTES) . " " . $sortlink[7]; ?></th>
245 <th><?php echo htmlspecialchars( xl('Email Sent'), ENT_NOQUOTES) . " " . $sortlink[8]; ?></th>
246 <th><?php echo htmlspecialchars( xl('SMS Sent'), ENT_NOQUOTES) . " " . $sortlink[9]; ?></th>
247 <th><?php echo htmlspecialchars( xl('Mail Sent'), ENT_NOQUOTES) . " " . $sortlink[10]; ?></th>
248 </thead>
249 <tbody>
250 <?php
251 $sql = "SELECT a.id, a.due_status, a.category, a.item, a.date_created, a.date_sent, a.voice_status, " .
252 "a.sms_status, a.email_status, a.mail_status, b.fname, b.lname, b.hipaa_allowemail, b.hipaa_allowsms " .
253 "FROM `patient_reminders` as a, `patient_data` as b " .
254 "WHERE a.active='1' AND a.pid=b.pid " . $add_sql .
255 "ORDER BY " . add_escape_custom($sortby) . " " .
256 add_escape_custom($sortorder) . " " .
257 "LIMIT " . add_escape_custom($begin) . ", " .
258 add_escape_custom($listnumber);
259 $result = sqlStatement($sql,$sqlBindArray);
260 while ($myrow = sqlFetchArray($result)) { ?>
261 <tr>
262 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'),$myrow['category']) . " : " .
263 generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'),$myrow['item']); ?></td>
264 <td><?php echo htmlspecialchars($myrow['lname'].", ".$myrow['fname'], ENT_NOQUOTES); ?></td>
265 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_reminder_due_opt'),$myrow['due_status']); ?></td>
266 <td><?php echo ($myrow['date_created']) ? htmlspecialchars($myrow['date_created'], ENT_NOQUOTES) : " "; ?></td>
267 <td><?php echo ($myrow['hipaa_allowemail']=='YES') ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
268 <td><?php echo ($myrow['hipaa_allowsms']=='YES') ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
269 <td><?php echo ($myrow['date_sent']) ? htmlspecialchars($myrow['date_sent'], ENT_NOQUOTES) : htmlspecialchars( xl("Not Sent Yet") , ENT_NOQUOTES); ?></td>
270 <td><?php echo ($myrow['voice_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
271 <td><?php echo ($myrow['email_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
272 <td><?php echo ($myrow['sms_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
273 <td><?php echo ($myrow['mail_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
274 </tr>
275 <?php } ?>
276 </tbody>
277 </table>
278 </div>
280 <?php if ($mode == "simple") { // show the per patient rule setting option ?>
281 </div>
282 <div class="tab" style="height:auto;width:97%;">
283 <div id='report_results'>
284 <table>
285 <tr>
286 <th rowspan="2"><?php echo htmlspecialchars( xl('Rule'), ENT_NOQUOTES); ?></th>
287 <th colspan="2"><?php echo htmlspecialchars( xl('Patient Reminder'), ENT_NOQUOTES); ?></th>
288 </tr>
289 <tr>
290 <th><?php echo htmlspecialchars( xl('Patient Setting'), ENT_NOQUOTES); ?></th>
291 <th style="left-margin:1em;"><?php echo htmlspecialchars( xl('Practice Default Setting'), ENT_NOQUOTES); ?></th>
292 </tr>
293 <?php foreach ($rules_default as $rule) { ?>
294 <tr>
295 <td style="border-right:1px solid black;"><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $rule['id']); ?></td>
296 <td align="center">
297 <?php
298 $patient_rule = collect_rule($rule['id'],$patient_id);
299 // Set the patient specific setting for gui
300 if (empty($patient_rule)) {
301 $select = "default";
303 else {
304 if ($patient_rule['patient_reminder_flag'] == "1") {
305 $select = "on";
307 else if ($patient_rule['patient_reminder_flag'] == "0"){
308 $select = "off";
310 else { // $patient_rule['patient_reminder_flag'] == NULL
311 $select = "default";
313 } ?>
314 <select class="patient_reminder" name="<?php echo htmlspecialchars( $rule['id'], ENT_NOQUOTES); ?>">
315 <option value="default" <?php if ($select == "default") echo "selected"; ?>><?php echo htmlspecialchars( xl('Default'), ENT_NOQUOTES); ?></option>
316 <option value="on" <?php if ($select == "on") echo "selected"; ?>><?php echo htmlspecialchars( xl('On'), ENT_NOQUOTES); ?></option>
317 <option value="off" <?php if ($select == "off") echo "selected"; ?>><?php echo htmlspecialchars( xl('Off'), ENT_NOQUOTES); ?></option>
318 </select>
319 </td>
320 <td align="center" style="border-right:1px solid black;">
321 <?php if ($rule['patient_reminder_flag'] == "1") {
322 echo htmlspecialchars( xl('On'), ENT_NOQUOTES);
324 else {
325 echo htmlspecialchars( xl('Off'), ENT_NOQUOTES);
326 } ?>
327 </td>
328 </tr>
329 <?php } ?>
330 </table>
331 </div>
332 </div>
333 </div>
334 <?php } ?>
336 <script language="javascript">
338 $(document).ready(function(){
340 tabbify();
342 $(".patient_reminder").change(function() {
343 top.restoreSession();
344 $.post( "../../../library/ajax/rule_setting.php", {
345 rule: this.name,
346 type: 'patient_reminder',
347 setting: this.value,
348 patient_id: '<?php echo htmlspecialchars($patient_id, ENT_QUOTES); ?>'
354 // Show a template popup of patient reminders batch sending tool.
355 function ReminderBatch() {
356 top.restoreSession();
357 dlgopen('../../batchcom/batch_reminders.php', '_blank', 600, 500);
358 return false;
360 </script>
361 </body>
362 </html>