2 //INCLUDES, DO ANY ACTIONS, THEN GET OUR DATA
3 include_once("../globals.php");
4 include_once("$srcdir/registry.inc");
5 include_once("$srcdir/sql.inc");
6 include_once("../../library/acl.inc");
7 include_once("batchcom.inc.php");
10 $thisauth = acl_check('admin', 'batchcom');
13 echo "<html>\n<body>\n";
14 echo "<p>".xl('You are not authorized for this.','','','</p>')."\n";
15 echo "</body>\n</html>\n";
19 // menu arrays (done this way so it's easier to validate input on validate selections)
20 $choices=Array (xl('CSV File'),xl('Email'),xl('Phone call list'));
21 $gender=Array (xl('Any'),xl('Male'),xl('Female'));
22 $hipaa=Array (xl('NO'),xl('YES'));
23 $sort_by=Array (xl('Zip Code')=>'patient_data.postal_code',xl('Last Name')=>'patient_data.lname',xl('Appointment Date')=>'last_ap' );
26 if ($_POST['form_action']=='Process') {
27 //validation uses the functions in batchcom.inc.php
29 if (!check_date_format($_POST['app_s'])) $form_err.=xl('Date format for "appointment start" is not valid','','<br>');
30 if (!check_date_format($_POST['app_e'])) $form_err.=xl('Date format for "appointment end" is not valid','','<br>');
31 if (!check_date_format($_POST['seen_since'])) $form_err.=xl('Date format for "seen since" is not valid','','<br>');
32 if (!check_date_format($_POST['not_seen_since'])) $form_err.=xl('Date format for "not seen since" is not valid','','<br>');
34 if (!check_age($_POST['age_from'])) $form_err.=xl('Age format for "age from" is not valid','','<br>');
35 if (!check_age($_POST['age_upto'])) $form_err.=xl('Age format for "age up to" is not valid','','<br>');
36 // validate selections
37 if (!check_select($_POST['gender'],$gender)) $form_err.=xl('Error in "Gender" selection','','<br>');
38 if (!check_select($_POST['process_type'],$choices)) $form_err.=xl('Error in "Process" selection','','<br>');
39 if (!check_select($_POST['hipaa_choice'],$hipaa)) $form_err.=xl('Error in "HIPAA" selection','','<br>');
40 if (!check_select($_POST['sort_by'],$sort_by)) $form_err.=xl('Error in "Sort By" selection','','<br>');
42 if (!check_yes_no ($_POST['and_or_gender'])) $form_err.=xl('Error in YES or NO option','','<br>');
43 if (!check_yes_no ($_POST['and_or_app_within'])) $form_err.=xl('Error in YES or NO option','','<br>');
44 if (!check_yes_no ($_POST['and_or_seen_since'])) $form_err.=xl('Error in YES or NO option','','<br>');
45 if (!check_yes_no ($_POST['and_or_not_seen_since'])) $form_err.=xl('Error in YES or NO option','','<br>');
51 $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";
53 if ($_POST['app_s']!=0 AND $_POST['app_s']!='') {
54 $and=where_or_and ($and);
55 $sql_where_a=" $and cal_events.pc_eventDate > '".$_POST['app_s']."'";
57 if ($_POST['app_e']!=0 AND $_POST['app_e']!='') {
58 $and=where_or_and ($and);
59 $sql_where_a.=" $and cal_events.pc_endDate < '".$_POST['app_e']."'";
64 if ($_POST['seen_since']!=0 AND $_POST['seen_since']!='') {
65 $and=where_or_and ($and);
66 $sql.=" $and forms.date > '".$_POST['seen_since']."' " ;
68 if ($_POST['seen_upto']!=0 AND $_POST['not_seen_since']!='') {
69 $and=where_or_and ($and);
70 $sql.=" $and forms.date > '".$_POST['seen_since']."' " ;
74 if ($_POST['age_from']!=0 AND $_POST['age_from']!='') {
75 $and=where_or_and ($and);
76 $sql.=" $and DATEDIFF( CURDATE( ), patient_data.DOB )/ 365.25 >= '".$_POST['age_from']."' ";
78 if ($_POST['age_upto']!=0 AND $_POST['age_upto']!='') {
79 $and=where_or_and ($and);
80 $sql.=" $and DATEDIFF( CURDATE( ), patient_data.DOB )/ 365.25 <= '".$_POST['age_upto']."' ";
84 if ($_POST['gender']!='Any') {
85 $and=where_or_and ($and);
86 $sql.=" $and patient_data.sex='".$_POST['gender']."' ";
90 if ($_POST['hipaa_choice']!='NO') {
91 $and=where_or_and ($and);
92 $sql.=" $and patient_data.hipaa_mail='YES' ";
95 switch ($_POST['process_type']):
96 case $choices[1]: // Email
97 $and=where_or_and ($and);
98 $sql.=" $and patient_data.email IS NOT NULL ";
103 $sql.=' ORDER BY '.$_POST['sort_by'];
105 // send query for results.
106 $res = sqlStatement($sql);
109 if (mysql_num_rows($res)==0){
113 <?php
html_header_show();?
>
114 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
115 <link rel
="stylesheet" href
="batchcom.css" type
="text/css">
116 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
117 <script type
="text/javascript" src
="../../library/calendar.js"></script
>
119 <body
class="body_top">
120 <!-- larry
's sms/email notification -->
121 <span class="title"><?php include_once("batch_navigation.php");?></span>
122 <!--- end of larry's insert
-->
123 <span
class="title"><?php
xl('Batch Communication Tool','e')?
></span
>
127 echo (xl('No results found, please try again.','','<br>'));
128 ?
> </div
></body
></html
> <?php
131 switch ($_POST['process_type']):
132 case $choices[0]: // CSV File
133 require_once ('batchCSV.php');
135 case $choices[1]: // Email
136 require_once ('batchEmail.php');
138 case $choices[2]: // Phone list
139 require_once ('batchPhoneList.php');
149 //START OUT OUR PAGE....
153 <?php
html_header_show();?
>
154 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
155 <link rel
="stylesheet" href
="batchcom.css" type
="text/css">
156 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
157 <script type
="text/javascript" src
="../../library/calendar.js"></script
>
161 <body
class="body_top">
162 <!-- larry
's sms/email notification -->
163 <span class="title"><?php include_once("batch_navigation.php");?></span>
164 <!--- end of larry's insert
-->
165 <span
class="title"><?php
xl('Batch Communication Tool','e')?
></span
>
168 <!-- for the popup date selector
-->
169 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
170 <FORM name
="select_form" METHOD
=POST ACTION
="">
172 <div
class="main_box">
173 <table
class="table" ><tr
><td
>
176 echo (xl('The following errors occurred')."<br>$form_err<br><br>");
179 xl('Process','e')?
>:</td
><td
><SELECT NAME
="process_type">
181 foreach ($choices as $value) {
182 echo ("<option>$value</option>");
186 <td
> 
;</td
><td
> 
;</td
>
189 <?php
xl('Overwrite HIPAA choice','e')?
> :</td
><td align
='left'><SELECT NAME
="hipaa_choice">
191 foreach ($hipaa as $value) {
192 echo ("<option>$value</option>");
196 <td
> 
;</td
><td
> 
;</td
>
198 <?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
>
199 <?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
>
200 <?php
xl('Gender','e')?
> :<SELECT NAME
="gender">
202 foreach ($gender as $value) {
203 echo ("<option>$value</option>");
209 <br
>Insurance
: <SELECT multiple NAME
="insurance" Rows
="10" cols
="20">
213 <?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')"
214 title
="<?php xl('Click here to choose a date','e')?>"
215 ><img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22' border
='0' ></a
></td
><td
>
217 <?php
xl('And','e')?
> : <INPUT TYPE
='text' size
='12' NAME
='app_e'> <a href
="javascript:show_calendar('select_form.app_e')"
218 title
="<?php xl('Click here to choose a date','e')?>"
219 ><img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22' border
='0' ></a
></td
>
222 <?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')"
223 title
="<?php xl('Click here to choose a date','e')?>"
224 ><img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22' border
='0'></a
></td
>
228 <?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')"
229 title
="<?php xl('Click here to choose a date','e')?>"
230 ><img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22' border
='0'></a
></td
>
233 <?php
xl('Sort by','e')?
> :</td
><td
><SELECT NAME
="sort_by">
235 foreach ($sort_by as $key => $value) {
236 echo ("<option value=\"".$value."\">$key</option>");
240 <td
> 
;</td
><td
> 
;</td
>
241 </tr
><tr
><td colspan
='3'>
242 (<?php
xl('Fill here only if sending email notification to patients','e')?
>)</td
>
243 <td
> 
;</td
><td
> 
;</td
><td
> 
;</td
>
245 <?php
xl('Email Sender','e')?
> :</td
><td
><INPUT TYPE
="text" NAME
="email_sender" value
="your@example.com"></td
>
246 <td
> 
;</td
><td
> 
;</td
>
248 <?php
xl('Email Subject','e')?
>:</td
><td
><INPUT TYPE
="text" NAME
="email_subject" value
="From your clinic"></td
>
249 <td
> 
;</td
><td
> 
;</td
>
250 </tr
><tr
><td colspan
='3'>
251 <?php
echo xlt('Email Text, Usable Tag: ***NAME*** , i.e. Dear ***NAME***{{Do Not translate the ***NAME*** elements of this constant.}}')?
></td
>
252 <td
> 
;</td
><td
> 
;</td
><td
> 
;</td
></tr
>
254 <TEXTAREA NAME
="email_body" ROWS
="8" COLS
="40"></TEXTAREA
></td
>
255 <td
> 
;</td
><td
> 
;</td
><td
> 
;</td
>
258 <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
>