added cache clearing support for dialog.js (#411)
[openemr.git] / interface / reports / edi_270.php
blob77b36754a7b561bc2dc4ee4a18cc7a2a5b25e238
1 <?php
2 /*
3 * main file for the 270 batch creation.
4 * This report is the batch report required for batch eligibility verification.
6 * This program creates the batch for the x12 270 eligibility file
8 * Copyright (C) 2016 Terry Hill <terry@lillysystems.com>
9 * Copyright (C) 2010 MMF Systems, Inc
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see http://opensource.org/licenses/gpl-license.php.
22 * @package OpenEMR
23 * @author Terry Hill <terry@lilysystems.com>
24 * @link http://www.open-emr.org
27 //SANITIZE ALL ESCAPES
28 $sanitize_all_escapes=true;
31 //STOP FAKE REGISTER GLOBALS
32 $fake_register_globals=false;
35 require_once("../globals.php");
36 require_once("$srcdir/forms.inc");
37 require_once("$srcdir/billing.inc");
38 require_once("$srcdir/patient.inc");
39 require_once("$srcdir/formatting.inc.php");
40 require_once "$srcdir/options.inc.php";
41 require_once "$srcdir/formdata.inc.php";
42 include_once("$srcdir/calendar.inc");
43 include_once("$srcdir/edi.inc");
45 // Element data seperator
46 $eleDataSep = "*";
48 // Segment Terminator
49 $segTer = "~";
51 // Component Element seperator
52 $compEleSep = ":";
54 // filter conditions for the report and batch creation
56 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
57 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
58 $form_facility = $_POST['form_facility'] ? $_POST['form_facility'] : '';
59 $form_provider = $_POST['form_users'] ? $_POST['form_users'] : '';
60 $exclude_policy = $_POST['removedrows'] ? $_POST['removedrows'] : '';
61 $X12info = $_POST['form_x12'] ? explode("|",$_POST['form_x12']) : '';
63 //Set up the sql variable binding array (this prevents sql-injection attacks)
64 $sqlBindArray = array();
66 $where = "e.pc_pid IS NOT NULL AND e.pc_eventDate >= ?";
67 array_push($sqlBindArray, $from_date);
69 //$where .="and e.pc_eventDate = (select max(pc_eventDate) from openemr_postcalendar_events where pc_aid = d.id)";
71 if ($to_date) {
72 $where .= " AND e.pc_eventDate <= ?";
73 array_push($sqlBindArray, $to_date);
76 if($form_facility != "") {
77 $where .= " AND f.id = ? ";
78 array_push($sqlBindArray, $form_facility);
81 if($form_provider != "") {
82 $where .= " AND d.id = ? ";
83 array_push($sqlBindArray, $form_provider);
86 if($exclude_policy != ""){ $arrayExplode = explode(",", $exclude_policy);
87 array_walk($arrayExplode, 'arrFormated');
88 $exclude_policy = implode(",",$arrayExplode);
89 $where .= " AND i.policy_number not in (".stripslashes($exclude_policy).")";
92 $where .= " AND (i.policy_number is not null and i.policy_number != '')";
94 $query = sprintf(" SELECT DATE_FORMAT(e.pc_eventDate, '%%Y%%m%%d') as pc_eventDate,
95 e.pc_facility,
96 p.lname,
97 p.fname,
98 p.mname,
99 DATE_FORMAT(p.dob, '%%Y%%m%%d') as dob,
100 p.ss,
101 p.sex,
102 p.pid,
103 p.pubpid,
104 i.policy_number,
105 i.provider as payer_id,
106 i.subscriber_relationship,
107 i.subscriber_lname,
108 i.subscriber_fname,
109 i.subscriber_mname,
110 DATE_FORMAT(i.subscriber_dob, '%%m/%%d/%%Y') as subscriber_dob,
111 i.subscriber_ss,
112 i.subscriber_sex,
113 DATE_FORMAT(i.date,'%%Y%%m%%d') as date,
114 d.lname as provider_lname,
115 d.fname as provider_fname,
116 d.npi as provider_npi,
117 d.upin as provider_pin,
118 f.federal_ein as federal_ein,
119 f.facility_npi as facility_npi,
120 f.name as facility_name,
121 c.name as payer_name
122 FROM openemr_postcalendar_events AS e
123 LEFT JOIN users AS d on (e.pc_aid is not null and e.pc_aid = d.id)
124 LEFT JOIN facility AS f on (f.id = e.pc_facility)
125 LEFT JOIN patient_data AS p ON p.pid = e.pc_pid
126 LEFT JOIN insurance_data AS i ON (i.id =(
127 SELECT id
128 FROM insurance_data AS i
129 WHERE pid = p.pid AND type = 'primary'
130 ORDER BY date DESC
131 LIMIT 1
134 LEFT JOIN insurance_companies as c ON (c.id = i.provider)
135 WHERE %s ", $where );
137 // Run the query
138 $res = sqlStatement($query, $sqlBindArray);
140 // Get the facilities information
141 $facilities = getUserFacilities($_SESSION['authId']);
143 // Get the Providers information
144 $providers = getUsernames();
146 //Get the x12 partners information
147 $clearinghouses = getX12Partner();
150 if (isset($_POST['form_savefile']) && !empty($_POST['form_savefile']) && $res) {
151 header('Content-Type: text/plain');
152 header(sprintf('Content-Disposition: attachment; filename="elig-270..%s.%s.txt"',
153 $from_date,
154 $to_date
156 print_elig($res,$X12info,$segTer,$compEleSep);
157 exit;
161 <html>
163 <head>
165 <?php html_header_show();?>
167 <title><?php echo htmlspecialchars( xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES); ?></title>
169 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
171 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
173 <style type="text/css">
175 /* specifically include & exclude from printing */
176 @media print {
177 #report_parameters {
178 visibility: hidden;
179 display: none;
181 #report_parameters_daterange {
182 visibility: visible;
183 display: inline;
185 #report_results table {
186 margin-top: 0px;
190 /* specifically exclude some from the screen */
191 @media screen {
192 #report_parameters_daterange {
193 visibility: hidden;
194 display: none;
198 </style>
200 <script type="text/javascript" src="../../library/textformat.js"></script>
201 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
202 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
203 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
204 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
205 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script>
207 <script type="text/javascript">
209 var mypcc = "<?php echo htmlspecialchars( $GLOBALS['phone_country_code'], ENT_QUOTES); ?>";
210 var stringDelete = "<?php echo htmlspecialchars( xl('Do you want to remove this record?'), ENT_QUOTES); ?>?";
211 var stringBatch = "<?php echo htmlspecialchars( xl('Please select X12 partner, required to create the 270 batch'), ENT_QUOTES); ?>";
213 // for form refresh
215 function refreshme() {
216 document.forms[0].submit();
219 // To delete the row from the reports section
220 function deletetherow(id){
221 var suredelete = confirm(stringDelete);
222 if(suredelete == true){
223 document.getElementById('PR'+id).style.display="none";
224 if(document.getElementById('removedrows').value == ""){
225 document.getElementById('removedrows').value = "'" + id + "'";
226 }else{
227 document.getElementById('removedrows').value = document.getElementById('removedrows').value + ",'" + id + "'";
234 // To validate the batch file generation - for the required field [clearing house/x12 partner]
235 function validate_batch()
237 if(document.getElementById('form_x12').value=='')
239 alert(stringBatch);
240 return false;
242 else
244 document.getElementById('form_savefile').value = "true";
245 document.theform.submit();
252 // To Clear the hidden input field
254 function validate_policy()
256 document.getElementById('removedrows').value = "";
257 document.getElementById('form_savefile').value = "";
258 return true;
261 // To toggle the clearing house empty validation message
262 function toggleMessage(id,x12){
264 var spanstyle = new String();
266 spanstyle = document.getElementById(id).style.visibility;
267 selectoption = document.getElementById(x12).value;
269 if(selectoption != '')
271 document.getElementById(id).style.visibility = "hidden";
273 else
275 document.getElementById(id).style.visibility = "visible";
276 document.getElementById(id).style.display = "inline";
278 return true;
282 </script>
284 </head>
285 <body class="body_top">
287 <!-- Required for the popup date selectors -->
288 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
290 <span class='title'><?php echo htmlspecialchars( xl('Report'), ENT_NOQUOTES); ?> - <?php echo htmlspecialchars( xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES); ?></span>
292 <div id="report_parameters_daterange">
293 <?php echo htmlspecialchars( date("d F Y", strtotime($form_from_date)), ENT_NOQUOTES) .
294 " &nbsp; " . htmlspecialchars( xl('to'), ENT_NOQUOTES) .
295 "&nbsp; ". htmlspecialchars( date("d F Y", strtotime($form_to_date)), ENT_NOQUOTES); ?>
296 </div>
298 <form method='post' name='theform' id='theform' action='edi_270.php' onsubmit="return top.restoreSession()">
299 <input type="hidden" name="removedrows" id="removedrows" value="">
300 <div id="report_parameters">
301 <table>
302 <tr>
303 <td width='550px'>
304 <div style='float:left'>
305 <table class='text'>
306 <tr>
307 <td class='label'>
308 <?php xl('From','e'); ?>:
309 </td>
310 <td>
311 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo htmlspecialchars( $from_date, ENT_QUOTES) ?>' onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
312 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
313 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
314 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
315 </td>
316 <td class='label'>
317 <?php echo htmlspecialchars( xl('To'), ENT_NOQUOTES); ?>:
318 </td>
319 <td>
320 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo htmlspecialchars( $to_date, ENT_QUOTES) ?>'
321 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
322 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
323 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
324 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
325 </td>
326 <td>&nbsp;</td>
327 </tr>
329 <tr>
330 <td class='label'>
331 <?php echo htmlspecialchars( xl('Facility'), ENT_NOQUOTES); ?>:
332 </td>
333 <td>
334 <?php dropdown_facility($form_facility,'form_facility',false); ?>
335 </td>
336 <td class='label'>
337 <?php echo htmlspecialchars( xl('Provider'), ENT_NOQUOTES); ?>:
338 </td>
339 <td>
340 <select name='form_users' onchange='form.submit();'>
341 <option value=''>-- <?php echo htmlspecialchars( xl('All'), ENT_NOQUOTES); ?> --</option>
342 <?php foreach($providers as $user): ?>
343 <option value='<?php echo htmlspecialchars( $user['id'], ENT_QUOTES); ?>'
344 <?php echo $form_provider == $user['id'] ? " selected " : null; ?>
345 ><?php echo htmlspecialchars( $user['fname']." ".$user['lname'], ENT_NOQUOTES); ?></option>
346 <?php endforeach; ?>
347 </select>
348 </td>
349 <td>&nbsp;
350 </td>
351 </tr>
353 <tr>
354 <td class='label'>
355 <?php echo htmlspecialchars( xl('X12 Partner'), ENT_NOQUOTES); ?>:
356 </td>
357 <td colspan='5'>
358 <select name='form_x12' id='form_x12' onchange='return toggleMessage("emptyVald","form_x12");' >
359 <option value=''>--<?php echo htmlspecialchars( xl('select'), ENT_NOQUOTES); ?>--</option>
360 <?php
361 if(isset($clearinghouses) && !empty($clearinghouses))
363 foreach($clearinghouses as $clearinghouse): ?>
364 <option value='<?php echo htmlspecialchars( $clearinghouse['id']."|".$clearinghouse['id_number']."|".$clearinghouse['x12_sender_id']."|".$clearinghouse['x12_receiver_id']."|".$clearinghouse['x12_version']."|".$clearinghouse['processing_format'], ENT_QUOTES); ?>'
365 <?php echo $clearinghouse['id'] == $X12info[0] ? " selected " : null; ?>
366 ><?php echo htmlspecialchars( $clearinghouse['name'], ENT_NOQUOTES); ?></option>
367 <?php endforeach;
371 </select>
372 <span id='emptyVald' style='color:red;font-size:12px;'> * <?php echo htmlspecialchars( xl('Clearing house info required for EDI 270 batch creation.'), ENT_NOQUOTES); ?></span>
373 </td>
374 </tr>
375 </table>
376 </div>
377 </td>
378 <td align='left' valign='middle' height="100%">
379 <table style='border-left:1px solid; width:100%; height:100%' >
380 <tr>
381 <td>
382 <div style='margin-left:15px'>
383 <a href='#' class='css_button' onclick='validate_policy(); $("#theform").submit();'>
384 <span>
385 <?php echo htmlspecialchars( xl('Refresh'), ENT_NOQUOTES); ?>
386 </span>
387 </a>
389 <a href='#' class='css_button' onclick='return validate_batch();'>
390 <span>
391 <?php echo htmlspecialchars( xl('Create batch'), ENT_NOQUOTES); ?>
392 <input type='hidden' name='form_savefile' id='form_savefile' value=''></input>
393 </span>
394 </a>
396 </div>
397 </td>
398 </tr>
399 </table>
400 </td>
401 </tr>
402 </table>
403 </div>
405 <div class='text'>
406 <?php echo htmlspecialchars( xl('Please choose date range criteria above, and click Refresh to view results.'), ENT_NOQUOTES); ?>
407 </div>
409 </form>
411 <?php
412 if ($res){
413 show_elig($res,$X12info,$segTer,$compEleSep);
416 </body>
418 <script language='JavaScript'>
419 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
420 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
421 <?php if ($alertmsg) { echo " alert('$alertmsg');\n"; } ?>
422 </script>
424 </html>