ongoing internationalization of date widget
[openemr.git] / interface / reports / edi_270.php
blobcca3eee0677793f3b4f382b8aa1f211770beb046
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 * 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.
23 * @package OpenEMR
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
40 $eleDataSep = "*";
42 // Segment Terminator
43 $segTer = "~";
45 // Component Element seperator
46 $compEleSep = ":";
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)";
65 if ($to_date) {
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,
90 e.pc_facility,
91 p.lname,
92 p.fname,
93 p.mname,
94 DATE_FORMAT(p.dob, '%%Y%%m%%d') as dob,
95 p.ss,
96 p.sex,
97 p.pid,
98 p.pubpid,
99 i.policy_number,
100 i.provider as payer_id,
101 i.subscriber_relationship,
102 i.subscriber_lname,
103 i.subscriber_fname,
104 i.subscriber_mname,
105 DATE_FORMAT(i.subscriber_dob, '%%m/%%d/%%Y') as subscriber_dob,
106 i.subscriber_ss,
107 i.subscriber_sex,
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,
116 c.name as payer_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 =(
122 SELECT id
123 FROM insurance_data AS i
124 WHERE pid = p.pid AND type = 'primary'
125 ORDER BY date DESC
126 LIMIT 1
129 LEFT JOIN insurance_companies as c ON (c.id = i.provider)
130 WHERE %s ", $where);
132 // Run the query
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');
147 header(sprintf(
148 'Content-Disposition: attachment; filename="elig-270..%s.%s.txt"',
149 $from_date,
150 $to_date
152 print_elig($res, $X12info, $segTer, $compEleSep);
153 exit;
157 <html>
159 <head>
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 */
168 @media print {
169 #report_parameters {
170 visibility: hidden;
171 display: none;
173 #report_parameters_daterange {
174 visibility: visible;
175 display: inline;
177 #report_results table {
178 margin-top: 0px;
182 /* specifically exclude some from the screen */
183 @media screen {
184 #report_parameters_daterange {
185 visibility: hidden;
186 display: none;
190 </style>
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); ?>";
198 // for form refresh
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 + "'";
211 }else{
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=='')
224 alert(stringBatch);
225 return false;
227 else
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 = "";
243 return true;
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";
258 else
260 document.getElementById(id).style.visibility = "visible";
261 document.getElementById(id).style.display = "inline";
263 return true;
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 ?>
277 </script>
279 </head>
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 " &nbsp; " . htmlspecialchars(xl('to'), ENT_NOQUOTES) .
290 "&nbsp; ". htmlspecialchars(date("d F Y", strtotime($form_to_date)), ENT_NOQUOTES); ?>
291 </div>
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">
296 <table>
297 <tr>
298 <td width='550px'>
299 <div style='float:left'>
300 <table class='text'>
301 <tr>
302 <td class='control-label'>
303 <?php xl('From', 'e'); ?>:
304 </td>
305 <td>
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'>
307 </td>
308 <td class='control-label'>
309 <?php echo htmlspecialchars(xl('To'), ENT_NOQUOTES); ?>:
310 </td>
311 <td>
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) ?>'
313 title='yyyy-mm-dd'>
314 </td>
315 <td>&nbsp;</td>
316 </tr>
318 <tr>
319 <td class='control-label'>
320 <?php echo htmlspecialchars(xl('Facility'), ENT_NOQUOTES); ?>:
321 </td>
322 <td>
323 <?php dropdown_facility($form_facility, 'form_facility', false); ?>
324 </td>
325 <td class='control-label'>
326 <?php echo htmlspecialchars(xl('Provider'), ENT_NOQUOTES); ?>:
327 </td>
328 <td>
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>
335 <?php endforeach; ?>
336 </select>
337 </td>
338 <td>&nbsp;
339 </td>
340 </tr>
342 <tr>
343 <td class='control-label'>
344 <?php echo htmlspecialchars(xl('X12 Partner'), ENT_NOQUOTES); ?>:
345 </td>
346 <td colspan='5'>
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>
349 <?php
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>
355 <?php
359 </select>
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>
361 </td>
362 </tr>
363 </table>
364 </div>
365 </td>
366 <td align='left' valign='middle' height="100%">
367 <table style='border-left:1px solid; width:100%; height:100%' >
368 <tr>
369 <td>
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'); ?>
374 </a>
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>
378 </a>
379 </div>
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 <?php if ($alertmsg) {
404 echo " alert('$alertmsg');\n";
405 } ?>
406 </script>
408 </html>