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 //SANITIZE ALL ESCAPES
30 $sanitize_all_escapes=true;
33 //STOP FAKE REGISTER GLOBALS
34 $fake_register_globals=false;
37 require_once("../globals.php");
38 require_once("$srcdir/forms.inc");
39 require_once("$srcdir/billing.inc");
40 require_once("$srcdir/patient.inc");
41 require_once("$srcdir/formatting.inc.php");
42 require_once "$srcdir/options.inc.php";
43 include_once("$srcdir/calendar.inc");
44 include_once("$srcdir/edi.inc");
46 // Element data seperator
52 // Component Element seperator
55 // filter conditions for the report and batch creation
57 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
58 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
59 $form_facility = $_POST['form_facility'] ?
$_POST['form_facility'] : '';
60 $form_provider = $_POST['form_users'] ?
$_POST['form_users'] : '';
61 $exclude_policy = $_POST['removedrows'] ?
$_POST['removedrows'] : '';
62 $X12info = $_POST['form_x12'] ?
explode("|",$_POST['form_x12']) : '';
64 //Set up the sql variable binding array (this prevents sql-injection attacks)
65 $sqlBindArray = array();
67 $where = "e.pc_pid IS NOT NULL AND e.pc_eventDate >= ?";
68 array_push($sqlBindArray, $from_date);
70 //$where .="and e.pc_eventDate = (select max(pc_eventDate) from openemr_postcalendar_events where pc_aid = d.id)";
73 $where .= " AND e.pc_eventDate <= ?";
74 array_push($sqlBindArray, $to_date);
77 if($form_facility != "") {
78 $where .= " AND f.id = ? ";
79 array_push($sqlBindArray, $form_facility);
82 if($form_provider != "") {
83 $where .= " AND d.id = ? ";
84 array_push($sqlBindArray, $form_provider);
87 if($exclude_policy != ""){ $arrayExplode = explode(",", $exclude_policy);
88 array_walk($arrayExplode, 'arrFormated');
89 $exclude_policy = implode(",",$arrayExplode);
90 $where .= " AND i.policy_number not in (".stripslashes($exclude_policy).")";
93 $where .= " AND (i.policy_number is not null and i.policy_number != '')";
95 $query = sprintf(" SELECT DATE_FORMAT(e.pc_eventDate, '%%Y%%m%%d') as pc_eventDate,
100 DATE_FORMAT(p.dob, '%%Y%%m%%d') as dob,
106 i.provider as payer_id,
107 i.subscriber_relationship,
111 DATE_FORMAT(i.subscriber_dob, '%%m/%%d/%%Y') as subscriber_dob,
114 DATE_FORMAT(i.date,'%%Y%%m%%d') as date,
115 d.lname as provider_lname,
116 d.fname as provider_fname,
117 d.npi as provider_npi,
118 d.upin as provider_pin,
119 f.federal_ein as federal_ein,
120 f.facility_npi as facility_npi,
121 f.name as facility_name,
123 FROM openemr_postcalendar_events AS e
124 LEFT JOIN users AS d on (e.pc_aid is not null and e.pc_aid = d.id)
125 LEFT JOIN facility AS f on (f.id = e.pc_facility)
126 LEFT JOIN patient_data AS p ON p.pid = e.pc_pid
127 LEFT JOIN insurance_data AS i ON (i.id =(
129 FROM insurance_data AS i
130 WHERE pid = p.pid AND type = 'primary'
135 LEFT JOIN insurance_companies as c ON (c.id = i.provider)
136 WHERE %s ", $where );
139 $res = sqlStatement($query, $sqlBindArray);
141 // Get the facilities information
142 $facilities = getUserFacilities($_SESSION['authId']);
144 // Get the Providers information
145 $providers = getUsernames();
147 //Get the x12 partners information
148 $clearinghouses = getX12Partner();
151 if (isset($_POST['form_savefile']) && !empty($_POST['form_savefile']) && $res) {
152 header('Content-Type: text/plain');
153 header(sprintf('Content-Disposition: attachment; filename="elig-270..%s.%s.txt"',
157 print_elig($res,$X12info,$segTer,$compEleSep);
166 <?php
html_header_show();?
>
168 <title
><?php
echo htmlspecialchars( xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES
); ?
></title
>
170 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
171 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
173 <style type
="text/css">
175 /* specifically include & exclude from printing */
181 #report_parameters_daterange {
185 #report_results table {
190 /* specifically exclude some from the screen */
192 #report_parameters_daterange {
200 <script type
="text/javascript" src
="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
201 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
202 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
203 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
205 <script type
="text/javascript">
207 var mypcc
= "<?php echo htmlspecialchars( $GLOBALS['phone_country_code'], ENT_QUOTES); ?>";
208 var stringDelete
= "<?php echo htmlspecialchars( xl('Do you want to remove this record?'), ENT_QUOTES); ?>?";
209 var stringBatch
= "<?php echo htmlspecialchars( xl('Please select X12 partner, required to create the 270 batch'), ENT_QUOTES); ?>";
213 function refreshme() {
214 document
.forms
[0].submit();
217 // To delete the row from the reports section
218 function deletetherow(id
){
219 var suredelete
= confirm(stringDelete
);
220 if(suredelete
== true){
221 document
.getElementById('PR'+id
).style
.display
="none";
222 if(document
.getElementById('removedrows').value
== ""){
223 document
.getElementById('removedrows').value
= "'" + id +
"'";
225 document
.getElementById('removedrows').value
= document
.getElementById('removedrows').value +
",'" + id +
"'";
232 // To validate the batch file generation - for the required field [clearing house/x12 partner]
233 function validate_batch()
235 if(document
.getElementById('form_x12').value
=='')
242 document
.getElementById('form_savefile').value
= "true";
243 document
.theform
.submit();
250 // To Clear the hidden input field
252 function validate_policy()
254 document
.getElementById('removedrows').value
= "";
255 document
.getElementById('form_savefile').value
= "";
259 // To toggle the clearing house empty validation message
260 function toggleMessage(id
,x12
){
262 var spanstyle
= new String();
264 spanstyle
= document
.getElementById(id
).style
.visibility
;
265 selectoption
= document
.getElementById(x12
).value
;
267 if(selectoption
!= '')
269 document
.getElementById(id
).style
.visibility
= "hidden";
273 document
.getElementById(id
).style
.visibility
= "visible";
274 document
.getElementById(id
).style
.display
= "inline";
280 $
(document
).ready(function() {
281 $
('.datepicker').datetimepicker({
282 <?php
$datetimepicker_timepicker = false; ?
>
283 <?php
$datetimepicker_formatInput = false; ?
>
284 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
285 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
292 <body
class="body_top">
294 <!-- Required
for the popup date selectors
-->
295 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
297 <span
class='title'><?php
echo htmlspecialchars( xl('Report'), ENT_NOQUOTES
); ?
> - <?php
echo htmlspecialchars( xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES
); ?
></span
>
299 <div id
="report_parameters_daterange">
300 <?php
echo htmlspecialchars( date("d F Y", strtotime($form_from_date)), ENT_NOQUOTES
) .
301 " " . htmlspecialchars( xl('to'), ENT_NOQUOTES
) .
302 " ". htmlspecialchars( date("d F Y", strtotime($form_to_date)), ENT_NOQUOTES
); ?
>
305 <form method
='post' name
='theform' id
='theform' action
='edi_270.php' onsubmit
="return top.restoreSession()">
306 <input type
="hidden" name
="removedrows" id
="removedrows" value
="">
307 <div id
="report_parameters">
311 <div style
='float:left'>
315 <?php
xl('From','e'); ?
>:
318 <input type
='text' class='datepicker' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo htmlspecialchars( $from_date, ENT_QUOTES) ?>' title
='yyyy-mm-dd'>
321 <?php
echo htmlspecialchars( xl('To'), ENT_NOQUOTES
); ?
>:
324 <input type
='text' class='datepicker' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo htmlspecialchars( $to_date, ENT_QUOTES) ?>'
332 <?php
echo htmlspecialchars( xl('Facility'), ENT_NOQUOTES
); ?
>:
335 <?php
dropdown_facility($form_facility,'form_facility',false); ?
>
338 <?php
echo htmlspecialchars( xl('Provider'), ENT_NOQUOTES
); ?
>:
341 <select name
='form_users' onchange
='form.submit();'>
342 <option value
=''>-- <?php
echo htmlspecialchars( xl('All'), ENT_NOQUOTES
); ?
> --</option
>
343 <?php
foreach($providers as $user): ?
>
344 <option value
='<?php echo htmlspecialchars( $user['id
'], ENT_QUOTES); ?>'
345 <?php
echo $form_provider == $user['id'] ?
" selected " : null; ?
>
346 ><?php
echo htmlspecialchars( $user['fname']." ".$user['lname'], ENT_NOQUOTES
); ?
></option
>
356 <?php
echo htmlspecialchars( xl('X12 Partner'), ENT_NOQUOTES
); ?
>:
359 <select name
='form_x12' id
='form_x12' onchange
='return toggleMessage("emptyVald","form_x12");' >
360 <option value
=''>--<?php
echo htmlspecialchars( xl('select'), ENT_NOQUOTES
); ?
>--</option
>
362 if(isset($clearinghouses) && !empty($clearinghouses))
364 foreach($clearinghouses as $clearinghouse): ?
>
365 <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); ?>'
366 <?php
echo $clearinghouse['id'] == $X12info[0] ?
" selected " : null; ?
>
367 ><?php
echo htmlspecialchars( $clearinghouse['name'], ENT_NOQUOTES
); ?
></option
>
373 <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
>
379 <td align
='left' valign
='middle' height
="100%">
380 <table style
='border-left:1px solid; width:100%; height:100%' >
383 <div style
='margin-left:15px'>
384 <a href
='#' class='css_button' onclick
='validate_policy(); $("#theform").submit();'>
386 <?php
echo htmlspecialchars( xl('Refresh'), ENT_NOQUOTES
); ?
>
390 <a href
='#' class='css_button' onclick
='return validate_batch();'>
392 <?php
echo htmlspecialchars( xl('Create batch'), ENT_NOQUOTES
); ?
>
393 <input type
='hidden' name
='form_savefile' id
='form_savefile' value
=''></input
>
407 <?php
echo htmlspecialchars( xl('Please choose date range criteria above, and click Refresh to view results.'), ENT_NOQUOTES
); ?
>
414 show_elig($res,$X12info,$segTer,$compEleSep);
419 <script language
='JavaScript'>
420 <?php
if ($alertmsg) { echo " alert('$alertmsg');\n"; } ?
>