Ejemplo n.º 1
0
/** 
 * Create an html report on rejected files or transactions
 *
 * @uses edih_997_ta1_code()
 * @uses edih_997_code_text()
 * @uses edih_rsp_st_match()
 * 
 * @param object
 * @return array
 */
function edih_997_err_report($err_array)
{
    //
    if (!is_array($err_array) || !count($err_array)) {
        $str_html = "Error: invalid argument for error report";
        csv_edihist_log('edih_997_err_report: invalid function argument');
        return $str_html;
    }
    //
    $str_html = "";
    $batchfile = "";
    //
    if (isset($err_array['summary'])) {
        extract($err_array['summary'], EXTR_OVERWRITE);
        //
        $str_html .= "<p class='rpt997'>" . PHP_EOL;
        $str_html .= isset($sub_icn) ? "<em>Submitted ICN</em> {$sub_icn}" : "Submitted file unknown";
        $str_html .= isset($subdate) ? " <em>Date</em> " . edih_format_date($subdate) : "";
        $str_html .= isset($subtime) ? " <em>Time</em> {$subtime}<br />" : "<br />";
        $str_html .= isset($ackcode) ? " TA1 {$ackcode} : " . edih_997_ta1_code($ackcode) . " <br />" : "";
        $str_html .= isset($acknote) ? " TA1 {$acknote} : " . edih_997_ta1_code($acknote) . " <br />" . PHP_EOL : "<br />" . PHP_EOL;
        if (isset($fg_type)) {
            $fgtp = csv_file_type($fg_type);
            $str_html .= " <em>Functional Group Type</em> {$fg_type} ({$fgtp})";
            $str_html .= isset($fg_id) ? " <em>GS06</em> {$fg_id} <br />" . PHP_EOL : "<br />" . PHP_EOL;
        }
        //
        //$str_html .= "</p>".PHP_EOL;
        //
        $str_html .= isset($ak901) ? "999/997 {$ak901} " . edih_997_code_text('ak501', $ak901) . "<br />" : "";
        $str_html .= isset($ak902) ? " Transactions: submitted {$ak902}" : " ";
        $str_html .= isset($ak903) ? " received {$ak903}" : "";
        $str_html .= isset($ak904) ? " accepted {$ak904}" : "";
        $str_html .= isset($ak905) && $ak905 ? "<br />{$ak905} " . edih_997_code_text('ak502', $ak905) . "<br />" : "";
        $str_html .= isset($ak906) && $ak906 ? $ak906 . " " . edih_997_code_text('ak502', $ak906) . "<br />" : "";
        $str_html .= isset($ak907) && $ak907 ? $ak907 . " " . edih_997_code_text('ak502', $ak907) . "<br />" : "";
        $str_html .= isset($ak908) && $ak908 ? $ak908 . " " . edih_997_code_text('ak502', $ak908) . "<br />" : "";
        $str_html .= isset($ak909) && $ak909 ? $ak909 . " " . edih_997_code_text('ak502', $ak909) . "<br />" : "";
        //
        $str_html .= "</p>" . PHP_EOL;
    }
    //
    foreach ($err_array['err'] as $k => $v) {
        //
        $ct = $k + 1;
        $icn = isset($sub_icn) ? $sub_icn : '';
        $stn = isset($v['substn']) ? $v['substn'] : '';
        $rtp = isset($v['subtype']) ? $v['subtype'] : '';
        //
        $str_html .= "<p class='err997'>" . PHP_EOL;
        $str_html .= "Error {$ct} ";
        $str_html .= $stn ? "<em>ST</em> {$stn} <br />" : "<br />";
        //
        if ($icn && $stn && $rtp) {
            $trc = sprintf("%s%04d", $icn, $stn);
            $srch = array('s_val' => $trc, 's_col' => 4, 'r_cols' => 'All');
            // array('s_val'=>'0024', 's_col'=>9, 'r_cols'=>array(1, 2, 7)),
            $trn_ar = csv_search_record($rtp, 'claim', $srch);
            if (is_array($trn_ar) && count($trn_ar)) {
                //'f837':array('PtName', 'SvcDate', 'CLM01', 'InsLevel', 'BHT03', 'FileName', 'Fee', 'PtPaid', 'Provider' );
                //'f276':array('PtName', 'SvcDate', 'CLM01', 'ClaimID', 'BHT03', 'FileName', 'Payer', 'Trace'); break;
                //'f270':array('PtName', 'ReqDate', 'Trace', 'InsBnft', 'BHT03', 'FileName', 'Payer'); break;
                $pt_name = $trn_ar[0][0];
                // $trn_ar['PtName'];
                $clm01 = $rtp == 'f837' ? $trn_ar[0][2] : $trn_ar[0][4];
                // $trn_ar['CLM01'] : $trn_ar['BHT03'];
                $svcdate = $trn_ar[0][1];
                // ($rtp == 'f270') ? $trn_ar['ReqDate'] : $trn_ar['SvcDate'];
                $btfn = $trn_ar[0][5];
                // $trn_ar['FileName'];
                $str_html .= "{$pt_name} {$svcdate} <em>Trace</em> <a class='rpt' href='edih_main.php?gtbl=claim&fname={$btfn}&ftype={$rtp}&pid={$clm01}&fmt=seg'>{$clm01}</a> <br />" . PHP_EOL;
            } else {
                $str_html .= "Unable to locate transaction  <em>Trace</em> {$trc} <br />" . PHP_EOL;
            }
        } else {
            $str_html .= "Unable to trace, did not get all of icn, type, and st number <br />" . PHP_EOL;
        }
        //
        $str_html .= isset($v['ctxacct']) ? "<em>Transaction ID</em> " . $v['ctxacct'] : "";
        $str_html .= isset($v['ik3segid']) ? " Segment <em>ID</em> " . $v['ik3segid'] : "";
        $str_html .= isset($v['ik3segpos']) ? " <em>Position</em> " . $v['ik3segpos'] : "";
        $str_html .= isset($v['ik3loop']) ? " <em>Loop</em> " . $v['ik3loop'] : "";
        $str_html .= isset($v['ik3code']) ? "<br /> <em>Code</em> " . $v['ik3code'] . " " . edih_997_code_text('ak304', $v['ik3code']) . "<br />" : "<br />";
        //
        $str_html .= isset($v['ctxid']) ? "Situational " . PHP_EOL . "<em>Segment</em> " . $v['ctxid'] : "";
        $str_html .= isset($v['ctxpos']) ? " <em>Position</em> " . $v['ctxpos'] : "";
        $str_html .= isset($v['ctxloop']) ? " <em>Position</em> " . $v['ctxloop'] : "";
        $str_html .= isset($v['ctxelem']) ? " <em>Element</em> " . $v['ctxelem'] . "<br />" . PHP_EOL : PHP_EOL;
        //
        $str_html .= isset($v['ik401']) ? "Data Element <em>element</em> " . $v['ik401'] : "";
        $str_html .= isset($v['ik402']) ? " <em>ref</em> " . $v['ik402'] : "";
        $str_html .= isset($v['ik404']) ? " <em>data</em> " . $v['ik404'] : "";
        $str_html .= isset($v['ik403']) ? "<br /> <em>code</em> " . $v['ik403'] . " " . edih_997_code_text('ak403', $v['ik403']) . "<br />" : "<br />";
        //
        $str_html .= isset($v['ik501']) && $v['ik501'] ? "<em>Status</em> " . $v['ik501'] . " " . edih_997_code_text('ak501', $v['ik501']) . "<br />" : "";
        $str_html .= isset($v['ik502']) && $v['ik502'] ? " <em>code</em> " . $v['ik502'] . " " . edih_997_code_text('ak502', $v['ik502']) . "<br />" : "";
        $str_html .= isset($v['ik503']) && $v['ik503'] ? " <em>code</em> " . $v['ik503'] . " " . edih_997_code_text('ak502', $v['ik503']) . "<br />" : "";
        $str_html .= isset($v['ik504']) && $v['ik504'] ? " <em>code</em> " . $v['ik504'] . " " . edih_997_code_text('ak502', $v['ik504']) . "<br />" : "";
        $str_html .= isset($v['ik505']) && $v['ik505'] ? " <em>code</em> " . $v['ik505'] . " " . edih_997_code_text('ak502', $v['ik505']) . "<br />" : "";
        //
        $str_html .= "</p>" . PHP_EOL;
    }
    return $str_html;
}
Ejemplo n.º 2
0
/**
 * look in the csv table claims_batch.csv and find the pid-encounter 
 *
 * @deprecated
 * @uses csv_search_record() 
 * @param string $bht837     the icn and st numbers concatenated 
 * @return string          the pid-encounter, expect only one match
 */
