migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / patient_file / reminder / patient_reminders.php
blob37dc4d67aad14f91a36fa1a6ab6c61dc3cadd644
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/reminders.php");
20 require_once("$srcdir/clinical_rules.php");
21 require_once "$srcdir/report_database.inc";
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?v=<?php echo $v_js_includes; ?>"></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="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.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 if (!empty($patient_id)) {
54 //Only update one patient
55 $update_rem_log = update_reminders('', $patient_id);
58 if ($mode == "simple") {
59 // Collect the rules for the per patient rules selection tab
60 $rules_default = resolve_rules_sql('','0',TRUE);
65 <script language="javascript">
66 // This is for callback by the find-patient popup.
67 function setpatient(pid, lname, fname, dob) {
68 var f = document.forms[0];
69 f.form_patient.value = lname + ', ' + fname;
70 f.patient_id.value = pid;
73 // This invokes the find-patient popup.
74 function sel_patient() {
75 dlgopen('../../main/calendar/find_patient_popup.php', '_blank', 500, 400);
77 </script>
79 <body class='body_top'>
80 <div>
81 <span class='title'><?php echo htmlspecialchars( xl('Patient Reminders'), ENT_NOQUOTES); ?></span>
82 </div>
83 <?php if ($mode == "simple") { ?>
84 <div id='namecontainer_preminders' class='namecontainer_preminders' style='float:left;margin-right:10px'>
85 <?php echo htmlspecialchars( xl('for'), ENT_NOQUOTES);?>&nbsp;
86 <span class="title">
87 <a href="../summary/demographics.php" onclick="top.restoreSession()"><?php echo htmlspecialchars( getPatientName($pid), ENT_NOQUOTES); ?></a>
88 </span>
89 </div>
90 <div>
91 <a href="../summary/demographics.php" class="css_button" onclick="top.restoreSession()">
92 <span><?php echo htmlspecialchars( xl('Back To Patient'), ENT_NOQUOTES);?></span>
93 </a>
94 </div>
95 <?php } ?>
96 <div>
97 &nbsp;
98 </div>
100 <?php
101 // This is for sorting the records.
102 $sort = array("category, item", "lname, fname", "due_status", "date_created", "hipaa_allowemail", "hipaa_allowsms", "date_sent", "voice_status", "email_status", "sms_status", "mail_status");
103 if($sortby == "") {
104 $sortby = $sort[0];
106 if($sortorder == "") {
107 $sortorder = "asc";
109 for($i = 0; $i < count($sort); $i++) {
110 $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=" . attr($patient_id) ."&mode=" . attr($mode) . "&sortby=" . attr($sort[$i]) . "&sortorder=asc\" onclick=\"top.restoreSession()\">" .
111 "<img src=\"../../../images/sortdown.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Up'), ENT_QUOTES)."\"></a>";
113 for($i = 0; $i < count($sort); $i++) {
114 if($sortby == $sort[$i]) {
115 switch($sortorder) {
116 case "asc" : $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=" . attr($patient_id) . "&mode=" . attr($mode) . "&sortby=" . attr($sortby) . "&sortorder=desc\" onclick=\"top.restoreSession()\">" .
117 "<img src=\"../../../images/sortup.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Up'), ENT_QUOTES)."\"></a>";
118 break;
119 case "desc" : $sortlink[$i] = "<a href=\"patient_reminders.php?patient_id=" . attr($patient_id) . "&mode=" . attr($mode) . "&sortby=" . attr($sortby) . "&sortorder=asc\" onclick=\"top.restoreSession()\">" .
120 "<img src=\"../../../images/sortdown.gif\" border=0 alt=\"".htmlspecialchars(xl('Sort Down'), ENT_QUOTES)."\"></a>";
121 break;
122 } break;
125 // This is for managing page numbering and display beneath the Patient Reminders table.
126 $listnumber = 25;
127 $sqlBindArray = array();
128 if (!empty($patient_id)) {
129 $add_sql = "AND a.pid=? ";
130 array_push($sqlBindArray,$patient_id);
132 $sql = "SELECT a.id, a.due_status, a.category, a.item, a.date_created, a.date_sent, b.fname, b.lname " .
133 "FROM `patient_reminders` as a, `patient_data` as b " .
134 "WHERE a.active='1' AND a.pid=b.pid ".$add_sql;
135 $result = sqlStatement($sql, $sqlBindArray);
136 if(sqlNumRows($result) != 0) {
137 $total = sqlNumRows($result);
139 else {
140 $total = 0;
142 if($begin == "" or $begin == 0) {
143 $begin = 0;
145 $prev = $begin - $listnumber;
146 $next = $begin + $listnumber;
147 $start = $begin + 1;
148 $end = $listnumber + $start - 1;
149 if($end >= $total) {
150 $end = $total;
152 if($end < $start) {
153 $start = 0;
155 if($prev >= 0) {
156 $prevlink = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=$sortorder&begin=$prev\" onclick=\"top.restoreSession()\"><<</a>";
158 else {
159 $prevlink = "<<";
162 if($next < $total) {
163 $nextlink = "<a href=\"patient_reminders.php?patient_id=$patient_id&mode=$mode&sortby=$sortby&sortorder=$sortorder&begin=$next\" onclick=\"top.restoreSession()\">>></a>";
165 else {
166 $nextlink = ">>";
171 <br>
172 <br>
174 <?php if ($mode == "simple") { // show the per patient rule setting option ?>
175 <ul class="tabNav">
176 <li class='current'><a href='#'><?php echo htmlspecialchars( xl('Main'), ENT_NOQUOTES); ?></a></li>
177 <li ><a href='#' onclick='top.restoreSession()'><?php echo htmlspecialchars( xl('Rules'), ENT_NOQUOTES); ?></a></li>
178 </ul>
179 <div class="tabContainer">
180 <div class="tab current" style="height:auto;width:97%;">
181 <?php } ?>
183 <form method='post' name='theform' id='theform'>
185 <div id='report_parameters'>
186 <table>
187 <tr>
188 <td width='410px'>
189 <div style='float:left'>
190 <table class='text'>
191 <tr>
192 <td class='label'>
193 <?php echo " "; ?>
194 </td>
195 </tr>
196 </table>
197 </div>
198 </td>
199 <td align='left' valign='middle' height="100%">
200 <table style='border-left:1px solid; width:100%; height:100%' >
201 <tr>
202 <td>
203 <div style='margin-left:15px'>
204 <?php if ($mode == "admin") { ?>
205 <a id='process_button' href='#' class='css_button' onclick='return ReminderBatch("process")'>
206 <span><?php echo htmlspecialchars( xl('Process Reminders'), ENT_NOQUOTES); ?></span>
207 </a>
208 <a id='process_send_button' href='#' class='css_button' onclick='return ReminderBatch("process_send")'>
209 <span><?php echo htmlspecialchars( xl('Process and Send Reminders'), ENT_NOQUOTES); ?></span>
210 </a>
211 <span id='status_span'></span>
212 <div id='processing' style='margin:10px;display:none;'><img src='../../pic/ajax-loader.gif'/></div>
213 <?php } else { ?>
214 <a href='patient_reminders.php?patient_id=<?php echo $patient_id; ?>&mode=<?php echo $mode; ?>' class='css_button' onclick='top.restoreSession()'>
215 <span><?php echo htmlspecialchars( xl('Refresh'), ENT_NOQUOTES); ?></span>
216 </a>
217 <?php } ?>
218 </div>
219 </td>
220 <td align=right class='text'><?php echo $prevlink." ".$end." of ".$total." ".$nextlink; ?></td>
221 </tr>
222 </table>
223 </td>
224 </tr>
225 </table>
226 </div>
228 <div id='report_results'>
229 <table>
230 <thead>
231 <th><?php echo htmlspecialchars( xl('Item'), ENT_NOQUOTES) . " " . $sortlink[0]; ?></th>
232 <th><?php echo htmlspecialchars( xl('Patient'), ENT_NOQUOTES) . " " . $sortlink[1]; ?></th>
233 <th><?php echo htmlspecialchars( xl('Due Status'), ENT_NOQUOTES) . " " . $sortlink[2]; ?></th>
234 <th><?php echo htmlspecialchars( xl('Date Created'), ENT_NOQUOTES) . " " . $sortlink[3]; ?></th>
235 <th><?php echo htmlspecialchars( xl('Email Auth'), ENT_NOQUOTES) . " " . $sortlink[4]; ?></th>
236 <th><?php echo htmlspecialchars( xl('SMS Auth'), ENT_NOQUOTES) . " " . $sortlink[5]; ?></th>
237 <th><?php echo htmlspecialchars( xl('Date Sent'), ENT_NOQUOTES) . " " . $sortlink[6]; ?></th>
238 <th><?php echo htmlspecialchars( xl('Voice Sent'), ENT_NOQUOTES) . " " . $sortlink[7]; ?></th>
239 <th><?php echo htmlspecialchars( xl('Email Sent'), ENT_NOQUOTES) . " " . $sortlink[8]; ?></th>
240 <th><?php echo htmlspecialchars( xl('SMS Sent'), ENT_NOQUOTES) . " " . $sortlink[9]; ?></th>
241 <th><?php echo htmlspecialchars( xl('Mail Sent'), ENT_NOQUOTES) . " " . $sortlink[10]; ?></th>
242 </thead>
243 <tbody>
244 <?php
245 $sql = "SELECT a.id, a.due_status, a.category, a.item, a.date_created, a.date_sent, a.voice_status, " .
246 "a.sms_status, a.email_status, a.mail_status, b.fname, b.lname, b.hipaa_allowemail, b.hipaa_allowsms " .
247 "FROM `patient_reminders` as a, `patient_data` as b " .
248 "WHERE a.active='1' AND a.pid=b.pid " . $add_sql .
249 "ORDER BY " . add_escape_custom($sortby) . " " .
250 add_escape_custom($sortorder) . " " .
251 "LIMIT " . add_escape_custom($begin) . ", " .
252 add_escape_custom($listnumber);
253 $result = sqlStatement($sql,$sqlBindArray);
254 while ($myrow = sqlFetchArray($result)) { ?>
255 <tr>
256 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'),$myrow['category']) . " : " .
257 generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'),$myrow['item']); ?></td>
258 <td><?php echo htmlspecialchars($myrow['lname'].", ".$myrow['fname'], ENT_NOQUOTES); ?></td>
259 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_reminder_due_opt'),$myrow['due_status']); ?></td>
260 <td><?php echo ($myrow['date_created']) ? htmlspecialchars($myrow['date_created'], ENT_NOQUOTES) : " "; ?></td>
261 <td><?php echo ($myrow['hipaa_allowemail']=='YES') ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
262 <td><?php echo ($myrow['hipaa_allowsms']=='YES') ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
263 <td><?php echo ($myrow['date_sent']) ? htmlspecialchars($myrow['date_sent'], ENT_NOQUOTES) : htmlspecialchars( xl("Not Sent Yet") , ENT_NOQUOTES); ?></td>
264 <td><?php echo ($myrow['voice_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
265 <td><?php echo ($myrow['email_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
266 <td><?php echo ($myrow['sms_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
267 <td><?php echo ($myrow['mail_status']==1) ? htmlspecialchars( xl("YES"), ENT_NOQUOTES) : htmlspecialchars( xl("NO"), ENT_NOQUOTES); ?></td>
268 </tr>
269 <?php } ?>
270 </tbody>
271 </table>
272 </div>
274 <?php if ($mode == "simple") { // show the per patient rule setting option ?>
275 </div>
276 <div class="tab" style="height:auto;width:97%;">
277 <div id='report_results'>
278 <table>
279 <tr>
280 <th rowspan="2"><?php echo htmlspecialchars( xl('Rule'), ENT_NOQUOTES); ?></th>
281 <th colspan="2"><?php echo htmlspecialchars( xl('Patient Reminder'), ENT_NOQUOTES); ?></th>
282 </tr>
283 <tr>
284 <th><?php echo htmlspecialchars( xl('Patient Setting'), ENT_NOQUOTES); ?></th>
285 <th style="left-margin:1em;"><?php echo htmlspecialchars( xl('Practice Default Setting'), ENT_NOQUOTES); ?></th>
286 </tr>
287 <?php foreach ($rules_default as $rule) { ?>
288 <tr>
289 <td style="border-right:1px solid black;"><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $rule['id']); ?></td>
290 <td align="center">
291 <?php
292 $patient_rule = collect_rule($rule['id'],$patient_id);
293 // Set the patient specific setting for gui
294 if (empty($patient_rule)) {
295 $select = "default";
297 else {
298 if ($patient_rule['patient_reminder_flag'] == "1") {
299 $select = "on";
301 else if ($patient_rule['patient_reminder_flag'] == "0"){
302 $select = "off";
304 else { // $patient_rule['patient_reminder_flag'] == NULL
305 $select = "default";
307 } ?>
308 <select class="patient_reminder" name="<?php echo htmlspecialchars( $rule['id'], ENT_NOQUOTES); ?>">
309 <option value="default" <?php if ($select == "default") echo "selected"; ?>><?php echo htmlspecialchars( xl('Default'), ENT_NOQUOTES); ?></option>
310 <option value="on" <?php if ($select == "on") echo "selected"; ?>><?php echo htmlspecialchars( xl('On'), ENT_NOQUOTES); ?></option>
311 <option value="off" <?php if ($select == "off") echo "selected"; ?>><?php echo htmlspecialchars( xl('Off'), ENT_NOQUOTES); ?></option>
312 </select>
313 </td>
314 <td align="center" style="border-right:1px solid black;">
315 <?php if ($rule['patient_reminder_flag'] == "1") {
316 echo htmlspecialchars( xl('On'), ENT_NOQUOTES);
318 else {
319 echo htmlspecialchars( xl('Off'), ENT_NOQUOTES);
320 } ?>
321 </td>
322 </tr>
323 <?php } ?>
324 </table>
325 </div>
326 </div>
327 </div>
328 <?php } ?>
330 <input type='hidden' name='form_new_report_id' id='form_new_report_id' value=''/>
331 </form>
333 <script language="javascript">
335 $(document).ready(function(){
337 tabbify();
339 $(".patient_reminder").change(function() {
340 top.restoreSession();
341 $.post( "../../../library/ajax/rule_setting.php", {
342 rule: this.name,
343 type: 'patient_reminder',
344 setting: this.value,
345 patient_id: '<?php echo htmlspecialchars($patient_id, ENT_QUOTES); ?>'
351 // Show a template popup of patient reminders batch sending tool.
352 function ReminderBatch(processType) {
353 //Hide the buttons and show the processing animation
354 $("#process_button").hide();
355 $("#process_send_button").hide();
356 $("#processing").show();
358 top.restoreSession();
359 $.get("../../../library/ajax/collect_new_report_id.php",
360 function(data){
361 // Set the report id in page form
362 $("#form_new_report_id").attr("value",data);
364 // Start collection status checks
365 collectStatus($("#form_new_report_id").val());
367 // Run the report
368 top.restoreSession();
369 $.post("../../../library/ajax/execute_pat_reminder.php",
370 {process_type: processType,
371 execute_report_id: $("#form_new_report_id").val()
375 return false;
378 function collectStatus(report_id) {
379 // Collect the status string via an ajax request and place in DOM at timed intervals
380 top.restoreSession();
381 // Do not send the skip_timeout_reset parameter, so don't close window before report is done.
382 $.post("../../../library/ajax/status_report.php",
383 {status_report_id: report_id},
384 function(data){
385 if (data == "PENDING") {
386 // Place the pending string in the DOM
387 $('#status_span').replaceWith("<span id='status_span'><?php echo xlt("Preparing To Run Report"); ?></span>");
389 else if (data == "COMPLETE") {
390 // Go into the results page
391 top.restoreSession();
392 link_report = "patient_reminders.php?mode=admin&patient_id=";
393 window.open(link_report,'_self',false);
395 else {
396 // Place the string in the DOM
397 $('#status_span').replaceWith("<span id='status_span'>"+data+"</span>");
400 // run status check every 10 seconds
401 var repeater = setTimeout("collectStatus("+report_id+")", 10000);
404 </script>
405 </body>
406 </html>