/** * Look up file name by control number * * @param string * @param string * * @return string */ function edih_997_sbmtfile($icn, $filetype) { // if (strlen($icn) == 13) { $bticn = substr($icn, 0, 9); $stn = substr($icn, -4); } else { $bticn = $icn; } if (is_numeric($filetype)) { $ftp = 'f' . $filetype; } else { $ftp = $filetype; } // $btfn = csv_file_by_controlnum($ftp, $bticn); $bfullpath = $btfn ? csv_check_filepath($btfn, $ftp) : ''; // return $bfullpath; }
/** * open and verify a default edih_x12_file object * * @uses csv_check_filepath() * * @param string filepath or filename * @parm string file x12 type * @return object edih_x12_file class */ function csv_check_x12_obj($filepath, $type = '') { // $x12obj = false; $ok = false; // $fp = csv_check_filepath($filepath, $type); // if ($fp) { $x12obj = new edih_x12_file($fp); if ('edih_x12_file' == get_class($x12obj)) { if ($x12obj->edih_valid() == 'ovigs') { $ok = count($x12obj->edih_segments()); $ok = $ok ? count($x12obj->edih_envelopes()) : false; $ok = $ok ? count($x12obj->edih_delimiters()) : false; if (!$ok) { csv_edihist_log("csv_check_x12_obj: object missing properties [{$filepath}]"); csv_edihist_log($x12obj->edih_message()); return false; } } else { csv_edihist_log("csv_check_x12_obj: invalid object {$filepath}"); return false; } } else { csv_edihist_log("csv_check_x12_obj: object not edih_x12_file {$filepath}"); return false; } } else { csv_edihist_log("csv_check_x12_obj: invalid file path {$filepath}"); return false; } // return $x12obj; }
/** * Verify readibility and check for some expected content. * * @uses csv_check_filepath() * @param string $file_path full path to file * @param string $type one of our file types * @param bool $val_array optional; default is false, whether to return filepath only * or array(filepath, next_segment) * @return string|array string file path or array if valid, otherwise 'false' */ function csv_verify_file($file_path, $type, $val_array = FALSE) { // check whether $file_path actually leads to a plausible x12 file // and supply proper directory if needed $fp = csv_check_filepath($file_path, $type); // // verify that the file is correct format by checking the first ST segment if ($fp) { // $type = strtolower($type); // if ($type == "batch" || $type == "837") { $st_str = "ST*837"; $next_segment = "GS"; $slen = 250; } if ($type == "era" || $type == "835") { $st_str = "ST*835"; $next_segment = "GS"; $slen = 250; } if ($type == "997" || $type == "f997") { $st_str = "ST*997"; $next_segment = "TA1"; $slen = 250; } if ($type == "999" || $type == "f999") { $st_str = "ST*999"; $next_segment = "TA1"; $slen = 250; } if ($type == "277" || $type == "f277") { $st_str = "ST*277"; $next_segment = "GS"; $slen = 250; } if ($type == "271" || $type == "f271") { $st_str = "ST*271"; $next_segment = "GS"; $slen = 250; } if ($type == "ta1") { $st_str = "TA1*"; $next_segment = "TA1"; $slen = 200; } // note the ebr, ibr, dpr ack checks will not be valid for years < 2010 or > 2019 if ($type == "ebr") { $st_str = "1|201"; $slen = 10; } if ($type == "ibr") { $st_str = "1|201"; $slen = 10; } if ($type == "dpr") { $st_str = "DPR|201"; $slen = 10; } if ($type == "ack") { $st_str = "1|201"; $slen = 10; } if ($type == "text") { $st_str = "Date Received"; $slen = 800; } // for proprietary file formats, if we have a list of clearinghouses, // the $st_str could be "Availity|Emdeon|ABC " etc. and name probably found in the first 100 characters // instead of Date Received, which I just guess will be standard and within the first 500 characters $f_str = file_get_contents($fp, FALSE, NULL, 0, $slen); $st_pos = strpos($f_str, $st_str); // // special check for 997/999 types, since 999 may be type 997 if (($type == "997" || $type == "f997") && preg_match('/\\.999$/', $fp)) { $st_pos = strpos($f_str, "ST*999"); $next_segment = "TA1"; } //$f_str = file_get_contents($fp); //$st_pos = strpos(substr($f_str, 0, $slen), $st_str); if ($st_pos === FALSE) { // did not find the magic word csv_edihist_log("csv_verify_file: Error, not a valid {$type} file: {$file_path}"); //echo "ibr_era_check_path Error, not a valid $type file: $file_path <br />" $fp = FALSE; $next_segment = FALSE; } } else { $next_segment = ''; } if ($val_array) { return array($fp, $next_segment); } else { return $fp; } }
/** * display fule uploaded from x12 File tab * wrap individual transactions in accordian jquery ui widget * * @uses csv_check_x12_obj() * @uses edih_html_heading() * @uses edih_271_transaction_html() * @uses edih_278_transaction_html() * @uses edih_277_transaction_html() * @uses edih_835_html_page() * @uses edih_display_text() * * @param string path to x12 file * @return string */ function edih_disp_x12file() { // $str_htm = ''; $fn = $ft = $icn = $trace = $rsptype = $format = ''; // if (isset($_POST['x12_html'])) { $htmval = filter_input(INPUT_POST, 'x12_html', FILTER_SANITIZE_STRING); $format = $htmval == 'html' ? 'htm' : 'seg'; $upldir = csv_edih_tmpdir(); } else { $format = 'seg'; } // post request from x12 file tab if (count($_FILES) && isset($_FILES['fileUplx12'])) { $fnupl = htmlentities($_FILES['fileUplx12']['name']); // the upload files validator $f_array = edih_upload_files(); // if (is_array($f_array) && count($f_array)) { // was file rejected? if (isset($f_array['reject'])) { $fn = count($f_array['reject'][0]) ? $f_array['reject'][0]['name'] : ''; $cmt = count($f_array['reject'][0]) ? $f_array['reject'][0]['comment'] : ''; //$str_html = edih_html_heading('error'); $str_htm .= "<p>Rejected file:</p>" . PHP_EOL; $str_htm .= "<p>{$fn}<br>" . PHP_EOL; $str_htm .= " -- {$cmt}</p>" . PHP_EOL; // csv_edihist_log("edih_disp_x12file: rejected file {$fn} comment: {$cmt}"); // return $str_htm; } else { $fnar = reset($f_array); // type filename array $ft = key($f_array); // type $fn1 = $f_array[$ft][0]; //$upldir.DS. $fn = csv_check_filepath($fn1); csv_edihist_log("edih_disp_x12file: submitted POST {$format} {$ft} {$fn1} {$fnupl}"); // if (!$fn) { //$str_htm = edih_html_heading('error'); $str_htm .= "<p>Path error for {$fn1}</p>" . PHP_EOL; csv_edihist_log("edih_disp_x12file: Path error for {$fn1}"); return $str_htm; } } } else { //$str_htm = edih_html_heading('error'); $str_htm .= "<p>File not accepted {$fnupl}</p>" . PHP_EOL; csv_edihist_log("edih_disp_x12file: File not accepted {$fnupl}"); return $str_htm; } } elseif (isset($_GET['gtbl']) && $_GET['gtbl'] == 'file') { // this is a GET request from csv files table // assemble variables $fn = isset($_GET['fname']) ? filter_input(INPUT_GET, 'fname', FILTER_SANITIZE_STRING) : ''; $ft = isset($_GET['ftype']) ? filter_input(INPUT_GET, 'ftype', FILTER_SANITIZE_STRING) : ''; $icn = isset($_GET['icn']) ? filter_input(INPUT_GET, 'icn', FILTER_SANITIZE_STRING) : ''; $trace = isset($_GET['trace']) ? filter_input(INPUT_GET, 'trace', FILTER_SANITIZE_STRING) : ''; $rsptype = isset($_GET['rsptype']) ? filter_input(INPUT_GET, 'rsptype', FILTER_SANITIZE_STRING) : ''; $format = isset($_GET['fmt']) ? filter_input(INPUT_GET, 'fmt', FILTER_SANITIZE_STRING) : ''; // } else { //$str_htm = edih_html_heading('error'); $str_htm .= "<p>Error: No request received by server</p>" . PHP_EOL; csv_edihist_log("edih_disp_x12file: No request received by server"); return $str_htm; } // if (!$fn) { if ($ft && $icn) { $fnr = csv_file_by_controlnum($ft, $icn); $fn = csv_check_filepath($fnr); } elseif ($ft && $trace && $rsptype) { $fnr = csv_file_by_trace($trace, $ft, $rsptype); $fn = csv_check_filepath($fnr); $ft = $rsptype; $trace = ''; } elseif ($ft == 'f835' && $trace) { $fnr = csv_file_by_trace($trace, $ft, $rsptype); $fn = csv_check_filepath($fnr); } elseif ($ft == 'f997' && $trace && $rsptype) { $fnr = csv_file_by_controlnum($rsptype, $trace); $fn = csv_check_filepath($fnr); $ft = $rsptype; $trace = ''; if (!$fn) { $str_htm .= "<p>997/999 Trace value {$trace} not found for type {$rsptype}</p>" . PHP_EOL; csv_edihist_log("edih_disp_x12file: 997/999 Trace value {$trace} not found for type {$rsptype}"); return $str_htm; } } } if (!$fn) { //$str_htm = edih_html_heading('error'); $str_htm .= "<p>Name error for file: type {$ft} icn {$icn} trace {$trace} rsp {$rsptype}</p>" . PHP_EOL; csv_edihist_log("edih_disp_x12file: Name error for file: type {$ft} icn {$icn} trace {$trace} rsp {$rsptype}"); return $str_htm; } // if ($format == 'seg') { if ($ft == 'f835' && $trace) { $str_htm .= edih_display_text($fn, $ft, $trace, true); } elseif ($icn) { $str_htm .= edih_display_text($fn, $ft, $icn, true); } else { $str_htm .= edih_display_text($fn, $ft); } csv_edihist_log("edih_disp_x12file: segments display {$fn}"); // return $str_htm; } // request is for html display // now go through each file type // 'HB'=>'271', 'HS'=>'270', 'HR'=>'276', 'HI'=>'278','HN'=>'277', // 'HP'=>'835', 'FA'=>'999', 'HC'=>'837'); if ($ft == 'f271' || $ft == 'f270') { //$str_htm .= edih_html_heading('eligibility', $fn); $str_htm .= edih_271_html($fn); //$str_htm .= "</body>".PHP_EOL."</html>".PHP_EOL; } elseif ($ft == 'f276' || $ft == 'f277') { //$str_htm .= edih_html_heading('claimstatus', $fn); $str_htm .= edih_277_html($fn); //$str_htm .= "</body>".PHP_EOL."</html>".PHP_EOL; } elseif ($ft == 'f278') { //$str_htm .= edih_html_heading('claimstatus', $fn); $str_htm .= edih_278_html($fn); //$str_htm .= "</body>".PHP_EOL."</html>".PHP_EOL; } elseif ($ft == 'f835') { //$str_htm .= edih_html_heading('eradisplay', $fn); $str_htm = edih_835_html($fn, $trace); //$str_htm .= "</body>".PHP_EOL."</html>".PHP_EOL; } else { // no html format for this type // object is created in edih_display_text function // edih_display_text($filepath, $filetype='', $claimid='', $trace=false, $err_info='') //$str_htm .= edih_html_heading('x12display', $fn); $str_htm .= edih_display_text($fn, $ft); //$str_htm .= "</body>".PHP_EOL."</html>".PHP_EOL; } // return $str_htm; }