function ibr_batch_find_pid_with_ctl_st($bht837)
{
    //
    $bval = $bht837 ? trim($bht837) : '';
    if (strlen($bval) == 13) {
        $b = $bval;
    } else {
        csv_edihist_log("ibr_batch_find_pid_with_ctl_st: invalid argument {$bht837}");
        return false;
    }
    //$search = array('s_val'=>$b, 's_col'=>7, 'r_cols'=>array(2));
    $search = array('s_val' => $b, 's_col' => 4, 'r_cols' => array(2));
    $finfo = csv_search_record('batch', 'claim', $search, "1");
    if (is_array($finfo) && count($finfo)) {
        // we seem to have found something
        return $finfo[0][0];
    } else {
        // nothing found
        return false;
    }
}
Ejemplo n.º 3
0
/**
 * 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>&nbsp;&nbsp;<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>&nbsp;&nbsp;<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;
}
Ejemplo n.º 4
0
/**
 * check if the batch control number is found in the 997/999 files table
 * 
 * @uses csv_search_record()
 * @return string 
 */
function ibr_disp_997_for_batch()
{
    $str_html = '';
    $batch_icn = filter_input(INPUT_GET, 'batchicn', FILTER_SANITIZE_STRING);
    if ($batch_icn) {
        $ctln = strlen($batch_icn) >= 9 ? substr($batch_icn, 0, 9) : trim(strval($batch_icn));
        $search = array('s_val' => $ctln, 's_col' => 3, 'r_cols' => 'all');
        $result = csv_search_record('f997', 'file', $search, "1");
        //
        // should be matching row(s) from files_997.csv
        if (is_array($result) && count($result)) {
            $str_html .= "<p>Acknowledgement information</p>" . PHP_EOL;
            foreach ($result as $rslt) {
                $ext = substr($rslt[1], -3);
                //
                $str_html .= "Date: {$rslt[0]} <br />" . PHP_EOL;
                $str_html .= "File: <a target=\"blank\" href=edi_history_main.php?fvkey={$rslt[1]}>{$rslt[1]}</a> <br />" . PHP_EOL;
                $str_html .= "Batch ICN: {$rslt[3]} <br />";
                // error count or code in position 4
                if ($ext == '999' || $ext == '997') {
                    $str_html .= "Rejects: {$rslt[4]} <br />" . PHP_EOL;
                    // don't have dialog from this dialog, so don't link
                    //$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;
                } elseif ($ext == 'ta1' || $ext == 'ack') {
                    $str_html .= "Code: {$rslt[4]} <br />" . PHP_EOL;
                    //$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;
                }
            }
        } else {
            $str_html .= "Did not find corresponding 997/999 file for {$ctln}<br />" . PHP_EOL;
        }
    } else {
        $str_html .= "Invalid value for ICN number<br />" . PHP_EOL;
    }
    return $str_html;
}
Ejemplo n.º 5
0
/**
 * Search the csv table to obtain the file name for a given 
 * trace value (835 / 997 999 type only)
 * 
 * Note: the 997/999 trace is the ISA13 of a batch file
 * 
 * 
 * @param string	 trace value (TRN02, TA101, or BHT03)
 * @param string     from type (default is f835)
 * @param string	 to type (default is f835)
 * @return string    file name or empty string
 */
