change eligibility batch from ssn to policy number, minor fix to filename with extra...
[openemr.git] / interface / reports / edi_270.php
blobe2e6cb666552b27885a00760923a3a9862743262
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 * @package OpenEMR
9 * @link http://www.open-emr.org
10 * @author Terry Hill <terry@lilysystems.com>
11 * @author Brady Miller <brady.g.miller@gmail.com>
12 * @copyright Copyright (c) 2010 MMF Systems, Inc
13 * @copyright Copyright (c) 2016 Terry Hill <terry@lillysystems.com>
14 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
19 require_once("../globals.php");
20 require_once("$srcdir/forms.inc");
21 require_once("$srcdir/billing.inc");
22 require_once("$srcdir/patient.inc");
23 require_once "$srcdir/options.inc.php";
24 require_once("$srcdir/calendar.inc");
25 require_once("$srcdir/edi.inc");
27 use OpenEMR\Core\Header;
29 // Element data seperator
30 $eleDataSep = "*";
32 // Segment Terminator
33 $segTer = "~";
35 // Component Element seperator
36 $compEleSep = ":";
38 // filter conditions for the report and batch creation
40 $from_date = (isset($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-m-d');
41 $to_date = (isset($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
42 $form_facility = $_POST['form_facility'] ? $_POST['form_facility'] : '';
43 $form_provider = $_POST['form_users'] ? $_POST['form_users'] : '';
44 $exclude_policy = $_POST['removedrows'] ? $_POST['removedrows'] : '';
45 $X12info = $_POST['form_x12'] ? explode("|", $_POST['form_x12']) : '';
47 //Set up the sql variable binding array (this prevents sql-injection attacks)
48 $sqlBindArray = array();
50 $where = "e.pc_pid IS NOT NULL AND e.pc_eventDate >= ?";
51 array_push($sqlBindArray, $from_date);
53 //$where .="and e.pc_eventDate = (select max(pc_eventDate) from openemr_postcalendar_events where pc_aid = d.id)";
55 if ($to_date) {
56 $where .= " AND e.pc_eventDate <= ?";
57 array_push($sqlBindArray, $to_date);
60 if ($form_facility != "") {
61 $where .= " AND f.id = ? ";
62 array_push($sqlBindArray, $form_facility);
65 if ($form_provider != "") {
66 $where .= " AND d.id = ? ";
67 array_push($sqlBindArray, $form_provider);
70 if ($exclude_policy != "") {
71 $arrayExplode = explode(",", $exclude_policy);
72 array_walk($arrayExplode, 'arrFormated');
73 $exclude_policy = implode(",", $arrayExplode);
74 $where .= " AND i.policy_number not in (".add_escape_custom($exclude_policy).")";
77 $where .= " AND (i.policy_number is not null and i.policy_number != '')";
79 $query = sprintf(" SELECT DATE_FORMAT(e.pc_eventDate, '%%Y%%m%%d') as pc_eventDate,
80 e.pc_facility,
81 p.lname,
82 p.fname,
83 p.mname,
84 DATE_FORMAT(p.dob, '%%Y%%m%%d') as dob,
85 p.ss,
86 p.sex,
87 p.pid,
88 p.pubpid,
89 i.subscriber_ss,
90 i.policy_number,
91 i.provider as payer_id,
92 i.subscriber_relationship,
93 i.subscriber_lname,
94 i.subscriber_fname,
95 i.subscriber_mname,
96 DATE_FORMAT(i.subscriber_dob, '%%m/%%d/%%Y') as subscriber_dob,
97 i.policy_number,
98 i.subscriber_sex,
99 DATE_FORMAT(i.date,'%%Y%%m%%d') as date,
100 d.lname as provider_lname,
101 d.fname as provider_fname,
102 d.npi as provider_npi,
103 d.upin as provider_pin,
104 f.federal_ein as federal_ein,
105 f.facility_npi as facility_npi,
106 f.name as facility_name,
107 c.name as payer_name
108 FROM openemr_postcalendar_events AS e
109 LEFT JOIN users AS d on (e.pc_aid is not null and e.pc_aid = d.id)
110 LEFT JOIN facility AS f on (f.id = e.pc_facility)
111 LEFT JOIN patient_data AS p ON p.pid = e.pc_pid
112 LEFT JOIN insurance_data AS i ON (i.id =(
113 SELECT id
114 FROM insurance_data AS i
115 WHERE pid = p.pid AND type = 'primary'
116 ORDER BY date DESC
117 LIMIT 1
120 LEFT JOIN insurance_companies as c ON (c.id = i.provider)
121 WHERE %s ", $where);
123 // Run the query
124 $res = sqlStatement($query, $sqlBindArray);
126 // Get the facilities information
127 $facilities = getUserFacilities($_SESSION['authId']);
129 // Get the Providers information
130 $providers = getUsernames();
132 //Get the x12 partners information
133 $clearinghouses = getX12Partner();
136 if (isset($_POST['form_savefile']) && !empty($_POST['form_savefile']) && $res) {
137 header('Content-Type: text/plain');
138 header(sprintf(
139 'Content-Disposition: attachment; filename="elig-270.%s.%s.txt"',
140 $from_date,
141 $to_date
143 print_elig($res, $X12info, $segTer, $compEleSep);
144 exit;
148 <html>
150 <head>
152 <title><?php echo xlt('Eligibility 270 Inquiry Batch'); ?></title>
154 <?php Header::setupHeader('datetime-picker'); ?>
156 <style type="text/css">
158 /* specifically include & exclude from printing */
159 @media print {
160 #report_parameters {
161 visibility: hidden;
162 display: none;
164 #report_parameters_daterange {
165 visibility: visible;
166 display: inline;
168 #report_results table {
169 margin-top: 0px;
173 /* specifically exclude some from the screen */
174 @media screen {
175 #report_parameters_daterange {
176 visibility: hidden;
177 display: none;
181 </style>
183 <script type="text/javascript">
185 var stringDelete = "<?php echo xla('Do you want to remove this record?'); ?>?";
186 var stringBatch = "<?php echo xla('Please select X12 partner, required to create the 270 batch'); ?>";
188 // for form refresh
190 function refreshme() {
191 document.forms[0].submit();
194 // To delete the row from the reports section
195 function deletetherow(id){
196 var suredelete = confirm(stringDelete);
197 if(suredelete == true){
198 document.getElementById('PR'+id).style.display="none";
199 if(document.getElementById('removedrows').value == ""){
200 document.getElementById('removedrows').value = "'" + id + "'";
201 }else{
202 document.getElementById('removedrows').value = document.getElementById('removedrows').value + ",'" + id + "'";
209 // To validate the batch file generation - for the required field [clearing house/x12 partner]
210 function validate_batch()
212 if(document.getElementById('form_x12').value=='')
214 alert(stringBatch);
215 return false;
217 else
219 document.getElementById('form_savefile').value = "true";
220 document.theform.submit();
227 // To Clear the hidden input field
229 function validate_policy()
231 document.getElementById('removedrows').value = "";
232 document.getElementById('form_savefile').value = "";
233 return true;
236 // To toggle the clearing house empty validation message
237 function toggleMessage(id,x12){
239 var spanstyle = new String();
241 spanstyle = document.getElementById(id).style.visibility;
242 selectoption = document.getElementById(x12).value;
244 if(selectoption != '')
246 document.getElementById(id).style.visibility = "hidden";
248 else
250 document.getElementById(id).style.visibility = "visible";
251 document.getElementById(id).style.display = "inline";
253 return true;
257 $(document).ready(function() {
258 $('.datepicker').datetimepicker({
259 <?php $datetimepicker_timepicker = false; ?>
260 <?php $datetimepicker_showseconds = false; ?>
261 <?php $datetimepicker_formatInput = true; ?>
262 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
263 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
267 </script>
269 </head>
270 <body class="body_top">
272 <!-- Required for the popup date selectors -->
273 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
275 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Eligibility 270 Inquiry Batch'); ?></span>
277 <div id="report_parameters_daterange">
278 <?php echo text(oeFormatShortDate($form_from_date)) . " &nbsp; " . xlt('to') . "&nbsp; ". text(oeFormatShortDate($form_to_date)); ?>
279 </div>
281 <form method='post' name='theform' id='theform' action='edi_270.php' onsubmit="return top.restoreSession()">
282 <input type="hidden" name="removedrows" id="removedrows" value="">
283 <div id="report_parameters">
284 <table>
285 <tr>
286 <td width='550px'>
287 <div style='float:left'>
288 <table class='text'>
289 <tr>
290 <td class='control-label'>
291 <?php echo xlt('From'); ?>:
292 </td>
293 <td>
294 <input type='text' class='datepicker form-control' name='form_from_date' id="form_from_date" size='10' value='<?php echo attr(oeFormatShortDate($from_date)); ?>'>
295 </td>
296 <td class='control-label'>
297 <?php echo xlt('To'); ?>:
298 </td>
299 <td>
300 <input type='text' class='datepicker form-control' name='form_to_date' id="form_to_date" size='10' value='<?php echo attr(oeFormatShortDate($to_date)); ?>'>
301 </td>
302 <td>&nbsp;</td>
303 </tr>
305 <tr>
306 <td class='control-label'>
307 <?php echo xlt('Facility'); ?>:
308 </td>
309 <td>
310 <?php dropdown_facility($form_facility, 'form_facility', false); ?>
311 </td>
312 <td class='control-label'>
313 <?php echo xlt('Provider'); ?>:
314 </td>
315 <td>
316 <select name='form_users' class='form-control' onchange='form.submit();'>
317 <option value=''>-- <?php echo xlt('All'); ?> --</option>
318 <?php foreach ($providers as $user) : ?>
319 <option value='<?php echo attr($user['id']); ?>'
320 <?php echo $form_provider == $user['id'] ? " selected " : null; ?>
321 ><?php echo text($user['fname']." ".$user['lname']); ?></option>
322 <?php endforeach; ?>
323 </select>
324 </td>
325 <td>&nbsp;
326 </td>
327 </tr>
329 <tr>
330 <td class='control-label'>
331 <?php echo xlt('X12 Partner'); ?>:
332 </td>
333 <td colspan='5'>
334 <select name='form_x12' id='form_x12' class='form-control' onchange='return toggleMessage("emptyVald","form_x12");' >
335 <option value=''>--<?php echo xlt('select'); ?>--</option>
336 <?php
337 if (isset($clearinghouses) && !empty($clearinghouses)) {
338 foreach ($clearinghouses as $clearinghouse) { ?>
339 <option value='<?php echo attr($clearinghouse['id']."|".$clearinghouse['id_number']."|".$clearinghouse['x12_sender_id']."|".$clearinghouse['x12_receiver_id']."|".$clearinghouse['x12_version']."|".$clearinghouse['processing_format']); ?>'
340 <?php echo $clearinghouse['id'] == $X12info[0] ? " selected " : null; ?>
341 ><?php echo text($clearinghouse['name']); ?></option>
342 <?php
346 </select>
347 <span id='emptyVald' style='color:red;font-size:12px;'> * <?php echo xlt('Clearing house info required for EDI 270 batch creation.'); ?></span>
348 </td>
349 </tr>
350 </table>
351 </div>
352 </td>
353 <td align='left' valign='middle' height="100%">
354 <table style='border-left:1px solid; width:100%; height:100%' >
355 <tr>
356 <td>
357 <div class="text-center">
358 <div class="btn-group" role="group">
359 <a href='#' class='btn btn-default btn-refresh' onclick='validate_policy(); $("#theform").submit();'>
360 <?php echo xlt('Refresh'); ?>
361 </a>
362 <a href='#' class='btn btn-default btn-transmit' onclick='return validate_batch();'>
363 <?php echo xlt('Create batch'); ?>
364 <input type='hidden' name='form_savefile' id='form_savefile' value=''></input>
365 </a>
366 </div>
367 </div>
368 </td>
369 </tr>
370 </table>
371 </td>
372 </tr>
373 </table>
374 </div>
376 <div class='text'>
377 <?php echo xlt('Please choose date range criteria above, and click Refresh to view results.'); ?>
378 </div>
380 </form>
382 <?php
383 if ($res) {
384 show_elig($res, $X12info, $segTer, $compEleSep);
387 </body>
389 <script language='JavaScript'>
390 <?php
391 if ($alertmsg) {
392 echo " alert('$alertmsg');\n";
393 } ?>
394 </script>
396 </html>