Ejemplo n.º 1
0
/**
 * 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;
}
Ejemplo n.º 2
0
/**
 * create a display for an individual claim status response	
 * 
 * @uses csv_file_by_controlnum()
 * @uses csv_x12_segments()
 * @uses ibr_277_bhtblock()
 * @uses ibr_277_bht_array()
 * @uses ibr_277_bhthtml()
 * @param string  $filename the filename
 * @param string  $isa13 the isa13 control number for the file
 * @param string  $bht03 the identifier from the 837 bht segment
 * @param string  $clm01 the pid-encounter from the 837 clm segment
 * @param string  $st02 the st number from the 277 file
 * @return string  either an error message or a table with the information from the response
 */
function ibr_277_response_html($filename = '', $isa13 = '', $bht03 = '', $clm01 = '', $st02 = '')
{
    // create a display for an individual 277 response
    $html_str = '';
    //
    if (!$filename && !$isa13) {
        csv_edihist_log("ibr_277_response_html: called with no file arguments");
        $html_str .= "Error, no file given<br />" . PHP_EOL;
        return $html_str;
    } elseif (!$filename && $isa13) {
        $fn = csv_file_by_controlnum('f277', $isa13);
    } elseif ($filename) {
        $fn = basename($filename);
    }
    if ($fn) {
        //
        $ar_277_seg = csv_x12_segments($fn, "f277", false);
        if (!is_array($ar_277_seg)) {
            $html_str .= "Error in file name or file parsing <br />" . PHP_EOL;
            return $html_str;
        }
    }
    //
    if ($bht03 || $clm01 || $st02) {
        //
        $sliceparams = ibr_277_bhtblock($ar_277_seg['segments'], $ar_277_seg['delimiters'], $clm01, $bht03, $st02);
        if ($sliceparams) {
            $bhtsegs = array_slice($ar_277_seg['segments'], $sliceparams[0], $sliceparams[1]);
            $bht_ar = ibr_277_bht_array($bhtsegs, $ar_277_seg['delimiters']);
            $bht_html = ibr_277_bhthtml($bht_ar);
            if ($bht_html) {
                $html_str .= $bht_html;
            } else {
                $html_str .= "Error encountered in generating display <br />" . PHP_EOL;
            }
        } else {
            $html_str .= "Did not find status for {$bht03} {$clm01} {$st02} in {$fn} <br />" . PHP_EOL;
        }
    } else {
        csv_edihist_log("ibr_277_response_html: called with no claim identifying arguments");
        $html_str .= "Error, no claim identification given<br />" . PHP_EOL;
    }
    //
    return $html_str;
}
Ejemplo n.º 3
0
/**
 * Search a batch file to identify a claim by the ST number
 * 
 * Claims identified in .997/999 files must be located in batch files
 * The .997 file is per a transaction control number in the TA1 segment, 
 * which is used to identify the batch file.  However, the TA1 segment may
 * not be provided in the .999 file, so the batch file may be unknown. 
 * The ST02 and CLM01 values may also be obtrained fromt the .999 file and
 * we can use those to try and identify the batch file, but we may
 * identify the wrong file.  The .997 file gives the limited information
 * for the particular claim, so this function is to get more information on the claim.
 * array($st_num, $enc_pid, $enc_enctr, $enc_pt_lname, $enc_pt_fname, $enc_pt_dob, $batch_file);
 * 
 * @see ibr_997_rejects() in ibr_997_read.php
 * @todo accept an array of $st_clm_num so batch file needs only one read 
 * @uses csv_file_by_controlnum()
 * @uses csv_verify_file()
 * @param string $stnum      the ST number of a claim
 * @param string $batchnam   the batch file contents which contain the st_num
 * @param string $pidenctr   the pid-encounter for the desired claim	
 * @return array
 */