function csv_file_by_trace($trace, $from_type = 'f835', $to_type = 'f837')
{
    // get the file referenced by the trace value
    //
    $ft = $from_type ? csv_file_type($from_type) : '';
    $tt = $to_type ? csv_file_type($to_type) : '';
    $fn = '';
    $csv_type = '';
    $type = '';
    $search = array();
    //
    csv_edihist_log("csv_file_by_trace: {$trace} from  {$ft} to {$tt}");
    //
    // $search_ar should have keys ['s_val']['s_col'] array(['r_cols'])
    //    like "f837', 'claim, array(9, '0024', array(1, 2, 7))
    //
    if ($ft == 'f835') {
        // trace payment to status or claim
        $search = array('s_val' => $trace, 's_col' => 3, 'r_cols' => 'All');
        $type = $tt;
        $csv_type = 'file';
    } elseif ($ft == 'f997') {
        // trace ACK to batch file
        $icn = is_numeric($trace) && strlen($trace) >= 9 ? substr($trace, 0, 9) : $trace;
        $search = array('s_val' => $icn, 's_col' => 2, 'r_cols' => 'All');
        $type = $tt;
        $csv_type = 'file';
    } elseif ($ft == 'f277') {
        // trace status to status req or claim
        if ($tt == 'f276') {
            $search = array('s_val' => $trace, 's_col' => 7, 'r_cols' => 'All');
            $type = $tt;
            $csv_type = 'claim';
        } elseif ($tt == 'f837') {
            // expect CLM01 for trace value
            $search = array('s_val' => $trace, 's_col' => 2, 'r_cols' => 'All');
            $type = $tt;
            $csv_type = 'claim';
        }
    } elseif ($ft == 'f271') {
        // trace benefit to benefit req
        if ($tt == 'f270') {
            $search = array('s_val' => $trace, 's_col' => 2, 'r_cols' => 'All');
            $type = $tt;
            $csv_type = 'claim';
        }
    } elseif ($ft == 'f278') {
        // trace auth to auth req
        $search = array('s_val' => $trace, 's_col' => 2, 'r_cols' => 'All');
        $type = 'f278';
        $csv_type = 'claim';
    } else {
        csv_edihist_log('csv_file_by_trace: incorrect file type ' . $file_type);
        return $fn;
    }
    //
    if ($type && $csv_type && $search) {
        $result = csv_search_record($type, $csv_type, $search, false);
        if (is_array($result) && count($result)) {
            if ($ft == 'f278') {
                foreach ($result as $r) {
                    if ($r[6] == 'Rsp' || $r[6] == 'Reply') {
                        $fn = $result[0][5];
                        break;
                    }
                }
            } elseif ($csv_type == 'claim') {
                $fn = $result[0][5];
            } else {
                $fn = $result[0][1];
            }
        } else {
            csv_edihist_log("csv_file_by_trace: search failed {$type} csv {$csv_type} for trace {$trace} {$from_type} {$to_type}");
        }
    } else {
        csv_edihist_log("csv_file_by_trace: error type {$type} csv {$csv_type} for trace {$trace} {$from_type} {$to_type}");
    }
    return $fn;
}
Ejemplo n.º 6
0
/** 
 * Obtain claim information from batch 837|270|276|278 file to match 997/999 response
 * Note, we assume each batch ST envelope contains a single transaction.
 * Manual inspection is required if more than one transaction in an ST block, 
 * 
 * The 997/999 parse script creates a BHT03 reference by concatenating the
 * response ISA13 (in TA1 segment) and the ST02 from the AK2 segment
 * 	return array ['pt_name'] ['clm01'] ['svcdate'] ['batch_name'] ['stn']
 * 
 * @uses csv_file_type()
 * @uses csv_search_record()
 * 
 * @param string    concatenate ISA13 and ST02 for source file
 * @param string    type of source file
 * @return array
 */
