edihistory -- revisions and cleanup of 277 claim status functions
[openemr.git] / library / edihistory / ibr_io.php
blobb585236d4b9adee58fbe13a0fd5eed3d9aab759d
1 <?php
2 /*
3 * ibr_io.php
4 *
5 * Copyright 2012 Kevin McCormick Longview, Texas
6 *
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; version 3 or later. You should have
16 * received a copy of the GNU General Public License along with this program;
17 * if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * <http://opensource.org/licenses/gpl-license.php>
22 * @author Kevin McCormick
23 * @link: http://www.open-emr.org
24 * @package OpenEMR
25 * @subpackage ediHistory
28 /**
29 * Get some values from php ini functions for interface
31 * @return array json
33 function ibr_inivals() {
34 $ival = array();
35 $td = basename(sys_get_temp_dir());
36 $ival['mfilesize'] = ini_get('upload_max_filesize');
37 $ival['mfuploads'] = ini_get('max_file_uploads');
38 $ival['pmsize'] = ini_get('post_max_size');
39 $ival['tmpdir'] = $td;
40 $json = json_encode($ival);
42 return $json;
45 /**
46 * read or write simple notes to a text file
48 * @uses csv_notes_file()
49 * @return string
51 function ibr_history_notes() {
53 if (isset($_GET['getnotes']) && $_GET['getnotes'] == 'yes') {
54 $out_text = csv_notes_file();
55 $str_html = str_replace('|:|', PHP_EOL, $out_text);
56 } elseif (isset($_POST['putnotes']) && $_POST['putnotes'] == 'yes') {
57 $notetext = $_POST['tnotes'];
58 $notetext = str_replace(PHP_EOL, '|:|', $notetext);
59 $filtered = filter_var($notetext, FILTER_SANITIZE_STRING);
60 //echo $filtered .PHP_EOL;
61 $str_html = csv_notes_file($filtered, false);
63 return $str_html;
66 /**
67 * generate the heading string for an html page
69 * @return string html heading stanza
71 function ibr_html_heading($option, $title='') {
73 //if (!is_string($title)) { $title=''; }
74 $title = (is_string($title)) ? $title : '';
75 $srcdir = $GLOBALS['srcdir'];
76 $webdir = $GLOBALS['webroot'];
78 $str_html = "<!DOCTYPE html>".PHP_EOL."<html>".PHP_EOL."<head>".PHP_EOL;
79 $str_html .= " <meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />".PHP_EOL;
80 $str_html .= " <title>##TITLE##</title>".PHP_EOL;
81 //$str_html .= " <link rel='stylesheet' href='jscript/style/csv_new.css' type='text/css' media='print, projection, screen' />".PHP_EOL;
82 $str_html .= "<link rel=\"stylesheet\" href=\"$webdir/library/css/edi_history.css\" type=\"text/css\" />".PHP_EOL;
83 //$str_html .= " <link rel='stylesheet' href='../css/edi_history.css' type='text/css' />".PHP_EOL;
84 $str_html .= "</head>".PHP_EOL."<body>".PHP_EOL;
86 if (!strpos("|newfiles|eradisplay|x12display|csvtable|textdisplay|readme", $option)) {
87 $str_html = str_replace('##TITLE##', 'Error', $str_html);
88 return $str_html;
89 } elseif ($option == 'newfiles') {
90 $str_html = str_replace('##TITLE##', 'Process New Files '.$title, $str_html);
91 } elseif ($option == 'eradisplay') {
92 $str_html = str_replace('##TITLE##', 'ERA Display '.$title, $str_html);
93 } elseif ($option == 'claimstatus') {
94 $str_html = str_replace('##TITLE##', 'Claim Status '.$title, $str_html);
95 } elseif ($option == 'x12display') {
96 $str_html = str_replace('##TITLE##', 'x12 File '.$title, $str_html);
97 } elseif ($option == 'csvtable') {
98 $str_html = str_replace('##TITLE##', 'CSV Table '.$title, $str_html);
99 } elseif ($option == 'textdisplay') {
100 $str_html = str_replace('##TITLE##', 'Text '.$title, $str_html);
101 } elseif ($option == 'readme') {
102 $str_html = str_replace('##TITLE##', 'Readme '.$title, $str_html);
103 } else {
104 $str_html = str_replace('##TITLE##', 'Unknown '.$title, $str_html);
107 return $str_html;
111 * generate the trailing tags for html page
113 * @return string
115 function ibr_html_tail() {
116 $str_html = PHP_EOL."</body></html>";
117 return $str_html;
121 * call new uploaded files process functions
123 * @todo save the newfiles lists to file so they can
124 * be re-displayed if user has to close app before
125 * finishing review (need to have csv_write option)
127 * @uses csv_newfile_list()
128 * @uses ibr_batch_process_new()
129 * @uses ibr_ack_process_new()
130 * @uses ibr_997_process_new()
131 * @uses ibr_277_process_new()
132 * @uses ibr_ebr_process_new()
133 * @uses ibr_dpr_process_new()
134 * @uses ibr_era_process_new()
136 * @return string html format
138 function ibr_disp_newfiles() {
140 if (!isset($_POST['NewFiles']) ) {
141 // should only be called with this value existing
142 $str_html = "Error: invalid value for Process New <br />".PHP_EOL;
143 return $str_html;
145 $htm = $er = false;
146 if (isset($_POST['htmlout'])) {
147 $htmval = filter_input(INPUT_POST, 'htmlout', FILTER_SANITIZE_STRING);
148 $htm = ($htmval == 'on') ? true : false;
150 if (isset($_POST['erronly'])) {
151 $errval = filter_input(INPUT_POST, 'erronly', FILTER_SANITIZE_STRING);
152 $er = ($errval == 'on') ? true : false;
154 $str_html = "<p>Process new files</p>".PHP_EOL;
156 $p = csv_parameters();
157 $ftype = array_keys($p);
159 foreach($ftype as $tp) {
160 $checkdir = false;
161 // check for directory contents
162 $ckdir = $p[$tp]['directory'];
163 if (is_dir($ckdir)) {
164 $dh = opendir($ckdir);
165 if ($dh) {
166 while (($file = readdir($dh)) !== false) {
167 if ($file != '.' && $file != '..') {
168 $checkdir = true;
169 break;
172 closedir($dh);
175 // if false, no files in directory
176 if (!$checkdir) { continue; }
178 $upload_ar = csv_newfile_list($tp);
180 if (count($upload_ar) > 0) {
181 if ($tp == 'batch') {
182 $str_html .= ibr_batch_process_new($upload_ar, $htm);
183 } elseif ($tp == 'ack') {
184 $str_html .= ibr_ack_process_new($upload_ar, $htm);
185 } elseif ($tp == 'ta1') {
186 $str_html .= ibr_ta1_process_new($upload_ar, $htm);
187 } elseif ($tp == 'f997') {
188 $str_html .= ibr_997_process_new($upload_ar, $htm, $er);
189 } elseif ($tp == 'f277') {
190 $str_html .= ibr_277_process_new($upload_ar, $htm, $er);
191 } elseif ($tp == 'ibr') {
192 $str_html .= ibr_ebr_process_new_files($upload_ar, 'ibr', $htm, $er);
193 } elseif ($tp == 'ebr') {
194 $str_html .= ibr_ebr_process_new_files($upload_ar, 'ebr', $htm, $er);
195 } elseif ($tp == 'dpr') {
196 $str_html .= ibr_dpr_process_new($upload_ar, $htm, $er);
197 } elseif ($tp == 'era') {
198 $str_html .= ibr_era_process_new($upload_ar, $htm, $er);
199 } elseif ($tp == 'text') {
200 // do nothing
201 continue;
202 } else {
203 $str_html .= "unknown type $tp <br />".PHP_EOL;
205 } else {
206 $str_html .= "No new files for type $tp <br />".PHP_EOL;
210 return $str_html;
214 * display the ST...SE segments for a claim from a batch file
216 * @uses csv_file_with_pid_enctr()
217 * @uses csv_file_by_controlnum()
218 * @uses ibr_batch_get_st_block()
219 * @return string
221 function ibr_disp_claimst() {
223 $str_html = '';
224 $filename = ''; $clmid = ''; $st02 = '';
226 $filename = isset($_GET['fvbatch']) ? filter_input(INPUT_GET, 'fvbatch', FILTER_SANITIZE_STRING) : '';
228 $st02 = isset($_GET['stnum']) ? filter_input(INPUT_GET, 'stnum', FILTER_SANITIZE_STRING) : '';
230 if (isset($_GET['btpid'])) {
231 $clmid = filter_input(INPUT_GET, 'btpid', FILTER_SANITIZE_STRING);
232 } elseif (isset($_POST['enctrbatch'])) {
233 $clmid = filter_input(INPUT_POST, 'enctrbatch', FILTER_SANITIZE_STRING);
234 } else {
235 $clmid = '';
238 if ( !$clmid && !$st02 ) {
239 $str_html .= "Invalid claim ID <br />";
240 return $str_html;
242 // see if we have a usable filename
243 if (strpos($filename, 'batch')) {
244 // maybe we have the OpenEMR filename
245 $btname = trim($filename);
246 } elseif (strlen($filename) >= 9 && strlen($filename) < 14) {
247 // try bht03 number: batch_icn + stnum; not '0123'
248 $isa13 = substr($filename, 0, 9);
249 $st02 = (strlen($filename) == 13) ? substr($filename, -4) : '';
250 $btname = csv_file_by_controlnum('batch', $isa13);
251 } elseif (!$filename || strlen($filename) < 9) {
252 // nothing useful
253 $btname = '';
256 if ($btname) {
257 $stblk = ibr_batch_get_st_block ($btname, $st02, $clmid);
258 if ($stblk) {
259 $str_html .= $stblk;
260 } else {
261 $btname = '';
264 if (!$btname) {
265 // search for file with the claim id
266 $enc_ar = csv_file_with_pid_enctr($clmid, 'batch', 'ptctln');
267 // (encounter, number, filename,)
268 if (is_array($enc_ar) && count($enc_ar) ) {
269 if (count($enc_ar) > 1) {
270 $str_html .= '<p>Found '. count($enc_ar) . ' instances</p>'.PHP_EOL;
271 // hopefully, only _GET 277 related queries will lack the filename
272 $str_html .= (isset($_POST['enctrbatch'])) ? '' : '<p>May not match to status response</p>'.PHP_EOL;
274 foreach($enc_ar as $enc) {
275 $str_html .= ibr_batch_get_st_block ( $enc[2], $enc[1] );
277 } elseif( is_string($enc_ar) && count($enc_ar) ) {
278 $str_html .= $enc_ar;
279 } else {
280 $str_html .= "Failed to find the batch file for $clmid <br />";
284 return $str_html;
288 * display the x12 segments for an era claim remittance advice
290 * @uses csv_file_with_pid_enctr()
291 * @uses ibr_era_get_clp_text()
292 * @return string
294 function ibr_disp_eraClp() {
295 // get the clp and related segments
296 $str_html = '';
297 $era_enc = filter_input(INPUT_POST, 'enctrEra', FILTER_SANITIZE_STRING);
298 $enc_ar = ($era_enc) ? csv_file_with_pid_enctr($era_enc, 'era', 'encounter') : false;
299 // $enc_ar is an array [i](pid, encounter, filename)
300 if (is_array($enc_ar) && count($enc_ar) ) {
301 foreach($enc_ar as $enc) {
302 //$pe = $enc[0] . "-" . $enc[1];
303 $pe = $enc[0];
304 $str_html .= ibr_era_get_clp_text($pe, $enc[2]);
306 } elseif( count($enc_ar) && is_string($enc_ar) ) {
307 $str_html .= $enc_ar;
308 } else {
309 $str_html .= "Failed to find the remittance for encounter ". strval($era_enc) ."<br />".PHP_EOL;
311 return $str_html;
315 * csv tables filter input and generate table
317 * @uses csv_to_html()
318 * @return string
320 function ibr_disp_csvtable() {
322 $rowp = filter_input(INPUT_POST, 'csvpctrows', FILTER_VALIDATE_INT);
323 $ds = filter_input(INPUT_POST, 'csv_date_start', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
324 $de = filter_input(INPUT_POST, 'csv_date_end', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
325 $csvfile = filter_input(INPUT_POST, 'csvtables', FILTER_SANITIZE_STRING);
327 $row_pct = ($rowp) ? $rowp/100 : 1;
328 if ($ds == NULL || $ds === FALSE ) { $ds = ''; }
329 if ($de == NULL) { $e = ($ds) ? date("Y/M/D", time()) : ''; }
330 if ($csvfile == NULL || $csvfile === FALSE ) {
331 // here we have an error and must quit
332 $str_html= "<p>Error in CSV table name </p>".PHP_EOL;
333 return $str_html;
334 } else {
335 $tp_ar = explode('_', $csvfile);
336 $tbl_type = ($tp_ar[0] == 'claims') ? 'claim' : 'file';
337 $f_type = strval($tp_ar[1]);
338 if ($f_type == '999' || $f_type == '997' || $f_type == '277') {
339 $f_type = 'f'.$f_type;
342 $str_html = csv_to_html($f_type, $tbl_type, $row_pct, $ds, $de);
344 return $str_html;
348 * links for RA info from POST for trace, patient ID, or encounter
350 * @uses csv_file_by_controlnum(
351 * @uses csv_file_with_pid_enctr()
352 * @uses ibr_era_html_page()
353 * @return string
355 function ibr_disp_era_post() {
357 $str_html = '';
358 // POST request from ERA tab -- era by pid, encounter, or trace
359 // there will not be a filename supplied with these values
360 $trace = ''; $pid = ''; $enctr = ''; $search = '';
361 //ibr_era_html_page ( $file_path, $trn_trace=0, $pid_enctr=0, $searchtype='ALL', $fname='835 Remittance Advice')
362 if ( isset($_POST['subtrace835']) && isset($_POST['trace835']) && $_POST['trace835'] ) {
363 $istrc = true;
364 $search = 'trace';
365 $trace = filter_input(INPUT_POST, 'trace835', FILTER_SANITIZE_STRING);
366 $eft = csv_file_by_controlnum('era', $trace);
367 if ($eft) {
368 $str_html .= ibr_era_html_page($eft, $trace, 0, $search, $eft);
369 } else {
370 $str_html .= "Did not find $trace in data <br />".PHP_EOL;
372 } elseif ( isset($_POST['subpid835']) && isset($_POST['pid835']) && $_POST['pid835']) {
373 $ispid = true; $isenc = false;
374 $search = 'pid';
375 $pid = filter_input(INPUT_POST, 'pid835', FILTER_SANITIZE_STRING);
376 $ef = ($pid) ? csv_file_with_pid_enctr ($pid, 'era', 'pid') : false;
377 } elseif (isset($_POST['subenctr835']) && isset($_POST['enctr835']) && $_POST['enctr835'] ) {
378 $isenc = true; $ispid = false;
379 $search = 'encounter';
380 $enctr = filter_input(INPUT_POST, 'enctr835', FILTER_SANITIZE_STRING);
381 $ef = ($enctr) ? csv_file_with_pid_enctr ($enctr, 'era', 'encounter') : false;
384 if ($isenc || $ispid) {
385 if ( is_array($ef) && count($ef) ) {
386 $fn = array();
387 foreach($ef as $val) {
388 // do not repeat filename since all occurences in a file are found
389 if ( in_array($val[2], $fn) ) {
390 continue;
391 } else {
392 $fn[] = $val[2];
393 $str_html .= ibr_era_html_page($val[2], 0, $val[0], $search, $val[2]);
396 } else {
397 $str_html .= "Did not find $pid $enctr in data <br />".PHP_EOL;
401 return $str_html;
406 * links for RA info from GET for patient ID or encounter
408 * @uses csv_file_with_pid_enctr()
409 * @uses ibr_era_claim_summary()
410 * @uses ibr_era_html_page()
411 * @return string
413 function ibr_disp_era_get() {
415 $str_html = '';
417 // all these should open in a new window or tab (target='_blank') except summary
418 $fname = isset($_GET['erafn']) ? filter_input(INPUT_GET, 'erafn', FILTER_SANITIZE_STRING) : '';
419 $pe = isset($_GET['pidenc']) ? filter_input(INPUT_GET, 'pidenc', FILTER_SANITIZE_STRING) : '';
420 $trace = isset($_GET['trace']) ? filter_input(INPUT_GET, 'trace', FILTER_SANITIZE_STRING) : '';
421 $stype = isset($_GET['srchtp']) ? filter_input(INPUT_GET, 'srchtp', FILTER_SANITIZE_STRING) : '';
422 $smy = isset($_GET['summary']) ? filter_input(INPUT_GET, 'summary', FILTER_SANITIZE_STRING) : '';
424 if (!$fname && $pe && $stype=='encounter') {
425 // all RA's for this encounter
426 $ef = csv_file_with_pid_enctr($pe, 'era', $stype);
427 if (is_array($ef) && count($ef) ) {
428 foreach($ef as $val) {
429 // -- do not repeat filename since all occurences in a file are found
430 // (pid-enctr, trace, filename)
431 if ( in_array($val[2], $fn) ) {
432 continue;
433 } else {
434 $fn[] = $val[2];
435 $pe = $val[0];
436 $str_html .= ibr_era_html_page($val[2], 0, $pe, 'encounter', $val[2]);
439 } else {
440 $str_html .= "Did not find $pe in data <br />".PHP_EOL;
442 } elseif (!$fname && $trace) {
443 $fname = csv_file_by_controlnum('era', $trace);
444 if ($fname) {
445 $str_html .= ibr_era_html_page($fname, $trace, 0, 'trace', $fname);
446 } else {
447 $str_html .= "Did not find file for trace $trace <br />".PHP_EOL;
449 } elseif ($fname && $pe && $smy=='yes') {
450 // payment summary for popup dialog
451 $str_html .= ibr_era_claim_summary($fname, $pe);
452 } elseif ($fname && $pe && !$smy) {
453 // all RA's for this patient ID in transaction
454 $str_html .= ibr_era_html_page($fname, 0, $pe, 'encounter', $fname);
455 } elseif ($fname && $trace) {
456 // RA for this trace number
457 $str_html .= ibr_era_html_page($fname, $trace, 0, 'trace', $fname);
460 return $str_html;
463 function ibr_disp_clmhist() {
465 if (isset($_GET['chenctr']) && strlen($_GET['chenctr'])) {
466 $pe = filter_input(INPUT_GET, 'chenctr', FILTER_SANITIZE_STRING);
467 $str_html = csv_claim_history($pe);
468 } else {
469 $str_html = "Error in processing request.<br />".PHP_EOL;
471 return $str_html;
475 * filter input and generate display for claim status response
477 * @uses ibr_277_response_html()
478 * @return string
480 function ibr_disp_status_resp() {
482 $fname = filter_input(INPUT_GET, 'rspfile', FILTER_SANITIZE_STRING);
483 $st = ''; $pe = '';
484 if (isset($_GET['pidenc']) && strlen($_GET['pidenc'])) {
485 $pe = filter_input(INPUT_GET, 'pidenc', FILTER_SANITIZE_STRING);
486 } elseif (isset($_GET['rspstnum']) && strpos($_GET['rspstnum'], '_')) {
487 // the rspstnum is the 277 ISA13_ST02
488 $st = filter_input(INPUT_GET, 'rspstnum', FILTER_SANITIZE_STRING);
491 if (!$pe && !$st) {
492 $str_html = "No claim identification information for claim status.<br />".PHP_EOL;
493 } else {
494 $str_html = ibr_277_response_html($fname, '', '', $pe, $st);
496 return $str_html;
500 * display the message part of a DPR response
502 * @uses ibr_dpr_message()
503 * @return string
505 function ibr_disp_dpr_message() {
507 $fname = filter_input(INPUT_GET, 'dprfile', FILTER_SANITIZE_STRING);
508 if (isset($_GET['dprclm']) && strlen($_GET['dprclm'])) {
509 $pe = filter_input(INPUT_GET, 'dprclm', FILTER_SANITIZE_STRING);
511 if (!$fname || !$pe) {
512 $str_html = "Missing file or claim ID.<br />".PHP_EOL;
513 } else {
514 $str_html = ibr_dpr_message($fname, $pe);
516 return $str_html;
520 * display the message part of a EBR or IBR response
522 * @uses ibr_ebr_message()
523 * @return string
525 function ibr_disp_ebr_message() {
527 $fname = ''; $pe = ''; $btfnm = '';
528 $fname = filter_input(INPUT_GET, 'ebrfile', FILTER_SANITIZE_STRING);
529 if (isset($_GET['ebrclm']) && strlen($_GET['ebrclm'])) {
530 $pe = filter_input(INPUT_GET, 'ebrclm', FILTER_SANITIZE_STRING);
532 if (isset($_GET['batchfile']) && strlen($_GET['batchfile'])) {
533 $btfnm = filter_input(INPUT_GET, 'batchfile', FILTER_SANITIZE_STRING);
535 if (!$fname || !$pe) {
536 $str_html = "Missing file or claim ID.<br />".PHP_EOL;
537 } else {
538 $str_html = ibr_ebr_message($fname, $pe, $btfnm);
540 return $str_html;
544 * display the message part of a 999 response
546 * @uses ibr_997_errscan()
547 * @return string
549 function ibr_disp_997_message() {
551 $fname = ''; $akval = ''; $errval = '';
552 $fname = filter_input(INPUT_GET, 'fv997', FILTER_SANITIZE_STRING);
553 if (isset($_GET['aknum'])) { $akval = filter_input(INPUT_GET, 'aknum', FILTER_SANITIZE_STRING); }
554 if (isset($_GET['err997'])) { $errval = filter_input(INPUT_GET, 'err997', FILTER_SANITIZE_STRING); }
555 if (!$fname) {
556 $str_html = "Missing file name.<br />".PHP_EOL;
557 } else {
558 $str_html = ibr_997_errscan($fname, $akval);
560 return $str_html;
564 * display the message part of a ACK or TA1 response
566 * @uses ibr_ack_error()
567 * @return string
569 function ibr_disp_ta1_message() {
571 $fname = ''; $code = '';
572 $fname = filter_input(INPUT_GET, 'ackfile', FILTER_SANITIZE_STRING);
573 if (isset($_GET['ackcode'])) $code = filter_input(INPUT_GET, 'ackcode', FILTER_SANITIZE_STRING);
574 if ($fname && $code) {
575 $str_html = ibr_ack_error($fname, $code);
576 } else {
577 $str_html = 'Code value invalid <br />'.PHP_EOL;
579 return $str_html;
584 * filter input and display local era file
586 * @uses ibr_upload_files()
587 * @uses ibr_era_html_page()
588 * @return string
590 function ibr_disp_erafileUpl() {
591 // file uploads; single file controls
592 $str_html = '';
594 if ( count($_FILES) ) {
595 $f_array = ibr_upload_files($str_html);
596 if ( is_array($f_array) && count($f_array) ) {
597 $f_name = basename($f_array['era'][0]);
598 $str_html .= ibr_era_html_page($f_array['era'][0], 0, 0, 0, $f_name);
599 } else {
600 $str_html .= "no files accepted <br />" . PHP_EOL;
602 } else {
603 $str_html .= "no file submitted <br />" . PHP_EOL;
605 return $str_html;
609 * uploading of new files
611 * @uses ibr_upload_files()
612 * @uses ibr_sort_upload()
613 * @return string
615 function ibr_disp_fileMulti() {
616 // multiple file upload
617 $str_html = '';
618 if ( count($_FILES) ) {
619 $f_array = ibr_upload_files($str_html);
620 if ( is_array($f_array) && count($f_array) ) {
621 $str_html .= "sending ".count($f_array)." type for sorting <br />" .PHP_EOL;
622 $str_html .= ibr_sort_upload($f_array, $htm, $er);
623 } else {
624 $str_html .= "no files accepted <br />".PHP_EOL;
626 } else {
627 $str_html .= "no files submitted <br />" . PHP_EOL;
629 $str_html .= PHP_EOL."<form>".PHP_EOL;
630 $str_html .= "<input type='button' id='closepopup' value='Close' onclick='self.close()'>".PHP_EOL;
631 $str_html .= "</form>".PHP_EOL;
633 return $str_html;
638 * filter input and generate display of x12 file
640 * @uses csv_filetohtml()
641 * @uses ibr_upload_files()
642 * @uses ibr_ebr_ebt_name()
643 * @return string
645 function ibr_disp_fileText() {
647 $str_html = '';
648 //isset($_POST['fileX12']) && isset($_FILES['fileUplx12'])
649 if ( count($_FILES) && isset($_FILES['fileUplx12']) ) {
650 $fn = htmlentities($_FILES['fileUplx12']['name']);
651 $str_html = ibr_html_heading('newfiles', $fn);
652 $f_array = ibr_upload_files($str_html);
653 if ( is_array($f_array) && count($f_array) ) {
654 $str_html .= csv_filetohtml($f_array);
655 } else {
656 $str_html = ibr_html_heading('error');
657 $str_html .= "no files accepted <br />" . PHP_EOL;
659 } elseif ( isset($_GET['fvkey']) ) {
660 $fn = filter_input(INPUT_GET, 'fvkey', FILTER_SANITIZE_STRING);
661 // Availity 'readable' versions ibr, ebr, dpr
662 $ishr = (isset($_GET['readable']) && $_GET['readable']=='yes') ? true : false;
663 if (!$fn) {
664 $str_html = ibr_html_heading('error');
665 } elseif ($ishr && $fn) {
666 $ftxt = ibr_ebr_ebt_name($fn);
667 $str_html = ibr_html_heading('textdisplay', $ftxt);
668 $str_html .= csv_filetohtml($ftxt);
669 } else {
670 $bn = basename($fn);
671 $str_html = ibr_html_heading('textdisplay', $bn);
672 $str_html .= csv_filetohtml($fn);
674 } elseif (isset($_GET['btctln']) ) {
675 $btisa13 = filter_input(INPUT_GET, 'btctln', FILTER_SANITIZE_STRING);
676 if ($btisa13) {
677 //$btname = ibr_batch_find_file_with_controlnum($btisa13);
678 $btname = csv_file_by_controlnum('batch', $btisa13);
679 $str_html = ibr_html_heading('textdisplay', $btname);
680 if ($btname) {
681 $str_html .= csv_filetohtml($btname);
682 } else {
683 $str_html .= "Failed to identify file with control number $btisa13 <br />".PHP_EOL;
685 } else {
686 $str_html .= "error in file display <br />";
688 } else {
689 $str_html = ibr_html_heading('error');
690 $str_html .= "error in file display <br />";
692 return $str_html;
696 * check if the batch control number is found in the 997/999 files table
698 * @uses csv_search_record()
699 * @return string
701 function ibr_disp_997_for_batch() {
702 $str_html = '';
703 $batch_icn = filter_input(INPUT_GET, 'batchicn', FILTER_SANITIZE_STRING);
704 if ($batch_icn) {
705 $ctln = (strlen($batch_icn) >= 9) ? substr($batch_icn, 0, 9) : trim(strval($batch_icn));
706 $search = array('s_val'=>$ctln, 's_col'=>3, 'r_cols'=>'all');
707 $result = csv_search_record('f997', 'file', $search, "1");
709 // should be matching row(s) from files_997.csv
710 if (is_array($result) && count($result)) {
711 $str_html .= "<p>Acknowledgement information</p>".PHP_EOL;
712 foreach($result as $rslt) {
713 $ext = substr($rslt[1], -3);
715 $str_html .= "Date: {$rslt[0]} <br />".PHP_EOL;
716 $str_html .= "File: <a target=\"blank\" href=edi_history_main.php?fvkey={$rslt[1]}>{$rslt[1]}</a> <br />".PHP_EOL;
717 $str_html .= "Batch ICN: {$rslt[3]} <br />";
718 // error count or code in position 4
719 if ($ext == '999' || $ext == '997') {
720 $str_html .= "Rejects: {$rslt[4]} <br />".PHP_EOL;
721 // don't have dialog from this dialog, so don't link
722 //$str_html .= "Rejects: <a class=\"codeval\" target=\"_blank\" href=\"edi_history_main.php?fv997={$rslt[1]}&err997={$rslt[4]}\">{$rslt[4]}</a><br />".PHP_EOL;
723 } elseif ($ext == 'ta1' || $ext == 'ack') {
724 $str_html .= "Code: {$rslt[4]} <br />".PHP_EOL;
725 //$str_html .= "Code: <a class=\"codeval\" target=\"_blank\" href=\"edi_history_main.php?ackfile={$rslt[1]}&ackcode={$rslt[4]}\">{$rslt[4]}</a><br />".PHP_EOL;
728 } else {
729 $str_html .= "Did not find corresponding 997/999 file for $ctln<br />".PHP_EOL;
731 } else {
732 $str_html .= "Invalid value for ICN number<br />".PHP_EOL;
734 return $str_html;
738 * function to check whether an era payment has been processed and applied
740 * @uses sqlQuery()
742 * @return string
744 function ibr_disp_is_era_processed() {
746 $str_html = '';
747 $ckno = filter_input(INPUT_GET, 'tracecheck', FILTER_SANITIZE_STRING);
748 if ($ckno) {
749 $srchval = 'ePay - '.$ckno;
750 // reference like '%".$srchval."%'"
751 $row = sqlQuery("SELECT reference, pay_total, global_amount FROM ar_session WHERE reference = ?", array($srchval) );
752 if (!empty($row)) {
753 $str_html .= "trace {$row['reference']} total \${$row['pay_total']}";
754 if ($row['global_amount'] === '0') {
755 $str_html .= " fully allocated";
756 } else {
757 $str_html .= " ({$row['global_amount']} not allocated)";
759 } else {
760 $str_html .= "trace $ckno not posted";
762 } else {
763 $str_html .= "trace not valid ID";
765 return $str_html;
769 * jQuery adds a special HTTP header for ajax requests
771 * @return bool
773 function is_xhr() {
774 return @ $_SERVER[ 'HTTP_X_REQUESTED_WITH' ] === 'XMLHttpRequest';