Removes frames from login gui and condense login gui into a single file.
[openemr.git] / interface / reports / edi_270.php
blobc3f6dc5be2529f3f81bffe42c09b48a14a983d8c
1 <?php
2 // Copyright (C) 2010 MMF Systems, Inc>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 /** This report is the batch report required for batch eligibility verification. **/
11 //SANITIZE ALL ESCAPES
12 $sanitize_all_escapes=true;
15 //STOP FAKE REGISTER GLOBALS
16 $fake_register_globals=false;
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/formatting.inc.php");
24 require_once "$srcdir/options.inc.php";
25 require_once "$srcdir/formdata.inc.php";
26 include_once("$srcdir/calendar.inc");
27 include_once("$srcdir/edi.inc");
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 = fixDate($_POST['form_from_date'], date('Y-m-d'));
41 $to_date = fixDate($_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 != ""){ $arrayExplode = explode(",", $exclude_policy);
71 array_walk($arrayExplode, 'arrFormated');
72 $exclude_policy = implode(",",$arrayExplode);
73 $where .= " AND i.policy_number not in (".stripslashes($exclude_policy).")";
76 $where .= " AND (i.policy_number is not null and i.policy_number != '')";
78 $query = sprintf(" SELECT DATE_FORMAT(e.pc_eventDate, '%%Y%%m%%d') as pc_eventDate,
79 e.pc_facility,
80 p.lname,
81 p.fname,
82 p.mname,
83 DATE_FORMAT(p.dob, '%%Y%%m%%d') as dob,
84 p.ss,
85 p.sex,
86 p.pid,
87 p.pubpid,
88 i.policy_number,
89 i.provider as payer_id,
90 i.subscriber_relationship,
91 i.subscriber_lname,
92 i.subscriber_fname,
93 i.subscriber_mname,
94 DATE_FORMAT(i.subscriber_dob, '%%m/%%d/%%Y') as subscriber_dob,
95 i.subscriber_ss,
96 i.subscriber_sex,
97 DATE_FORMAT(i.date,'%%Y%%m%%d') as date,
98 d.lname as provider_lname,
99 d.fname as provider_fname,
100 d.npi as provider_npi,
101 d.upin as provider_pin,
102 f.federal_ein,
103 f.facility_npi,
104 f.name as facility_name,
105 c.name as payer_name
106 FROM openemr_postcalendar_events AS e
107 LEFT JOIN users AS d on (e.pc_aid is not null and e.pc_aid = d.id)
108 LEFT JOIN facility AS f on (f.id = e.pc_facility)
109 LEFT JOIN patient_data AS p ON p.pid = e.pc_pid
110 LEFT JOIN insurance_data AS i ON (i.id =(
111 SELECT id
112 FROM insurance_data AS i
113 WHERE pid = p.pid AND type = 'primary'
114 ORDER BY date DESC
115 LIMIT 1
118 LEFT JOIN insurance_companies as c ON (c.id = i.provider)
119 WHERE %s ", $where );
121 // Run the query
122 $res = sqlStatement($query, $sqlBindArray);
124 // Get the facilities information
125 $facilities = getUserFacilities($_SESSION['authId']);
127 // Get the Providers information
128 $providers = getUsernames();
130 //Get the x12 partners information
131 $clearinghouses = getX12Partner();
134 if (isset($_POST['form_savefile']) && !empty($_POST['form_savefile']) && $res) {
135 header('Content-Type: text/plain');
136 header(sprintf('Content-Disposition: attachment; filename="elig-270..%s.%s.txt"',
137 $from_date,
138 $to_date
140 print_elig($res,$X12info,$segTer,$compEleSep);
141 exit;
145 <html>
147 <head>
149 <?php html_header_show();?>
151 <title><?php echo htmlspecialchars( xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES); ?></title>
153 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
155 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
157 <style type="text/css">
159 /* specifically include & exclude from printing */
160 @media print {
161 #report_parameters {
162 visibility: hidden;
163 display: none;
165 #report_parameters_daterange {
166 visibility: visible;
167 display: inline;
169 #report_results table {
170 margin-top: 0px;
174 /* specifically exclude some from the screen */
175 @media screen {
176 #report_parameters_daterange {
177 visibility: hidden;
178 display: none;
182 </style>
184 <script type="text/javascript" src="../../library/textformat.js"></script>
185 <script type="text/javascript" src="../../library/dialog.js"></script>
186 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
187 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
188 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
189 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
191 <script type="text/javascript">
193 var mypcc = "<?php echo htmlspecialchars( $GLOBALS['phone_country_code'], ENT_QUOTES); ?>";
194 var stringDelete = "<?php echo htmlspecialchars( xl('Do you want to remove this record?'), ENT_QUOTES); ?>?";
195 var stringBatch = "<?php echo htmlspecialchars( xl('Please select X12 partner, required to create the 270 batch'), ENT_QUOTES); ?>";
197 // for form refresh
199 function refreshme() {
200 document.forms[0].submit();
203 // To delete the row from the reports section
204 function deletetherow(id){
205 var suredelete = confirm(stringDelete);
206 if(suredelete == true){
207 document.getElementById('PR'+id).style.display="none";
208 if(document.getElementById('removedrows').value == ""){
209 document.getElementById('removedrows').value = "'" + id + "'";
210 }else{
211 document.getElementById('removedrows').value = document.getElementById('removedrows').value + ",'" + id + "'";
218 // To validate the batch file generation - for the required field [clearing house/x12 partner]
219 function validate_batch()
221 if(document.getElementById('form_x12').value=='')
223 alert(stringBatch);
224 return false;
226 else
228 document.getElementById('form_savefile').value = "true";
229 document.theform.submit();
236 // To Clear the hidden input field
238 function validate_policy()
240 document.getElementById('removedrows').value = "";
241 document.getElementById('form_savefile').value = "";
242 return true;
245 // To toggle the clearing house empty validation message
246 function toggleMessage(id,x12){
248 var spanstyle = new String();
250 spanstyle = document.getElementById(id).style.visibility;
251 selectoption = document.getElementById(x12).value;
253 if(selectoption != '')
255 document.getElementById(id).style.visibility = "hidden";
257 else
259 document.getElementById(id).style.visibility = "visible";
260 document.getElementById(id).style.display = "inline";
262 return true;
266 </script>
268 </head>
269 <body class="body_top">
271 <!-- Required for the popup date selectors -->
272 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
274 <span class='title'><?php echo htmlspecialchars( xl('Report'), ENT_NOQUOTES); ?> - <?php echo htmlspecialchars( xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES); ?></span>
276 <div id="report_parameters_daterange">
277 <?php echo htmlspecialchars( date("d F Y", strtotime($form_from_date)), ENT_NOQUOTES) .
278 " &nbsp; " . htmlspecialchars( xl('to'), ENT_NOQUOTES) .
279 "&nbsp; ". htmlspecialchars( date("d F Y", strtotime($form_to_date)), ENT_NOQUOTES); ?>
280 </div>
282 <form method='post' name='theform' id='theform' action='edi_270.php' onsubmit="return top.restoreSession()">
283 <input type="hidden" name="removedrows" id="removedrows" value="">
284 <div id="report_parameters">
285 <table>
286 <tr>
287 <td width='550px'>
288 <div style='float:left'>
289 <table class='text'>
290 <tr>
291 <td class='label'>
292 <?php xl('From','e'); ?>:
293 </td>
294 <td>
295 <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'>
296 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
297 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
298 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
299 </td>
300 <td class='label'>
301 <?php echo htmlspecialchars( xl('To'), ENT_NOQUOTES); ?>:
302 </td>
303 <td>
304 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo htmlspecialchars( $to_date, ENT_QUOTES) ?>'
305 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
306 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
307 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
308 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
309 </td>
310 <td>&nbsp;</td>
311 </tr>
313 <tr>
314 <td class='label'>
315 <?php echo htmlspecialchars( xl('Facility'), ENT_NOQUOTES); ?>:
316 </td>
317 <td>
318 <?php dropdown_facility($form_facility,'form_facility',false); ?>
319 </td>
320 <td class='label'>
321 <?php echo htmlspecialchars( xl('Provider'), ENT_NOQUOTES); ?>:
322 </td>
323 <td>
324 <select name='form_users' onchange='form.submit();'>
325 <option value=''>-- <?php echo htmlspecialchars( xl('All'), ENT_NOQUOTES); ?> --</option>
326 <?php foreach($providers as $user): ?>
327 <option value='<?php echo htmlspecialchars( $user['id'], ENT_QUOTES); ?>'
328 <?php echo $form_provider == $user['id'] ? " selected " : null; ?>
329 ><?php echo htmlspecialchars( $user['fname']." ".$user['lname'], ENT_NOQUOTES); ?></option>
330 <?php endforeach; ?>
331 </select>
332 </td>
333 <td>&nbsp;
334 </td>
335 </tr>
337 <tr>
338 <td class='label'>
339 <?php echo htmlspecialchars( xl('X12 Partner'), ENT_NOQUOTES); ?>:
340 </td>
341 <td colspan='5'>
342 <select name='form_x12' id='form_x12' onchange='return toggleMessage("emptyVald","form_x12");' >
343 <option value=''>--<?php echo htmlspecialchars( xl('select'), ENT_NOQUOTES); ?>--</option>
344 <?php
345 if(isset($clearinghouses) && !empty($clearinghouses))
347 foreach($clearinghouses as $clearinghouse): ?>
348 <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); ?>'
349 <?php echo $clearinghouse['id'] == $X12info[0] ? " selected " : null; ?>
350 ><?php echo htmlspecialchars( $clearinghouse['name'], ENT_NOQUOTES); ?></option>
351 <?php endforeach;
355 </select>
356 <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>
357 </td>
358 </tr>
359 </table>
360 </div>
361 </td>
362 <td align='left' valign='middle' height="100%">
363 <table style='border-left:1px solid; width:100%; height:100%' >
364 <tr>
365 <td>
366 <div style='margin-left:15px'>
367 <a href='#' class='css_button' onclick='validate_policy(); $("#theform").submit();'>
368 <span>
369 <?php echo htmlspecialchars( xl('Refresh'), ENT_NOQUOTES); ?>
370 </span>
371 </a>
373 <a href='#' class='css_button' onclick='return validate_batch();'>
374 <span>
375 <?php echo htmlspecialchars( xl('Create batch'), ENT_NOQUOTES); ?>
376 <input type='hidden' name='form_savefile' id='form_savefile' value=''></input>
377 </span>
378 </a>
380 </div>
381 </td>
382 </tr>
383 </table>
384 </td>
385 </tr>
386 </table>
387 </div>
389 <div class='text'>
390 <?php echo htmlspecialchars( xl('Please choose date range criteria above, and click Refresh to view results.'), ENT_NOQUOTES); ?>
391 </div>
393 </form>
395 <?php
396 if ($res){
397 show_elig($res,$X12info,$segTer,$compEleSep);
400 </body>
402 <script language='JavaScript'>
403 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
404 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
405 <?php if ($alertmsg) { echo " alert('$alertmsg');\n"; } ?>
406 </script>
408 </html>