function ibr_batch_get_st_info($st_num, $batchname = '', $pidenctr = '')
{
    //ibr_batch_get_st_info($ak2st02, $bt_file, $ctx302)
    $stnum = $st_num ? strval($st_num) : '';
    $pe = $pidenctr ? strval($pidenctr) : '';
    $btfname = '';
    //
    if (!$stnum) {
        // error - st number not supplied
        csv_edihist_log("ibr_batch_get_st_info: ST number not supplied");
        return FALSE;
    }
    if (strlen($stnum) == 13) {
        // assume concatenation of isa13 and st02
        $ctln = substr($stnum, 0, 9);
        $stnum = substr($stnum, -4);
        $btfname = csv_file_by_controlnum('batch', $ctln);
    } elseif (strlen($stnum) < 4) {
        $stnum = str_pad($stnum, 4, "0", STR_PAD_LEFT);
    }
    if (strlen($batchname) == 9 && !$btfname) {
        // assume isa13 control number
        $btfname = csv_file_by_controlnum('batch', $batchname);
    } else {
        $btfname = $batchname;
    }
    //
    $fp = $btfname ? csv_verify_file($btfname, 'batch') : '';
    //
    if ($fp) {
        $bstr = file_get_contents($fp);
        $batch_name = basename($fp);
    } else {
        // unable to get the file, quit here
        csv_edihist_log("ibr_batch_get_st_info: could not read batch file");
        return FALSE;
    }
    // $st_clm_num must be in format "000N" like "0004" or "0012"
    // we are looking for, e.g. ST*837*0017~
    $seg_st = 'ST' . SEG_ELEM_DELIM . '837' . SEG_ELEM_DELIM . $stnum;
    // particular ST block
    //
    $seg_se = SEG_TERM_DELIM . "SE" . SEG_ELEM_DELIM;
    // prepend the "~" to avoid SE* as substring in a segment
    $seg_st2 = SEG_ELEM_DELIM . $st_num . SEG_TERM_DELIM;
    //second search string *0021*  e.g. SE*47*0021*
    //
    // get segment positions
    $st_pos = strpos($bstr, $seg_st, 0);
    // break it off if $st_pos is not found
    if ($st_pos == FALSE) {
        //echo "ibr_find_claim_enctr $st_num $seg_st not found in file $batch_file" . PHP_EOL;
        return FALSE;
    }
    //
    $se_pos = strpos($bstr, $seg_se, $st_pos);
    $se_pos2 = strpos($bstr, $seg_st2, $se_pos);
    $se_pos3 = strpos($bstr, SEG_TERM_DELIM, $se_pos2);
    //
    $seg_block = substr($bstr, $st_pos, $se_pos3 - $st_pos + 1);
    $segs_ar = explode(SEG_TERM_DELIM, $seg_block);
    //
    $has_sbr = FALSE;
    $has_dep = FALSE;
    $enc_pt_lname = '';
    $enc_pt_fname = '';
    $pid_enctr = '';
    $svcdate = '';
    //
    foreach ($segs_ar as $seg_str) {
        // a 'trim($seg_str)' is needed if newlines are present
        $seg = explode(SEG_ELEM_DELIM, $seg_str);
        //
        if ($seg[0] == "HL") {
            if ($seg[3] == "22") {
                $has_sbr = TRUE;
            }
            if ($seg[3] == "23") {
                $has_dep = TRUE;
            }
            continue;
        }
        if ($seg[0] == "NM1" && ($seg[1] == "IL" || $seg[1] == "QC")) {
            // name can be in first NM1*IL and blank in second
            if ($seg[1] == "IL" && !$enc_pt_lname) {
                $enc_pt_lname = $seg[3];
                $enc_pt_fname = $seg[4];
            }
            if ($seg[1] == "QC" && $has_dep) {
                if ($enc_pt_lname && strlen($seg[3])) {
                    $enc_pt_lname = $seg[3];
                    $enc_pt_fname = $seg[4];
                } elseif (!$enc_pt_lname) {
                    $enc_pt_lname = $seg[3];
                    $enc_pt_fname = $seg[4];
                }
            }
            //
            continue;
        }
        if ($seg[0] == "CLM") {
            $pid_enctr = $seg[1];
        }
        if ($seg[0] == 'DTP' && $seg[1] == '472') {
            $svcdate = $seg[3];
            // we are done, since DTP segment comes after SVC, near end
            break;
        }
    }
    //
    return array($st_num, $pid_enctr, $enc_pt_lname, $enc_pt_fname, $batch_name, $svcdate);
}
Ejemplo n.º 4
0
/**
 * Html output for errors in 997/999 files
 * 
 * @uses csv_file_by_controlnum()
 * @uses ibr_batch_get_st_info()
 * @uses ibr_997_code_text()
 * 
 * @param array $aksegments
 * @param array $delims
 * @param string $btisa13
 * @param bool $html
 * @return string 
 */
