3 * Batch Communication Tool for selecting/communicating with subsets of patients
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>";
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');
36 if ($_POST['form_action']=='process') {
37 //validation uses the functions in batchcom.inc.php
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');
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');
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";
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']);
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']);
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']);
127 if ($_POST['gender']!='Any') {
128 $sql .= " and patient_data.sex=?";
129 array_push($params, $_POST['gender']);
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 ";
144 $sql .= ' ORDER BY ' . escape_identifier($_POST['sort_by'], array_values($sort_by_choices), true);
145 // send query for results.
147 $res = sqlStatement($sql, $params);
149 if (sqlNumRows($res) == 0) {
150 $form_err = xl('No results found, please try again.');
152 switch ($_POST['process_type']) :
153 case $process_choices[0]: // CSV File
156 case $process_choices[1]: // Email
157 require_once('batchEmail.php');
159 case $process_choices[2]: // Phone list
160 require_once('batchPhoneList.php');
170 <title
><?php
echo xlt('BatchCom'); ?
></title
>
171 <?php Header
::setupHeader(['datetime-picker']); ?
>
173 <body
class="body_top container">
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')?
>
183 echo '<div class="alert alert-danger">' . xlt('The following errors occurred') . ': ' . text($form_err) . '</div>';
186 <form name
="select_form" method
="post" action
="">
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">
192 foreach ($process_choices as $choice) {
193 echo "<option>" . text($choice) . "</option>";
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">
202 foreach ($hipaa_choices as $choice) {
203 echo "<option>" . text($choice) . "</option>";
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">
212 foreach ($sort_by_choices as $choice => $sorting_code) {
213 echo "<option value=\"$sorting_code\">" . text($choice) . "</option>";
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">
222 foreach ($gender_choices as $choice) {
223 echo "<option>" . text($choice) . "</option>";
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
"); ?>">
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'); ?>">
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'); ?>">
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">
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">
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
>
264 <div
class="col-md-12">
265 <textarea
class="form-control" name
="email_body" id
="" cols
="40" rows
="8"></textarea
>
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"); ?
>
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
);
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 ?>