bug fixins (#2475)
[openemr.git] / library / edihistory / edih_csv_data.php
blob7dd41d3af0c5045f9bea5eac3eb471713dcbc480
1 <?php
2 /*
3 * edih_csv_data.php
5 * Copyright 2016 Kevin McCormick Longview, Texas
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; version 3 or later. You should have
16 * received a copy of the GNU General Public License along with this program;
17 * if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * <http://opensource.org/licenses/gpl-license.php>
23 * @link: https://www.open-emr.org
24 * @package ediHistory
28 /**
29 * Display csv table data in an HTML table for newly processed files
31 * This function uses the csv table header row to order the csv data
32 * The data array should be file table rows and claim table rows,
33 * and have this structure:
34 * array[icn]['type'] => x12 type
35 * array[icn]['file'][i][array( --- data row---) ]
36 * array[icn]['claim'][i][array( --- data row---) ]
38 * @uses csv_table_header()
39 * @uses csv_thead_html()
40 * @param array
41 * @param bool
42 * @return string
44 function edih_csv_process_html($data_ar, $err_only = false)
47 $str_html = '';
48 $clm_html = '';
50 foreach ($data_ar as $icn => $csvdata) {
51 if (array_key_exists('type', $csvdata)) {
52 $ft = $csvdata['type'];
53 } else {
54 $str_html .= 'edih_csv_process_html() for ' . text($icn) . ' did not get type value';
55 csv_edihist_log('edih_csv_process_html: for '.$icn.' did not get type value');
56 return $str_html;
60 $cls = (strpos('|f837|f270|f276|f278', $ft)) ? 'sub' : 'rsp';
62 if (array_key_exists('file', $csvdata)) {
64 $fidx = 0;
65 foreach ($csvdata['file'] as $key => $csvfile) {
67 $oe = ( $fidx % 2 == 1 ) ? 'fodd' : 'feven';
68 $cls = (strpos('|f837|f270|f276|f278', $ft)) ? 'sub' : 'rsp';
70 $dt_str = "";
72 $dte = (isset($csvfile['Date'])) ? $csvfile['Date'] : '';
73 $fn1 = (isset($csvfile['FileName'])) ? $csvfile['FileName'] : '';
74 $ctl = (isset($csvfile['Control'])) ? $csvfile['Control'] : '';
75 $clmct = (isset($csvfile['Claim_ct'])) ? $csvfile['Claim_ct'] : '';
76 $trc = (isset($csvfile['Trace'])) ? $csvfile['Trace'] : '';
77 $typ = (isset($csvfile['RspType'])) ? $csvfile['RspType'] : '';
78 $rej = (isset($csvfile['RejCt'])) ? $csvfile['RejCt'] : '';
80 $dt_str .= ($fn1) ? "<a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($fn1) . "&ftype=" . attr_url($ft) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($fn1) . "</a>&nbsp;" : "";
81 $dt_str .= ($dte) ? " &nbsp;" . text(substr($dte, 0, 4)) . "-" . text(substr($dte, 4, 2)) . "-" . text(substr($dte, 6, 2)) : "";
82 $dt_str .= ($clmct) ? " &nbsp;<em>Claims</em> " . text($clmct) : "";
83 if ($ft == 'f997' || $ft == 'ta1') {
84 $dt_str .= ($typ) ? " &nbsp;" . text($typ) : "";
85 $dt_str .= ($rej) ? " &nbsp;" . text($rej) : "";
86 $dt_str .= ($trc) ? "&nbsp; <a class='" . attr($cls) . "' title='" . attr($trc) . "' href='edih_main.php?gtbl=file&trace=" . attr_url($trc) . "&ftype=" . attr_url($ft) . "&rsptype=" . attr_url($typ) . "&csrf_token_form=" . attr_url(collectCsrfToken()) . "'><em>trace</em></a>&nbsp;" : "";
87 } elseif ($ft == 'f277') {
88 $dt_str .= (isset($csvfile['Accept'])) ? " &nbsp;<em>Accpt</em> " . text($csvfile['Accept']) : "";
89 $dt_str .= (isset($csvfile['Reject'])) ? " &nbsp;<em>Rej</em> " . text($csvfile['Reject']) : "";
90 } elseif ($ft == 'f835') {
91 $dt_str .= (isset($csvfile['Denied'])) ? " &nbsp;<em>Denied</em> " . text($csvfile['Denied']) : "";
92 $dt_str .= ($trc) ? " &nbsp;<em>Chk</em> <a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($fn1) . "&trace=" . attr_url($trc) . "&ftype=" . attr_url($ft) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($trc) . "</a>&nbsp;" : "";
93 $dt_str .= (isset($csvfile['Payer'])) ? " &nbsp;" . text($csvfile['Payer']) : "";
97 $str_html .= "<dt class=" . attr($oe) . ">$dt_str</dt>".PHP_EOL;
98 $fidx++;
102 // &nbsp;&nbsp;
103 // handle the claim array
104 if (array_key_exists('claim', $csvdata)) {
106 $cidx = 0;
107 $errct = 0;
109 foreach ($csvdata['claim'] as $claim) {
110 if ($err_only) {
111 // output err_only is when claim status is a rejected type
112 if ($ft == 'f835') {
113 if (in_array($claim['Status'], array('1', '2', '3', '19', '20', '21'))) {
114 continue;
116 } elseif ($ft == 'f277') {
117 if (substr_count($claim['Status'], 'A1') || substr_count($claim['Status'], 'A2') || substr_count($claim['Status'], 'A5')) {
118 continue;
120 } elseif (strpos('|f997|f999|f271', $ft) && $claim['Status'] == 'A') {
121 continue;
122 } elseif (strpos('|f837|f270|f276', $ft)) {
123 continue;
128 $errct++;
129 $dd_str = "";
130 $oe = ( $errct % 2 ) ? 'codd' : 'ceven';
132 $ptn = (isset($claim['PtName'])) ? $claim['PtName'] : '';
133 $fn1 = (isset($claim['FileName'])) ? $claim['FileName'] : '';
134 $ctl = (isset($claim['Control'])) ? $claim['Control'] : '';
135 $pid = (isset($claim['CLM01'])) ? $claim['CLM01'] : '';
136 $sts = (isset($claim['Status'])) ? $claim['Status'] : '';
137 $err = (isset($claim['err_seg'])) ? $claim['err_seg'] : '';
138 $trc = (isset($claim['Trace'])) ? $claim['Trace'] : '';
139 $bht03 = (isset($claim['BHT03'])) ? $claim['BHT03'] : '';
140 $pay = (isset($claim['Payer'])) ? $claim['Payer'] : '';
141 $typ = (isset($csvfile['RspType'])) ? $claim['RspType'] : '';
142 $auth = (isset($csvfile['Auth'])) ? $claim['Auth'] : '';
144 $ins = (isset($csvfile['InsBnft'])) ? $claim['InsBnft'] : '';
145 $ins = (isset($csvfile['InsLevel'])) ? $claim['InsLevel'] : $ins;
147 $clm = (isset($csvfile['ClaimID'])) ? $claim['ClaimID'] : $ins;
149 $dte = (isset($claim['SvcDate'])) ? $claim['SvcDate'] : '';
150 $dte = (isset($claim['ReqDate'])) ? $claim['ReqDate'] : $dte;
151 $dte = (isset($claim['RspDate'])) ? $claim['RspDate'] : $dte;
152 $dte = (isset($claim['FileDate'])) ? $claim['FileDate'] : $dte;
154 $dd_str .= ($ptn) ? text($ptn) . "&nbsp; " : "";
155 $dd_str .= ($dte) ? " &nbsp;" . text(substr($dte, 0, 4)) . "-" . text(substr($dte, 4, 2)) . "-" . text(substr($dte, 6, 2)) : "";
156 if (strpos('|f277|f276|f270|f271|f278', $ft)) {
157 $dd_str .= ($sts) ? " &nbsp;" . text($sts) : "";
158 $dd_str .= ($ins) ? " &nbsp;" . text($ins) : "";
159 $dd_str .= ($clm) ? " &nbsp;" . text($clm) : "";
160 $dd_str .= ($bht03) ? " &nbsp;<em>view</em> <a class='" . attr($cls) . "' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn1) . "&ftype=" . attr_url($ft) . "&bht03=" . attr_url($bht03) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a>&nbsp; <a class='seg' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn1) . "&ftype=" . attr_url($ft) . "&bht03=" . attr_url($bht03) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a>&nbsp;" : "";
161 $dd_str .= ($pid) ? " &nbsp;<em>trace</em> <a class='sub' href='edih_main.php?gtbl=claim&ftype=" . attr_url($ft) . "&rsptype=f837&trace=" . attr_url($pid) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($pid) . "</a>" : "";
162 $dd_str .= ($auth && $auth == 'Rsp' || $auth == 'Reply') ? "<a class='sub' href='edih_main.php?gtbl=claim&ftype=" . attr_url($ft) . "&rsptype=f278&trace=" . attr_url($trc) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'><em>trace</em></a>" : "";
163 } elseif ($ft == 'f835') {
164 $dd_str .= ($clm) ? " &nbsp;<em>Claim ID</em> $ins" : "";
165 $dd_str .= ($ins) ? " &nbsp;<em>InsLevel</em> $ins" : "";
166 $dd_str .= ($pid) ? " &nbsp;$pid <a class='" . attr($cls) . "' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn1) . "&ftype=" . attr_url($ft) . "&pid=" . attr_url($pid) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a> <a class='" . attr($cls) . "' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn1) . "&ftype=" . attr_url($ft) . "&pid=" . attr_url($pid) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a>" : "";
167 } elseif ($ft == 'f997') {
168 $dd_str .= ($trc) ? " &nbsp;<a class='" . attr($cls) . "' title='" . attr($trc) . "' href='edih_main.php?gtbl=claim&ftype=" . attr_url($ft) . "&trace=" . attr_url($trc) . "&rsptype=" . attr_url($typ) . "&errseg=" . attr_url($err) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'><em>trace</em></a>" : "";
169 $dd_str .= ($err) ? " &nbsp;" . text(substr($err, 0, 8)) : "";
170 } else {
171 $dd_str .= ($pid) ? " &nbsp;<a class='" . attr($cls) . "' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn1) . "&ftype=" . attr_url($ft) . "&pid=" . attr_url($pid) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($pid) . "</a>" : "";
174 $dd_str .= ($fn1) ? " &nbsp;<a class='" . attr($cls) . "' title='" . attr($fn1) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($fn1) . "&ftype=" . attr_url($ft) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'><em>file</em></a>" : "";
176 $clm_html .= "<dd class='" . attr($oe) . "'>$dd_str</dd>".PHP_EOL;
182 if ($err_only) {
183 if ($errct) {
184 $str_html .= $clm_html;
186 } else {
187 $str_html .= $clm_html;
189 } // end foreach ($data_ar as $icn=>$csvdata)
191 return $str_html;
195 * make a list of brief information and links to claims where a problem
196 * has been identified.
198 * @uses csv_file_type()
199 * @uses edih_997_error()
200 * @uses csv_denied_by_file()
202 * @param string
203 * @param string
204 * @param string
206 * @return string
208 function edih_list_denied_claims($filetype, $filename, $trace = '')
211 $str_html = '';
212 $row_ar = array();
214 $ft = csv_file_type($filetype);
215 if ($ft == 'f997') {
216 $str_html = edih_997_error($filename);
217 return $str_html;
218 } elseif (strpos('|f271|f277|f835', $ft)) {
219 $row_ar = csv_denied_by_file($ft, $filename, $trace);
220 } else {
221 $str_html .= "Invalid file type " . text($filetype) . " for denied claim search<br />";
222 csv_edihist_log("edih_list_denied_claims: wrong filetype $filetype");
223 return $str_html;
227 if (count($row_ar)) {
228 $rw_ct = count($row_ar);
229 $rwct = 0;
230 $str_html .= "<h4>Denied/Rejected Claims Listing</h4>".PHP_EOL;
231 $str_html .= "<dl class ='" . attr($ft) . "'>" . text($rw_ct) . " claims <em>File</em>" . text($filename) . " ";
232 $str_html .= ($trace) ? "<em>Trace</em> $trace</dl>".PHP_EOL : "".PHP_EOL;
233 if ($ft == 'f835') {
234 foreach ($row_ar as $row) {
235 $oe = ( $rwct % 2 ) ? 'codd' : 'ceven';
236 $rwct++;
237 $str_html .= "<dt class='" . attr($oe) . "'>" . text($row[0]) . " <a class='rpt' href='edih_main.php?gtbl=claim&fname=" . attr_url($row[5]) . "&ftype=" . attr_url($ft) . "&pid=" . attr_url($row[2]) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($row[2]) . "</a></dt>".PHP_EOL;
239 } elseif ($ft == 'f277') {
240 foreach ($row_ar as $row) {
241 $oe = ( $rwct % 2 ) ? 'codd' : 'ceven';
242 $rwct++;
243 $str_html .= "<dt class='" . attr($oe) . "'>" . text($row[0]) . " <a class='rpt' href='edih_main.php?gtbl=claim&fname=" . attr_url($row[5]) . "&ftype=" . attr_url($ft) . "&bht03=" . attr_url($row[4]) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($row[4]) . "</a></dt>".PHP_EOL;
245 } elseif ($ft == 'f271') {
246 foreach ($row_ar as $row) {
247 $oe = ( $rwct % 2 ) ? 'codd' : 'ceven';
248 $rwct++;
249 $str_html .= "<dt class='" . attr($oe) . "'>" . text($row[0]) . " <a class='rpt' href='edih_main.php?gtbl=claim&fname=" . attr_url($row[5]) . "&ftype=" . attr_url($ft) . "&bht03=" . attr_url($row[4]) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($row[4]) . "</a></dt>".PHP_EOL;
251 } elseif ($ft == 'f997') {
252 foreach ($row_ar as $row) {
253 $oe = ( $rwct % 2 ) ? 'codd' : 'ceven';
254 $rwct++;
255 $str_html .= "<dt class='" . attr($oe) . "'>" . text($row[0]) . " <a class='rpt' href='edih_main.php?gtbl=claim&ftype=" . attr_url($tp) . "&trace=" . attr_url($row[2]) . "&rsptype=" . attr_url($row[6]) . "&err=" . attr_url($row[7]) . "&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($row[2]) . "</a></dt>".PHP_EOL;
260 $str_html .= "</dl>".PHP_EOL;
261 } else {
262 $str_html .= "Search returned no data rows from file " . text($filename) . "<br />";
263 csv_edihist_log("edih_list_denied_claims: no rows returned $filetype $filename $trace");
267 return $str_html;
272 * check the csv claims tables and return rows for a particular encounter
274 * @uses csv_pid_enctr_parse()
275 * @uses csv_file_with_pid_enctr()
276 * @uses csv_table_select_list()
277 * @uses csv_search_record()
279 * @param string encounter number
281 * @return string
283 function edih_claim_history($encounter)
286 if ($encounter) {
287 $e = (string)$encounter;
288 } else {
289 return 'invalid encounter value ' . text($encounter) . '<br />'.PHP_EOL;
292 // use function csv_table_select_list() so that only
293 // existing csv tables are queried
294 $tbl2 = csv_table_select_list('array');
296 $rtypes = array();
297 if (is_array($tbl2['claims']) && count($tbl2['claims'])) {
298 $rtypes = array_keys($tbl2['claims']);
299 } else {
300 csv_edihist_log("csv_claim_history: failed to get csv table names");
301 return "failed to get csv table names";
305 $ch_html = "<table class='clmhist' columns=4><caption>Encounter Record for " . text($e) . "</caption>";
306 $ch_html .= "<tbody>".PHP_EOL;
308 if (in_array('f837', $rtypes)) {
309 $tp = 'f837';
310 $btar = csv_file_by_enctr($e, $tp);
312 if (is_array($btar) && count($btar)) {
313 $ch_html .= "<tr class='ch837'><td colspan=4>837 Claim " . text(count($btar)) . "</td></tr>".PHP_EOL;
314 $ch_html .= "<tr class='chhead'>".PHP_EOL;
315 $ch_html .= "<td>Name</td><td>SvcDate</td><td>CLM01</td><td>File</td>".PHP_EOL;
316 $ch_html .= "</tr>".PHP_EOL;
317 foreach ($btar as $ch) {
318 $dt = substr($ch['SvcDate'], 0, 4).'-'.substr($ch['SvcDate'], 4, 2).'-'.substr($ch['SvcDate'], 6, 2);
319 //array('PtName', 'SvcDate', 'CLM01', 'InsLevel', 'Control', 'FileName', 'Fee', 'PtPaid', 'Provider' );
320 $ch_html .= "<tr class='ch837'>".PHP_EOL;
322 $ch_html .= "<td>" . text($ch['PtName']) . "</td>".PHP_EOL;
323 $ch_html .= "<td>" . text($dt) . "</td>".PHP_EOL;
324 $ch_html .= "<td><a class='seg' href='edih_main.php?gtbl=claim&fname=" . attr_url($ch['FileName']) . "&ftype=" . attr_url($tp) . "&pid=" . attr_url($ch['CLM01']) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($ch['CLM01']) . "</a></td>".PHP_EOL;
325 $ch_html .= "<td title='" . attr($ch['Control']) . "'><a class='seg' href='edih_main.php?gtbl=file&fname=" . attr_url($ch['FileName']) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($ch['FileName']) . "</a></td>".PHP_EOL;
327 $ch_html .= "</tr>".PHP_EOL;
329 } else {
330 $ch_html .= "<tr class='ch837'>".PHP_EOL;
331 $ch_html .= "<td colspan=4>837 Claim -- Nothing found for " . text($e) . "</td>".PHP_EOL;
332 $ch_html .= "</tr>".PHP_EOL;
337 if (in_array('f997', $rtypes)) {
338 $tp = 'f997';
339 $f997ar = csv_file_by_enctr($e, $tp);
341 if (is_array($f997ar) && count($f997ar)) {
342 $ch_html .= "<tr class='ch997'><td colspan=4>Ack 997/999 " . text(count($f997ar)) . "</td></tr>".PHP_EOL;
343 $ch_html .= "<tr class='chhead'>".PHP_EOL;
344 $ch_html .= "<td colspan=3>Acknowledgement File</td><td>Notes</td>".PHP_EOL;
345 $ch_html .= "</tr>".PHP_EOL;
346 foreach ($f997ar as $ch) {
348 $msg = strlen($ch[7]) ? $ch[7] : 'ST Number';
349 //array('PtName', 'RspDate', 'Trace', 'Status', 'Control', 'FileName', 'RspType', 'err_seg');;
350 $ch_html .= "<tr class='ch997'>";
351 $ch_html .= "<td>Rsp Ack</td>".PHP_EOL;
352 $ch_html .= "<td><a class='rsp' target='_blank' href='edih_main.php?gtbl=claim&fname=" . attr_url($ch['FileName']) . "&ftype=" . attr_url($tp) . "&trace=" . attr_url($ch['Trace']) . "&rsptype=" . attr_url($ch['RspType']) . "&errseg=" . attr_url($ch['err_seg']) . "&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($ch['Status']) . "</a></td>".PHP_EOL;
353 $ch_html .= "<td><a class='seg' href='edih_main.php?gtbl=file&fname=" . attr_url($ch['FileName']) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($ch['FileName']) . "</a></td>".PHP_EOL;
354 $ch_html .= "<td title='Response type/date'>" . text($ch['RspType']) . " " . text($ch['RspDate']) . "</td>".PHP_EOL;
355 $ch_html .= "</tr>".PHP_EOL;
357 } else {
358 $ch_html .= "<tr class='ch997'>";
359 $ch_html .= "<td colspan=4>Ack 997/999 -- Nothing found for " . text($e) . "</td>".PHP_EOL;
360 $ch_html .= "</tr>".PHP_EOL;
365 if (in_array('f277', $rtypes)) {
366 $tp = 'f277';
367 $f277ar = csv_file_by_enctr($e, $tp);
369 if (is_array($f277ar) && count($f277ar)) {
370 $ch_html .= "<tr class='ch277'><td colspan=4>Status 277 " . text(count($f277ar)) . "</td></tr>".PHP_EOL;
371 $ch_html .= "<tr class='chhead'>".PHP_EOL;
372 $ch_html .= "<td>Response</td><td>Status</td><td>File</td><td>ClaimID</td>".PHP_EOL;
373 $ch_html .= "</tr>".PHP_EOL;
374 foreach ($f277ar as $ch) {
375 //'f277':array('PtName', 'SvcDate', 'CLM01', 'Status', 'BHT03', 'FileName', 'Payer', 'Trace');
376 $ch_html .= "<tr class='ch277'>";
378 $ch_html .= "<td>Claim Status</td>".PHP_EOL;
379 $ch_html .= "<td><a class='rsp' href='edih_main.php?gtbl=claim&fname=" . attr_url($ch['FileName']) . "&ftype=" . attr_url($tp) . "&bht03=" . attr_url($ch['BHT03']) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($ch['Status']) . "</a></td>".PHP_EOL;
380 $ch_html .= "<td title='" . attr($ch['FileName']) . "'><a href='edih_main.php?gtbl=file&fname=" . attr_url($ch['FileName']) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($ch['FileName']) . "</a></td>".PHP_EOL;
381 $ch_html .= "<td title='Payer " . attr($ch['Payer']) . "'>" . text($ch['Trace']) . "</td>".PHP_EOL;
383 $ch_html .= "</tr>".PHP_EOL;
385 } else {
386 $ch_html .= "<tr class='ch277'>";
387 $ch_html .= "<td colspan=4>Status 277 -- Nothing found for " . text($e) . "</td>".PHP_EOL;
388 $ch_html .= "</tr>".PHP_EOL;
393 if (in_array('f835', $rtypes)) {
394 $tp = 'f835';
395 $f835ar = csv_file_by_enctr($e, $tp);
397 if (is_array($f835ar) && count($f835ar)) {
398 $ch_html .= "<tr class='ch835'><td colspan=4>Payment 835 " . text(count($f835ar)) . "</td></tr>".PHP_EOL;
399 $ch_html .= "<tr class='chhead'>".PHP_EOL;
400 $ch_html .= "<td>Response</td><td>Status</td><td>Trace</td><td>Payer</td>".PHP_EOL;
401 $ch_html .= "</tr>".PHP_EOL;
402 foreach ($f835ar as $ch) {
404 $msg = $ch['ClaimID'] .' '.$ch['Pmt'].' '.$ch['PtResp'];
405 // array('PtName', 'SvcDate', 'CLM01', 'Status', 'Trace', 'FileName', 'ClaimID', 'Pmt', 'PtResp', 'Payer');
406 $ch_html .= "<tr class='ch835'>";
408 $ch_html .= "<td>" . text($ch['PtName']) . "</td>".PHP_EOL;
409 $ch_html .= "<td><a class='rsp' href='edih_main.php?gtbl=claim&fname=" . attr_url($ch['FileName']) . "&ftype=" . attr_url($tp) . "&pid=" . attr_url($ch['CLM01']) . "&summary=no&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($ch['Status']) . "</a></td>".PHP_EOL;
410 $ch_html .= "<td><a href='edih_main.php?gtbl=file&fname=" . attr_url($ch['FileName']) . "&ftype=" . attr_url($tp) . "&trace=" . attr_url($ch['Trace']) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($ch['Trace']) . "</a></td>".PHP_EOL;
411 $ch_html .= "<td title='" . attr($msg) . "'>" . text($ch['Payer']) . "</td>".PHP_EOL;
413 $ch_html .= "</tr>".PHP_EOL;
415 } else {
416 $ch_html .= "<tr class='ch835'>";
417 $ch_html .= "<td colspan=4>Payment 835 -- Nothing found for " . text($e) . "</td>".PHP_EOL;
418 $ch_html .= "</tr>".PHP_EOL;
422 } // end if($tp ...
423 // -- this is where a query on the payments datatable could be used to show if payment
424 // has been received, even if no era file shows the payment.
426 $ch_html .= "</tbody>".PHP_EOL;
427 $ch_html .= "</table>".PHP_EOL;
429 return $ch_html;
434 * Render one of our csv record files as an html table
436 * This function determines the actual csv file from the file_type and the
437 * csv_type. Tthe date field of each row is checked against the optional
438 * lookback period or date parameters.
440 * @uses csv_file_type()
441 * @uses csv_parameters()
442 * @uses csv_thead_html()
444 * @param string $file_type -- see function csv_file_type()
445 * @param string $csv_type -- either "file" or "claim"
446 * @param string $period -- lookback 2 weeks, 1 month, ALL, etc
447 * @param string $datestart -- from date CCYY-MM-DD
448 * @param string $dateend -- to date CCYY-MM-DD
450 * @return string
452 function edih_csv_to_html($file_type, $csv_type, $period = '', $datestart = '', $dateend = '')
455 $csv_html = "";
456 $modstr = '';
457 $csv_d = array();
458 // debug
459 csv_edihist_log("edih_csv_to_html: period $period datestart $datestart dateend $dateend");
461 $is_date = false;
462 $is_period = false;
464 if ($file_type && $csv_type) {
465 $csv_ar = csv_assoc_array($file_type, $csv_type);
466 if (is_array($csv_ar) && count($csv_ar)) {
467 $rwct = count($csv_ar);
468 } else {
469 csv_edihist_log("edih_csv_to_html: error opening csv file $file_type $csv_type");
470 $csv_html .= "error opening csv file " . text($file_type) . " " . text($csv_type) . "<br>";
471 return false;
473 } else {
474 $csv_html .= "invalid arguments for opening csv table<br>";
475 return false;
478 $tp = csv_file_type($file_type);
479 if ($tp) {
480 $params = csv_parameters($tp);
481 } else {
482 csv_edihist_log("csv_to_html error: incorrect file type $file_type");
483 $csv_html .= "csv_to_html error: incorrect file type " . text($file_type) . " <br />".PHP_EOL;
484 return false;
487 // csv tables date is in col 0 for file, col 5 for claim
488 // file name is under FileName for all tables
489 $dtcol = (strpos($csv_type, "aim")) ? $params['claimdate'] : $params['filedate'];
490 $tp_lbl = (strpos($csv_type, "aim")) ? 'Claims' : 'Files';
492 // given dates shold be in CCYY-MM-DD or CCYY/MM/DD format
493 // edih_view.php is supposed to use CCYY-MM-DD
494 $dts = $dt4 = $dte = '';
495 if (preg_match('/(19|20)\d{2}\D[01][0-9]\D[0-3][0-9]/', $datestart)) {
496 $dts = implode('', preg_split("/\D/", $datestart));
497 if ($dateend && preg_match('/(19|20)\d{2}\D[01][0-9]\D[0-3][0-9]/', $dateend)) {
498 $dte = implode('', preg_split("/\D/", $dateend));
499 } else {
500 $dt4 = date_create(date('Y-m-d'));
501 $dte = date_format($dt4, 'Ymd');
504 // php DateTime is poorly documented
505 $is_date = ($dts && $dte);
506 // debug
507 csv_edihist_log("edih_csv_to_html: dts $dts dte $dte isdate ".strval($is_date));
510 } elseif ($period) {
511 $dtstr1 = '';
512 $is_period = preg_match('/\d{1,2}(?=w|m|y)/', $period, $matches);
513 if (count($matches)) {
514 $pd = $matches[0];
515 $gtdt = getdate();
516 $mon = (string)$gtdt['mon'];
517 $day = (string)($gtdt['mday']); // - $gtdt['wday'] + 1); not sure why this was valuable
518 $yr = (string)$gtdt['year'];
519 if (strtoupper($period) == 'ALL') {
520 $is_period = false;
521 $modstr = '';
522 } elseif (strpos($period, 'w')) {
523 // take the first character of 'period'
524 $modstr = '-'.$pd.' week';
525 $dtstr1 = $mon.'/'.$day.'/'.$yr;
526 } elseif (strpos($period, 'm')) {
527 $modstr = '-'.$pd.' month';
528 $dtstr1 = $mon.'/01/'.$yr;
529 } elseif (strpos($period, 'y')) {
530 $modstr = '-'.$pd.' year';
531 $dtstr1 = $mon.'/01/'.$yr;
532 } else {
533 csv_edihist_log("csv_to_html error: incorrect date period $period");
534 return false;
539 // debug
540 csv_edihist_log("edih_csv_to_html: period $period modstr $modstr dtstr1 $dtstr1");
542 if ($is_period && $modstr) {
543 $dtpd1 = date_create($dtstr1);
544 $dtm = date_modify($dtpd1, $modstr);
545 $dtpd2 = $dtm->format('Ymd');
546 $dtpdlbl = $dtm->format('Y-m-d');
547 } else {
548 $dtpd2 = '';
549 $dtpdlbl = 'All Dates';
554 if ($is_date) {
555 $isok = false;
556 $idx = 0;
557 foreach ($csv_ar as $data) {
558 $isok = (strcmp($data[$dtcol], $dts) >= 0) ? true : false;
559 $isok = (strcmp($data[$dtcol], $dte) > 0) ? false : $isok;
561 if ($isok) {
562 $csv_d[] = $data;
565 } elseif ($is_period) {
566 foreach ($csv_ar as $data) {
567 if (strcmp($data[$dtcol], $dtpd2) > 0) {
568 $csv_d[] = $data;
571 } else {
572 $csv_d = &$csv_ar;
576 $ln_ct = count($csv_d);
578 if ($is_date) {
579 //$csv_html .= "<div id='dttl'>".PHP_EOL;
580 $csv_html .= "<h4>Table: " . text($tp_lbl) . " &nbsp;" . text($tp) . " &nbsp; Start: " . text($datestart) . " &nbsp; End: " . text($dateend) . " &nbsp;Rows: " . text($rwct) . " &nbsp;Shown: " . text($ln_ct) . "</h4>".PHP_EOL;
581 //$csv_html .= "</div>".PHP_EOL;
582 } elseif ($is_period) {
583 //div id='dttl'></div>
584 $csv_html .= "<h4>Table: " . text($tp_lbl) . " &nbsp;" . text($tp) . " &nbsp;From Date: " . text($dtpdlbl) . " &nbsp;Rows: " . text($rwct) . " &nbsp;Shown: " . text($ln_ct) . "</h4>".PHP_EOL;
585 } else {
586 //<div id='dttl'></div>
587 $csv_html .= "<h4>Table: " . text($tp_lbl) . " &nbsp;" . text($tp) . " &nbsp;All Dates Rows: " . text($rwct) . " &nbsp; Shown: " . text($ln_ct) . "</h4>".PHP_EOL;
591 //$csv_html .= "<table id='csvTable' class='csvDisplay'>".PHP_EOL; class='display'max-width: fit-content
592 $csv_html .= "<table id='csvTable' style='width: fit-content; float: left'>".PHP_EOL;
593 $csv_html .= csv_thead_html($tp, $csv_type);
594 $csv_html .= "<tbody>".PHP_EOL;
596 // now create the body of the table
598 $cls = (strpos('|f837|f270|f276|f278', $tp)) ? 'sub' : 'rsp';
600 $idx = 0;
601 if ($csv_type == 'file') {
603 if ($tp == 'f835') {
604 //array('Date', 'FileName', 'Control', 'Trace', 'Claim_ct', 'Denied', 'Payer')
605 foreach ($csv_d as $val) {
606 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
607 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
608 foreach ($val as $k => $v) {
609 if ($k == 'Date') {
610 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>".PHP_EOL;
611 } elseif ($k == 'FileName') {
612 $fn = $v;
613 $csv_html .= "<td><a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
614 } elseif ($k == 'Control') {
615 $csv_html .= "<td><a class='seg' href='edih_main.php?gtbl=file&icn=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
616 } elseif ($k == 'Trace') {
617 $trc = $v;
618 $csv_html .= "<td><a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&trace=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&rsptype=" . attr_url($tp) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
619 } elseif ($k == 'Claim_ct') {
620 $csv_html .= "<td>" . text($v) . " <a class='sub' href='edih_main.php?tracecheck=" . attr_url($trc) . "&ckprocessed=yes&csrf_token_form=" . attr_url(collectCsrfToken()) . "'><em>P?</em></a></td>".PHP_EOL;
621 } elseif ($k == 'Denied') {
622 if ((int)$v > 0) {
623 $csv_html .= "<td><a class='sub' href='edih_main.php?chkdenied=yes&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&trace=" . attr_url($trc) . "&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
624 } else {
625 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
627 } else {
628 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
632 $csv_html .= "</tr>".PHP_EOL;
633 $idx++;
635 } elseif ($tp == 'f997') {
636 //array('Date', 'FileName', 'Control', 'Trace', 'RspType', 'RejCt')
637 foreach ($csv_d as $val) {
638 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
639 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
641 $rsp = $val['RspType'];
642 foreach ($val as $k => $v) {
643 if ($k == 'Date') {
644 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) ."</td>".PHP_EOL;
645 } elseif ($k == 'FileName') {
646 $fn = $v;
647 $csv_html .= "<td><a class='seg' href='edih_main.php?gtbl=file&fname=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
648 } elseif ($k == 'Trace') {
649 $csv_html .= "<td><a class='seg' href='edih_main.php?gtbl=file&trace=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&rsptype=" . attr_url($rsp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
650 } elseif ($k == 'RejCt') {
651 if ((int)$v > 0) {
652 $csv_html .= "<td><a class='rpt' href='edih_main.php?chkdenied=yes&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
653 } else {
654 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
656 } else {
657 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
661 $csv_html .= "</tr>".PHP_EOL;
662 $idx++;
666 } else {
667 // the generic case -- for 'file' type tables
668 foreach ($csv_d as $val) {
669 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
670 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
671 foreach ($val as $k => $v) {
672 if ($k == 'Date') {
673 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>".PHP_EOL;
674 } elseif ($k == 'FileName') {
675 $csv_html .= "<td><a class='seg' href='edih_main.php?gtbl=file&fname=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
676 } elseif ($k == 'Control') {
677 $csv_html .= "<td><a class='seg' href='edih_main.php?gtbl=file&icn=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
678 } elseif ($k == 'Reject') {
679 if ((int)$v > 0) {
680 $csv_html .= "<td><a class='sub' href='edih_main.php?&chkdenied=yes&fname=" . attr_url($val['FileName']) . "&ftype=" . attr_url($tp) . "&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
681 } else {
682 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
684 } else {
685 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
689 $csv_html .= "</tr>".PHP_EOL;
690 $idx++;
693 } elseif ($csv_type == 'claim') {
695 if ($tp == 'f837') {
696 // array('PtName', 'SvcDate', 'CLM01', 'InsLevel', 'Control', 'FileName', 'Fee', 'PtPaid', 'Provider' );
697 foreach ($csv_d as $val) {
698 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
699 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
700 // needed values for links
701 $fn = $val['FileName'];
702 foreach ($val as $k => $v) {
703 if ($k == 'CLM01') {
704 $csv_html .= "<td><a class='sub' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&pid=" . attr_url($v) . "&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
705 } elseif ($k == 'SvcDate') {
706 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>".PHP_EOL;
707 } elseif ($k == 'FileName') {
708 $csv_html .= "<td><a class='seg' href='edih_main.php?gtbl=file&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
709 } else {
710 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
714 $csv_html .= "</tr>".PHP_EOL;
715 $idx++;
717 } elseif ($tp == 'f835') {
718 // array('PtName', 'SvcDate', 'CLM01', 'Status', 'Trace', 'FileName', 'ClaimID', 'Pmt', 'PtResp', 'Payer')
719 foreach ($csv_d as $val) {
720 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
721 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
722 // needed values for links
723 $fn = $val['FileName'];
724 $pid = $val['CLM01'];
725 foreach ($val as $k => $v) {
726 if ($k == 'SvcDate') {
727 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>".PHP_EOL;
728 } elseif ($k == 'CLM01') {
729 $csv_html .= "<td>" . text($v) . " <a class='" . attr($cls) . "' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&pid=" . attr_url($pid) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a>&nbsp;";
730 $csv_html .= "&nbsp;<a class='seg' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&pid=" . attr_url($pid) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a></td>".PHP_EOL;
731 } elseif ($k == 'Trace') {
732 $csv_html .= "<td><a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($fn) . "&trace=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
733 } elseif ($k == 'FileName') {
734 $csv_html .= "<td title='" . attr($v) . "'>File <a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a>&nbsp;";
735 $csv_html .= "&nbsp;<a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a></td>".PHP_EOL;
736 } else {
737 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
741 $csv_html .= "</tr>".PHP_EOL;
742 $idx++;
744 } elseif ($tp == 'f277') {
745 // array('PtName', 'SvcDate', 'CLM01', 'Status', 'BHT03', 'FileName', 'Payer', 'Ins_ID', 'Trace');
746 foreach ($csv_d as $val) {
747 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
748 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
749 // needed values for links
750 $fn = $val['FileName'];
751 $bht03 = $val['BHT03'];
752 $trc = $val['CLM01'];
753 foreach ($val as $k => $v) {
754 if ($k == 'SvcDate') {
755 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>".PHP_EOL;
756 } elseif ($k == 'CLM01') {
757 $csv_html .= "<td><a class='sub' href='edih_main.php?gtbl=claim&trace=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&rsptype=f837&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
758 } elseif ($k == 'BHT03') {
759 $csv_html .= "<td>" . text($v) . " <a class='rsp' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&bht03=" . attr_url($v) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a>&nbsp;";
760 $csv_html .= "&nbsp;<a class='seg' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&bht03=" . attr_url($v) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a></td>".PHP_EOL;
761 } elseif ($k == 'FileName') {
762 $csv_html .= "<td title='" . attr($v) . "'>File <a class='rsp' href='edih_main.php?gtbl=file&fname=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a>&nbsp;";
763 $csv_html .= "&nbsp;<a class='seg' href='edih_main.php?gtbl=file&fname=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a></td>".PHP_EOL;
764 } else {
765 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
769 $csv_html .= "</tr>".PHP_EOL;
770 $idx++;
772 } elseif ($tp == 'f276') {
773 // array('PtName', 'ReqDate', 'CLM01', 'InsBnft', 'BHT03', 'FileName', 'Payer', 'Trace');
774 foreach ($csv_d as $val) {
775 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
776 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
777 // needed values for links
778 $fn = $val['FileName'];
779 $bht03 = $val['BHT03'];
780 $trc = $val['CLM01'];
781 foreach ($val as $k => $v) {
782 if ($k == 'ReqDate') {
783 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>".PHP_EOL;
784 } elseif ($k == 'CLM01') {
785 $csv_html .= "<td><a class='sub' href='edih_main.php?gtbl=claim&trace=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&rsptype=f837&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
786 } elseif ($k == 'BHT03') {
787 $csv_html .= "<td>" . text($v) . " <a class='" . attr($cls) . "' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&bht03=" . attr_url($v) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a>&nbsp;";
788 $csv_html .= "&nbsp;<a class='seg' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&bht03=" . attr_url($v) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a></td>".PHP_EOL;
789 } elseif ($k == 'FileName') {
790 $csv_html .= "<td><a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
791 } else {
792 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
796 $csv_html .= "</tr>".PHP_EOL;
797 $idx++;
799 } elseif ($tp == 'f270') {
800 // array('PtName', 'ReqDate', 'Trace', 'InsBnft', 'BHT03', 'FileName', 'Payer');
801 foreach ($csv_d as $val) {
802 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
803 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
804 // needed values for links
805 $fn = $val['FileName'];
806 $bht03 = $val['BHT03'];
807 foreach ($val as $k => $v) {
808 if ($k == 'ReqDate') {
809 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>".PHP_EOL;
810 } elseif ($k == 'BHT03') {
811 $csv_html .= "<td> <a class='" . attr($cls) . "' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&bht03=" . attr_url($v) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
812 } elseif ($k == 'FileName') {
813 $csv_html .= "<td><a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
814 } else {
815 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
819 $csv_html .= "</tr>".PHP_EOL;
820 $idx++;
822 } elseif ($tp == 'f271') {
823 // array('PtName', 'RspDate', 'Trace', 'Status', 'BHT03', 'FileName', 'Payer');
824 foreach ($csv_d as $val) {
825 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
826 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
827 // needed values for links
828 $fn = $val['FileName'];
829 $bht03 = $val['BHT03'];
830 foreach ($val as $k => $v) {
831 if ($k == 'RspDate') {
832 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>".PHP_EOL;
833 } elseif ($k == 'BHT03') {
834 $csv_html .= "<td>" . text($v) . " <a class='" . attr($cls) . "' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&bht03=" . attr_url($v) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a>&nbsp;".PHP_EOL;
835 $csv_html .= "&nbsp;<a class='seg' target='_blank' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&bht03=" . attr_url($v) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a></td>".PHP_EOL;
836 } elseif ($k == 'FileName') {
837 $csv_html .= "<td title='" . attr($v) . "'> File <a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a>&nbsp;";
838 $csv_html .= "&nbsp;<a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a></td>".PHP_EOL;
839 } else {
840 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
844 $csv_html .= "</tr>".PHP_EOL;
845 $idx++;
847 } elseif ($tp == 'f278') {
848 // array('PtName', 'FileDate', 'Trace', 'Status', 'BHT03', 'FileName', 'Auth', 'Payer')
849 foreach ($csv_d as $val) {
850 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
851 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
852 // needed values for links
853 $fn = $val['FileName'];
854 $bht03 = $val['BHT03'];
855 foreach ($val as $k => $v) {
856 if ($k == 'FileDate') {
857 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>".PHP_EOL;
858 } elseif ($k == 'BHT03') {
859 $csv_html .= "<td>" . text($v) . " <a class='" . attr($cls) . "' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&bht03=" . attr_url($v) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a>&nbsp;".PHP_EOL;
860 $csv_html .= "&nbsp;<a class='seg' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&bht03=" . attr_url($v) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a></td>".PHP_EOL;
861 } elseif ($k == 'FileName') {
862 $csv_html .= "<td title='" . attr($v) . "'> File <a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=htm&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>H</a>&nbsp;";
863 $csv_html .= "&nbsp;<a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>T</a></td>".PHP_EOL;
864 } else {
865 $csv_html .= "<td>$v</td>".PHP_EOL;
869 $csv_html .= "</tr>".PHP_EOL;
870 $idx++;
872 } elseif ($tp == 'f997') {
873 // array('PtName', 'RspDate', 'Trace', 'Status', 'Control', 'FileName', 'RspType', 'err_seg');
874 foreach ($csv_d as $val) {
875 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
876 $csv_html .= "<tr class='$bgc'>".PHP_EOL;
877 // needed values for links
878 $fn = $val['FileName'];
879 $rsp = $val['RspType'];
880 $err = $val['err_seg'];
881 foreach ($val as $k => $v) {
882 if ($k == 'RspDate') {
883 $csv_html .= "<td>" . text(substr($v, 0, 4)) .'-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>".PHP_EOL;
884 } elseif ($k == 'FileName') {
885 $csv_html .= "<td><a class='seg' href='edih_main.php?gtbl=file&fname=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
886 } elseif ($k == 'Trace') {
887 $csv_html .= "<td><a class='seg' href='edih_main.php?gtbl=claim&fname=" . attr_url($fn) . "&ftype=" . attr_url($tp) . "&trace=" . attr_url($v) . "&rsptype=" . attr_url($rsp) . "&err=" . attr_url($err) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
888 } elseif ($k == 'err_seg') {
889 $csv_html .= "<td title='" . attr($v) . "'>" . text(substr($v, 0, 8)) . "...</td>".PHP_EOL;
890 } else {
891 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
895 $csv_html .= "</tr>".PHP_EOL;
896 $idx++;
898 } else {
899 // all types in the tables are covered in an elseif, so this is unexpected
900 foreach ($csv_d as $val) {
901 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
902 $csv_html .= "<tr class='" . attr($bgc) . "'>".PHP_EOL;
903 foreach ($val as $k => $v) {
904 if ($k == 'FileName') {
905 $csv_html .= "<td><a class='" . attr($cls) . "' href='edih_main.php?gtbl=file&fname=" . attr_url($v) . "&ftype=" . attr_url($tp) . "&fmt=seg&csrf_token_form=" . attr_url(collectCsrfToken()) . "'>" . text($v) . "</a></td>".PHP_EOL;
906 } else {
907 $csv_html .= "<td>" . text($v) . "</td>".PHP_EOL;
911 $csv_html .= "</tr>".PHP_EOL;
912 $idx++;
915 } // end body of the table
916 //$csv_html .= "</tbody>".PHP_EOL."</table>".PHP_EOL."</div>".PHP_EOL;
917 $csv_html .= "</tbody>".PHP_EOL."</table>".PHP_EOL;
919 return $csv_html;