/** * check the csv claims tables and return rows for a particular encounter * * @uses csv_pid_enctr_parse() * @uses csv_file_with_pid_enctr() * @uses csv_table_select_list() * @uses csv_search_record() * @param string encounter number * @return string */ function csv_claim_history($encounter) { // if ($encounter) { $enct = csv_pid_enctr_parse(strval($encounter)); $e = $enct ? $enct['enctr'] : false; } // if (!$e) { return "invalid encounter value {$encounter} <br />" . PHP_EOL; } // get complete pid-encounter from the batch claims record $efp = csv_file_with_pid_enctr($e); if (is_array($efp) && count($efp)) { $pe = $efp[0][0]; } else { csv_edihist_log("csv_claim_history: failed to locate {$e} in batch claims record"); return "failed to locate {$e} in batch claims record"; } // use function csv_table_select_list() so that only // existing csv tables are queried $tbl2 = csv_table_select_list('array'); $rtypes = array(); if (is_array($tbl2) && count($tbl2)) { foreach ($tbl2 as $tbl) { $tp1 = explode(' ', $tbl['desc']); if ($tp1[1] == 'files') { continue; } if ($tp1[0] == '999' || $tp1[0] == '997' || $tp1[0] == '277') { $k = 'f' . $tp1[0]; $rtypes[$k] = $k; } elseif ($tp1[0] == 'ibr' || $tp1[0] == 'ebr' || $tp1[0] == 'dpr') { $k = $tp1[0]; $rtypes['prop'][] = $k; } else { $k = $tp1[0]; $rtypes[$k] = $k; } } } else { csv_edihist_log("csv_claim_history: failed to get csv table names"); return "failed to get csv table names"; } // $ch_html .= "<table class='clmhist' columns=4><caption>Encounter Record for {$pe}</caption>"; $ch_html .= "<tbody>" . PHP_EOL; // if (isset($rtypes['batch'])) { $tp = 'batch'; $srchar = array('s_val' => $pe, 's_col' => 2, 'r_cols' => 'all'); $btar = csv_search_record($tp, 'claim', $srchar, '2'); // $ch_html .= "<tr class='chhead'>" . PHP_EOL; $ch_html .= "<td>Name</td><td>SvcDate</td><td>CLM01</td><td>File</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; if (is_array($btar) && count($btar)) { foreach ($btar as $ch) { $dt = substr($ch[1], 0, 4) . '-' . substr($ch[1], 4, 2) . '-' . substr($ch[1], 6, 2); //array('PtName', 'SvcDate', 'clm01', 'InsLevel', 'Ctn_837', 'File_837', 'Fee', 'PtPaid', 'Provider' ); $ch_html .= "<tr class='chbatch'>" . PHP_EOL; // $ch_html .= "<td>{$ch[0]}</td>" . PHP_EOL; $ch_html .= "<td>{$dt}</td>" . PHP_EOL; $ch_html .= "<td><a class='btclm' target='_blank' href='edi_history_main.php?fvbatch={$ch[5]}&btpid={$ch[2]}'>{$ch[2]}</a></td>" . PHP_EOL; $ch_html .= "<td title='{$ch[4]}'><a target='_blank' href='edi_history_main.php?fvkey={$ch[5]}'>{$ch[5]}</a></td>" . PHP_EOL; // $ch_html .= "</tr>" . PHP_EOL; } } else { $ch_html .= "<tr class='chbatch'>" . PHP_EOL; $ch_html .= "<td colspan=4>Batch -- Nothing found for {$pe} in {$tp} record</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; } } // if (isset($rtypes['f997'])) { $tp = 'f997'; $srchar = array('s_val' => $pe, 's_col' => 2, 'r_cols' => 'all'); $f997ar = csv_search_record($tp, 'claim', $srchar, '2'); // $ch_html .= "<tr class='chhead'>" . PHP_EOL; $ch_html .= "<td>Response</td><td>Status</td><td>File</td><td>Notes</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; if (is_array($f997ar) && count($f997ar)) { foreach ($f997ar as $ch) { // $msg = strlen($ch[7]) ? $ch[7] : 'ST Number'; //array('PtName', 'SvcDate', 'clm01', 'Status', 'ak_num', 'File_997', 'Ctn_837', 'err_seg'); $ch_html .= "<tr class='chf997'>"; $ch_html .= "<td>997/999</td>" . PHP_EOL; $ch_html .= "<td><a class='clmstatus' target='_blank' href='edi_history_main.php?fv997={$ch[5]}&aknum={$ch[4]}'>{$ch[3]}</a></td>" . PHP_EOL; $ch_html .= "<td><a target='_blank' href='edi_history_main.php?fvkey={$ch[5]}'>{$ch[5]}</a></td>" . PHP_EOL; $ch_html .= "<td title='{$msg}'>{$ch[6]} {$ch[4]}</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; } } else { $ch_html .= "<tr class='chf997'>"; $ch_html .= "<td colspan=4>x12 999 -- Nothing found for {$pe}</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; } } // if (isset($rtypes['f277'])) { $tp = 'f277'; // $srchar = array('s_val' => $pe, 's_col' => 2, 'r_cols' => 'all'); $f277ar = csv_search_record($tp, 'claim', $srchar, '2'); // $ch_html .= "<tr class='chhead'>" . PHP_EOL; $ch_html .= "<td>Response</td><td>Status</td><td>File</td><td>ClaimID</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; if (is_array($f277ar) && count($f277ar)) { foreach ($f277ar as $ch) { // array('PtName', 'SvcDate', 'clm01', 'Status', 'st_277', 'File_277', 'payer_name', 'claim_id', 'bht03_837'); $ch_html .= "<tr class='chf277'>"; // $ch_html .= "<td>x12 277</td>" . PHP_EOL; $ch_html .= "<td><a class='clmstatus' target='_blank' href='edi_history_main.php?rspfile={$ch[5]}&pidenc={$ch[2]}&rspstnum={$ch[4]}'>{$ch[3]}</a></td>" . PHP_EOL; $ch_html .= "<td title='{$ch[5]}'><a target='_blank' href='edi_history_main.php?fvkey={$ch[5]}'>File</a></td>" . PHP_EOL; $ch_html .= "<td title='{$ch[6]}'>{$ch[7]}</td>" . PHP_EOL; // $ch_html .= "</tr>" . PHP_EOL; } } else { $ch_html .= "<tr class='chf277'>"; $ch_html .= "<td colspan=4>x12 277 -- Nothing found for {$pe}</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; } } // if (is_array($rtypes['prop']) && count($rtypes['prop'])) { foreach ($rtypes['prop'] as $tp) { // $rspnm = strtoupper($tp); $srchar = array('s_val' => $pe, 's_col' => 2, 'r_cols' => 'all'); $ibrar = csv_search_record($tp, 'claim', $srchar, '2'); // $ch_html .= "<tr class='chhead'>" . PHP_EOL; $ch_html .= "<td>Response</td><td>Status</td><td>File</td><td>Payer</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; if (is_array($ibrar) && count($ibrar)) { foreach ($ibrar as $ch) { //array('PtName','SvcDate', 'clm01', 'Status', 'Batch', 'FileName', 'Payer'); $ch_html .= "<tr class='ch{$tp}'>"; // $ch_html .= "<td>{$rspnm}</td>" . PHP_EOL; if ($tp == 'dpr') { $ch_html .= "<td><a class='clmstatus' target='_blank' href='edi_history_main.php?dprfile={$ch[5]}&dprclm={$ch[2]}'>{$ch[3]}</a></td>" . PHP_EOL; } else { $ch_html .= "<td><a class='clmstatus' target='_blank' href='edi_history_main.php?ebrfile={$ch[5]}&ebrclm={$ch[2]}&batchfile={$ch[4]}'>{$ch[3]}</a></td>" . PHP_EOL; } $ch_html .= "<td title='{$ch[5]}'><a target='_blank' href='edi_history_main.php?fvkey={$ch[5]}'>File</a></td>" . PHP_EOL; $ch_html .= "<td>{$ch[6]}</td>" . PHP_EOL; // $ch_html .= "</tr>" . PHP_EOL; } } else { $ch_html .= "<tr class='ch{$tp}'>"; $ch_html .= "<td colspan=4>{$rspnm} -- Nothing found for {$pe}</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; } } } // if (isset($rtypes['era'])) { $tp = 'era'; // $srchar = array('s_val' => $pe, 's_col' => 2, 'r_cols' => 'all'); $eraar = csv_search_record($tp, 'claim', $srchar, '2'); // $ch_html .= "<tr class='chhead'>" . PHP_EOL; $ch_html .= "<td>Response</td><td>Status</td><td>Trace</td><td>Payer</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; if (is_array($eraar) && count($eraar)) { foreach ($eraar as $ch) { // $msg = $ch[6] . ' ' . $ch[7] . ' ' . $ch[8]; // array('PtName', 'SvcDate', 'clm01', 'Status', 'trace', 'File_835', 'claimID', 'Pmt', 'PtResp', 'Payer'); $ch_html .= "<tr class='ch835'>"; // $ch_html .= "<td>x12 ERA</td>" . PHP_EOL; $ch_html .= "<td>{$ch[3]} <a class='clmstatus' target='_blank' href='edi_history_main.php?erafn={$ch[5]}&pidenc={$ch[2]}&summary=yes'>S</a> <a target='_blank' href='edi_history_main.php?erafn={$ch[5]}&pidenc={$ch[2]}&srchtp=encounter'>RA</a></td>" . PHP_EOL; $ch_html .= "<td><a target='_blank' href='edi_history_main.php?erafn={$ch[5]}&trace={$ch[4]}&srchtp=trace'>{$ch[4]}</a> <a target='_blank' href='edi_history_main.php?fvkey={$ch[5]}'>x12</a></td>" . PHP_EOL; $ch_html .= "<td title={$msg}>{$ch[9]}</td>" . PHP_EOL; // $ch_html .= "</tr>" . PHP_EOL; } } else { $ch_html .= "<tr class='ch835'>"; $ch_html .= "<td colspan=4>x12 835 ERA -- Nothing found for {$pe}</td>" . PHP_EOL; $ch_html .= "</tr>" . PHP_EOL; } // } // end if($tp ... // -- this is where a query on the payments datatable could be used to show if payment // has been received, even if no era file shows the payment. // $ch_html .= "</tbody>" . PHP_EOL; $ch_html .= "</table>" . PHP_EOL; // return $ch_html; }
/** * Select the substring of ST...SE segments comprising a claim in a batch file. * * one of $st_clm_num or $pid_enctr must be provided * the batch file, if unknown and given as '', may be found if a $pid_enctr is supplied * * @uses csv_parameters() * @uses csv_verify_file() * @uses ibr_batch_st_html() * @uses csv_file_with_pid_enctr() * @param string $batch_file the batch file name * @param string $st_clm_num the ST02 number in the batch file * @param string $pid_enctr the pid-encounter identifying the claim * @param boolean $plain_text just return the ST...SE segments substring * @return string html table from ibr_batch_st_html() */ function ibr_batch_get_st_block($batch_file, $st_clm_num = NULL, $pid_enctr = NULL, $plain_text = FALSE) { // // get the substring of the batch file containing the ST number // if (is_null($st_clm_num) && is_null($pid_enctr)) { csv_edihist_log("ibr_batch_get_st_block: both st_clm_num and pid_enctr were NULL"); $out_str .= "ibr_batch_get_st_block: you must provide either ST number or pid-encounter <br />" . PHP_EOL; return $out_str; } // $out_str = ""; $msg_str = ''; $btchname = basename($batch_file); // $bfullpath = $batch_file ? csv_verify_file($batch_file, 'batch') : ''; if ($bfullpath) { $out_str .= $batch_file . PHP_EOL; $btchname = basename($bfullpath); } else { // possibly batch file was not determined when parsing a response file if ($batch_file && !$bfullpath) { if (strlen($batch_file) >= 9) { // try control number search $btchname = csv_file_by_controlnum('batch', $batch_file); $bfullpath = csv_verify_file($btchname, 'batch'); if (!$bfullpath) { $msg_str .= "batch file not found: {$batch_file}" . PHP_EOL; } } else { $msg_str .= "batch file not found: {$batch_file}" . PHP_EOL; } } elseif (!$batch_file) { $msg_str .= "batch file name not supplied"; } if (!$bfullpath && $pid_enctr) { $pe1 = trim($pid_enctr); $btnm1 = csv_file_with_pid_enctr($pe1, 'batch', 'ptctln'); // select the last file found $btnm2 = count($btnm1) ? $btnm1[count($btnm1) - 1][1] : FALSE; if ($btnm2) { $bfullpath = csv_verify_file($btnm2, 'batch'); for ($i = 0; $i < count($btnm1); $i++) { $msg_str .= "found {$btnm1[$i][1]}" . PHP_EOL; } $msg_str .= "using {$btnm2}" . PHP_EOL; } else { $bfullpath = FALSE; } // } elseif (!$bfullpath && strlen($st_clm_num) == 13) { $ctln = substr($st_clm_num, 0, 9); $stnum = substr($st_clm_num, -4); $btnm1 = csv_file_by_controlnum('batch', $ctln); $bfullpath = $btnm1 ? csv_verify_file($btnm1, 'batch') : FALSE; } else { csv_edihist_log("ibr_batch_get_st_block: batch file not found"); return false; } } // Now, if we determined the file name $bstr = $bfullpath ? file_get_contents($bfullpath) : FALSE; if (!$bstr) { csv_edihist_log("ibr_batch_get_st_block: failed to read file {$btchname}"); return false; } // if ($pid_enctr) { $pe = trim($pid_enctr); $seg_clm = "CLM*{$pe}*"; $seg_st = "ST*837*"; $clm_pos = strpos($bstr, $seg_clm, 0); // php directions for strrpos are wrong $st_pos = strrpos(substr($bstr, 0, $clm_pos), $seg_st); $seg_st = substr($bstr, $st_pos, 11); $st_num = substr($seg_st, -4); } elseif ($st_clm_num) { $st_num = substr($st_clm_num, -4) ? substr($st_clm_num, -4) : trim($st_clm_num); if (strlen($st_num) < 4) { $st_num = str_pad($st_num, 4, "0", STR_PAD_LEFT); } $seg_st = 'ST' . SEG_ELEM_DELIM . '837' . SEG_ELEM_DELIM . $st_num; // particular ST block $st_pos = strpos($bstr, $seg_st, 0); } else { csv_edihist_log("ibr_batch_get_st_block: ST number and Encounter missing"); return FALSE; } // break it off if $st_pos is not found if ($st_pos === FALSE) { csv_edihist_log("ibr_batch_get_st_block: ST {$st_num} not found in {$btchname}"); return FALSE; } // $seg_se = SEG_TERM_DELIM . 'SE' . SEG_ELEM_DELIM; // $se1 = strpos($bstr, $seg_se, $st_pos); $se2 = strpos($bstr, SEG_TERM_DELIM, $se1 + 1) + 1; // $str_st = substr($bstr, $st_pos, $se2 - $st_pos); // if ($plain_text) { $out_str = $str_st; } else { $bnm = basename($bfullpath); $clmid = $pe ? $pe : $st_num; $out_str = ibr_batch_st_html($str_st, $bnm, $clmid, $msg_str); } // return $out_str; }
/** * links for RA info from GET for patient ID or encounter * * @uses csv_file_with_pid_enctr() * @uses ibr_era_claim_summary() * @uses ibr_era_html_page() * @return string */ function ibr_disp_era_get() { // $str_html = ''; // // all these should open in a new window or tab (target='_blank') except summary $fname = isset($_GET['erafn']) ? filter_input(INPUT_GET, 'erafn', FILTER_SANITIZE_STRING) : ''; $pe = isset($_GET['pidenc']) ? filter_input(INPUT_GET, 'pidenc', FILTER_SANITIZE_STRING) : ''; $trace = isset($_GET['trace']) ? filter_input(INPUT_GET, 'trace', FILTER_SANITIZE_STRING) : ''; $stype = isset($_GET['srchtp']) ? filter_input(INPUT_GET, 'srchtp', FILTER_SANITIZE_STRING) : ''; $smy = isset($_GET['summary']) ? filter_input(INPUT_GET, 'summary', FILTER_SANITIZE_STRING) : ''; // if (!$fname && $pe && $stype == 'encounter') { // all RA's for this encounter $ef = csv_file_with_pid_enctr($pe, 'era', $stype); if (is_array($ef) && count($ef)) { foreach ($ef as $val) { // -- do not repeat filename since all occurences in a file are found // (pid-enctr, trace, filename) if (in_array($val[2], $fn)) { continue; } else { $fn[] = $val[2]; $pe = $val[0]; $str_html .= ibr_era_html_page($val[2], 0, $pe, 'encounter', $val[2]); } } } else { $str_html .= "Did not find {$pe} in data <br />" . PHP_EOL; } } elseif (!$fname && $trace) { $fname = csv_file_by_controlnum('era', $trace); if ($fname) { $str_html .= ibr_era_html_page($fname, $trace, 0, 'trace', $fname); } else { $str_html .= "Did not find file for trace {$trace} <br />" . PHP_EOL; } } elseif ($fname && $pe && $smy == 'yes') { // payment summary for popup dialog $str_html .= ibr_era_claim_summary($fname, $pe); } elseif ($fname && $pe && !$smy) { // all RA's for this patient ID in transaction $str_html .= ibr_era_html_page($fname, 0, $pe, 'encounter', $fname); } elseif ($fname && $trace) { // RA for this trace number $str_html .= ibr_era_html_page($fname, $trace, 0, 'trace', $fname); } // return $str_html; }