Refactor previous name into dedicated service (#7571)
[openemr.git] / library / edihistory / edih_csv_data.php
blob6cc3c4698022a87e170cc26046a888d8a9676eb1
1 <?php
3 /*
4 * edih_csv_data.php
6 * Copyright 2016 Kevin McCormick Longview, Texas
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; version 3 or later. You should have
17 * received a copy of the GNU General Public License along with this program;
18 * if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * <http://opensource.org/licenses/gpl-license.php>
24 * @link: https://www.open-emr.org
25 * @package ediHistory
28 use OpenEMR\Common\Csrf\CsrfUtils;
30 /**
31 * Display csv table data in an HTML table for newly processed files
33 * This function uses the csv table header row to order the csv data
34 * The data array should be file table rows and claim table rows,
35 * and have this structure:
36 * array[icn]['type'] => x12 type
37 * array[icn]['file'][i][array( --- data row---) ]
38 * array[icn]['claim'][i][array( --- data row---) ]
40 * @uses csv_table_header()
41 * @uses csv_thead_html()
42 * @param array
43 * @param bool
44 * @return string
46 function edih_csv_process_html($data_ar, $err_only = false)
49 $str_html = '';
50 $clm_html = '';
52 foreach ($data_ar as $icn => $csvdata) {
53 if (array_key_exists('type', $csvdata)) {
54 $ft = $csvdata['type'];
55 } else {
56 $str_html .= 'edih_csv_process_html() for ' . text($icn) . ' did not get type value';
57 csv_edihist_log('edih_csv_process_html: for ' . $icn . ' did not get type value');
58 return $str_html;
62 $cls = (strpos('|f837|f270|f276|f278', $ft)) ? 'sub' : 'rsp';
64 if (array_key_exists('file', $csvdata)) {
66 $fidx = 0;
67 foreach ($csvdata['file'] as $key => $csvfile) {
69 $oe = ( $fidx % 2 == 1 ) ? 'fodd' : 'feven';
70 $cls = (strpos('|f837|f270|f276|f278', $ft)) ? 'sub' : 'rsp';
72 $dt_str = "";
74 $dte = (isset($csvfile['Date'])) ? $csvfile['Date'] : '';
75 $fn1 = (isset($csvfile['FileName'])) ? $csvfile['FileName'] : '';
76 $ctl = (isset($csvfile['Control'])) ? $csvfile['Control'] : '';
77 $clmct = (isset($csvfile['Claim_ct'])) ? $csvfile['Claim_ct'] : '';
78 $trc = (isset($csvfile['Trace'])) ? $csvfile['Trace'] : '';
79 $typ = (isset($csvfile['RspType'])) ? $csvfile['RspType'] : '';
80 $rej = (isset($csvfile['RejCt'])) ? $csvfile['RejCt'] : '';
82 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($fn1) . "</a>&nbsp;" : "";
83 $dt_str .= ($dte) ? " &nbsp;" . text(substr($dte, 0, 4)) . "-" . text(substr($dte, 4, 2)) . "-" . text(substr($dte, 6, 2)) : "";
84 $dt_str .= ($clmct) ? " &nbsp;<em>Claims</em> " . text($clmct) : "";
85 if ($ft == 'f997' || $ft == 'ta1') {
86 $dt_str .= ($typ) ? " &nbsp;" . text($typ) : "";
87 $dt_str .= ($rej) ? " &nbsp;" . text($rej) : "";
88 $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(CsrfUtils::collectCsrfToken()) . "'><em>trace</em></a>&nbsp;" : "";
89 } elseif ($ft == 'f277') {
90 $dt_str .= (isset($csvfile['Accept'])) ? " &nbsp;<em>Accpt</em> " . text($csvfile['Accept']) : "";
91 $dt_str .= (isset($csvfile['Reject'])) ? " &nbsp;<em>Rej</em> " . text($csvfile['Reject']) : "";
92 } elseif ($ft == 'f835') {
93 $dt_str .= (isset($csvfile['Denied'])) ? " &nbsp;<em>Denied</em> " . text($csvfile['Denied']) : "";
94 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($trc) . "</a>&nbsp;" : "";
95 $dt_str .= (isset($csvfile['Payer'])) ? " &nbsp;" . text($csvfile['Payer']) : "";
99 $str_html .= "<dt class=" . attr($oe) . ">$dt_str</dt>" . PHP_EOL;
100 $fidx++;
104 // &nbsp;&nbsp;
105 // handle the claim array
106 if (array_key_exists('claim', $csvdata)) {
108 $cidx = 0;
109 $errct = 0;
111 foreach ($csvdata['claim'] as $claim) {
112 if ($err_only) {
113 // output err_only is when claim status is a rejected type
114 if ($ft == 'f835') {
115 if (in_array($claim['Status'], array('1', '2', '3', '19', '20', '21'))) {
116 continue;
118 } elseif ($ft == 'f277') {
119 if (substr_count($claim['Status'], 'A1') || substr_count($claim['Status'], 'A2') || substr_count($claim['Status'], 'A5')) {
120 continue;
122 } elseif (strpos('|f997|f999|f271', $ft) && $claim['Status'] == 'A') {
123 continue;
124 } elseif (strpos('|f837|f270|f276', $ft)) {
125 continue;
130 $errct++;
131 $dd_str = "";
132 $oe = ( $errct % 2 ) ? 'codd' : 'ceven';
134 $ptn = (isset($claim['PtName'])) ? $claim['PtName'] : '';
135 $fn1 = (isset($claim['FileName'])) ? $claim['FileName'] : '';
136 $ctl = (isset($claim['Control'])) ? $claim['Control'] : '';
137 $pid = (isset($claim['CLM01'])) ? $claim['CLM01'] : '';
138 $sts = (isset($claim['Status'])) ? $claim['Status'] : '';
139 $err = (isset($claim['err_seg'])) ? $claim['err_seg'] : '';
140 $trc = (isset($claim['Trace'])) ? $claim['Trace'] : '';
141 $bht03 = (isset($claim['BHT03'])) ? $claim['BHT03'] : '';
142 $pay = (isset($claim['Payer'])) ? $claim['Payer'] : '';
143 $typ = (isset($csvfile['RspType'])) ? $claim['RspType'] : '';
144 $auth = (isset($csvfile['Auth'])) ? $claim['Auth'] : '';
146 $ins = (isset($csvfile['InsBnft'])) ? $claim['InsBnft'] : '';
147 $ins = (isset($csvfile['InsLevel'])) ? $claim['InsLevel'] : $ins;
149 $clm = (isset($csvfile['ClaimID'])) ? $claim['ClaimID'] : $ins;
151 $dte = (isset($claim['SvcDate'])) ? $claim['SvcDate'] : '';
152 $dte = (isset($claim['ReqDate'])) ? $claim['ReqDate'] : $dte;
153 $dte = (isset($claim['RspDate'])) ? $claim['RspDate'] : $dte;
154 $dte = (isset($claim['FileDate'])) ? $claim['FileDate'] : $dte;
156 $dd_str .= ($ptn) ? text($ptn) . "&nbsp; " : "";
157 $dd_str .= ($dte) ? " &nbsp;" . text(substr($dte, 0, 4)) . "-" . text(substr($dte, 4, 2)) . "-" . text(substr($dte, 6, 2)) : "";
158 if (strpos('|f277|f276|f270|f271|f278', $ft)) {
159 $dd_str .= ($sts) ? " &nbsp;" . text($sts) : "";
160 $dd_str .= ($ins) ? " &nbsp;" . text($ins) : "";
161 $dd_str .= ($clm) ? " &nbsp;" . text($clm) : "";
162 $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(CsrfUtils::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(CsrfUtils::collectCsrfToken()) . "'>T</a>&nbsp;" : "";
163 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($pid) . "</a>" : "";
164 $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(CsrfUtils::collectCsrfToken()) . "'><em>trace</em></a>" : "";
165 } elseif ($ft == 'f835') {
166 $dd_str .= ($clm) ? " &nbsp;<em>Claim ID</em> $ins" : "";
167 $dd_str .= ($ins) ? " &nbsp;<em>InsLevel</em> $ins" : "";
168 $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(CsrfUtils::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(CsrfUtils::collectCsrfToken()) . "'>T</a>" : "";
169 } elseif ($ft == 'f997') {
170 $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(CsrfUtils::collectCsrfToken()) . "'><em>trace</em></a>" : "";
171 $dd_str .= ($err) ? " &nbsp;" . text(substr($err, 0, 8)) : "";
172 } else {
173 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($pid) . "</a>" : "";
176 $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(CsrfUtils::collectCsrfToken()) . "'><em>file</em></a>" : "";
178 $clm_html .= "<dd class='" . attr($oe) . "'>$dd_str</dd>" . PHP_EOL;
184 if ($err_only) {
185 if ($errct) {
186 $str_html .= $clm_html;
188 } else {
189 $str_html .= $clm_html;
191 } // end foreach ($data_ar as $icn=>$csvdata)
193 return $str_html;
197 * make a list of brief information and links to claims where a problem
198 * has been identified.
200 * @uses csv_file_type()
201 * @uses edih_997_error()
202 * @uses csv_denied_by_file()
204 * @param string
205 * @param string
206 * @param string
208 * @return string
210 function edih_list_denied_claims($filetype, $filename, $trace = '')
213 $str_html = '';
214 $row_ar = array();
216 $ft = csv_file_type($filetype);
217 if ($ft == 'f997') {
218 $str_html = edih_997_error($filename);
219 return $str_html;
220 } elseif (strpos('|f271|f277|f835', $ft)) {
221 $row_ar = csv_denied_by_file($ft, $filename, $trace);
222 } else {
223 $str_html .= "Invalid file type " . text($filetype) . " for denied claim search<br />";
224 csv_edihist_log("edih_list_denied_claims: wrong filetype $filetype");
225 return $str_html;
229 if (count($row_ar)) {
230 $rw_ct = count($row_ar);
231 $rwct = 0;
232 $str_html .= "<h4>Denied/Rejected Claims Listing</h4>" . PHP_EOL;
233 $str_html .= "<dl class ='" . attr($ft) . "'>" . text($rw_ct) . " claims <em>File</em>" . text($filename) . " ";
234 $str_html .= ($trace) ? "<em>Trace</em> $trace</dl>" . PHP_EOL : "" . PHP_EOL;
235 if ($ft == 'f835') {
236 foreach ($row_ar as $row) {
237 $oe = ( $rwct % 2 ) ? 'codd' : 'ceven';
238 $rwct++;
239 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($row[2]) . "</a></dt>" . PHP_EOL;
241 } elseif ($ft == 'f277') {
242 foreach ($row_ar as $row) {
243 $oe = ( $rwct % 2 ) ? 'codd' : 'ceven';
244 $rwct++;
245 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($row[4]) . "</a></dt>" . PHP_EOL;
247 } elseif ($ft == 'f271') {
248 foreach ($row_ar as $row) {
249 $oe = ( $rwct % 2 ) ? 'codd' : 'ceven';
250 $rwct++;
251 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($row[4]) . "</a></dt>" . PHP_EOL;
253 } elseif ($ft == 'f997') {
254 foreach ($row_ar as $row) {
255 $oe = ( $rwct % 2 ) ? 'codd' : 'ceven';
256 $rwct++;
257 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($row[2]) . "</a></dt>" . PHP_EOL;
262 $str_html .= "</dl>" . PHP_EOL;
263 } else {
264 $str_html .= "Search returned no data rows from file " . text($filename) . "<br />";
265 csv_edihist_log("edih_list_denied_claims: no rows returned $filetype $filename $trace");
269 return $str_html;
274 * check the csv claims tables and return rows for a particular encounter
276 * @uses csv_pid_enctr_parse()
277 * @uses csv_file_with_pid_enctr()
278 * @uses csv_table_select_list()
279 * @uses csv_search_record()
281 * @param string encounter number
283 * @return string
285 function edih_claim_history($encounter)
288 if ($encounter) {
289 $e = (string)$encounter;
290 } else {
291 return 'invalid encounter value ' . text($encounter) . '<br />' . PHP_EOL;
294 // use function csv_table_select_list() so that only
295 // existing csv tables are queried
296 $tbl2 = csv_table_select_list('array');
298 $rtypes = array();
299 if (is_array($tbl2['claims']) && count($tbl2['claims'])) {
300 $rtypes = array_keys($tbl2['claims']);
301 } else {
302 csv_edihist_log("csv_claim_history: failed to get csv table names");
303 return "failed to get csv table names";
307 $ch_html = "<table class='clmhist' columns=4><caption>Encounter Record for " . text($e) . "</caption>";
308 $ch_html .= "<tbody>" . PHP_EOL;
310 if (in_array('f837', $rtypes)) {
311 $tp = 'f837';
312 $btar = csv_file_by_enctr($e, $tp);
314 if (is_array($btar) && count($btar)) {
315 $ch_html .= "<tr class='ch837'><td colspan=4>837 Claim " . text(count($btar)) . "</td></tr>" . PHP_EOL;
316 $ch_html .= "<tr class='chhead'>" . PHP_EOL;
317 $ch_html .= "<td>Name</td><td>SvcDate</td><td>CLM01</td><td>File</td>" . PHP_EOL;
318 $ch_html .= "</tr>" . PHP_EOL;
319 foreach ($btar as $ch) {
320 $dt = substr($ch['SvcDate'], 0, 4) . '-' . substr($ch['SvcDate'], 4, 2) . '-' . substr($ch['SvcDate'], 6, 2);
321 //array('PtName', 'SvcDate', 'CLM01', 'InsLevel', 'Control', 'FileName', 'Fee', 'PtPaid', 'Provider' );
322 $ch_html .= "<tr class='ch837'>" . PHP_EOL;
324 $ch_html .= "<td>" . text($ch['PtName']) . "</td>" . PHP_EOL;
325 $ch_html .= "<td>" . text($dt) . "</td>" . PHP_EOL;
326 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($ch['CLM01']) . "</a></td>" . PHP_EOL;
327 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($ch['FileName']) . "</a></td>" . PHP_EOL;
329 $ch_html .= "</tr>" . PHP_EOL;
331 } else {
332 $ch_html .= "<tr class='ch837'>" . PHP_EOL;
333 $ch_html .= "<td colspan=4>837 Claim -- Nothing found for " . text($e) . "</td>" . PHP_EOL;
334 $ch_html .= "</tr>" . PHP_EOL;
339 if (in_array('f997', $rtypes)) {
340 $tp = 'f997';
341 $f997ar = csv_file_by_enctr($e, $tp);
343 if (is_array($f997ar) && count($f997ar)) {
344 $ch_html .= "<tr class='ch997'><td colspan=4>Ack 997/999 " . text(count($f997ar)) . "</td></tr>" . PHP_EOL;
345 $ch_html .= "<tr class='chhead'>" . PHP_EOL;
346 $ch_html .= "<td colspan=3>Acknowledgement File</td><td>Notes</td>" . PHP_EOL;
347 $ch_html .= "</tr>" . PHP_EOL;
348 foreach ($f997ar as $ch) {
350 $msg = strlen($ch[7]) ? $ch[7] : 'ST Number';
351 //array('PtName', 'RspDate', 'Trace', 'Status', 'Control', 'FileName', 'RspType', 'err_seg');;
352 $ch_html .= "<tr class='ch997'>";
353 $ch_html .= "<td>Rsp Ack</td>" . PHP_EOL;
354 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($ch['Status']) . "</a></td>" . PHP_EOL;
355 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($ch['FileName']) . "</a></td>" . PHP_EOL;
356 $ch_html .= "<td title='Response type/date'>" . text($ch['RspType']) . " " . text($ch['RspDate']) . "</td>" . PHP_EOL;
357 $ch_html .= "</tr>" . PHP_EOL;
359 } else {
360 $ch_html .= "<tr class='ch997'>";
361 $ch_html .= "<td colspan=4>Ack 997/999 -- Nothing found for " . text($e) . "</td>" . PHP_EOL;
362 $ch_html .= "</tr>" . PHP_EOL;
367 if (in_array('f277', $rtypes)) {
368 $tp = 'f277';
369 $f277ar = csv_file_by_enctr($e, $tp);
371 if (is_array($f277ar) && count($f277ar)) {
372 $ch_html .= "<tr class='ch277'><td colspan=4>Status 277 " . text(count($f277ar)) . "</td></tr>" . PHP_EOL;
373 $ch_html .= "<tr class='chhead'>" . PHP_EOL;
374 $ch_html .= "<td>Response</td><td>Status</td><td>File</td><td>ClaimID</td>" . PHP_EOL;
375 $ch_html .= "</tr>" . PHP_EOL;
376 foreach ($f277ar as $ch) {
377 //'f277':array('PtName', 'SvcDate', 'CLM01', 'Status', 'BHT03', 'FileName', 'Payer', 'Trace');
378 $ch_html .= "<tr class='ch277'>";
380 $ch_html .= "<td>Claim Status</td>" . PHP_EOL;
381 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($ch['Status']) . "</a></td>" . PHP_EOL;
382 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($ch['FileName']) . "</a></td>" . PHP_EOL;
383 $ch_html .= "<td title='Payer " . attr($ch['Payer']) . "'>" . text($ch['Trace']) . "</td>" . PHP_EOL;
385 $ch_html .= "</tr>" . PHP_EOL;
387 } else {
388 $ch_html .= "<tr class='ch277'>";
389 $ch_html .= "<td colspan=4>Status 277 -- Nothing found for " . text($e) . "</td>" . PHP_EOL;
390 $ch_html .= "</tr>" . PHP_EOL;
395 if (in_array('f835', $rtypes)) {
396 $tp = 'f835';
397 $f835ar = csv_file_by_enctr($e, $tp);
399 if (is_array($f835ar) && count($f835ar)) {
400 $ch_html .= "<tr class='ch835'><td colspan=4>Payment 835 " . text(count($f835ar)) . "</td></tr>" . PHP_EOL;
401 $ch_html .= "<tr class='chhead'>" . PHP_EOL;
402 $ch_html .= "<td>Response</td><td>Status</td><td>Trace</td><td>Payer</td>" . PHP_EOL;
403 $ch_html .= "</tr>" . PHP_EOL;
404 foreach ($f835ar as $ch) {
406 $msg = $ch['ClaimID'] . ' ' . $ch['Pmt'] . ' ' . $ch['PtResp'];
407 // array('PtName', 'SvcDate', 'CLM01', 'Status', 'Trace', 'FileName', 'ClaimID', 'Pmt', 'PtResp', 'Payer');
408 $ch_html .= "<tr class='ch835'>";
410 $ch_html .= "<td>" . text($ch['PtName']) . "</td>" . PHP_EOL;
411 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($ch['Status']) . "</a></td>" . PHP_EOL;
412 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($ch['Trace']) . "</a></td>" . PHP_EOL;
413 $ch_html .= "<td title='" . attr($msg) . "'>" . text($ch['Payer']) . "</td>" . PHP_EOL;
415 $ch_html .= "</tr>" . PHP_EOL;
417 } else {
418 $ch_html .= "<tr class='ch835'>";
419 $ch_html .= "<td colspan=4>Payment 835 -- Nothing found for " . text($e) . "</td>" . PHP_EOL;
420 $ch_html .= "</tr>" . PHP_EOL;
424 } // end if($tp ...
425 // -- this is where a query on the payments datatable could be used to show if payment
426 // has been received, even if no era file shows the payment.
428 $ch_html .= "</tbody>" . PHP_EOL;
429 $ch_html .= "</table>" . PHP_EOL;
431 return $ch_html;
436 * Render one of our csv record files as an html table
438 * This function determines the actual csv file from the file_type and the
439 * csv_type. Tthe date field of each row is checked against the optional
440 * lookback period or date parameters.
442 * @uses csv_file_type()
443 * @uses csv_parameters()
444 * @uses csv_thead_html()
446 * @param string $file_type -- see function csv_file_type()
447 * @param string $csv_type -- either "file" or "claim"
448 * @param string $period -- lookback 2 weeks, 1 month, ALL, etc
449 * @param string $datestart -- from date CCYY-MM-DD
450 * @param string $dateend -- to date CCYY-MM-DD
452 * @return string
454 function edih_csv_to_html($file_type, $csv_type, $period = '', $datestart = '', $dateend = '')
457 $csv_html = "";
458 $modstr = '';
459 $csv_d = array();
460 // debug
461 csv_edihist_log("edih_csv_to_html: period $period datestart $datestart dateend $dateend");
463 $is_date = false;
464 $is_period = false;
466 if ($file_type && $csv_type) {
467 $csv_ar = csv_assoc_array($file_type, $csv_type);
468 if (is_array($csv_ar) && count($csv_ar)) {
469 $rwct = count($csv_ar);
470 } else {
471 csv_edihist_log("edih_csv_to_html: error opening csv file $file_type $csv_type");
472 $csv_html .= "error opening csv file " . text($file_type) . " " . text($csv_type) . "<br />";
473 return false;
475 } else {
476 $csv_html .= "invalid arguments for opening csv table<br />";
477 return false;
480 $tp = csv_file_type($file_type);
481 if ($tp) {
482 $params = csv_parameters($tp);
483 } else {
484 csv_edihist_log("csv_to_html error: incorrect file type $file_type");
485 $csv_html .= "csv_to_html error: incorrect file type " . text($file_type) . " <br />" . PHP_EOL;
486 return false;
489 // csv tables date is in col 0 for file, col 5 for claim
490 // file name is under FileName for all tables
491 $dtcol = (strpos($csv_type, "aim")) ? $params['claimdate'] : $params['filedate'];
492 $tp_lbl = (strpos($csv_type, "aim")) ? 'Claims' : 'Files';
494 // given dates shold be in CCYY-MM-DD or CCYY/MM/DD format
495 // edih_view.php is supposed to use CCYY-MM-DD
496 $dts = $dt4 = $dte = '';
497 if (preg_match('/(19|20)\d{2}\D[01][0-9]\D[0-3][0-9]/', $datestart)) {
498 $dts = implode('', preg_split("/\D/", $datestart));
499 if ($dateend && preg_match('/(19|20)\d{2}\D[01][0-9]\D[0-3][0-9]/', $dateend)) {
500 $dte = implode('', preg_split("/\D/", $dateend));
501 } else {
502 $dt4 = date_create(date('Y-m-d'));
503 $dte = date_format($dt4, 'Ymd');
506 // php DateTime is poorly documented
507 $is_date = ($dts && $dte);
508 // debug
509 csv_edihist_log("edih_csv_to_html: dts $dts dte $dte isdate " . strval($is_date));
512 } elseif ($period) {
513 $dtstr1 = '';
514 $is_period = preg_match('/\d{1,2}(?=w|m|y)/', $period, $matches);
515 if (count($matches)) {
516 $pd = $matches[0];
517 $gtdt = getdate();
518 $mon = (string)$gtdt['mon'];
519 $day = (string)($gtdt['mday']); // - $gtdt['wday'] + 1); not sure why this was valuable
520 $yr = (string)$gtdt['year'];
521 if (strtoupper($period) == 'ALL') {
522 $is_period = false;
523 $modstr = '';
524 } elseif (strpos($period, 'w')) {
525 // take the first character of 'period'
526 $modstr = '-' . $pd . ' week';
527 $dtstr1 = $mon . '/' . $day . '/' . $yr;
528 } elseif (strpos($period, 'm')) {
529 $modstr = '-' . $pd . ' month';
530 $dtstr1 = $mon . '/01/' . $yr;
531 } elseif (strpos($period, 'y')) {
532 $modstr = '-' . $pd . ' year';
533 $dtstr1 = $mon . '/01/' . $yr;
534 } else {
535 csv_edihist_log("csv_to_html error: incorrect date period $period");
536 return false;
541 // debug
542 csv_edihist_log("edih_csv_to_html: period $period modstr $modstr dtstr1 $dtstr1");
544 if ($is_period && $modstr) {
545 $dtpd1 = date_create($dtstr1);
546 $dtm = date_modify($dtpd1, $modstr);
547 $dtpd2 = $dtm->format('Ymd');
548 $dtpdlbl = $dtm->format('Y-m-d');
549 } else {
550 $dtpd2 = '';
551 $dtpdlbl = 'All Dates';
556 if ($is_date) {
557 $isok = false;
558 $idx = 0;
559 foreach ($csv_ar as $data) {
560 $isok = (strcmp($data[$dtcol], $dts) >= 0) ? true : false;
561 $isok = (strcmp($data[$dtcol], $dte) > 0) ? false : $isok;
563 if ($isok) {
564 $csv_d[] = $data;
567 } elseif ($is_period) {
568 foreach ($csv_ar as $data) {
569 if (strcmp($data[$dtcol], $dtpd2) > 0) {
570 $csv_d[] = $data;
573 } else {
574 $csv_d = &$csv_ar;
578 $ln_ct = count($csv_d);
580 if ($is_date) {
581 //$csv_html .= "<div id='dttl'>".PHP_EOL;
582 $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;
583 //$csv_html .= "</div>".PHP_EOL;
584 } elseif ($is_period) {
585 //div id='dttl'></div>
586 $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;
587 } else {
588 //<div id='dttl'></div>
589 $csv_html .= "<h4>Table: " . text($tp_lbl) . " &nbsp;" . text($tp) . " &nbsp;All Dates Rows: " . text($rwct) . " &nbsp; Shown: " . text($ln_ct) . "</h4>" . PHP_EOL;
593 //$csv_html .= "<table id='csvTable' class='csvDisplay'>".PHP_EOL; class='display'max-width: fit-content
594 $csv_html .= "<table id='csvTable' style='width: fit-content; float: left'>" . PHP_EOL;
595 $csv_html .= csv_thead_html($tp, $csv_type);
596 $csv_html .= "<tbody>" . PHP_EOL;
598 // now create the body of the table
600 $cls = (strpos('|f837|f270|f276|f278', $tp)) ? 'sub' : 'rsp';
602 $idx = 0;
603 if ($csv_type == 'file') {
605 if ($tp == 'f835') {
606 //array('Date', 'FileName', 'Control', 'Trace', 'Claim_ct', 'Denied', 'Payer')
607 foreach ($csv_d as $val) {
608 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
609 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
610 foreach ($val as $k => $v) {
611 if ($k == 'Date') {
612 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
613 } elseif ($k == 'FileName') {
614 $fn = $v;
615 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
616 } elseif ($k == 'Control') {
617 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
618 } elseif ($k == 'Trace') {
619 $trc = $v;
620 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
621 } elseif ($k == 'Claim_ct') {
622 $csv_html .= "<td>" . text($v) . " <a class='sub' href='edih_main.php?tracecheck=" . attr_url($trc) . "&ckprocessed=yes&csrf_token_form=" . attr_url(CsrfUtils::collectCsrfToken()) . "'><em>P?</em></a></td>" . PHP_EOL;
623 } elseif ($k == 'Denied') {
624 if ((int)$v > 0) {
625 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
626 } else {
627 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
629 } else {
630 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
634 $csv_html .= "</tr>" . PHP_EOL;
635 $idx++;
637 } elseif ($tp == 'f997') {
638 //array('Date', 'FileName', 'Control', 'Trace', 'RspType', 'RejCt')
639 foreach ($csv_d as $val) {
640 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
641 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
643 $rsp = $val['RspType'];
644 foreach ($val as $k => $v) {
645 if ($k == 'Date') {
646 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
647 } elseif ($k == 'FileName') {
648 $fn = $v;
649 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
650 } elseif ($k == 'Trace') {
651 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
652 } elseif ($k == 'RejCt') {
653 if ((int)$v > 0) {
654 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
655 } else {
656 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
658 } else {
659 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
663 $csv_html .= "</tr>" . PHP_EOL;
664 $idx++;
668 } else {
669 // the generic case -- for 'file' type tables
670 foreach ($csv_d as $val) {
671 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
672 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
673 foreach ($val as $k => $v) {
674 if ($k == 'Date') {
675 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
676 } elseif ($k == 'FileName') {
677 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
678 } elseif ($k == 'Control') {
679 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
680 } elseif ($k == 'Reject') {
681 if ((int)$v > 0) {
682 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
683 } else {
684 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
686 } else {
687 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
691 $csv_html .= "</tr>" . PHP_EOL;
692 $idx++;
695 } elseif ($csv_type == 'claim') {
697 if ($tp == 'f837') {
698 // array('PtName', 'SvcDate', 'CLM01', 'InsLevel', 'Control', 'FileName', 'Fee', 'PtPaid', 'Provider' );
699 foreach ($csv_d as $val) {
700 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
701 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
702 // needed values for links
703 $fn = $val['FileName'];
704 foreach ($val as $k => $v) {
705 if ($k == 'CLM01') {
706 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
707 } elseif ($k == 'SvcDate') {
708 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
709 } elseif ($k == 'FileName') {
710 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
711 } else {
712 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
716 $csv_html .= "</tr>" . PHP_EOL;
717 $idx++;
719 } elseif ($tp == 'f835') {
720 // array('PtName', 'SvcDate', 'CLM01', 'Status', 'Trace', 'FileName', 'ClaimID', 'Pmt', 'PtResp', 'Payer')
721 foreach ($csv_d as $val) {
722 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
723 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
724 // needed values for links
725 $fn = $val['FileName'];
726 $pid = $val['CLM01'];
727 foreach ($val as $k => $v) {
728 if ($k == 'SvcDate') {
729 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
730 } elseif ($k == 'CLM01') {
731 $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(CsrfUtils::collectCsrfToken()) . "'>H</a>&nbsp;";
732 $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(CsrfUtils::collectCsrfToken()) . "'>T</a></td>" . PHP_EOL;
733 } elseif ($k == 'Trace') {
734 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
735 } elseif ($k == 'FileName') {
736 $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(CsrfUtils::collectCsrfToken()) . "'>H</a>&nbsp;";
737 $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(CsrfUtils::collectCsrfToken()) . "'>T</a></td>" . PHP_EOL;
738 } else {
739 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
743 $csv_html .= "</tr>" . PHP_EOL;
744 $idx++;
746 } elseif ($tp == 'f277') {
747 // array('PtName', 'SvcDate', 'CLM01', 'Status', 'BHT03', 'FileName', 'Payer', 'Ins_ID', 'Trace');
748 foreach ($csv_d as $val) {
749 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
750 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
751 // needed values for links
752 $fn = $val['FileName'];
753 $bht03 = $val['BHT03'];
754 $trc = $val['CLM01'];
755 foreach ($val as $k => $v) {
756 if ($k == 'SvcDate') {
757 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
758 } elseif ($k == 'CLM01') {
759 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
760 } elseif ($k == 'BHT03') {
761 $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(CsrfUtils::collectCsrfToken()) . "'>H</a>&nbsp;";
762 $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(CsrfUtils::collectCsrfToken()) . "'>T</a></td>" . PHP_EOL;
763 } elseif ($k == 'FileName') {
764 $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(CsrfUtils::collectCsrfToken()) . "'>H</a>&nbsp;";
765 $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(CsrfUtils::collectCsrfToken()) . "'>T</a></td>" . PHP_EOL;
766 } else {
767 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
771 $csv_html .= "</tr>" . PHP_EOL;
772 $idx++;
774 } elseif ($tp == 'f276') {
775 // array('PtName', 'ReqDate', 'CLM01', 'InsBnft', 'BHT03', 'FileName', 'Payer', 'Trace');
776 foreach ($csv_d as $val) {
777 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
778 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
779 // needed values for links
780 $fn = $val['FileName'];
781 $bht03 = $val['BHT03'];
782 $trc = $val['CLM01'];
783 foreach ($val as $k => $v) {
784 if ($k == 'ReqDate') {
785 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
786 } elseif ($k == 'CLM01') {
787 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
788 } elseif ($k == 'BHT03') {
789 $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(CsrfUtils::collectCsrfToken()) . "'>H</a>&nbsp;";
790 $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(CsrfUtils::collectCsrfToken()) . "'>T</a></td>" . PHP_EOL;
791 } elseif ($k == 'FileName') {
792 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
793 } else {
794 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
798 $csv_html .= "</tr>" . PHP_EOL;
799 $idx++;
801 } elseif ($tp == 'f270') {
802 // array('PtName', 'ReqDate', 'Trace', 'InsBnft', 'BHT03', 'FileName', 'Payer');
803 foreach ($csv_d as $val) {
804 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
805 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
806 // needed values for links
807 $fn = $val['FileName'];
808 $bht03 = $val['BHT03'];
809 foreach ($val as $k => $v) {
810 if ($k == 'ReqDate') {
811 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
812 } elseif ($k == 'BHT03') {
813 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
814 } elseif ($k == 'FileName') {
815 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
816 } else {
817 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
821 $csv_html .= "</tr>" . PHP_EOL;
822 $idx++;
824 } elseif ($tp == 'f271') {
825 // array('PtName', 'RspDate', 'Trace', 'Status', 'BHT03', 'FileName', 'Payer');
826 foreach ($csv_d as $val) {
827 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
828 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
829 // needed values for links
830 $fn = $val['FileName'];
831 $bht03 = $val['BHT03'];
832 foreach ($val as $k => $v) {
833 if ($k == 'RspDate') {
834 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
835 } elseif ($k == 'BHT03') {
836 $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(CsrfUtils::collectCsrfToken()) . "'>H</a>&nbsp;" . PHP_EOL;
837 $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(CsrfUtils::collectCsrfToken()) . "'>T</a></td>" . PHP_EOL;
838 } elseif ($k == 'FileName') {
839 $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(CsrfUtils::collectCsrfToken()) . "'>H</a>&nbsp;";
840 $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(CsrfUtils::collectCsrfToken()) . "'>T</a></td>" . PHP_EOL;
841 } else {
842 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
846 $csv_html .= "</tr>" . PHP_EOL;
847 $idx++;
849 } elseif ($tp == 'f278') {
850 // array('PtName', 'FileDate', 'Trace', 'Status', 'BHT03', 'FileName', 'Auth', 'Payer')
851 foreach ($csv_d as $val) {
852 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
853 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
854 // needed values for links
855 $fn = $val['FileName'];
856 $bht03 = $val['BHT03'];
857 foreach ($val as $k => $v) {
858 if ($k == 'FileDate') {
859 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
860 } elseif ($k == 'BHT03') {
861 $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(CsrfUtils::collectCsrfToken()) . "'>H</a>&nbsp;" . PHP_EOL;
862 $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(CsrfUtils::collectCsrfToken()) . "'>T</a></td>" . PHP_EOL;
863 } elseif ($k == 'FileName') {
864 $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(CsrfUtils::collectCsrfToken()) . "'>H</a>&nbsp;";
865 $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(CsrfUtils::collectCsrfToken()) . "'>T</a></td>" . PHP_EOL;
866 } else {
867 $csv_html .= "<td>$v</td>" . PHP_EOL;
871 $csv_html .= "</tr>" . PHP_EOL;
872 $idx++;
874 } elseif ($tp == 'f997') {
875 // array('PtName', 'RspDate', 'Trace', 'Status', 'Control', 'FileName', 'RspType', 'err_seg');
876 foreach ($csv_d as $val) {
877 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
878 $csv_html .= "<tr class='$bgc'>" . PHP_EOL;
879 // needed values for links
880 $fn = $val['FileName'];
881 $rsp = $val['RspType'];
882 $err = $val['err_seg'];
883 foreach ($val as $k => $v) {
884 if ($k == 'RspDate') {
885 $csv_html .= "<td>" . text(substr($v, 0, 4)) . '-' . text(substr($v, 4, 2)) . '-' . text(substr($v, 6, 2)) . "</td>" . PHP_EOL;
886 } elseif ($k == 'FileName') {
887 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
888 } elseif ($k == 'Trace') {
889 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
890 } elseif ($k == 'err_seg') {
891 $csv_html .= "<td title='" . attr($v) . "'>" . text(substr($v, 0, 8)) . "...</td>" . PHP_EOL;
892 } else {
893 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
897 $csv_html .= "</tr>" . PHP_EOL;
898 $idx++;
900 } else {
901 // all types in the tables are covered in an elseif, so this is unexpected
902 foreach ($csv_d as $val) {
903 $bgc = ($idx % 2 == 1 ) ? 'odd' : 'even';
904 $csv_html .= "<tr class='" . attr($bgc) . "'>" . PHP_EOL;
905 foreach ($val as $k => $v) {
906 if ($k == 'FileName') {
907 $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(CsrfUtils::collectCsrfToken()) . "'>" . text($v) . "</a></td>" . PHP_EOL;
908 } else {
909 $csv_html .= "<td>" . text($v) . "</td>" . PHP_EOL;
913 $csv_html .= "</tr>" . PHP_EOL;
914 $idx++;
917 } // end body of the table
918 //$csv_html .= "</tbody>".PHP_EOL."</table>".PHP_EOL."</div>".PHP_EOL;
919 $csv_html .= "</tbody>" . PHP_EOL . "</table>" . PHP_EOL;
921 return $csv_html;