Bootstrapped admin.php for multisite installation (#2155)
[openemr.git] / interface / reports / edi_270.php
blob51bd4246a08f1d5d92df6f8ded6f41bf78626268
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/patient.inc");
22 require_once "$srcdir/options.inc.php";
23 require_once("$srcdir/calendar.inc");
24 require_once("$srcdir/edi.inc");
26 use OpenEMR\Core\Header;
28 if (!empty($_POST)) {
29 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
30 csrfNotVerified();
34 // Element data seperator
35 $eleDataSep = "*";
37 // Segment Terminator
38 $segTer = "~";
40 // Component Element seperator
41 $compEleSep = ":";
43 // filter conditions for the report and batch creation
45 $from_date = (isset($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-m-d');
46 $to_date = (isset($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
47 $form_facility = $_POST['form_facility'] ? $_POST['form_facility'] : '';
48 $form_provider = $_POST['form_users'] ? $_POST['form_users'] : '';
49 $exclude_policy = $_POST['removedrows'] ? $_POST['removedrows'] : '';
50 $X12info = $_POST['form_x12'] ? explode("|", $_POST['form_x12']) : '';
52 //Set up the sql variable binding array (this prevents sql-injection attacks)
53 $sqlBindArray = array();
55 $where = "e.pc_pid IS NOT NULL AND e.pc_eventDate >= ?";
56 array_push($sqlBindArray, $from_date);
58 //$where .="and e.pc_eventDate = (select max(pc_eventDate) from openemr_postcalendar_events where pc_aid = d.id)";
60 if ($to_date) {
61 $where .= " AND e.pc_eventDate <= ?";
62 array_push($sqlBindArray, $to_date);
65 if ($form_facility != "") {
66 $where .= " AND f.id = ? ";
67 array_push($sqlBindArray, $form_facility);
70 if ($form_provider != "") {
71 $where .= " AND d.id = ? ";
72 array_push($sqlBindArray, $form_provider);
75 if ($exclude_policy != "") {
76 $arrayExplode = explode(",", $exclude_policy);
77 array_walk($arrayExplode, 'arrFormated');
78 $exclude_policy = implode(",", $arrayExplode);
79 $where .= " AND i.policy_number not in (".add_escape_custom($exclude_policy).")";
82 $where .= " AND (i.policy_number is not null and i.policy_number != '')";
84 $query = sprintf(" SELECT DATE_FORMAT(e.pc_eventDate, '%%Y%%m%%d') as pc_eventDate,
85 e.pc_facility,
86 p.lname,
87 p.fname,
88 p.mname,
89 DATE_FORMAT(p.dob, '%%Y%%m%%d') as dob,
90 p.ss,
91 p.sex,
92 p.pid,
93 p.pubpid,
94 i.subscriber_ss,
95 i.policy_number,
96 i.provider as payer_id,
97 i.subscriber_relationship,
98 i.subscriber_lname,
99 i.subscriber_fname,
100 i.subscriber_mname,
101 DATE_FORMAT(i.subscriber_dob, '%%m/%%d/%%Y') as subscriber_dob,
102 i.policy_number,
103 i.subscriber_sex,
104 DATE_FORMAT(i.date,'%%Y%%m%%d') as date,
105 d.lname as provider_lname,
106 d.fname as provider_fname,
107 d.npi as provider_npi,
108 d.upin as provider_pin,
109 f.federal_ein as federal_ein,
110 f.facility_npi as facility_npi,
111 f.name as facility_name,
112 c.name as payer_name
113 FROM openemr_postcalendar_events AS e
114 LEFT JOIN users AS d on (e.pc_aid is not null and e.pc_aid = d.id)
115 LEFT JOIN facility AS f on (f.id = e.pc_facility)
116 LEFT JOIN patient_data AS p ON p.pid = e.pc_pid
117 LEFT JOIN insurance_data AS i ON (i.id =(
118 SELECT id
119 FROM insurance_data AS i
120 WHERE pid = p.pid AND type = 'primary'
121 ORDER BY date DESC
122 LIMIT 1
125 LEFT JOIN insurance_companies as c ON (c.id = i.provider)
126 WHERE %s ", $where);
128 // Run the query
129 $res = sqlStatement($query, $sqlBindArray);
131 // Get the facilities information
132 $facilities = getUserFacilities($_SESSION['authId']);
134 // Get the Providers information
135 $providers = getUsernames();
137 //Get the x12 partners information
138 $clearinghouses = getX12Partner();
141 if (isset($_POST['form_savefile']) && !empty($_POST['form_savefile']) && $res) {
142 header('Content-Type: text/plain');
143 header(sprintf(
144 'Content-Disposition: attachment; filename="elig-270.%s.%s.txt"',
145 $from_date,
146 $to_date
148 print_elig($res, $X12info, $segTer, $compEleSep);
149 exit;
153 <html>
155 <head>
157 <title><?php echo xlt('Eligibility 270 Inquiry Batch'); ?></title>
159 <?php Header::setupHeader('datetime-picker'); ?>
161 <style type="text/css">
163 /* specifically include & exclude from printing */
164 @media print {
165 #report_parameters {
166 visibility: hidden;
167 display: none;
169 #report_parameters_daterange {
170 visibility: visible;
171 display: inline;
173 #report_results table {
174 margin-top: 0px;
178 /* specifically exclude some from the screen */
179 @media screen {
180 #report_parameters_daterange {
181 visibility: hidden;
182 display: none;
186 </style>
188 <script type="text/javascript">
190 var stringDelete = <?php echo xlj('Do you want to remove this record?'); ?>;
191 var stringBatch = <?php echo xlj('Please select X12 partner, required to create the 270 batch'); ?>;
193 // for form refresh
195 function refreshme() {
196 document.forms[0].submit();
199 // To delete the row from the reports section
200 function deletetherow(id){
201 var suredelete = confirm(stringDelete);
202 if(suredelete == true){
203 document.getElementById('PR'+id).style.display="none";
204 if(document.getElementById('removedrows').value == ""){
205 document.getElementById('removedrows').value = "'" + id + "'";
206 }else{
207 document.getElementById('removedrows').value = document.getElementById('removedrows').value + ",'" + id + "'";
214 // To validate the batch file generation - for the required field [clearing house/x12 partner]
215 function validate_batch()
217 if(document.getElementById('form_x12').value=='')
219 alert(stringBatch);
220 return false;
222 else
224 document.getElementById('form_savefile').value = "true";
225 document.theform.submit();
232 // To Clear the hidden input field
234 function validate_policy()
236 document.getElementById('removedrows').value = "";
237 document.getElementById('form_savefile').value = "";
238 return true;
241 // To toggle the clearing house empty validation message
242 function toggleMessage(id,x12){
244 var spanstyle = new String();
246 spanstyle = document.getElementById(id).style.visibility;
247 selectoption = document.getElementById(x12).value;
249 if(selectoption != '')
251 document.getElementById(id).style.visibility = "hidden";
253 else
255 document.getElementById(id).style.visibility = "visible";
256 document.getElementById(id).style.display = "inline";
258 return true;
262 $(document).ready(function() {
263 $('.datepicker').datetimepicker({
264 <?php $datetimepicker_timepicker = false; ?>
265 <?php $datetimepicker_showseconds = false; ?>
266 <?php $datetimepicker_formatInput = true; ?>
267 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
268 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
272 </script>
274 </head>
275 <body class="body_top">
277 <!-- Required for the popup date selectors -->
278 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
280 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Eligibility 270 Inquiry Batch'); ?></span>
282 <div id="report_parameters_daterange">
283 <?php echo text(oeFormatShortDate($form_from_date)) . " &nbsp; " . xlt('to') . "&nbsp; ". text(oeFormatShortDate($form_to_date)); ?>
284 </div>
286 <form method='post' name='theform' id='theform' action='edi_270.php' onsubmit="return top.restoreSession()">
287 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
288 <input type="hidden" name="removedrows" id="removedrows" value="">
289 <div id="report_parameters">
290 <table>
291 <tr>
292 <td width='550px'>
293 <div style='float:left'>
294 <table class='text'>
295 <tr>
296 <td class='control-label'>
297 <?php echo xlt('From'); ?>:
298 </td>
299 <td>
300 <input type='text' class='datepicker form-control' name='form_from_date' id="form_from_date" size='10' value='<?php echo attr(oeFormatShortDate($from_date)); ?>'>
301 </td>
302 <td class='control-label'>
303 <?php echo xlt('To'); ?>:
304 </td>
305 <td>
306 <input type='text' class='datepicker form-control' name='form_to_date' id="form_to_date" size='10' value='<?php echo attr(oeFormatShortDate($to_date)); ?>'>
307 </td>
308 <td>&nbsp;</td>
309 </tr>
311 <tr>
312 <td class='control-label'>
313 <?php echo xlt('Facility'); ?>:
314 </td>
315 <td>
316 <?php dropdown_facility($form_facility, 'form_facility', false); ?>
317 </td>
318 <td class='control-label'>
319 <?php echo xlt('Provider'); ?>:
320 </td>
321 <td>
322 <select name='form_users' class='form-control' onchange='form.submit();'>
323 <option value=''>-- <?php echo xlt('All'); ?> --</option>
324 <?php foreach ($providers as $user) : ?>
325 <option value='<?php echo attr($user['id']); ?>'
326 <?php echo $form_provider == $user['id'] ? " selected " : null; ?>
327 ><?php echo text($user['fname']." ".$user['lname']); ?></option>
328 <?php endforeach; ?>
329 </select>
330 </td>
331 <td>&nbsp;
332 </td>
333 </tr>
335 <tr>
336 <td class='control-label'>
337 <?php echo xlt('X12 Partner'); ?>:
338 </td>
339 <td colspan='5'>
340 <select name='form_x12' id='form_x12' class='form-control' onchange='return toggleMessage("emptyVald","form_x12");' >
341 <option value=''>--<?php echo xlt('select'); ?>--</option>
342 <?php
343 if (isset($clearinghouses) && !empty($clearinghouses)) {
344 foreach ($clearinghouses as $clearinghouse) { ?>
345 <option value='<?php echo attr($clearinghouse['id']."|".$clearinghouse['id_number']."|".$clearinghouse['x12_sender_id']."|".$clearinghouse['x12_receiver_id']."|".$clearinghouse['x12_version']."|".$clearinghouse['processing_format']); ?>'
346 <?php echo $clearinghouse['id'] == $X12info[0] ? " selected " : null; ?>
347 ><?php echo text($clearinghouse['name']); ?></option>
348 <?php
352 </select>
353 <span id='emptyVald' style='color:red;font-size:12px;'> * <?php echo xlt('Clearing house info required for EDI 270 batch creation.'); ?></span>
354 </td>
355 </tr>
356 </table>
357 </div>
358 </td>
359 <td align='left' valign='middle' height="100%">
360 <table style='border-left:1px solid; width:100%; height:100%' >
361 <tr>
362 <td>
363 <div class="text-center">
364 <div class="btn-group" role="group">
365 <a href='#' class='btn btn-default btn-refresh' onclick='validate_policy(); $("#theform").submit();'>
366 <?php echo xlt('Refresh'); ?>
367 </a>
368 <a href='#' class='btn btn-default btn-transmit' onclick='return validate_batch();'>
369 <?php echo xlt('Create batch'); ?>
370 <input type='hidden' name='form_savefile' id='form_savefile' value=''></input>
371 </a>
372 </div>
373 </div>
374 </td>
375 </tr>
376 </table>
377 </td>
378 </tr>
379 </table>
380 </div>
382 <div class='text'>
383 <?php echo xlt('Please choose date range criteria above, and click Refresh to view results.'); ?>
384 </div>
386 </form>
388 <?php
389 if ($res) {
390 show_elig($res, $X12info, $segTer, $compEleSep);
393 </body>
395 <script language='JavaScript'>
396 <?php
397 if ($alertmsg) {
398 echo " alert(" . js_escape($alertmsg) . ");\n";
399 } ?>
400 </script>
402 </html>