Add back popup dialogs for tabs U.I. (#1434)
[openemr.git] / interface / batchcom / batchcom.php
blob227a1e92e72e99747f93d2f2ba30b9fcae1cd433
1 <?php
2 /**
3 * Batch Communication Tool for selecting/communicating with subsets of patients
5 * @package OpenEMR
6 * @author Brady Miller <brady.g.miller@gmail.com>
7 * @author Jason 'Toolbox' Oettinger <jason@oettinger.email>
8 * @link http://www.open-emr.org
9 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2017 Jason 'Toolbox' Oettinger <jason@oettinger.email>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 //INCLUDES, DO ANY ACTIONS, THEN GET OUR DATA
15 require_once("../globals.php");
16 require_once("$srcdir/registry.inc");
17 require_once("../../library/acl.inc");
18 require_once("batchcom.inc.php");
20 use OpenEMR\Core\Header;
22 if (!acl_check('admin', 'batchcom')) {
23 echo "<html>\n<body>\n<h1>";
24 echo xlt('You are not authorized for this.');
25 echo "</h1>\n</body>\n</html>";
26 exit();
29 // menu arrays (done this way so it's easier to validate input on validate selections)
30 $process_choices = array(xl('Download CSV File'), xl('Send Emails'), xl('Phone call list'));
31 $gender_choices = array(xl('Any'), xl('Male'), xl('Female'));
32 $hipaa_choices = array(xl('No'), xl('Yes'));
33 $sort_by_choices = array(xl('Zip Code')=>'patient_data.postal_code', xl('Last Name')=>'patient_data.lname', xl('Appointment Date')=>'last_appt');
35 // process form
36 if ($_POST['form_action']=='process') {
37 //validation uses the functions in batchcom.inc.php
38 //validate dates
39 if (!check_date_format($_POST['app_s'])) {
40 $form_err .= xl('Date format for "appointment start" is not valid');
43 if (!check_date_format($_POST['app_e'])) {
44 $form_err .= xl('Date format for "appointment end" is not valid');
47 if (!check_date_format($_POST['seen_since'])) {
48 $form_err .= xl('Date format for "seen since" is not valid');
51 if (!check_date_format($_POST['seen_before'])) {
52 $form_err .= xl('Date format for "seen before" is not valid');
55 // validate numbers
56 if (!check_age($_POST['age_from'])) {
57 $form_err .= xl('Age format for "age from" is not valid');
60 if (!check_age($_POST['age_upto'])) {
61 $form_err .= xl('Age format for "age up to" is not valid');
64 // validate selections
65 if (!check_select($_POST['gender'], $gender_choices)) {
66 $form_err .= xl('Error in "Gender" selection');
69 if (!check_select($_POST['process_type'], $process_choices)) {
70 $form_err .= xl('Error in "Process" selection');
73 if (!check_select($_POST['hipaa_choice'], $hipaa_choices)) {
74 $form_err .= xl('Error in "HIPAA" selection');
77 if (!check_select($_POST['sort_by'], $sort_by_choices)) {
78 $form_err.=xl('Error in "Sort By" selection');
81 //process sql
82 if (!$form_err) {
83 $sql = "select patient_data.*, cal_events.pc_eventDate as next_appt, cal_events.pc_startTime
84 as appt_start_time,cal_date.last_appt,forms.last_visit from patient_data
85 left outer join openemr_postcalendar_events as cal_events on patient_data.pid=cal_events.pc_pid
86 and curdate() < cal_events.pc_eventDate left outer join (select pc_pid,max(pc_eventDate)
87 as last_appt from openemr_postcalendar_events where curdate() >= pc_eventDate group by pc_pid )
88 as cal_date on cal_date.pc_pid=patient_data.pid left outer join (select pid,max(date)
89 as last_visit from forms where curdate() >= date group by pid)
90 as forms on forms.pid=patient_data.pid where 1=1";
91 $params = array();
93 //appointment dates
94 if ($_POST['app_s']!=0 and $_POST['app_s']!='') {
95 $sql .= " and cal_events.pc_eventDate >= ?";
96 array_push($params, $_POST['app_s']);
99 if ($_POST['app_e']!=0 and $_POST['app_e']!='') {
100 $sql .= " and cal_events.pc_endDate <= ?";
101 array_push($params, $_POST['app_e']);
104 // encounter dates
105 if ($_POST['seen_since']!=0 and $_POST['seen_since']!='') {
106 $sql .= " and forms.date >= ?" ;
107 array_push($params, $_POST['seen_since']);
110 if ($_POST['seen_before']!=0 and $_POST['seen_before']!='') {
111 $sql .= " and forms.date <= ?" ;
112 array_push($params, $_POST['seen_before']);
115 // age
116 if ($_POST['age_from']!=0 and $_POST['age_from']!='') {
117 $sql .= " and DATEDIFF( CURDATE( ), patient_data.DOB )/ 365.25 >= ?";
118 array_push($params, $_POST['age_from']);
121 if ($_POST['age_upto']!=0 and $_POST['age_upto']!='') {
122 $sql .= " and DATEDIFF( CURDATE( ), patient_data.DOB )/ 365.25 <= ?";
123 array_push($params, $_POST['age_upto']);
126 // gender
127 if ($_POST['gender']!='Any') {
128 $sql .= " and patient_data.sex=?";
129 array_push($params, $_POST['gender']);
132 // hipaa override
133 if ($_POST['hipaa_choice'] != $hipaa_choices[0]) {
134 $sql .= " and patient_data.hipaa_mail='YES' ";
137 switch ($_POST['process_type']) :
138 case $choices[1]: // Email
139 $sql.=" and patient_data.email IS NOT NULL ";
140 break;
141 endswitch;
143 // sort by
144 $sql .= ' ORDER BY ' . escape_identifier($_POST['sort_by'], array_values($sort_by_choices), true);
145 // send query for results.
146 //echo $sql;exit();
147 $res = sqlStatement($sql, $params);
149 if (sqlNumRows($res) == 0) {
150 $form_err = xl('No results found, please try again.');
151 } else {
152 switch ($_POST['process_type']) :
153 case $process_choices[0]: // CSV File
154 generate_csv($res);
155 exit();
156 case $process_choices[1]: // Email
157 require_once('batchEmail.php');
158 exit();
159 case $process_choices[2]: // Phone list
160 require_once('batchPhoneList.php');
161 exit();
162 endswitch;
168 <html>
169 <head>
170 <title><?php echo xlt('BatchCom'); ?></title>
171 <?php Header::setupHeader(['datetime-picker']); ?>
172 </head>
173 <body class="body_top container">
174 <header class="row">
175 <?php require_once("batch_navigation.php");?>
176 <h1 class="col-md-6 col-md-offset-3 text-center">
177 <?php echo xlt('Batch Communication Tool')?>
178 </h1>
179 </header>
180 <main>
181 <?php
182 if ($form_err) {
183 echo '<div class="alert alert-danger">' . xlt('The following errors occurred') . ': ' . text($form_err) . '</div>';
186 <form name="select_form" method="post" action="">
187 <div class="row">
188 <div class="col-md-3 well form-group">
189 <label for="process_type"><?php echo xlt("Process") . ":"; ?></label>
190 <select name="process_type" class="form-control">
191 <?php
192 foreach ($process_choices as $choice) {
193 echo "<option>" . text($choice) . "</option>";
196 </select>
197 </div>
198 <div class="col-md-3 well form-group">
199 <label for="hipaa_choice"><?php echo xlt("Override HIPAA choice") . ":"; ?></label>
200 <select name="hipaa_choice" class="form-control">
201 <?php
202 foreach ($hipaa_choices as $choice) {
203 echo "<option>" . text($choice) . "</option>";
206 </select>
207 </div>
208 <div class="col-md-3 well form-group">
209 <label for="sort_by"><?php echo xlt("Sort by"); ?></label>
210 <select name="sort_by" class="form-control">
211 <?php
212 foreach ($sort_by_choices as $choice => $sorting_code) {
213 echo "<option value=\"$sorting_code\">" . text($choice) . "</option>";
216 </select>
217 </div>
218 <div class="col-md-3 well form-group">
219 <label for="gender"><?php echo xlt('Gender') ?>:</label>
220 <select name="gender" class="form-control">
221 <?php
222 foreach ($gender_choices as $choice) {
223 echo "<option>" . text($choice) . "</option>";
226 </select>
227 </div>
228 </div>
229 <div class="row">
230 <div class="col-md-3 well form-group">
231 <label for="age_from"><?php echo xlt("Age Range") . ":"; ?></label>
232 <input name="age_from" size="2" type="num" class="form-control" placeholder="<?php echo xla("any"); ?>">
233 <label for="age_upto" class="text-center"><?php echo xlt('to'); ?></label>
234 <input name="age_upto" size="2" type="num" class="form-control" placeholder="<?php echo xla("any"); ?>">
235 </div>
236 <div class="col-md-3 well form-group">
237 <label for="app_s"><?php echo xlt('Appointment within') ?>:</label>
238 <input type="text" class="datepicker form-control" name="app_s" placeholder="<?php echo xla('any date'); ?>">
239 <div class="text-center"><?php echo xlt('to'); ?></div>
240 <input type="text" class="datepicker form-control" name="app_e" placeholder="<?php echo xla('any date'); ?>">
241 </div>
242 <!-- later gator <br>Insurance: <SELECT multiple NAME="insurance" Rows="10" cols="20"></SELECT> -->
243 <div class="col-md-3 well form-group">
244 <label for="app_s"><?php echo xlt('Seen within')?>:</label>
245 <input type="text" class="datepicker form-control" name="seen_since" placeholder="<?php echo xla('any date'); ?>">
246 <div class="text-center"><?php echo xlt('to'); ?></div>
247 <input type="text" class="datepicker form-control" name="seen_before" placeholder="<?php echo xla('any date'); ?>">
248 </div>
249 </div>
250 <div class="email row form-group">
251 <div class="col-md-6 col-md-offset-3 well">
252 <div class="col-md-6">
253 <label for="email_sender"><?php echo xlt('Email Sender'); ?>:</label>
254 <input class="form-control" type="text" name="email_sender" placeholder="your@email.email">
255 </div>
257 <div class="col-md-6">
258 <label for="email_subject"><?php echo xlt('Email Subject'); ?>:</label>
259 <input class="form-control" type="text" name="email_subject" placeholder="From your clinic">
260 </div>
261 <div class="col-md-12">
262 <label for="email_subject"><?php echo xlt('Email Text, Usable Tag: ***NAME*** , i.e. Dear ***NAME***{{Do Not translate the ***NAME*** elements of this constant.}}'); ?>:</label>
263 </div>
264 <div class="col-md-12">
265 <textarea class="form-control" name="email_body" id="" cols="40" rows="8"></textarea>
266 </div>
267 </div>
268 </div>
269 <div class="row">
270 <div class="col-md-12 form-group">
271 <input type="hidden" name="form_action" value="process">
272 <button type="submit" name="submit" class="btn btn-default btn-save">
273 <?php echo xla("Process"); ?>
274 </button>
275 </div>
276 </div>
277 </form>
278 </main>
279 </body>
281 <script>
282 (function() {
283 var email = document.querySelector('.email');
284 var process = document.querySelector('select[name="process_type"]');
285 function hideEmail() {
286 if (process.value !== '<?php echo attr($process_choices[1]); ?>') { email.style.display = 'none'; } else { email.style.display = ''; }
288 process.addEventListener('change', hideEmail);
289 hideEmail();
290 $('.datepicker').datetimepicker({
291 <?php $datetimepicker_timepicker = false; ?>
292 <?php $datetimepicker_showseconds = false; ?>
293 <?php $datetimepicker_formatInput = false; ?>
294 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
295 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
297 })();
298 </script>
299 </html>