Support for larger size codes (such as SNOMED US Extension codes)
[openemr.git] / interface / batchcom / batchcom.php
blob450d09add9ae1d20a502c07073fb7ea6fc88e831
1 <?php
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");
9 // gacl control
10 $thisauth = acl_check('admin', 'batchcom');
12 if (!$thisauth) {
13 echo "<html>\n<body>\n";
14 echo "<p>".xl('You are not authorized for this.','','','</p>')."\n";
15 echo "</body>\n</html>\n";
16 exit();
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' );
25 // process form
26 if ($_POST['form_action']=='Process') {
27 //validation uses the functions in batchcom.inc.php
28 //validate dates
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>');
33 // validate numbers
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>');
41 // validates and or
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>');
47 //process sql
48 if (!$form_err) {
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";
52 //appointment dates
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']."'";
61 $sql.=$sql_where_a;
63 // encounter dates
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']."' " ;
73 // age
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']."' ";
83 // gender
84 if ($_POST['gender']!='Any') {
85 $and=where_or_and ($and);
86 $sql.=" $and patient_data.sex='".$_POST['gender']."' ";
89 // hipaa overwrite
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 ";
99 break;
100 endswitch;
102 // sort by
103 $sql.=' ORDER BY '.$_POST['sort_by'];
104 //echo $sql;
105 // send query for results.
106 $res = sqlStatement($sql);
108 // if no results.
109 if (mysql_num_rows($res)==0){
111 <html>
112 <head>
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>
118 </head>
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>
124 <br><br>
125 <div class="text">
126 <?php
127 echo (xl('No results found, please try again.','','<br>'));
128 ?> </div></body></html> <?php
129 //if results
130 } else {
131 switch ($_POST['process_type']):
132 case $choices[0]: // CSV File
133 require_once ('batchCSV.php');
134 break;
135 case $choices[1]: // Email
136 require_once ('batchEmail.php');
137 break;
138 case $choices[2]: // Phone list
139 require_once ('batchPhoneList.php');
140 break;
141 endswitch;
143 // end results
145 exit ();
149 //START OUT OUR PAGE....
151 <html>
152 <head>
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>
160 </head>
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>
166 <br><br>
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="">
171 <div class="text">
172 <div class="main_box">
173 <table class="table" ><tr><td >
174 <?php
175 if ($form_err) {
176 echo (xl('The following errors occurred')."<br>$form_err<br><br>");
179 xl('Process','e')?>:</td><td><SELECT NAME="process_type">
180 <?php
181 foreach ($choices as $value) {
182 echo ("<option>$value</option>");
185 </SELECT></td>
186 <td>&nbsp;</td><td>&nbsp;</td>
187 </tr><tr><td >
189 <?php xl('Overwrite HIPAA choice','e')?> :</td><td align='left'><SELECT NAME="hipaa_choice">
190 <?php
191 foreach ($hipaa as $value) {
192 echo ("<option>$value</option>");
195 </SELECT></td>
196 <td>&nbsp;</td><td>&nbsp;</td>
197 </tr><tr><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">
201 <?php
202 foreach ($gender as $value) {
203 echo ("<option>$value</option>");
206 </SELECT></td>
207 </tr><tr><td>
208 <!-- later gator
209 <br>Insurance: <SELECT multiple NAME="insurance" Rows="10" cols="20">
211 </SELECT>
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>
220 </tr><tr><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>
225 <td>&nbsp;</td>
226 </tr><tr><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>
231 <td>&nbsp;</td>
232 </tr><tr><td>
233 <?php xl('Sort by','e')?> :</td><td><SELECT NAME="sort_by">
234 <?php
235 foreach ($sort_by as $key => $value) {
236 echo ("<option value=\"".$value."\">$key</option>");
239 </SELECT></td>
240 <td>&nbsp;</td><td>&nbsp;</td>
241 </tr><tr><td colspan='3'>
242 (<?php xl('Fill here only if sending email notification to patients','e')?>)</td>
243 <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
244 </tr><tr><td>
245 <?php xl('Email Sender','e')?> :</td><td><INPUT TYPE="text" NAME="email_sender" value="your@example.com"></td>
246 <td>&nbsp;</td><td>&nbsp;</td>
247 </tr><tr><td>
248 <?php xl('Email Subject','e')?>:</td><td><INPUT TYPE="text" NAME="email_subject" value="From your clinic"></td>
249 <td>&nbsp;</td><td>&nbsp;</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>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
253 <tr><td colspan='4'>
254 <TEXTAREA NAME="email_body" ROWS="8" COLS="40"></TEXTAREA></td>
255 <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
256 </tr><tr><td>
258 <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>
259 </table>
260 </div>
261 </div>
262 </FORM>