function edih_rsp_st_match($rsp_trace, $file_type)
{
    //
    $info_ar = array();
    //
    if (strlen($rsp_trace) == 13) {
        $bticn = substr($rsp_trace, 0, 9);
        $stn = substr($rsp_trace, -4);
        $btsrch = $rsp_trace;
    } else {
        // debug
        csv_edihist_log('edih_rsp_st_match() invalid trace argument ' . $rsp_trace);
        return $info_ar;
    }
    //
    $ft = csv_file_type($file_type);
    //
    if (strpos('|f837|f276|f270|f278', $ft) === false) {
        // debug
        csv_edihist_log('edih_rsp_st_match: file type ' . $ft . ' not in |f837|f276|f270|278');
        return $info_ar;
    }
    //
    $batch_srch = csv_search_record($ft, 'claim', array('s_val' => $rsp_trace, 's_col' => 4, 'r_cols' => 'All'), '1');
    if (is_array($batch_srch) && count($batch_srch[0])) {
        $info_ar['pt_name'] = $batch_srch[0][0];
        // $batch_srch['PtName'];
        $info_ar['clm01'] = $rtp == 'f837' ? $batch_srch[0][2] : $batch_srch[0][4];
        // $batch_srch['CLM01'] : $batch_srch['BHT03'];
        $info_ar['svcdate'] = $batch_srch[0][1];
        // ($rtp == 'f270') ? $batch_srch['ReqDate'] : $batch_srch['SvcDate'];
        $info_ar['batch_name'] = $batch_srch[0][5];
        // $batch_srch['FileName'];
    }
    //
    return $info_ar;
}