Improved/optimized CDR engine reports (and patient reminders) and added a
[openemr.git] / interface / patient_file / reminder / patient_reminders.php
blob2eadc150b3a9bd4a39baa080964e10721f8178ae
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");
22 require_once "$srcdir/report_database.inc";
25 <html>
26 <head>
27 <?php html_header_show();?>
28 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
30 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
31 <script type="text/javascript" src="../../../library/dialog.js"></script>
32 <script type="text/javascript" src="../../../library/textformat.js"></script>
33 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
34 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
35 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
36 <script type="text/javascript" src="../../../library/js/common.js"></script>
37 <script type="text/javascript" src="../../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
38 <link rel="stylesheet" type="text/css" href="../../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
39 <script type="text/javascript" src="../../../library/js/jquery.1.3.2.js"></script>
41 <script LANGUAGE="JavaScript">
42 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
43 </script>
45 </head>
47 <?php
48 $patient_id = ($_GET['patient_id']) ? $_GET['patient_id'] : "";
49 $mode = ($_GET['mode']) ? $_GET['mode'] : "simple";
50 $sortby = $_GET['sortby'];
51 $sortorder = $_GET['sortorder'];
52 $begin = $_GET['begin'];
54 if (!empty($patient_id)) {
55 //Only update one patient
56 $update_rem_log = update_reminders('', $patient_id);
59 if ($mode == "simple") {
60 // Collect the rules for the per patient rules selection tab
61 $rules_default = resolve_rules_sql('','0',TRUE);
66 <script language="javascript">
67 // This is for callback by the find-patient popup.
68 function setpatient(pid, lname, fname, dob) {
69 var f = document.forms[0];
70 f.form_patient.value = lname + ', ' + fname;
71 f.patient_id.value = pid;
74 // This invokes the find-patient popup.
75 function sel_patient() {
76 dlgopen('../../main/calendar/find_patient_popup.php', '_blank', 500, 400);
78 </script>
80 <body class='body_top'>
81 <div>
82 <span class='title'><?php echo htmlspecialchars( xl('Patient Reminders'), ENT_NOQUOTES); ?></span>
83 </div>
84 <?php if ($mode == "simple") { ?>
85 <div style='float:left;margin-right:10px'>
86 <?php echo htmlspecialchars( xl('for'), ENT_NOQUOTES);?>&nbsp;
87 <span class="title">
88 <a href="../summary/demographics.php" onclick="top.restoreSession()"><?php echo htmlspecialchars( getPatientName($pid), ENT_NOQUOTES); ?></a>
89 </span>
90 </div>
91 <div>
92 <a href="../summary/demographics.php" <?php if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?> class="css_button" onclick="top.restoreSession()">
93 <span><?php echo htmlspecialchars( xl('Back To Patient'), ENT_NOQUOTES);?></span>
94 </a>
95 </div>
96 <?php } ?>
97 <div>
98 &nbsp;
99 </div>
101 <?php
102 // This is for sorting the records.
103 $sort = array("category, item", "lname, fname", "due_status", "date_created", "hipaa_allowemail", "hipaa_allowsms", "date_sent", "voice_status", "email_status", "sms_status", "mail_status");
104 if($sortby == "") {
105 $sortby = $sort[0];
107 if($sortorder == "") {
108 $sortorder = "asc";
110 for($i = 0; $i < count($sort); $i++) {
111 $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sort[$i]&sortorder=asc\" onclick=\"top.restoreSession()\">" .
112 "<img src=\"../../../images/sortdown.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Up'), ENT_QUOTES)."\"></a>";
114 for($i = 0; $i < count($sort); $i++) {
115 if($sortby == $sort[$i]) {
116 switch($sortorder) {
117 case "asc" : $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=desc\" onclick=\"top.restoreSession()\">" .
118 "<img src=\"../../../images/sortup.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Up'), ENT_QUOTES)."\"></a>";
119 break;
120 case "desc" : $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=asc\" onclick=\"top.restoreSession()\">" .
121 "<img src=\"../../../images/sortdown.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Down'), ENT_QUOTES)."\"></a>";
122 break;
123 } break;
126 // This is for managing page numbering and display beneath the Patient Reminders table.
127 $listnumber = 25;
128 $sqlBindArray = array();
129 if (!empty($patient_id)) {
130 $add_sql = "AND a.pid=? ";
131 array_push($sqlBindArray,$patient_id);
133 $sql = "SELECT a.id, a.due_status, a.category, a.item, a.date_created, a.date_sent, b.fname, b.lname " .
134 "FROM `patient_reminders` as a, `patient_data` as b " .
135 "WHERE a.active='1' AND a.pid=b.pid ".$add_sql;
136 $result = sqlStatement($sql, $sqlBindArray);
137 if(sqlNumRows($result) != 0) {
138 $total = sqlNumRows($result);
140 else {
141 $total = 0;
143 if($begin == "" or $begin == 0) {
144 $begin = 0;
146 $prev = $begin - $listnumber;
147 $next = $begin + $listnumber;
148 $start = $begin + 1;
149 $end = $listnumber + $start - 1;
150 if($end >= $total) {
151 $end = $total;
153 if($end < $start) {
154 $start = 0;
156 if($prev >= 0) {
157 $prevlink = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=$sortorder&begin=$prev\" onclick=\"top.restoreSession()\"><<</a>";
159 else {
160 $prevlink = "<<";
163 if($next < $total) {
164 $nextlink = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=$sortorder&begin=$next\" onclick=\"top.restoreSession()\">>></a>";
166 else {
167 $nextlink = ">>";
172 <br>
173 <br>
175 <?php if ($mode == "simple") { // show the per patient rule setting option ?>
176 <ul class="tabNav">
177 <li class='current'><a href='/play/javascript-tabbed-navigation/'><?php echo htmlspecialchars( xl('Main'), ENT_NOQUOTES); ?></a></li>
178 <li ><a href='/play/javascript-tabbed-navigation/' onclick='top.restoreSession()'><?php echo htmlspecialchars( xl('Rules'), ENT_NOQUOTES); ?></a></li>
179 </ul>
180 <div class="tabContainer">
181 <div class="tab current" style="height:auto;width:97%;">
182 <?php } ?>
184 <form method='post' name='theform' id='theform'>
186 <div id='report_parameters'>
187 <table>
188 <tr>
189 <td width='410px'>
190 <div style='float:left'>
191 <table class='text'>
192 <tr>
193 <td class='label'>
194 <?php echo " "; ?>
195 </td>
196 </tr>
197 </table>
198 </div>
199 </td>
200 <td align='left' valign='middle' height="100%">
201 <table style='border-left:1px solid; width:100%; height:100%' >
202 <tr>
203 <td>
204 <div style='margin-left:15px'>
205 <?php if ($mode == "admin") { ?>
206 <a id='process_button' href='#' class='css_button' onclick='return ReminderBatch("process")'>
207 <span><?php echo htmlspecialchars( xl('Process Reminders'), ENT_NOQUOTES); ?></span>
208 </a>
209 <a id='process_send_button' href='#' class='css_button' onclick='return ReminderBatch("process_send")'>
210 <span><?php echo htmlspecialchars( xl('Process and Send Reminders'), ENT_NOQUOTES); ?></span>
211 </a>
212 <span id='status_span'></span>
213 <div id='processing' style='margin:10px;display:none;'><img src='../../pic/ajax-loader.gif'/></div>
214 <?php } else { ?>
215 <a href='patient_reminders.php?patient_id=<?php echo $patient_id; ?>&mode=<?php echo $mode; ?>' class='css_button' onclick='top.restoreSession()'>
216 <span><?php echo htmlspecialchars( xl('Refresh'), ENT_NOQUOTES); ?></span>
217 </a>
218 <?php } ?>
219 </div>
220 </td>
221 <td align=right class='text'><?php echo $prevlink." ".$end." of ".$total." ".$nextlink; ?></td>
222 </tr>
223 </table>
224 </td>
225 </tr>
226 </table>
227 </div>
229 <div id='report_results'>
230 <table>
231 <thead>
232 <th><?php echo htmlspecialchars( xl('Item'), ENT_NOQUOTES) . " " . $sortlink[0]; ?></th>
233 <th><?php echo htmlspecialchars( xl('Patient'), ENT_NOQUOTES) . " " . $sortlink[1]; ?></th>
234 <th><?php echo htmlspecialchars( xl('Due Status'), ENT_NOQUOTES) . " " . $sortlink[2]; ?></th>
235 <th><?php echo htmlspecialchars( xl('Date Created'), ENT_NOQUOTES) . " " . $sortlink[3]; ?></th>
236 <th><?php echo htmlspecialchars( xl('Email Auth'), ENT_NOQUOTES) . " " . $sortlink[4]; ?></th>
237 <th><?php echo htmlspecialchars( xl('SMS Auth'), ENT_NOQUOTES) . " " . $sortlink[5]; ?></th>
238 <th><?php echo htmlspecialchars( xl('Date Sent'), ENT_NOQUOTES) . " " . $sortlink[6]; ?></th>
239 <th><?php echo htmlspecialchars( xl('Voice Sent'), ENT_NOQUOTES) . " " . $sortlink[7]; ?></th>
240 <th><?php echo htmlspecialchars( xl('Email Sent'), ENT_NOQUOTES) . " " . $sortlink[8]; ?></th>
241 <th><?php echo htmlspecialchars( xl('SMS Sent'), ENT_NOQUOTES) . " " . $sortlink[9]; ?></th>
242 <th><?php echo htmlspecialchars( xl('Mail Sent'), ENT_NOQUOTES) . " " . $sortlink[10]; ?></th>
243 </thead>
244 <tbody>
245 <?php
246 $sql = "SELECT a.id, a.due_status, a.category, a.item, a.date_created, a.date_sent, a.voice_status, " .
247 "a.sms_status, a.email_status, a.mail_status, b.fname, b.lname, b.hipaa_allowemail, b.hipaa_allowsms " .
248 "FROM `patient_reminders` as a, `patient_data` as b " .
249 "WHERE a.active='1' AND a.pid=b.pid " . $add_sql .
250 "ORDER BY " . add_escape_custom($sortby) . " " .
251 add_escape_custom($sortorder) . " " .
252 "LIMIT " . add_escape_custom($begin) . ", " .
253 add_escape_custom($listnumber);
254 $result = sqlStatement($sql,$sqlBindArray);
255 while ($myrow = sqlFetchArray($result)) { ?>
256 <tr>
257 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'),$myrow['category']) . " : " .
258 generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'),$myrow['item']); ?></td>
259 <td><?php echo htmlspecialchars($myrow['lname'].", ".$myrow['fname'], ENT_NOQUOTES); ?></td>
260 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_reminder_due_opt'),$myrow['due_status']); ?></td>
261 <td><?php echo ($myrow['date_created']) ? htmlspecialchars($myrow['date_created'], ENT_NOQUOTES) : " "; ?></td>
262 <td><?php echo ($myrow['hipaa_allowemail']=='YES') ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
263 <td><?php echo ($myrow['hipaa_allowsms']=='YES') ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
264 <td><?php echo ($myrow['date_sent']) ? htmlspecialchars($myrow['date_sent'], ENT_NOQUOTES) : htmlspecialchars( xl("Not Sent Yet") , ENT_NOQUOTES); ?></td>
265 <td><?php echo ($myrow['voice_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
266 <td><?php echo ($myrow['email_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
267 <td><?php echo ($myrow['sms_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
268 <td><?php echo ($myrow['mail_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
269 </tr>
270 <?php } ?>
271 </tbody>
272 </table>
273 </div>
275 <?php if ($mode == "simple") { // show the per patient rule setting option ?>
276 </div>
277 <div class="tab" style="height:auto;width:97%;">
278 <div id='report_results'>
279 <table>
280 <tr>
281 <th rowspan="2"><?php echo htmlspecialchars( xl('Rule'), ENT_NOQUOTES); ?></th>
282 <th colspan="2"><?php echo htmlspecialchars( xl('Patient Reminder'), ENT_NOQUOTES); ?></th>
283 </tr>
284 <tr>
285 <th><?php echo htmlspecialchars( xl('Patient Setting'), ENT_NOQUOTES); ?></th>
286 <th style="left-margin:1em;"><?php echo htmlspecialchars( xl('Practice Default Setting'), ENT_NOQUOTES); ?></th>
287 </tr>
288 <?php foreach ($rules_default as $rule) { ?>
289 <tr>
290 <td style="border-right:1px solid black;"><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $rule['id']); ?></td>
291 <td align="center">
292 <?php
293 $patient_rule = collect_rule($rule['id'],$patient_id);
294 // Set the patient specific setting for gui
295 if (empty($patient_rule)) {
296 $select = "default";
298 else {
299 if ($patient_rule['patient_reminder_flag'] == "1") {
300 $select = "on";
302 else if ($patient_rule['patient_reminder_flag'] == "0"){
303 $select = "off";
305 else { // $patient_rule['patient_reminder_flag'] == NULL
306 $select = "default";
308 } ?>
309 <select class="patient_reminder" name="<?php echo htmlspecialchars( $rule['id'], ENT_NOQUOTES); ?>">
310 <option value="default" <?php if ($select == "default") echo "selected"; ?>><?php echo htmlspecialchars( xl('Default'), ENT_NOQUOTES); ?></option>
311 <option value="on" <?php if ($select == "on") echo "selected"; ?>><?php echo htmlspecialchars( xl('On'), ENT_NOQUOTES); ?></option>
312 <option value="off" <?php if ($select == "off") echo "selected"; ?>><?php echo htmlspecialchars( xl('Off'), ENT_NOQUOTES); ?></option>
313 </select>
314 </td>
315 <td align="center" style="border-right:1px solid black;">
316 <?php if ($rule['patient_reminder_flag'] == "1") {
317 echo htmlspecialchars( xl('On'), ENT_NOQUOTES);
319 else {
320 echo htmlspecialchars( xl('Off'), ENT_NOQUOTES);
321 } ?>
322 </td>
323 </tr>
324 <?php } ?>
325 </table>
326 </div>
327 </div>
328 </div>
329 <?php } ?>
331 <input type='hidden' name='form_new_report_id' id='form_new_report_id' value=''/>
332 </form>
334 <script language="javascript">
336 $(document).ready(function(){
338 tabbify();
340 $(".patient_reminder").change(function() {
341 top.restoreSession();
342 $.post( "../../../library/ajax/rule_setting.php", {
343 rule: this.name,
344 type: 'patient_reminder',
345 setting: this.value,
346 patient_id: '<?php echo htmlspecialchars($patient_id, ENT_QUOTES); ?>'
352 // Show a template popup of patient reminders batch sending tool.
353 function ReminderBatch(processType) {
354 //Hide the buttons and show the processing animation
355 $("#process_button").hide();
356 $("#process_send_button").hide();
357 $("#processing").show();
359 top.restoreSession();
360 $.get("../../../library/ajax/collect_new_report_id.php",
361 function(data){
362 // Set the report id in page form
363 $("#form_new_report_id").attr("value",data);
365 // Start collection status checks
366 collectStatus($("#form_new_report_id").val());
368 // Run the report
369 top.restoreSession();
370 $.post("../../../library/ajax/execute_pat_reminder.php",
371 {process_type: processType,
372 execute_report_id: $("#form_new_report_id").val()
376 return false;
379 function collectStatus(report_id) {
380 // Collect the status string via an ajax request and place in DOM at timed intervals
381 top.restoreSession();
382 // Do not send the skip_timeout_reset parameter, so don't close window before report is done.
383 $.post("../../../library/ajax/status_report.php",
384 {status_report_id: report_id},
385 function(data){
386 if (data == "PENDING") {
387 // Place the pending string in the DOM
388 $('#status_span').replaceWith("<span id='status_span'><?php echo xlt("Preparing To Run Report"); ?></span>");
390 else if (data == "COMPLETE") {
391 // Go into the results page
392 top.restoreSession();
393 link_report = "patient_reminders.php?mode=admin&patient_id=";
394 window.open(link_report,'_self',false);
396 else {
397 // Place the string in the DOM
398 $('#status_span').replaceWith("<span id='status_span'>"+data+"</span>");
401 // run status check every 10 seconds
402 var repeater = setTimeout("collectStatus("+report_id+")", 10000);
405 </script>
406 </body>
407 </html>