function ibr_997_akhtml($aksegments, $delims, $btisa13 = '', $html = true)
{
    //
    $str_html = '';
    if (!is_array($aksegments) || !count($aksegments)) {
        $str_html .= "<p class='ak999stat'>No rejected claims found in file</p>" . PHP_EOL;
        csv_edihist_log("ibr_997_akhtml: No rejected claims or invalid segments array");
        return $str_html;
    }
    $btctlnum = $btisa13 ? $btisa13 : 'unknown';
    $bt_file = $btisa13 ? csv_file_by_controlnum('batch', $btisa13) : 'unknown';
    //
    $elem_d = $delims['e'];
    $sub_d = $delims['s'];
    $isfound = false;
    $ak997 = array();
    $ak_pos = 0;
    $idx = -1;
    foreach ($aksegments as $segstr) {
        $idx++;
        $seg = explode($elem_d, $segstr);
        if ($seg[0] == 'AK2') {
            $batchst = sprintf("%04d", $seg[2]);
            $str_html .= "<p class='ak999stat'>" . PHP_EOL;
            $str_html .= "ST: {$batchst} <br /> (837 ICN: {$btctlnum} {$bt_file})<br /><br />";
            if ($bt_file && $bt_file != 'unknown') {
                $stinfo = ibr_batch_get_st_info($batchst, $bt_file);
                if (count($stinfo) > 0) {
                    $str_html .= "Name: {$stinfo[2]}, {$stinfo[3]} Ctl: {$stinfo[1]}<br /><br />" . PHP_EOL;
                }
            }
            continue;
        }
        // format IK3, CTX, IK4 segments
        if ($seg[0] == 'AK3' || $seg[0] == 'IK3') {
            $str_html .= "Loop: {$seg[3]}, Line: {$seg[2]}, Segment: {$seg[1]} <br />" . PHP_EOL;
            $ak3err = ibr_997_code_text('ak304', $seg[4]);
            $str_html .= "Code: {$seg[4]} {$ak3err} <br />" . PHP_EOL;
        }
        if ($seg[0] == "AK4" || $seg[0] == "IK4") {
            // IK401 is possibly a composite element $ik4pos:$ik4comppos:$ik4rep
            // for now, just get the first part, the element, such as '2' for error in N302
            $ak4msg = '';
            $ak4data = '';
            $ak4err = '';
            $sub = strpos($seg[1], $sub_d);
            if ($sub) {
                $ak4pos = explode($sub_d, $seg[1]);
                $ak4msg .= $ak4msg ? ' pos ' . $ak4pos[0] : 'pos ' . $ak4pos[0];
                $ak4msg .= isset($ak4pos[1]) ? ' sub ' . $ak4pos[1] : '';
                $ak4msg .= isset($ak4pos[2]) ? ' rep ' . $ak4pos[2] : '';
            } else {
                $ak4msg .= $ak4msg ? ' pos ' . $seg[1] : 'pos ' . $seg[1];
            }
            $ak4elem = $ar_seg[2];
            // Data element numbers defined in X12N Data Element Dictionary
            $ak4cause = $ar_seg[3];
            // error code
            //
            $ak4err = ibr_997_code_text("ak403", $seg[3]);
            if (array_key_exists(4, $seg)) {
                $ak4data = $seg[4];
            }
            $str_html .= "Data error: {$ak4msg} <br />" . PHP_EOL;
            $str_html .= "Code: {$seg[3]} {$ak4err} <br />" . PHP_EOL;
            $str_html .= $ak4data ? "Data: {$ak4data}  <br />" . PHP_EOL : '';
        }
        if ($seg[0] == "CTX") {
            if (strpos($seg[1], 'SITUATIONAL')) {
                $str_html .= "{$seg[1]} -- Line: {$seg[3]} Position: {$seg[5]} <br />" . PHP_EOL;
            } else {
                if (strpos($seg[1], $sub_d)) {
                    $busid = explode($sub_d, $seg[1]);
                    if ($busid[0] == 'CLM01') {
                        $str_html .= "Patient Ctl Num: {$busid[1]} <br />" . PHP_EOL;
                    } else {
                        $str_html .= "Identifier: {$busid[0]} Value: {$busid[1]} <br />" . PHP_EOL;
                    }
                } else {
                    $str_html .= "Identifier: {$seg[1]} <br />" . PHP_EOL;
                }
            }
        }
        if ($seg[0] == "AK5" || $seg[0] == "IK5") {
            $ak5txt = ibr_997_code_text("ak501", $seg[1]);
            $str_html .= "Status: {$seg[1]}  {$ak5txt} <br />" . PHP_EOL;
            $str_html .= "</p>" . PHP_EOL;
        }
    }
    return $str_html;
}
Ejemplo n.º 5
0
/**
 * process TA1 acknowledgment files
 * 
 * @return array
 */
