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
10 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
12 * LICENSE: This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 3
15 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see http://opensource.org/licenses/gpl-license.php.
24 * @author Terry Hill <terry@lilysystems.com>
25 * @author Brady Miller <brady.g.miller@gmail.com>
26 * @link http://www.open-emr.org
29 use OpenEMR\Core\Header
;
31 require_once("../globals.php");
32 require_once("$srcdir/forms.inc");
33 require_once("$srcdir/billing.inc");
34 require_once("$srcdir/patient.inc");
35 require_once "$srcdir/options.inc.php";
36 include_once("$srcdir/calendar.inc");
37 include_once("$srcdir/edi.inc");
39 // Element data seperator
45 // Component Element seperator
48 // filter conditions for the report and batch creation
50 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
51 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
52 $form_facility = $_POST['form_facility'] ?
$_POST['form_facility'] : '';
53 $form_provider = $_POST['form_users'] ?
$_POST['form_users'] : '';
54 $exclude_policy = $_POST['removedrows'] ?
$_POST['removedrows'] : '';
55 $X12info = $_POST['form_x12'] ?
explode("|", $_POST['form_x12']) : '';
57 //Set up the sql variable binding array (this prevents sql-injection attacks)
58 $sqlBindArray = array();
60 $where = "e.pc_pid IS NOT NULL AND e.pc_eventDate >= ?";
61 array_push($sqlBindArray, $from_date);
63 //$where .="and e.pc_eventDate = (select max(pc_eventDate) from openemr_postcalendar_events where pc_aid = d.id)";
66 $where .= " AND e.pc_eventDate <= ?";
67 array_push($sqlBindArray, $to_date);
70 if ($form_facility != "") {
71 $where .= " AND f.id = ? ";
72 array_push($sqlBindArray, $form_facility);
75 if ($form_provider != "") {
76 $where .= " AND d.id = ? ";
77 array_push($sqlBindArray, $form_provider);
80 if ($exclude_policy != "") {
81 $arrayExplode = explode(",", $exclude_policy);
82 array_walk($arrayExplode, 'arrFormated');
83 $exclude_policy = implode(",", $arrayExplode);
84 $where .= " AND i.policy_number not in (".stripslashes($exclude_policy).")";
87 $where .= " AND (i.policy_number is not null and i.policy_number != '')";
89 $query = sprintf(" SELECT DATE_FORMAT(e.pc_eventDate, '%%Y%%m%%d') as pc_eventDate,
94 DATE_FORMAT(p.dob, '%%Y%%m%%d') as dob,
100 i.provider as payer_id,
101 i.subscriber_relationship,
105 DATE_FORMAT(i.subscriber_dob, '%%m/%%d/%%Y') as subscriber_dob,
108 DATE_FORMAT(i.date,'%%Y%%m%%d') as date,
109 d.lname as provider_lname,
110 d.fname as provider_fname,
111 d.npi as provider_npi,
112 d.upin as provider_pin,
113 f.federal_ein as federal_ein,
114 f.facility_npi as facility_npi,
115 f.name as facility_name,
117 FROM openemr_postcalendar_events AS e
118 LEFT JOIN users AS d on (e.pc_aid is not null and e.pc_aid = d.id)
119 LEFT JOIN facility AS f on (f.id = e.pc_facility)
120 LEFT JOIN patient_data AS p ON p.pid = e.pc_pid
121 LEFT JOIN insurance_data AS i ON (i.id =(
123 FROM insurance_data AS i
124 WHERE pid = p.pid AND type = 'primary'
129 LEFT JOIN insurance_companies as c ON (c.id = i.provider)
133 $res = sqlStatement($query, $sqlBindArray);
135 // Get the facilities information
136 $facilities = getUserFacilities($_SESSION['authId']);
138 // Get the Providers information
139 $providers = getUsernames();
141 //Get the x12 partners information
142 $clearinghouses = getX12Partner();
145 if (isset($_POST['form_savefile']) && !empty($_POST['form_savefile']) && $res) {
146 header('Content-Type: text/plain');
148 'Content-Disposition: attachment; filename="elig-270..%s.%s.txt"',
152 print_elig($res, $X12info, $segTer, $compEleSep);
161 <title
><?php
echo htmlspecialchars(xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES
); ?
></title
>
163 <?php Header
::setupHeader('datetime-picker'); ?
>
165 <style type
="text/css">
167 /* specifically include & exclude from printing */
173 #report_parameters_daterange {
177 #report_results table {
182 /* specifically exclude some from the screen */
184 #report_parameters_daterange {
192 <script type
="text/javascript">
194 var mypcc
= "<?php echo htmlspecialchars($GLOBALS['phone_country_code'], ENT_QUOTES); ?>";
195 var stringDelete
= "<?php echo htmlspecialchars(xl('Do you want to remove this record?'), ENT_QUOTES); ?>?";
196 var stringBatch
= "<?php echo htmlspecialchars(xl('Please select X12 partner, required to create the 270 batch'), ENT_QUOTES); ?>";
200 function refreshme() {
201 document
.forms
[0].submit();
204 // To delete the row from the reports section
205 function deletetherow(id
){
206 var suredelete
= confirm(stringDelete
);
207 if(suredelete
== true){
208 document
.getElementById('PR'+id
).style
.display
="none";
209 if(document
.getElementById('removedrows').value
== ""){
210 document
.getElementById('removedrows').value
= "'" + id +
"'";
212 document
.getElementById('removedrows').value
= document
.getElementById('removedrows').value +
",'" + id +
"'";
219 // To validate the batch file generation - for the required field [clearing house/x12 partner]
220 function validate_batch()
222 if(document
.getElementById('form_x12').value
=='')
229 document
.getElementById('form_savefile').value
= "true";
230 document
.theform
.submit();
237 // To Clear the hidden input field
239 function validate_policy()
241 document
.getElementById('removedrows').value
= "";
242 document
.getElementById('form_savefile').value
= "";
246 // To toggle the clearing house empty validation message
247 function toggleMessage(id
,x12
){
249 var spanstyle
= new String();
251 spanstyle
= document
.getElementById(id
).style
.visibility
;
252 selectoption
= document
.getElementById(x12
).value
;
254 if(selectoption
!= '')
256 document
.getElementById(id
).style
.visibility
= "hidden";
260 document
.getElementById(id
).style
.visibility
= "visible";
261 document
.getElementById(id
).style
.display
= "inline";
267 $
(document
).ready(function() {
268 $
('.datepicker').datetimepicker({
269 <?php
$datetimepicker_timepicker = false; ?
>
270 <?php
$datetimepicker_showseconds = false; ?
>
271 <?php
$datetimepicker_formatInput = false; ?
>
272 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
273 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
280 <body
class="body_top">
282 <!-- Required
for the popup date selectors
-->
283 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
285 <span
class='title'><?php
echo htmlspecialchars(xl('Report'), ENT_NOQUOTES
); ?
> - <?php
echo htmlspecialchars(xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES
); ?
></span
>
287 <div id
="report_parameters_daterange">
288 <?php
echo htmlspecialchars(date("d F Y", strtotime($form_from_date)), ENT_NOQUOTES
) .
289 " " . htmlspecialchars(xl('to'), ENT_NOQUOTES
) .
290 " ". htmlspecialchars(date("d F Y", strtotime($form_to_date)), ENT_NOQUOTES
); ?
>
293 <form method
='post' name
='theform' id
='theform' action
='edi_270.php' onsubmit
="return top.restoreSession()">
294 <input type
="hidden" name
="removedrows" id
="removedrows" value
="">
295 <div id
="report_parameters">
299 <div style
='float:left'>
302 <td
class='control-label'>
303 <?php
xl('From', 'e'); ?
>:
306 <input type
='text' class='datepicker form-control' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo htmlspecialchars($from_date, ENT_QUOTES) ?>' title
='yyyy-mm-dd'>
308 <td
class='control-label'>
309 <?php
echo htmlspecialchars(xl('To'), ENT_NOQUOTES
); ?
>:
312 <input type
='text' class='datepicker form-control' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo htmlspecialchars($to_date, ENT_QUOTES) ?>'
319 <td
class='control-label'>
320 <?php
echo htmlspecialchars(xl('Facility'), ENT_NOQUOTES
); ?
>:
323 <?php
dropdown_facility($form_facility, 'form_facility', false); ?
>
325 <td
class='control-label'>
326 <?php
echo htmlspecialchars(xl('Provider'), ENT_NOQUOTES
); ?
>:
329 <select name
='form_users' class='form-control' onchange
='form.submit();'>
330 <option value
=''>-- <?php
echo htmlspecialchars(xl('All'), ENT_NOQUOTES
); ?
> --</option
>
331 <?php
foreach ($providers as $user) : ?
>
332 <option value
='<?php echo htmlspecialchars($user['id
'], ENT_QUOTES); ?>'
333 <?php
echo $form_provider == $user['id'] ?
" selected " : null; ?
>
334 ><?php
echo htmlspecialchars($user['fname']." ".$user['lname'], ENT_NOQUOTES
); ?
></option
>
343 <td
class='control-label'>
344 <?php
echo htmlspecialchars(xl('X12 Partner'), ENT_NOQUOTES
); ?
>:
347 <select name
='form_x12' id
='form_x12' class='form-control' onchange
='return toggleMessage("emptyVald","form_x12");' >
348 <option value
=''>--<?php
echo htmlspecialchars(xl('select'), ENT_NOQUOTES
); ?
>--</option
>
350 if (isset($clearinghouses) && !empty($clearinghouses)) {
351 foreach ($clearinghouses as $clearinghouse) { ?
>
352 <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); ?>'
353 <?php
echo $clearinghouse['id'] == $X12info[0] ?
" selected " : null; ?
>
354 ><?php
echo htmlspecialchars($clearinghouse['name'], ENT_NOQUOTES
); ?
></option
>
360 <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
>
366 <td align
='left' valign
='middle' height
="100%">
367 <table style
='border-left:1px solid; width:100%; height:100%' >
370 <div
class="text-center">
371 <div
class="btn-group" role
="group">
372 <a href
='#' class='btn btn-default btn-refresh' onclick
='validate_policy(); $("#theform").submit();'>
373 <?php
echo xlt('Refresh'); ?
>
375 <a href
='#' class='btn btn-default btn-transmit' onclick
='return validate_batch();'>
376 <?php
echo xlt('Create batch'); ?
>
377 <input type
='hidden' name
='form_savefile' id
='form_savefile' value
=''></input
>
390 <?php
echo htmlspecialchars(xl('Please choose date range criteria above, and click Refresh to view results.'), ENT_NOQUOTES
); ?
>
397 show_elig($res, $X12info, $segTer, $compEleSep);
402 <script language
='JavaScript'>
403 <?php
if ($alertmsg) {
404 echo " alert('$alertmsg');\n";