Пример #1
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;
}
Пример #2
0
/**
 * Search claims_era.csv table and find patient ID or encounter and associated filename
 * 
 * will search for only the pid value or only encounter value
 * 
 * @uses csv_pid_enctr_parse()
 * @uses csv_parameters()
 * @param string $encounter   the patient control (pid-encounter) number
 * @param string $srchtype    default is 'encounter'
 * @return array              [i](pid-enctr, trace, filename) possibly more than one
 */
function ibr_era_find_file_with_pid_enctr($pid_enctr, $srchtype = 'encounter')
{
    //
    // return the pid_encounter, trace, and filename, but there may be more than one file, so return an array
    //
    if (!$pid_enctr) {
        return "invalid encounter data<br />" . PHP_EOL;
    }
    $enctr = trim($pid_enctr);
    preg_match('/\\D/', $enctr, $match2, PREG_OFFSET_CAPTURE);
    if (count($match2)) {
        $idar = csv_pid_enctr_parse($enctr);
        if (is_array($idar) && count($idar)) {
            $p = strval($idar['pid']);
            $plen = strlen($p);
            $e = strval($idar['enctr']);
            $elen = strlen($e);
        } else {
            csv_edihist_log("ibr_era_find_file_with_pid_enctr: error parsing pid_encounter {$pid_enctr}");
            return FALSE;
        }
    } else {
        $p = strval($enctr);
        $e = strval($enctr);
        $plen = strlen($p);
        $elen = strlen($e);
    }
    $ret_ar = array();
    //array('PtName', 'SvcDate', 'clm01', 'Status', 'trace', 'claimID', 'File_835', 'Pmt', 'PtResp', 'Payer');
    //
    $params = csv_parameters('era');
    $fp = $params['claims_csv'];
    //
    if (($fh1 = fopen($fp, "r")) !== FALSE) {
        if ($srchtype == 'encounter') {
            while (($data = fgetcsv($fh1, 1024, ",")) !== FALSE) {
                // check for a match
                if (substr($data[2], -$elen) == $e) {
                    // since e=123 will match 1123 and 123
                    $peval = csv_pid_enctr_parse($data[2]);
                    if (is_array($peval) && count($peval)) {
                        if ($peval['enctr'] == $e) {
                            $ret_ar[] = array($data[2], $data[4], $data[5]);
                        }
                    }
                }
            }
        } else {
            while (($data = fgetcsv($fh1, 1024, ",")) !== FALSE) {
                // check for a match
                if (substr($data[2], 0, $plen) == $p) {
                    // since p=123 will match 1123 and 123
                    $peval = csv_pid_enctr_parse($data[2]);
                    if (is_array($peval) && count($peval)) {
                        if ($peval['pid'] == $p) {
                            $ret_ar[] = array($data[2], $data[4], $data[5]);
                        }
                    }
                }
            }
        }
        fclose($fh1);
    } else {
        csv_edihist_log("ibr_era_find_file_with_pid: failed to open file claims_era.csv");
    }
    return $ret_ar;
}
Пример #3
0
/**
 * Search the 'claims' csv table for the patient control and find the associated file name
 *
 * Searchtype 
 * In 'claims' csv tables, clm01 is position 2, ISA13 number is pos 4, and filename is pos 5;
 * Since we are interested usually in the filename, ISA13 is irrelevant usually.
 *
 * @uses csv_parameters()
 * @uses csv_pid_enctr_parse()
 * @param string                     patient control-- pid-encounter, encounter, or pid
 * @param string                     filetype -- x12 type or f837, f277, etc
 * @param string                     search type encounter, pid, or clm01
 * @return array|bool				 [i] data row array  or empty on error
 */
function csv_file_by_enctr($clm01, $filetype = 'f837')
{
    //
    // return array of [i](pid_encounter, filename), there may be more than one file
    //
    if (!$clm01) {
        return 'invalid encounter data<br>' . PHP_EOL;
    }
    //
    $ret_ar = array();
    $ft = csv_file_type($filetype);
    //
    if (!$ft) {
        csv_edihist_log('csv_file_by_enctr: incorrect file type ' . $filetype);
        return $ret_ar;
    } else {
        $params = csv_parameters($ft);
        //$fp = isset($params['claims_csv']) ? dirname(__FILE__).$params['claims_csv'] : false;
        $fp = isset($params['claims_csv']) ? $params['claims_csv'] : false;
        $h_ar = csv_table_header($ft, 'claim');
        $hct = count($h_ar);
        if (!$fp) {
            csv_edihist_log('csv_file_by_enctr: incorrect file type ' . $filetype);
            return $ret_ar;
        }
    }
    //
    $enct = csv_pid_enctr_parse(strval($clm01));
    $p = isset($enct['pid']) ? $enct['pid'] : '';
    $e = isset($enct['enctr']) ? $enct['enctr'] : '';
    if ($p && $e) {
        $pe = $p . '-' . $e;
        $srchtype = '';
    } elseif ($e) {
        $srchtype = 'encounter';
    } elseif ($p) {
        $srchtype = 'pid';
    } else {
        csv_edihist_log('csv_file_by_enctr: unable to determine encounter value ' . $clm01);
        return 'unable to determine encounter value ' . $clm01 . '<br />' . PHP_EOL;
    }
    // OpenEMR creates CLM01 as nnn-nnn in genX12 batch
    //$pm = preg_match('/\D/', $enctr, $match2, PREG_OFFSET_CAPTURE);
    $val = array();
    //array_combine ( array $keys , array $values )
    // in 'claims' csv tables, clm01 is position 2 and filename is position 5
    if (($fh1 = fopen($fp, "r")) !== FALSE) {
        if ($srchtype == 'encounter') {
            while (($data = fgetcsv($fh1, 1024, ",")) !== FALSE) {
                // check for a match
                if (strpos($data[2], $e)) {
                    $te = substr($data[2], strpos($data[2], '-') + 1);
                    if (strcmp($te, $e) === 0) {
                        for ($i = 0; $i < $hct; $i++) {
                            $val[$h_ar[$i]] = $data[$i];
                        }
                        $ret_ar[] = $val;
                        // array_combine($h_ar, $data);
                    }
                }
            }
        } elseif ($srchtype == 'pid') {
            while (($data = fgetcsv($fh1, 1024, ',')) !== FALSE) {
                if (strpos($data[2], $p) !== false) {
                    $te = strpos($data[2], '-') ? substr($data[2], 0, strpos($data[2], '-')) : '';
                    if (strcmp($te, $p) === 0) {
                        for ($i = 0; $i < $hct; $i++) {
                            $val[$h_ar[$i]] = $data[$i];
                        }
                        $ret_ar[] = $val;
                        // $ret_ar[] = array_combine($h_ar, $data);
                    }
                }
            }
        } else {
            while (($data = fgetcsv($fh1, 1024, ",")) !== FALSE) {
                // check for a match
                if (strcmp($data[2], $pe) === 0) {
                    for ($i = 0; $i < $hct; $i++) {
                        $val[$h_ar[$i]] = $data[$i];
                    }
                    $ret_ar[] = $val;
                    // $ret_ar[] = array_combine($h_ar, $data);
                }
            }
        }
        fclose($fh1);
    } else {
        csv_edihist_log('csv_file_by_enctr: failed to open csv file ' . basename($fp));
        return false;
    }
    return $ret_ar;
}