function ibr_process_ta1($filepath)
{
    //
    $ar_ackfile = array();
    //
    $seg_ar = csv_x12_segments($filepath, 'ta1', false);
    if (is_array($seg_ar) && isset($seg_ar['segments'])) {
        $ar_ta1_segments = $seg_ar['segments'];
        $ack_mtime = date('Ymd', filemtime($seg_ar['path']));
        $elem_d = $seg_ar['delimiters']['e'];
        $sub_d = $seg_ar['delimiters']['s'];
        $rep_d = $seg_ar['delimiters']['r'];
        //
        $ack_fname = basename($seg_ar['path']);
        $ack_txt = str_replace('.TA1', '.TAT', $ack_fname);
    } else {
        // error getting segments
        csv_edihist_log("ibr_process_ta1: error getting segments for {$filepath}");
        return false;
    }
    //
    $batch_file = '';
    $ack_msg = '';
    //
    foreach ($ar_ta1_segments as $segstr) {
        $seg = explode($elem_d, $segstr);
        if ($seg[0] == 'ISA') {
            $ack_mtime = $seg[9];
            if (strlen($seg[9]) == 6) {
                $ack_mtime = '20' . $seg[9];
            }
            $ack_isa13 = strval($seg[13]);
        }
        if ($seg[0] == 'TA1') {
            $ack_ctlnum = strval($seg[1]);
            $ack_date = '20' . $seg[2];
            // date is 6 digits, prepend century
            $ack_status = $seg[4];
            $ack_code = $seg[5];
            $ack_msg = $ack_code ? $seg[5] . ": " . ibr_ta1_code($seg[5]) : '';
        }
    }
    if (isset($ack_ctlnum) && strlen($ack_ctlnum)) {
        $batch_file = csv_file_by_controlnum('batch', $ack_ctlnum);
    }
    //
    $ar_ackfile["ack_time"] = isset($ack_mtime) ? $ack_mtime : "";
    //"date"
    $ar_ackfile["ack_file"] = isset($ack_fname) ? $ack_fname : "";
    //"file"
    $ar_ackfile["ack_isa13"] = isset($ack_isa13) ? $ack_isa13 : "";
    // $ta1 isa13
    $ar_ackfile["ack_ctrl"] = isset($ack_ctlnum) ? $ack_ctlnum : "";
    //"batch_ctrl"
    $ar_ackfile["ack_code"] = isset($ack_code) ? $ack_code : "";
    // error code
    $ar_ackfile["ack_msg"] = isset($ack_msg) ? $ack_msg : "";
    $ar_ackfile["ack_batch"] = $batch_file ? $batch_file : "batch not identified";
    $ar_ackfile["ack_ftxt"] = $ack_txt ? $ack_txt : "";
    //
    return $ar_ackfile;
}
Ejemplo n.º 6
0
/**
 * filter input and generate display of x12 file
 * 
 * @uses csv_filetohtml()
 * @uses ibr_upload_files()
 * @uses ibr_ebr_ebt_name()
 * @return string
 */
function ibr_disp_fileText()
{
    //
    $str_html = '';
    //isset($_POST['fileX12']) && isset($_FILES['fileUplx12'])
    if (count($_FILES) && isset($_FILES['fileUplx12'])) {
        $fn = htmlentities($_FILES['fileUplx12']['name']);
        $str_html = ibr_html_heading('newfiles', $fn);
        $f_array = ibr_upload_files($str_html);
        if (is_array($f_array) && count($f_array)) {
            $str_html .= csv_filetohtml($f_array);
        } else {
            $str_html = ibr_html_heading('error');
            $str_html .= "no files accepted <br />" . PHP_EOL;
        }
    } elseif (isset($_GET['fvkey'])) {
        $fn = filter_input(INPUT_GET, 'fvkey', FILTER_SANITIZE_STRING);
        // Availity 'readable' versions ibr, ebr, dpr
        $ishr = isset($_GET['readable']) && $_GET['readable'] == 'yes' ? true : false;
        if (!$fn) {
            $str_html = ibr_html_heading('error');
        } elseif ($ishr && $fn) {
            $ftxt = ibr_ebr_ebt_name($fn);
            $str_html = ibr_html_heading('textdisplay', $ftxt);
            $str_html .= csv_filetohtml($ftxt);
        } else {
            $bn = basename($fn);
            $str_html = ibr_html_heading('textdisplay', $bn);
            $str_html .= csv_filetohtml($fn);
        }
    } elseif (isset($_GET['btctln'])) {
        $btisa13 = filter_input(INPUT_GET, 'btctln', FILTER_SANITIZE_STRING);
        if ($btisa13) {
            //$btname = ibr_batch_find_file_with_controlnum($btisa13);
            $btname = csv_file_by_controlnum('batch', $btisa13);
            $str_html = ibr_html_heading('textdisplay', $btname);
            if ($btname) {
                $str_html .= csv_filetohtml($btname);
            } else {
                $str_html .= "Failed to identify file with control number {$btisa13} <br />" . PHP_EOL;
            }
        } else {
            $str_html .= "error in file display <br />";
        }
    } else {
        $str_html = ibr_html_heading('error');
        $str_html .= "error in file display <br />";
    }
    return $str_html;
}
Ejemplo n.º 7
0
/**
 * identify loops and format segments for display
 * of 997/999 (acknowledgement) type x12 edi files
 * 
 * @param array  $segments 
 * @param string  $delimiter
 * return string
 */
