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>;.
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");
29 $thisauth = acl_check('admin', 'batchcom');
32 echo "<html>\n<body>\n";
33 echo "<p>".xl('You are not authorized for this.','','','</p>')."\n";
34 echo "</body>\n</html>\n";
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' );
45 if ($_POST['form_action']=='Process') {
46 //validation uses the functions in batchcom.inc.php
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>');
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>');
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>');
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";
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']."'";
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']."' " ;
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']."' ";
103 if ($_POST['gender']!='Any') {
104 $and=where_or_and ($and);
105 $sql.=" $and patient_data.sex='".$_POST['gender']."' ";
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 ";
122 $sql.=' ORDER BY '.$_POST['sort_by'];
124 // send query for results.
125 $res = sqlStatement($sql);
128 if (sqlNumRows($res)==0){
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
>
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
>
147 echo (xl('No results found, please try again.','','<br>'));
148 ?
> </div
></body
></html
> <?php
151 switch ($_POST['process_type']):
152 case $choices[0]: // CSV File
153 require_once ('batchCSV.php');
155 case $choices[1]: // Email
156 require_once ('batchEmail.php');
158 case $choices[2]: // Phone list
159 require_once ('batchPhoneList.php');
169 //START OUT OUR PAGE....
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
>
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
>
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()'>
193 <div
class="main_box">
194 <table
class="table" ><tr
><td
>
197 echo (xl('The following errors occurred')."<br>$form_err<br><br>");
200 xl('Process','e')?
>:</td
><td
><SELECT NAME
="process_type">
202 foreach ($choices as $value) {
203 echo ("<option>$value</option>");
207 <td
> 
;</td
><td
> 
;</td
>
210 <?php
xl('Overwrite HIPAA choice','e')?
> :</td
><td align
='left'><SELECT NAME
="hipaa_choice">
212 foreach ($hipaa as $value) {
213 echo ("<option>$value</option>");
217 <td
> 
;</td
><td
> 
;</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">
223 foreach ($gender as $value) {
224 echo ("<option>$value</option>");
230 <br
>Insurance
: <SELECT multiple NAME
="insurance" Rows
="10" cols
="20">
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
>
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
>
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
>
254 <?php
xl('Sort by','e')?
> :</td
><td
><SELECT NAME
="sort_by">
256 foreach ($sort_by as $key => $value) {
257 echo ("<option value=\"".$value."\">$key</option>");
261 <td
> 
;</td
><td
> 
;</td
>
262 </tr
><tr
><td colspan
='3'>
263 (<?php
xl('Fill here only if sending email notification to patients','e')?
>)</td
>
264 <td
> 
;</td
><td
> 
;</td
><td
> 
;</td
>
266 <?php
xl('Email Sender','e')?
> :</td
><td
><INPUT TYPE
="text" NAME
="email_sender" value
="your@example.com"></td
>
267 <td
> 
;</td
><td
> 
;</td
>
269 <?php
xl('Email Subject','e')?
>:</td
><td
><INPUT TYPE
="text" NAME
="email_subject" value
="From your clinic"></td
>
270 <td
> 
;</td
><td
> 
;</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
> 
;</td
><td
> 
;</td
><td
> 
;</td
></tr
>
275 <TEXTAREA NAME
="email_body" ROWS
="8" COLS
="40"></TEXTAREA
></td
>
276 <td
> 
;</td
><td
> 
;</td
><td
> 
;</td
>
279 <INPUT TYPE
="submit" name
="form_action" value
=<?php
xl('Process','e','\'','\''); ?
>> </td
><td
><?php
xl('Process takes some time','e')?
></td
> <td
> 
;</td
><td
> 
;</td
></tr
>