migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / batchcom / batchcom.php
blob4d91c76fa7a1feecb0badba840e2513b4a193ac6
1 <?php
2 /**
3 * Batchcom script.
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
16 * @package OpenEMR
17 * @author Brady Miller <brady@sparmy.com>
18 * @link http://www.open-emr.org
21 //INCLUDES, DO ANY ACTIONS, THEN GET OUR DATA
22 include_once("../globals.php");
23 include_once("$srcdir/registry.inc");
24 include_once("$srcdir/sql.inc");
25 include_once("../../library/acl.inc");
26 include_once("batchcom.inc.php");
28 // gacl control
29 $thisauth = acl_check('admin', 'batchcom');
31 if (!$thisauth) {
32 echo "<html>\n<body>\n";
33 echo "<p>".xl('You are not authorized for this.','','','</p>')."\n";
34 echo "</body>\n</html>\n";
35 exit();
38 // menu arrays (done this way so it's easier to validate input on validate selections)
39 $choices=Array (xl('CSV File'),xl('Email'),xl('Phone call list'));
40 $gender=Array (xl('Any'),xl('Male'),xl('Female'));
41 $hipaa=Array (xl('NO'),xl('YES'));
42 $sort_by=Array (xl('Zip Code')=>'patient_data.postal_code',xl('Last Name')=>'patient_data.lname',xl('Appointment Date')=>'last_ap' );
44 // process form
45 if ($_POST['form_action']=='Process') {
46 //validation uses the functions in batchcom.inc.php
47 //validate dates
48 if (!check_date_format($_POST['app_s'])) $form_err.=xl('Date format for "appointment start" is not valid','','<br>');
49 if (!check_date_format($_POST['app_e'])) $form_err.=xl('Date format for "appointment end" is not valid','','<br>');
50 if (!check_date_format($_POST['seen_since'])) $form_err.=xl('Date format for "seen since" is not valid','','<br>');
51 if (!check_date_format($_POST['not_seen_since'])) $form_err.=xl('Date format for "not seen since" is not valid','','<br>');
52 // validate numbers
53 if (!check_age($_POST['age_from'])) $form_err.=xl('Age format for "age from" is not valid','','<br>');
54 if (!check_age($_POST['age_upto'])) $form_err.=xl('Age format for "age up to" is not valid','','<br>');
55 // validate selections
56 if (!check_select($_POST['gender'],$gender)) $form_err.=xl('Error in "Gender" selection','','<br>');
57 if (!check_select($_POST['process_type'],$choices)) $form_err.=xl('Error in "Process" selection','','<br>');
58 if (!check_select($_POST['hipaa_choice'],$hipaa)) $form_err.=xl('Error in "HIPAA" selection','','<br>');
59 if (!check_select($_POST['sort_by'],$sort_by)) $form_err.=xl('Error in "Sort By" selection','','<br>');
60 // validates and or
61 if (!check_yes_no ($_POST['and_or_gender'])) $form_err.=xl('Error in YES or NO option','','<br>');
62 if (!check_yes_no ($_POST['and_or_app_within'])) $form_err.=xl('Error in YES or NO option','','<br>');
63 if (!check_yes_no ($_POST['and_or_seen_since'])) $form_err.=xl('Error in YES or NO option','','<br>');
64 if (!check_yes_no ($_POST['and_or_not_seen_since'])) $form_err.=xl('Error in YES or NO option','','<br>');
66 //process sql
67 if (!$form_err) {
70 $sql="select patient_data.*, cal_events.pc_eventDate as next_appt,cal_events.pc_startTime as appt_start_time,cal_date.last_appt,forms.last_visit from patient_data left outer join openemr_postcalendar_events as cal_events on patient_data.pid=cal_events.pc_pid and curdate() < cal_events.pc_eventDate left outer join (select pc_pid,max(pc_eventDate) as last_appt from openemr_postcalendar_events where curdate() >= pc_eventDate group by pc_pid ) as cal_date on cal_date.pc_pid=patient_data.pid left outer join (select pid,max(date) as last_visit from forms where curdate() >= date group by pid) as forms on forms.pid=patient_data.pid";
71 //appointment dates
72 if ($_POST['app_s']!=0 AND $_POST['app_s']!='') {
73 $and=where_or_and ($and);
74 $sql_where_a=" $and cal_events.pc_eventDate > '".$_POST['app_s']."'";
76 if ($_POST['app_e']!=0 AND $_POST['app_e']!='') {
77 $and=where_or_and ($and);
78 $sql_where_a.=" $and cal_events.pc_endDate < '".$_POST['app_e']."'";
80 $sql.=$sql_where_a;
82 // encounter dates
83 if ($_POST['seen_since']!=0 AND $_POST['seen_since']!='') {
84 $and=where_or_and ($and);
85 $sql.=" $and forms.date > '".$_POST['seen_since']."' " ;
87 if ($_POST['seen_upto']!=0 AND $_POST['not_seen_since']!='') {
88 $and=where_or_and ($and);
89 $sql.=" $and forms.date > '".$_POST['seen_since']."' " ;
92 // age
93 if ($_POST['age_from']!=0 AND $_POST['age_from']!='') {
94 $and=where_or_and ($and);
95 $sql.=" $and DATEDIFF( CURDATE( ), patient_data.DOB )/ 365.25 >= '".$_POST['age_from']."' ";
97 if ($_POST['age_upto']!=0 AND $_POST['age_upto']!='') {
98 $and=where_or_and ($and);
99 $sql.=" $and DATEDIFF( CURDATE( ), patient_data.DOB )/ 365.25 <= '".$_POST['age_upto']."' ";
102 // gender
103 if ($_POST['gender']!='Any') {
104 $and=where_or_and ($and);
105 $sql.=" $and patient_data.sex='".$_POST['gender']."' ";
108 // hipaa overwrite
109 if ($_POST['hipaa_choice']!='NO') {
110 $and=where_or_and ($and);
111 $sql.=" $and patient_data.hipaa_mail='YES' ";
114 switch ($_POST['process_type']):
115 case $choices[1]: // Email
116 $and=where_or_and ($and);
117 $sql.=" $and patient_data.email IS NOT NULL ";
118 break;
119 endswitch;
121 // sort by
122 $sql.=' ORDER BY '.$_POST['sort_by'];
123 //echo $sql;
124 // send query for results.
125 $res = sqlStatement($sql);
127 // if no results.
128 if (sqlNumRows($res)==0){
130 <html>
131 <head>
132 <title><?php echo xlt('BatchCom'); ?></title>
133 <?php html_header_show();?>
134 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
135 <link rel="stylesheet" href="batchcom.css" type="text/css">
136 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
137 <script type="text/javascript" src="../../library/calendar.js"></script>
138 </head>
139 <body class="body_top">
140 <!-- larry's sms/email notification -->
141 <span class="title"><?php include_once("batch_navigation.php");?></span>
142 <!--- end of larry's insert -->
143 <span class="title"><?php xl('Batch Communication Tool','e')?></span>
144 <br><br>
145 <div class="text">
146 <?php
147 echo (xl('No results found, please try again.','','<br>'));
148 ?> </div></body></html> <?php
149 //if results
150 } else {
151 switch ($_POST['process_type']):
152 case $choices[0]: // CSV File
153 require_once ('batchCSV.php');
154 break;
155 case $choices[1]: // Email
156 require_once ('batchEmail.php');
157 break;
158 case $choices[2]: // Phone list
159 require_once ('batchPhoneList.php');
160 break;
161 endswitch;
163 // end results
165 exit ();
169 //START OUT OUR PAGE....
171 <html>
172 <head>
173 <title><?php echo xlt('BatchCom'); ?></title>
174 <?php html_header_show();?>
175 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
176 <link rel="stylesheet" href="batchcom.css" type="text/css">
177 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
178 <script type="text/javascript" src="../../library/calendar.js"></script>
181 </head>
182 <body class="body_top">
183 <!-- larry's sms/email notification -->
184 <span class="title"><?php include_once("batch_navigation.php");?></span>
185 <!--- end of larry's insert -->
186 <span class="title"><?php xl('Batch Communication Tool','e')?></span>
187 <br><br>
189 <!-- for the popup date selector -->
190 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
191 <FORM name="select_form" METHOD=POST ACTION="" onsubmit='return top.restoreSession()'>
192 <div class="text">
193 <div class="main_box">
194 <table class="table" ><tr><td >
195 <?php
196 if ($form_err) {
197 echo (xl('The following errors occurred')."<br>$form_err<br><br>");
200 xl('Process','e')?>:</td><td><SELECT NAME="process_type">
201 <?php
202 foreach ($choices as $value) {
203 echo ("<option>$value</option>");
206 </SELECT></td>
207 <td>&nbsp;</td><td>&nbsp;</td>
208 </tr><tr><td >
210 <?php xl('Overwrite HIPAA choice','e')?> :</td><td align='left'><SELECT NAME="hipaa_choice">
211 <?php
212 foreach ($hipaa as $value) {
213 echo ("<option>$value</option>");
216 </SELECT></td>
217 <td>&nbsp;</td><td>&nbsp;</td>
218 </tr><tr><td>
219 <?php xl('Age From','e')?>:<INPUT TYPE="text" size="2" NAME="age_from"></td><td> <?php xl('Up to','e')?>:<INPUT TYPE="text" size="2" NAME="age_upto"></td><td>
220 <?php xl('And','e')?>:<INPUT TYPE="radio" NAME="and_or_gender" value="AND" checked>, <?php xl('Or','e')?>:<INPUT TYPE="radio" NAME="and_or_gender" value="OR"></td><td>
221 <?php xl('Gender','e')?> :<SELECT NAME="gender">
222 <?php
223 foreach ($gender as $value) {
224 echo ("<option>$value</option>");
227 </SELECT></td>
228 </tr><tr><td>
229 <!-- later gator
230 <br>Insurance: <SELECT multiple NAME="insurance" Rows="10" cols="20">
232 </SELECT>
234 <?php xl('And','e')?>:<INPUT TYPE="radio" NAME="and_or_app_within" value="AND" checked>, <?php xl('Or','e')?>:<INPUT TYPE="radio" NAME="and_or_app_within" value="OR"></td><td> <?php xl('Appointment within','e')?>:</td><td><INPUT TYPE='text' size='12' NAME='app_s'> <a href="javascript:show_calendar('select_form.app_s')"
235 title="<?php xl('Click here to choose a date','e')?>"
236 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0' ></a></td><td>
238 <?php xl('And','e')?> : <INPUT TYPE='text' size='12' NAME='app_e'> <a href="javascript:show_calendar('select_form.app_e')"
239 title="<?php xl('Click here to choose a date','e')?>"
240 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0' ></a></td>
241 </tr><tr><td>
243 <?php xl('And','e')?>:<INPUT TYPE="radio" NAME="and_or_seen_since" value="AND" checked>, <?php xl('Or','e')?>:<INPUT TYPE="radio" NAME="and_or_seen_since" value="OR"></td><td> <?php xl('Seen since','e')?> :</td><td><INPUT TYPE='text' size='12' NAME='seen_since'> <a href="javascript:show_calendar('select_form.seen_since')"
244 title="<?php xl('Click here to choose a date','e')?>"
245 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a></td>
246 <td>&nbsp;</td>
247 </tr><tr><td>
249 <?php xl('And','e')?>:<INPUT TYPE="radio" NAME="and_or_not_seen_since" value="AND" checked>, <?php xl('Or','e')?>:<INPUT TYPE="radio" NAME="and_or_not_seen_since" value="OR"></td><td> <?php xl('Not seen since','e')?> :</td><td><INPUT TYPE='text' size='12' NAME='not_seen_since'> <a href="javascript:show_calendar('select_form.not_seen_since')"
250 title="<?php xl('Click here to choose a date','e')?>"
251 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a></td>
252 <td>&nbsp;</td>
253 </tr><tr><td>
254 <?php xl('Sort by','e')?> :</td><td><SELECT NAME="sort_by">
255 <?php
256 foreach ($sort_by as $key => $value) {
257 echo ("<option value=\"".$value."\">$key</option>");
260 </SELECT></td>
261 <td>&nbsp;</td><td>&nbsp;</td>
262 </tr><tr><td colspan='3'>
263 (<?php xl('Fill here only if sending email notification to patients','e')?>)</td>
264 <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
265 </tr><tr><td>
266 <?php xl('Email Sender','e')?> :</td><td><INPUT TYPE="text" NAME="email_sender" value="your@example.com"></td>
267 <td>&nbsp;</td><td>&nbsp;</td>
268 </tr><tr><td>
269 <?php xl('Email Subject','e')?>:</td><td><INPUT TYPE="text" NAME="email_subject" value="From your clinic"></td>
270 <td>&nbsp;</td><td>&nbsp;</td>
271 </tr><tr><td colspan='3'>
272 <?php echo xlt('Email Text, Usable Tag: ***NAME*** , i.e. Dear ***NAME***{{Do Not translate the ***NAME*** elements of this constant.}}')?></td>
273 <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
274 <tr><td colspan='4'>
275 <TEXTAREA NAME="email_body" ROWS="8" COLS="40"></TEXTAREA></td>
276 <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
277 </tr><tr><td>
279 <INPUT TYPE="submit" name="form_action" value=<?php xl('Process','e','\'','\''); ?>> </td><td><?php xl('Process takes some time','e')?></td> <td>&nbsp;</td><td>&nbsp;</td></tr>
280 </table>
281 </div>
282 </div>
283 </FORM>