function edih_997_text($segments, $delimiter)
{
    //
    $str_html = '';
    if (!is_array($segments) || !count($segments) || strlen($delimiter) != 1) {
        //debug
        csv_edihist_log('edih_997_text(): invalid segments');
        return $str_html;
    }
    //
    $de = $delimiter;
    $loopid = "0";
    //
    //echo 'edih_997_text() foreach segment count: '.count($segments).PHP_EOL;
    //
    foreach ($segments as $key => $seg) {
        //
        //echo var_dump($seg).PHP_EOL;
        //
        if (strncmp('TA1' . $de, $seg, 4) === 0) {
            $sar = explode($de, $seg);
            $rspicn = $sar[1];
            $loopid = 'ACK';
            // not official
            $str_html .= "<tr><td class='btloop'>{$loopid}</td><td class='btnum'>{$key}</td><td class='btseg'>{$seg}</td></tr>" . PHP_EOL;
            unset($sar);
            $loopid = '';
            // reset loop for subsequent segments
            continue;
        }
        //
        if (strncmp('ST' . $de, $seg, 3) === 0) {
            $loopid = 'Header';
            $str_html .= "<tr><td class='btloop'>{$loopid}</td><td class='btnum'>{$key}</td><td class='btseg'>{$seg}</td></tr>" . PHP_EOL;
            continue;
        }
        //
        if (strncmp('AK1' . $de, $seg, 4) === 0) {
            $sar = explode($de, $seg);
            $rsptp = csv_file_type($sar[1]);
            if ($rspicn && $rsptp) {
                $rspfile = csv_file_by_controlnum($rsptp, $rspicn);
            }
            $title = $rspfile ? 'response to ' . $rspfile : '';
            $loopid = '2000';
            $str_html .= "<tr><td class='btloop'>{$loopid}</td><td class='btnum'>{$key}</td><td title='{$title}' class='btseg'>{$seg}</td></tr>" . PHP_EOL;
            unset($sar);
            continue;
        }
        //
        if (strncmp('AK2' . $de, $seg, 4) === 0) {
            $loopid = 'AK2';
            $str_html .= "<tr><td class='btloop'>{$loopid}</td><td class='btnum'>{$key}</td><td class='btseg'>{$seg}</td></tr>" . PHP_EOL;
            continue;
        }
        //
        if (strncmp('IK3' . $de, $seg, 4) === 0 || strncmp('AK3' . $de, $seg, 4) === 0) {
            $loopid = '2100';
            $str_html .= "<tr><td class='btloop'>{$loopid}</td><td class='btnum'>{$key}</td><td class='btseg'>{$seg}</td></tr>" . PHP_EOL;
            continue;
        }
        //
        if (strncmp('IK4' . $de, $seg, 4) === 0 || strncmp('AK4' . $de, $seg, 4) === 0) {
            $loopid = '2110';
            $str_html .= "<tr><td class='btloop'>{$loopid}</td><td class='btnum'>{$key}</td><td class='btseg'>{$seg}</td></tr>" . PHP_EOL;
            continue;
        }
        //
        if (strncmp('SE' . $de, $seg, 3) === 0) {
            $loopid = 'Trailer';
            $str_html .= "<tr><td class='btloop'>{$loopid}</td><td class='btnum'>{$key}</td><td class='btseg'>{$seg}</td></tr>" . PHP_EOL;
            continue;
        }
        // for all the segments that do not begin loops	;
        $str_html .= "<tr><td class='btloop'> -- </td><td class='btnum'>{$key}</td><td class='btseg'>{$seg}</td></tr>" . PHP_EOL;
    }
    //
    return $str_html;
}
Ejemplo n.º 8
0
/**
 * 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;
}