acknowledgments update
[openemr.git] / interface / batchcom / batchcom.php
blob3c548b18c7d41914af56b1961b0ba50738224a2d
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 (mysql_num_rows($res)==0){
130 <html>
131 <head>
132 <?php html_header_show();?>
133 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
134 <link rel="stylesheet" href="batchcom.css" type="text/css">
135 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
136 <script type="text/javascript" src="../../library/calendar.js"></script>
137 </head>
138 <body class="body_top">
139 <!-- larry's sms/email notification -->
140 <span class="title"><?php include_once("batch_navigation.php");?></span>
141 <!--- end of larry's insert -->
142 <span class="title"><?php xl('Batch Communication Tool','e')?></span>
143 <br><br>
144 <div class="text">
145 <?php
146 echo (xl('No results found, please try again.','','<br>'));
147 ?> </div></body></html> <?php
148 //if results
149 } else {
150 switch ($_POST['process_type']):
151 case $choices[0]: // CSV File
152 require_once ('batchCSV.php');
153 break;
154 case $choices[1]: // Email
155 require_once ('batchEmail.php');
156 break;
157 case $choices[2]: // Phone list
158 require_once ('batchPhoneList.php');
159 break;
160 endswitch;
162 // end results
164 exit ();
168 //START OUT OUR PAGE....
170 <html>
171 <head>
172 <?php html_header_show();?>
173 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
174 <link rel="stylesheet" href="batchcom.css" type="text/css">
175 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
176 <script type="text/javascript" src="../../library/calendar.js"></script>
179 </head>
180 <body class="body_top">
181 <!-- larry's sms/email notification -->
182 <span class="title"><?php include_once("batch_navigation.php");?></span>
183 <!--- end of larry's insert -->
184 <span class="title"><?php xl('Batch Communication Tool','e')?></span>
185 <br><br>
187 <!-- for the popup date selector -->
188 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
189 <FORM name="select_form" METHOD=POST ACTION="" onsubmit='return top.restoreSession()'>
190 <div class="text">
191 <div class="main_box">
192 <table class="table" ><tr><td >
193 <?php
194 if ($form_err) {
195 echo (xl('The following errors occurred')."<br>$form_err<br><br>");
198 xl('Process','e')?>:</td><td><SELECT NAME="process_type">
199 <?php
200 foreach ($choices as $value) {
201 echo ("<option>$value</option>");
204 </SELECT></td>
205 <td>&nbsp;</td><td>&nbsp;</td>
206 </tr><tr><td >
208 <?php xl('Overwrite HIPAA choice','e')?> :</td><td align='left'><SELECT NAME="hipaa_choice">
209 <?php
210 foreach ($hipaa as $value) {
211 echo ("<option>$value</option>");
214 </SELECT></td>
215 <td>&nbsp;</td><td>&nbsp;</td>
216 </tr><tr><td>
217 <?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>
218 <?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>
219 <?php xl('Gender','e')?> :<SELECT NAME="gender">
220 <?php
221 foreach ($gender as $value) {
222 echo ("<option>$value</option>");
225 </SELECT></td>
226 </tr><tr><td>
227 <!-- later gator
228 <br>Insurance: <SELECT multiple NAME="insurance" Rows="10" cols="20">
230 </SELECT>
232 <?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')"
233 title="<?php xl('Click here to choose a date','e')?>"
234 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0' ></a></td><td>
236 <?php xl('And','e')?> : <INPUT TYPE='text' size='12' NAME='app_e'> <a href="javascript:show_calendar('select_form.app_e')"
237 title="<?php xl('Click here to choose a date','e')?>"
238 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0' ></a></td>
239 </tr><tr><td>
241 <?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')"
242 title="<?php xl('Click here to choose a date','e')?>"
243 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a></td>
244 <td>&nbsp;</td>
245 </tr><tr><td>
247 <?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')"
248 title="<?php xl('Click here to choose a date','e')?>"
249 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a></td>
250 <td>&nbsp;</td>
251 </tr><tr><td>
252 <?php xl('Sort by','e')?> :</td><td><SELECT NAME="sort_by">
253 <?php
254 foreach ($sort_by as $key => $value) {
255 echo ("<option value=\"".$value."\">$key</option>");
258 </SELECT></td>
259 <td>&nbsp;</td><td>&nbsp;</td>
260 </tr><tr><td colspan='3'>
261 (<?php xl('Fill here only if sending email notification to patients','e')?>)</td>
262 <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
263 </tr><tr><td>
264 <?php xl('Email Sender','e')?> :</td><td><INPUT TYPE="text" NAME="email_sender" value="your@example.com"></td>
265 <td>&nbsp;</td><td>&nbsp;</td>
266 </tr><tr><td>
267 <?php xl('Email Subject','e')?>:</td><td><INPUT TYPE="text" NAME="email_subject" value="From your clinic"></td>
268 <td>&nbsp;</td><td>&nbsp;</td>
269 </tr><tr><td colspan='3'>
270 <?php echo xlt('Email Text, Usable Tag: ***NAME*** , i.e. Dear ***NAME***{{Do Not translate the ***NAME*** elements of this constant.}}')?></td>
271 <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
272 <tr><td colspan='4'>
273 <TEXTAREA NAME="email_body" ROWS="8" COLS="40"></TEXTAREA></td>
274 <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
275 </tr><tr><td>
277 <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>
278 </table>
279 </div>
280 </div>
281 </FORM>