migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / reports / edi_270.php
bloba3e147708e465a3761cda97bc8acde66323f8fc8
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 include_once("$srcdir/calendar.inc");
42 include_once("$srcdir/edi.inc");
44 // Element data seperator
45 $eleDataSep = "*";
47 // Segment Terminator
48 $segTer = "~";
50 // Component Element seperator
51 $compEleSep = ":";
53 // filter conditions for the report and batch creation
55 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
56 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
57 $form_facility = $_POST['form_facility'] ? $_POST['form_facility'] : '';
58 $form_provider = $_POST['form_users'] ? $_POST['form_users'] : '';
59 $exclude_policy = $_POST['removedrows'] ? $_POST['removedrows'] : '';
60 $X12info = $_POST['form_x12'] ? explode("|",$_POST['form_x12']) : '';
62 //Set up the sql variable binding array (this prevents sql-injection attacks)
63 $sqlBindArray = array();
65 $where = "e.pc_pid IS NOT NULL AND e.pc_eventDate >= ?";
66 array_push($sqlBindArray, $from_date);
68 //$where .="and e.pc_eventDate = (select max(pc_eventDate) from openemr_postcalendar_events where pc_aid = d.id)";
70 if ($to_date) {
71 $where .= " AND e.pc_eventDate <= ?";
72 array_push($sqlBindArray, $to_date);
75 if($form_facility != "") {
76 $where .= " AND f.id = ? ";
77 array_push($sqlBindArray, $form_facility);
80 if($form_provider != "") {
81 $where .= " AND d.id = ? ";
82 array_push($sqlBindArray, $form_provider);
85 if($exclude_policy != ""){ $arrayExplode = explode(",", $exclude_policy);
86 array_walk($arrayExplode, 'arrFormated');
87 $exclude_policy = implode(",",$arrayExplode);
88 $where .= " AND i.policy_number not in (".stripslashes($exclude_policy).")";
91 $where .= " AND (i.policy_number is not null and i.policy_number != '')";
93 $query = sprintf(" SELECT DATE_FORMAT(e.pc_eventDate, '%%Y%%m%%d') as pc_eventDate,
94 e.pc_facility,
95 p.lname,
96 p.fname,
97 p.mname,
98 DATE_FORMAT(p.dob, '%%Y%%m%%d') as dob,
99 p.ss,
100 p.sex,
101 p.pid,
102 p.pubpid,
103 i.policy_number,
104 i.provider as payer_id,
105 i.subscriber_relationship,
106 i.subscriber_lname,
107 i.subscriber_fname,
108 i.subscriber_mname,
109 DATE_FORMAT(i.subscriber_dob, '%%m/%%d/%%Y') as subscriber_dob,
110 i.subscriber_ss,
111 i.subscriber_sex,
112 DATE_FORMAT(i.date,'%%Y%%m%%d') as date,
113 d.lname as provider_lname,
114 d.fname as provider_fname,
115 d.npi as provider_npi,
116 d.upin as provider_pin,
117 f.federal_ein as federal_ein,
118 f.facility_npi as facility_npi,
119 f.name as facility_name,
120 c.name as payer_name
121 FROM openemr_postcalendar_events AS e
122 LEFT JOIN users AS d on (e.pc_aid is not null and e.pc_aid = d.id)
123 LEFT JOIN facility AS f on (f.id = e.pc_facility)
124 LEFT JOIN patient_data AS p ON p.pid = e.pc_pid
125 LEFT JOIN insurance_data AS i ON (i.id =(
126 SELECT id
127 FROM insurance_data AS i
128 WHERE pid = p.pid AND type = 'primary'
129 ORDER BY date DESC
130 LIMIT 1
133 LEFT JOIN insurance_companies as c ON (c.id = i.provider)
134 WHERE %s ", $where );
136 // Run the query
137 $res = sqlStatement($query, $sqlBindArray);
139 // Get the facilities information
140 $facilities = getUserFacilities($_SESSION['authId']);
142 // Get the Providers information
143 $providers = getUsernames();
145 //Get the x12 partners information
146 $clearinghouses = getX12Partner();
149 if (isset($_POST['form_savefile']) && !empty($_POST['form_savefile']) && $res) {
150 header('Content-Type: text/plain');
151 header(sprintf('Content-Disposition: attachment; filename="elig-270..%s.%s.txt"',
152 $from_date,
153 $to_date
155 print_elig($res,$X12info,$segTer,$compEleSep);
156 exit;
160 <html>
162 <head>
164 <?php html_header_show();?>
166 <title><?php echo htmlspecialchars( xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES); ?></title>
168 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
170 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
172 <style type="text/css">
174 /* specifically include & exclude from printing */
175 @media print {
176 #report_parameters {
177 visibility: hidden;
178 display: none;
180 #report_parameters_daterange {
181 visibility: visible;
182 display: inline;
184 #report_results table {
185 margin-top: 0px;
189 /* specifically exclude some from the screen */
190 @media screen {
191 #report_parameters_daterange {
192 visibility: hidden;
193 display: none;
197 </style>
199 <script type="text/javascript" src="../../library/textformat.js"></script>
200 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
201 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
202 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
203 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
204 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script>
206 <script type="text/javascript">
208 var mypcc = "<?php echo htmlspecialchars( $GLOBALS['phone_country_code'], ENT_QUOTES); ?>";
209 var stringDelete = "<?php echo htmlspecialchars( xl('Do you want to remove this record?'), ENT_QUOTES); ?>?";
210 var stringBatch = "<?php echo htmlspecialchars( xl('Please select X12 partner, required to create the 270 batch'), ENT_QUOTES); ?>";
212 // for form refresh
214 function refreshme() {
215 document.forms[0].submit();
218 // To delete the row from the reports section
219 function deletetherow(id){
220 var suredelete = confirm(stringDelete);
221 if(suredelete == true){
222 document.getElementById('PR'+id).style.display="none";
223 if(document.getElementById('removedrows').value == ""){
224 document.getElementById('removedrows').value = "'" + id + "'";
225 }else{
226 document.getElementById('removedrows').value = document.getElementById('removedrows').value + ",'" + id + "'";
233 // To validate the batch file generation - for the required field [clearing house/x12 partner]
234 function validate_batch()
236 if(document.getElementById('form_x12').value=='')
238 alert(stringBatch);
239 return false;
241 else
243 document.getElementById('form_savefile').value = "true";
244 document.theform.submit();
251 // To Clear the hidden input field
253 function validate_policy()
255 document.getElementById('removedrows').value = "";
256 document.getElementById('form_savefile').value = "";
257 return true;
260 // To toggle the clearing house empty validation message
261 function toggleMessage(id,x12){
263 var spanstyle = new String();
265 spanstyle = document.getElementById(id).style.visibility;
266 selectoption = document.getElementById(x12).value;
268 if(selectoption != '')
270 document.getElementById(id).style.visibility = "hidden";
272 else
274 document.getElementById(id).style.visibility = "visible";
275 document.getElementById(id).style.display = "inline";
277 return true;
281 </script>
283 </head>
284 <body class="body_top">
286 <!-- Required for the popup date selectors -->
287 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
289 <span class='title'><?php echo htmlspecialchars( xl('Report'), ENT_NOQUOTES); ?> - <?php echo htmlspecialchars( xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES); ?></span>
291 <div id="report_parameters_daterange">
292 <?php echo htmlspecialchars( date("d F Y", strtotime($form_from_date)), ENT_NOQUOTES) .
293 " &nbsp; " . htmlspecialchars( xl('to'), ENT_NOQUOTES) .
294 "&nbsp; ". htmlspecialchars( date("d F Y", strtotime($form_to_date)), ENT_NOQUOTES); ?>
295 </div>
297 <form method='post' name='theform' id='theform' action='edi_270.php' onsubmit="return top.restoreSession()">
298 <input type="hidden" name="removedrows" id="removedrows" value="">
299 <div id="report_parameters">
300 <table>
301 <tr>
302 <td width='550px'>
303 <div style='float:left'>
304 <table class='text'>
305 <tr>
306 <td class='label'>
307 <?php xl('From','e'); ?>:
308 </td>
309 <td>
310 <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'>
311 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
312 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
313 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
314 </td>
315 <td class='label'>
316 <?php echo htmlspecialchars( xl('To'), ENT_NOQUOTES); ?>:
317 </td>
318 <td>
319 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo htmlspecialchars( $to_date, ENT_QUOTES) ?>'
320 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
321 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
322 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
323 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
324 </td>
325 <td>&nbsp;</td>
326 </tr>
328 <tr>
329 <td class='label'>
330 <?php echo htmlspecialchars( xl('Facility'), ENT_NOQUOTES); ?>:
331 </td>
332 <td>
333 <?php dropdown_facility($form_facility,'form_facility',false); ?>
334 </td>
335 <td class='label'>
336 <?php echo htmlspecialchars( xl('Provider'), ENT_NOQUOTES); ?>:
337 </td>
338 <td>
339 <select name='form_users' onchange='form.submit();'>
340 <option value=''>-- <?php echo htmlspecialchars( xl('All'), ENT_NOQUOTES); ?> --</option>
341 <?php foreach($providers as $user): ?>
342 <option value='<?php echo htmlspecialchars( $user['id'], ENT_QUOTES); ?>'
343 <?php echo $form_provider == $user['id'] ? " selected " : null; ?>
344 ><?php echo htmlspecialchars( $user['fname']." ".$user['lname'], ENT_NOQUOTES); ?></option>
345 <?php endforeach; ?>
346 </select>
347 </td>
348 <td>&nbsp;
349 </td>
350 </tr>
352 <tr>
353 <td class='label'>
354 <?php echo htmlspecialchars( xl('X12 Partner'), ENT_NOQUOTES); ?>:
355 </td>
356 <td colspan='5'>
357 <select name='form_x12' id='form_x12' onchange='return toggleMessage("emptyVald","form_x12");' >
358 <option value=''>--<?php echo htmlspecialchars( xl('select'), ENT_NOQUOTES); ?>--</option>
359 <?php
360 if(isset($clearinghouses) && !empty($clearinghouses))
362 foreach($clearinghouses as $clearinghouse): ?>
363 <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); ?>'
364 <?php echo $clearinghouse['id'] == $X12info[0] ? " selected " : null; ?>
365 ><?php echo htmlspecialchars( $clearinghouse['name'], ENT_NOQUOTES); ?></option>
366 <?php endforeach;
370 </select>
371 <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>
372 </td>
373 </tr>
374 </table>
375 </div>
376 </td>
377 <td align='left' valign='middle' height="100%">
378 <table style='border-left:1px solid; width:100%; height:100%' >
379 <tr>
380 <td>
381 <div style='margin-left:15px'>
382 <a href='#' class='css_button' onclick='validate_policy(); $("#theform").submit();'>
383 <span>
384 <?php echo htmlspecialchars( xl('Refresh'), ENT_NOQUOTES); ?>
385 </span>
386 </a>
388 <a href='#' class='css_button' onclick='return validate_batch();'>
389 <span>
390 <?php echo htmlspecialchars( xl('Create batch'), ENT_NOQUOTES); ?>
391 <input type='hidden' name='form_savefile' id='form_savefile' value=''></input>
392 </span>
393 </a>
395 </div>
396 </td>
397 </tr>
398 </table>
399 </td>
400 </tr>
401 </table>
402 </div>
404 <div class='text'>
405 <?php echo htmlspecialchars( xl('Please choose date range criteria above, and click Refresh to view results.'), ENT_NOQUOTES); ?>
406 </div>
408 </form>
410 <?php
411 if ($res){
412 show_elig($res,$X12info,$segTer,$compEleSep);
415 </body>
417 <script language='JavaScript'>
418 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
419 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
420 <?php if ($alertmsg) { echo " alert('$alertmsg');\n"; } ?>
421 </script>
423 </html>