3 * new_edih_835_html.php
5 * Copyright 2016 Kevin McCormick <kevin@kt61p>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 //require_once("$srcdir/edihistory/codes/edih_835_code_class.php");
28 //require_once("$srcdir/edihistory/codes/edih_271_code_class.php");
31 * callback to round floats to 2 digit precision
37 function edih_round_cb(&$v, $k)
42 * Create summary html string for an x12 835 claim payment
52 function edih_835_clp_summary($trans_array, $codes27x, $codes835, $delimiters, $fname = '')
56 if (is_array($trans_array) && count($trans_array)) {
57 if (csv_singlerecord_test($trans_array)) {
59 $clp_ar[] = $trans_array;
61 $clp_ar = $trans_array;
64 csv_edihist_log("edih_835_transaction_html: Did not get transaction segments");
65 $str_html .= "<p>Did not get transaction segments</p>".PHP_EOL
;
69 $de = (isset($delimiters['e'])) ?
$delimiters['e'] : "";
70 $ds = (isset($delimiters['s'])) ?
$delimiters['s'] : "";
71 $dr = (isset($delimiters['r'])) ?
$delimiters['r'] : "";
74 csv_edihist_log("edih_835_transaction_html: Did not get delimiters");
75 $str_html .= "<p>Did not get delimiters</p>".PHP_EOL
;
80 $fn = ($fname) ?
trim($fname) : "";
82 // get the code objects right
84 if ('edih_835_codes' == get_class($codes835)) {
86 } elseif ('edih_835_codes' == get_class($codes27x)) {
90 if ('edih_271_codes' == get_class($codes27x)) {
92 } elseif ('edih_271_codes' == get_class($codes835)) {
96 if (!$cd835 ||
!$cd27x) {
97 csv_edihist_log('edih_835_payment_html: invalid code class argument');
98 $str_html .= "<p>invalid code class argument</p>".PHP_EOL
;
107 $hdr_html = "<tr><th>Reference</th><th colspan=2>Information</th><th colspan=2>" . text($fn) . "</th></tr>".PHP_EOL
;
108 $hdr_html .= "</thead>".PHP_EOL
."<tbody>".PHP_EOL
;
112 $chksegs = array('CLP', 'NM1', 'AMT', 'QTY');
113 foreach ($trans_array as $trans) {
114 $capstr = "Summary ";
116 foreach ($trans as $seg) {
118 $test_str = substr($seg, 0, 3);
119 if ($test_str == 'SVC') {
123 if (!in_array($test_str, $chksegs, true)) {
128 if (strncmp('CLP'.$de, $seg, 4) === 0) {
129 $sar = explode($de, $seg);
133 $clp09ar = array('1'=>'Original', '7'=>'Replacement', '8'=>'Void');
135 $clp01 = $clp02 = $clp03 = $clp04 = $clp05 = $clp06 = $clp07 = '';
136 $clp08 = $clp09 = $clp11 = $clp12 = $clp13 = $capstr = $tblid = '';
137 foreach ($sar as $k => $v) {
145 break; // Pt ID CLM01
147 $clp02 = $cd835->get_835_code('CLAIM_STATUS', $v);
150 $clp03 = ($v) ?
"<em>Fee:</em> " . text(edih_format_money($v)) : "0";
153 $clp04 = ($v) ?
"<em>Pmt:</em> " . text(edih_format_money($v)) : "0";
156 $clp05 = ($v) ?
"<em>PtRsp:</em> " . text(edih_format_money($v)) : "0";
159 $clp07 = ($v) ?
"<em>PR Ref:</em> " . text($v) : "";
162 $clp08 = ($v) ?
"<em>Location</em> " . text($cd27x->get_271_code('POS', $v)) : '';
165 $clp09 = ($v && isset($clp09ar[$v])) ?
"<em>Freq</em> " . text($clp09ar[$v]) : text($v);
170 $clp_html .= "<tr class='" . attr($cls) . "'><td><em>PtID:</em> " . text($clp01) . "</td><td colspan=3><em>Status</em> " . text($clp02) . " <em>" . text($clp06) . "</em></td></tr>".PHP_EOL
;
171 $clp_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>$clp03 $clp04 $clp05 $clp07 </td></tr>".PHP_EOL
;
172 $clp_html .= ($clp08 ||
$clp09) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>$clp08 $clp09</td></tr>".PHP_EOL
: "";
178 if ($loopid == '2100') {
179 if (strncmp('AMT'.$de, $seg, 4) === 0) {
180 // Payment information
181 $sar = explode($de, $seg);
183 $amt01 = (isset($sar[1]) && $sar[1]) ?
$cd835->get_835_code('AMT', $sar[1]) : "";
184 $amt02 = (isset($sar[2]) && $sar[2]) ?
edih_format_money($sar[2]) : "";
186 $clp_html .= ($amt01) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($amt01 . " " . $amt02) . "</td></tr>".PHP_EOL
: "";
192 if (strncmp('QTY'.$de, $seg, 4) === 0) {
193 // Payment information
194 $sar = explode($de, $seg);
196 $qty01 = (isset($sar[1]) && $sar[1]) ?
$cd835->get_835_code('AMT', $sar[1]) : "";
197 $qty02 = (isset($sar[2]) && $sar[2]) ?
edih_format_money($sar[2]) : "";
199 if ($loopid == '2100') {
200 $clp_html .= ($qty01) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($qty01 . " " . $qty02) . "</td></tr>".PHP_EOL
: "";
207 if (strncmp('NM1'.$de, $seg, 4) === 0) {
208 $sar = explode($de, $seg);
210 $descr = (isset($sar[1]) && $sar[1]) ?
$cd27x->get_271_code('NM101', $sar[1]) : "";
212 $name = (isset($sar[3]) && $sar[3]) ?
$sar[3] : "";
213 $name .= (isset($sar[7]) && $sar[7]) ?
" {$sar[7]}" : "";
214 $name .= (isset($sar[4]) && $sar[4]) ?
", {$sar[4]}" : "";
215 $name .= (isset($sar[5]) && $sar[5]) ?
" {$sar[5]}" : "";
216 $name .= (isset($sar[7]) && $sar[7]) ?
" {$sar[7]}" : "";
218 $nm108 = (isset($sar[8]) && $sar[8]) ?
$cd27x->get_271_code('NM108', $sar[8]) : "";
219 $nm109 = (isset($sar[9]) && $sar[9]) ?
$sar[9] : "";
220 // complete table caption
221 if (isset($sar[1]) && $sar[1] == "QC") {
227 $sbr_html .= "<tr class='sbr'><td><em>" . text($descr) . "</em></td><td colspan=3>" . text($name) . " <em>" . text($nm108) . "</em> " . text($nm109) . "</td></tr>" .PHP_EOL
;
229 $sbr_html .= "<tr class='sbr'><td><em>" . text($descr) . "</em></td><td colspan=3>" . text($name) . " </td></tr>" .PHP_EOL
;
233 $descr = $name = $nm108 = $nm109 = '';
237 if (strncmp('CAS'.$de, $seg, 4) === 0) {
238 $sar = explode($de, $seg);
240 // claim adjustment group; expect CAS segment for each adjustment group
241 foreach ($sar as $k => $v) {
246 $cas_str .= "$v ".$cd835->get_835_code('CAS_GROUP', $v);
249 $cas_str .= ($v) ?
" $v" : "";
252 $cas_str .= ($v) ?
" ".edih_format_money($v) : "";
255 $cas_str .= ($v) ?
"x$v" : "";
258 $cas_str .= ($v) ?
" $v" : "";
261 $cas_str .= ($v) ?
" ".edih_format_money($v) : "";
264 $cas_str .= ($v) ?
"x$v" : "";
267 $cas_str .= ($v) ?
" $v" : "";
270 $cas_str .= ($v) ?
" ".edih_format_money($v) : "";
273 $cas_str .= ($v) ?
"x$v" : "";
280 $clp_html .= ($cas_str) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($cas_str) . "</td></tr>".PHP_EOL
: "";
288 $str_html .= "<table name='" . attr($tblid) . "' class='h835c' columns=4><caption>" . text($capstr) . "</caption>".PHP_EOL
."<thead>".PHP_EOL
;
289 $str_html .= $hdr_html;
290 $str_html .= $sbr_html;
291 $str_html .= $clp_html;
292 $str_html .= "</tbody>".PHP_EOL
."</table>".PHP_EOL
;
302 * Create html string for an x12 835 claim payment
312 function edih_835_transaction_html($trans_array, $codes27x, $codes835, $delimiters, $fname = '')
316 if (is_array($trans_array) && count($trans_array)) {
317 if (csv_singlerecord_test($trans_array)) {
319 $clp_ar[] = $trans_array;
321 $clp_ar = $trans_array;
324 csv_edihist_log("edih_835_transaction_html: Did not get transaction segments");
325 $str_html .= "<p>Did not get transaction segments</p>".PHP_EOL
;
329 $de = (isset($delimiters['e'])) ?
$delimiters['e'] : "";
330 $ds = (isset($delimiters['s'])) ?
$delimiters['s'] : "";
331 $dr = (isset($delimiters['r'])) ?
$delimiters['r'] : "";
334 csv_edihist_log("edih_835_transaction_html: Did not get delimiters");
335 $str_html .= "<p>Did not get delimiters</p>".PHP_EOL
;
340 $fn = ($fname) ?
trim($fname) : "";
342 // get the code objects right
343 $cd835 = $cd27x = '';
344 if ('edih_835_codes' == get_class($codes835)) {
346 } elseif ('edih_835_codes' == get_class($codes27x)) {
350 if ('edih_271_codes' == get_class($codes27x)) {
352 } elseif ('edih_271_codes' == get_class($codes835)) {
356 if (!$cd835 ||
!$cd27x) {
357 csv_edihist_log('edih_835_payment_html: invalid code class argument');
358 $str_html .= "<p>invalid code class argument</p>".PHP_EOL
;
369 $hdr_html = "<tr><th>Reference</th><th colspan=3>Information " . text($fn) . "</th></tr>".PHP_EOL
;
370 $hdr_html .= "</thead>".PHP_EOL
."<tbody>".PHP_EOL
;
376 foreach ($clp_ar as $trans) {
385 foreach ($trans as $seg) {
387 if (strncmp('REF'.$de, $seg, 4) === 0) {
388 $sar = explode($de, $seg);
390 if (isset($sar[1]) && $sar[1]) {
391 if ($sar[1] == 'LU') {
393 $ref02 = (isset($sar[2])) ?
$cd27x->get_271_code('POS', $sar[2]) : '';
396 $ref01 = (isset($sar[1])) ?
$cd27x->get_271_code('REF', $sar[1]) : '';
398 $ref02 = (isset($sar[2])) ?
$sar[2] : '';
402 if ($loopid == '2100') {
403 $clp_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>" . text($ref01) . "</em> " . text($ref02) . "</td></tr>".PHP_EOL
;
404 } elseif ($loopid == '2110') {
405 $svc_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>" . text($ref01) . "</em> " . text($ref02) . "</td></tr>".PHP_EOL
;
414 if (strncmp('DTM'.$de, $seg, 4) === 0) {
415 $sar = explode($de, $seg);
416 // DTM in 835 use DTP codes from 271 codes
417 $dtm01 = (isset($sar[1])) ?
$cd27x->get_271_code('DTP', $sar[1]) : ''; // date qualifier
418 $dtm02 = (isset($sar[2])) ?
edih_format_date($sar[2]) : ''; // production date
419 $dtm05 = (isset($sar[5])) ?
$sar[5] : '';
420 $dtm06 = (isset($sar[6])) ?
edih_format_date($sar[2]) : '';
422 //if ( $elem02 == 'D8' && $elem03) {
423 //$dtmar = edih_format_date($elem03);
424 //} elseif ( $elem02 == 'RD8' && $elem03) {
425 //$dtmar = edih_format_date( substr($elem03, 0, 8) );
426 //$dtmar .= ' - '.edih_format_date( substr($elem03, -8) );
429 if ($loopid == '2100') {
430 $clp_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>" . text($dtm01) . "</em> " . text($dtm02) . "</td></tr>".PHP_EOL
;
431 } elseif ($loopid == '2110') {
432 $svc_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>" . text($dtm01) . "</em> " . text($dtm02) . "</td></tr>".PHP_EOL
;
440 if (strncmp('PER'.$de, $seg, 4) === 0) {
441 $sar = explode($de, $seg);
443 $per01_ar = array('CX'=>'Claims Dept','BL'=>'Technical Dept','IC'=>'Website');
444 $per01 = $per02 = $per03 = $per04 = $per05 = $per06 = $per07 = $per08 = '';
445 foreach ($sar as $k => $v) {
450 $per01 = (isset($per01_ar[$v])) ?
$per01_ar[$v] : $v;
459 $per04 = ($per03=='TE') ?
edih_format_telephone($v) : $v;
465 $per06 = ($per03=='TE') ?
edih_format_telephone($v) : $v;
471 $per08 = ($per03=='TE') ?
edih_format_telephone($v) : $v;
476 if ($loopid == '2100') {
477 $clp_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($per01 . " " . $per02 . " " . $per03 . " " . $per04) . " </td></tr>".PHP_EOL
;
478 $clp_html .= ($per05 ||
$per07) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($per05 . " " . $per06 . " " . $per07 . " " . $per08) . "</td></tr>".PHP_EOL
: "";
486 if (strncmp('CLP'.$de, $seg, 4) === 0) {
487 $sar = explode($de, $seg);
491 $clp01 = $clp02 = $clp03 = $clp04 = $clp05 = $clp06 = $clp07 = $clp08 = $clp09 = $clp11 = $clp12 = $clp13 = $capstr = '';
493 $clp01 = (isset($sar[1]) && $sar[1]) ?
$sar[1] : ''; // Pt ID CLM01
494 $clp02 = (isset($sar[2]) && $sar[2]) ?
$cd835->get_835_code('CLAIM_STATUS', $sar[2]) : ''; // status code
495 $clp03 = (isset($sar[3]) && $sar[3]) ?
edih_format_money($sar[3]) : '0'; // fee amont
496 $clp04 = (isset($sar[4]) && $sar[4]) ?
edih_format_money($sar[4]) : '0'; // paid amount
497 $clp05 = (isset($sar[5]) && $sar[5]) ?
edih_format_money($sar[5]) : '0'; // pt responsibility amont
498 $clp06 = (isset($sar[6]) && $sar[6]) ?
$cd835->get_835_code('CLP06', $sar[6]) : ''; // filing indicator code
499 $clp07 = (isset($sar[7]) && $sar[7]) ?
$sar[7] : ''; // Payer reference ID
500 $clp08 = (isset($sar[8]) && $sar[8]) ?
"<em>Location</em> " . text($cd27x->get_271_code('POS', $sar[8])) : ''; // Faciliy code place of service
501 // frequency type code 1 original 7 replacement 8 void
502 $clp09ar = array('1'=>'original', '7'=>'replacement', '8'=>'void');
503 if (isset($sar[9]) && array_key_exists($sar[9], $clp09ar)) { // claim frequency code
504 $clp09 = "<em>Freq</em> " . text($clp09ar[$sar[9]]);
506 $clp09 = (isset($sar[9]) && $sar[9]) ?
"<em>Freq</em> " . text($sar[9]) : "";
509 // DRG code not expected
510 $clp11 = (isset($sar[11]) && $sar[11]) ?
"<em>DRG Code</em> " . text($sar[11]) : '';
512 $clp12 = (isset($sar[12]) && $sar[12]) ?
"<em>DRG Weight</em> " . text($sar[12]) : '';
514 $clp13 = (isset($sar[13]) && $sar[13]) ?
"<em>Dischg Frctn</em> " . text(edih_format_percent($sar[13])) : '';
516 // table caption PtID PtName
520 $clp_html .= "<tr class='" . attr($cls) . "'><td><em>Pt ID</em> " . text($clp01) . "</td><td colspan=3><em>Status</em> " . text($clp02) . " <em>" . text($clp06) . "</em></td></tr>".PHP_EOL
;
521 $clp_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>Fee</em> " . text($clp03) . " <em>Pmt</em> " . text($clp04) . " <em>PtRsp</em> " . text($clp05) . " <em>PR Ref</em> " . text($clp07) . " </td></tr>".PHP_EOL
;
522 $clp_html .= ($clp08 ||
$clp09) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>$clp08 $clp09</td></tr>".PHP_EOL
: "";
523 $clp_html .= ($clp11 ||
$clp12 ||
$clp13) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>$clp11 $clp12 $clp13</td></tr>".PHP_EOL
: "";
529 if (strncmp('CAS'.$de, $seg, 4) === 0) {
530 $sar = explode($de, $seg);
532 $cls = ($loopid == '2100') ?
'clp' : 'svc';
533 // claim adjustment group; expect CAS segment for each adjustment group
534 if (isset($sar[1]) && $sar[1]) {
535 $cas_ar[$loopid][$sar[1]] = array_chunk(array_slice($sar, 2), 3);
537 //echo '== array_chunk'.PHP_EOL;
538 //var_dump( $cas_ar ).PHP_EOL;
547 if (strncmp('NM1'.$de, $seg, 4) === 0) {
548 $sar = explode($de, $seg);
551 if (isset($sar[1]) && $sar[1]) {
552 if (strpos('|IL|QC|72', $sar[1])) {
558 $descr = $cd27x->get_271_code('NM101', $sar[1]);
565 $name = (isset($sar[3]) && $sar[3]) ?
$sar[3] : "";
566 $name .= (isset($sar[7]) && $sar[7]) ?
" {$sar[7]}" : "";
567 $name .= (isset($sar[4]) && $sar[4]) ?
", {$sar[4]}" : "";
568 $name .= (isset($sar[5]) && $sar[5]) ?
" {$sar[5]}" : "";
569 $name .= (isset($sar[6]) && $sar[6]) ?
" {$sar[6]}" : "";
571 $nm108 = (isset($sar[8]) && $sar[8]) ?
$cd27x->get_271_code('NM108', $sar[8]) : "";
572 $nm109 = (isset($sar[9]) && $sar[9]) ?
$sar[9] : "";
573 // complete table caption
574 if (isset($sar[1]) && $sar[1] == "QC") {
581 $nm1_str .= "<tr class='" . attr($cls) . "'><td><em>" . text($descr) . "</em></td><td colspan=3>" . text($name) . " <em>" . text($nm108) . "</em> " . text($nm109) . "</td></tr>" .PHP_EOL
;
583 $nm1_str .= "<tr class='" . attr($cls) . "'><td><em>" . text($descr) . "</em></td><td colspan=3>" . text($name) . " </td></tr>" .PHP_EOL
;
586 if ($loopid == '2100') {
587 $clp_html .= $nm1_str;
588 } elseif ($loopid == '2110') {
589 $svc_html .= $nm1_str;
593 $descr = $name = $nm108 = $nm109 = '';
598 if (strncmp('MIA'.$de, $seg, 4) === 0) {
599 // Inpatient Adjudication information
600 $sar = explode($de, $seg);
601 // <tr class='mia'><td>></td><td> </td></tr>".PHP_EOL;
602 $tr1 = "<tr class='mia'><td>></td><td colspan=3>";
603 $tr2 = "</td></tr>".PHP_EOL
;
605 $mia_str .= (isset($sar[1]) && $sar[1]) ?
$tr1."Covered Days or Visits: " . text($sar[1]) . $tr2 : ""; // days or visits
606 $mia_str .= (isset($sar[2]) && $sar[2]) ?
$tr1."PPS Operating Outlier Amt: " . text(edih_format_money($sar[2])) . $tr2 : "";
607 $mia_str .= (isset($sar[3]) && $sar[3]) ?
$tr1."Lifetime Psychiatric Days: " . text($sar[3]) . $tr2 : "";
608 $mia_str .= (isset($sar[4]) && $sar[4]) ?
$tr1."Claim DRG Amt: " . text(edih_format_money($sar[4])) . $tr2 : "";
609 $mia_str .= (isset($sar[5]) && $sar[5]) ?
"<tr class='mia'><td>" . text($sar[5]) . "</td><td colspan=3>" . text($cd835->get_835_code('RARC', $sar[5])) . $tr2 : "";
610 $mia_str .= (isset($sar[6]) && $sar[6]) ?
$tr1."Claim DSH Amt: " . text(edih_format_money($sar[6])) . $tr2 : "";
611 $mia_str .= (isset($sar[7]) && $sar[7]) ?
$tr1."Claim MSP Pass Thru Amt: " . text(edih_format_money($sar[7])) . $tr2 : "";
612 $mia_str .= (isset($sar[8]) && $sar[8]) ?
$tr1."Claim PPS Capital Amt: " . text(edih_format_money($sar[8])) . $tr2 : "";
613 $mia_str .= (isset($sar[9]) && $sar[9]) ?
$tr1."PPS Capital FSP DRG Amt: " . text(edih_format_money($sar[9])) . $tr2 : "";
614 $mia_str .= (isset($sar[10]) && $sar[10]) ?
$tr1."PPS Capital HSP DRG Amt: " . text(edih_format_money($sar[10])) . $tr2 : "";
615 $mia_str .= (isset($sar[11]) && $sar[11]) ?
$tr1."PPS Capital DSH DRG Amt: " . text(edih_format_money($sar[11])) . $tr2 : "";
616 $mia_str .= (isset($sar[12]) && $sar[12]) ?
$tr1."Old Capital Amt: " . text(edih_format_money($sar[12])) . $tr2 : "";
617 $mia_str .= (isset($sar[13]) && $sar[13]) ?
$tr1."PPS Capital Ind Med Edu Amt: " . text(edih_format_money($sar[13])) . $tr2 : "";
618 $mia_str .= (isset($sar[14]) && $sar[14]) ?
$tr1."PPS Oper HSP Spec DRG Amt: " . text(edih_format_money($sar[14])) . $tr2 : "";
619 $mia_str .= (isset($sar[15]) && $sar[15]) ?
$tr1."Cost Report Day Count: " . text($sar[15]) . $tr2 : "";
620 $mia_str .= (isset($sar[16]) && $sar[16]) ?
$tr1."PPS Oper FSP Spec DRG Amt: " . text(edih_format_money($sar[16])) . $tr2 : "";
621 $mia_str .= (isset($sar[17]) && $sar[17]) ?
$tr1."Claim PPS Outlier Amt: " . text(edih_format_money($sar[17])) . $tr2 : "";
622 $mia_str .= (isset($sar[18]) && $sar[18]) ?
$tr1."Claim Indirect Teaching: " . text(edih_format_money($sar[18])) . $tr2 : "";
623 $mia_str .= (isset($sar[19]) && $sar[19]) ?
$tr1."Non Pay Prof Component Amt: " . text(edih_format_money($sar[19])) . $tr2 : "";
624 $mia_str .= (isset($sar[20]) && $sar[20]) ?
"<tr class='mia'><td>" . text($sar[20]) . "</td><td colspan=3>" . text($cd835->get_835_code('RARC', $sar[20])) . $tr2 : "";
625 $mia_str .= (isset($sar[21]) && $sar[21]) ?
"<tr class='mia'><td>" . text($sar[21]) . "</td><td colspan=3>" . text($cd835->get_835_code('RARC', $sar[21])) . $tr2 : "";
626 $mia_str .= (isset($sar[22]) && $sar[22]) ?
"<tr class='mia'><td>" . text($sar[22]) . "</td><td colspan=3>" . text($cd835->get_835_code('RARC', $sar[22])) . $tr2 : "";
632 if (strncmp('MOA'.$de, $seg, 4) === 0) {
633 // Inpatient Adjudication information
634 $sar = explode($de, $seg);
636 $moa_str = 'Claim Level Remarks: ';
637 foreach ($sar as $k => $v) {
642 $moa_str .= ($v) ?
'Reimbursement Rate: '.edih_format_percent($v) : '';
645 $moa_str .= ($v) ?
'Allowed Amt: '.edih_format_money($v) : '';
648 $moa_str .= ($v) ?
'ESRD Amt: '.edih_format_money($v) : '';
651 $moa_str .= ($v) ?
'Non-Pay Prof Cmpnt: '.edih_format_money($v) : '';
654 // case 3, 4, 5, 6, 7 are remark codes
655 $moa_str .= ($v) ?
' '.$v : '';
656 $moa_ar[] = ($v) ?
$v : '';
661 $clp_html .= ($moa_str) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($moa_str) . "</td></tr>".PHP_EOL
: "";
667 if (strncmp('AMT'.$de, $seg, 4) === 0) {
668 // Payment information
669 $sar = explode($de, $seg);
671 $amt01 = (isset($sar[1]) && $sar[1]) ?
$cd835->get_835_code('AMT', $sar[1]) : "";
672 $amt02 = (isset($sar[2]) && $sar[2]) ?
edih_format_money($sar[2]) : "";
674 if ($loopid == '2100') {
675 $clp_html .= ($amt01) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($amt01 . " " . $amt02) . "</td></tr>".PHP_EOL
: "";
676 } elseif ($loopid == '2110') {
677 $svc_html .= ($amt01) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($amt01 . " " . $amt02) . "</td></tr>".PHP_EOL
: "";
685 if (strncmp('QTY'.$de, $seg, 4) === 0) {
686 // Payment information
687 $sar = explode($de, $seg);
689 $qty01 = (isset($sar[1]) && $sar[1]) ?
$cd835->get_835_code('AMT', $sar[1]) : "";
690 $qty02 = (isset($sar[2]) && $sar[2]) ?
edih_format_money($sar[2]) : "";
692 if ($loopid == '2100') {
693 $clp_html .= ($qty01) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($qty01 . " " . $qty02) . "</td></tr>".PHP_EOL
: "";
694 } elseif ($loopid == '2110') {
695 $svc_html .= ($qty01) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($qty01 . " " . $qty02) . "</td></tr>".PHP_EOL
: "";
703 if (strncmp('SVC'.$de, $seg, 4) === 0) {
705 $sar = explode($de, $seg);
708 $rarc_str = ''; // used in LQ segment stanza
709 // composite procedure code source:code:modifier:modifier
711 if (isset($sar[1]) && $sar[1]) {
712 // construct a code source code modifier string
713 if (strpos($sar[1], $ds)) {
714 $scda = explode($ds, $sar[1]);
716 while (list($key, $val) = each($scda)) {
717 if ($key == 0 && $val) {
718 $svc01 = $cd27x->get_271_code('EB13', $val);
729 $svc02 = (isset($sar[2]) && $sar[2]) ?
edih_format_money($sar[2]) : ""; // billed amount
730 $svc03 = (isset($sar[3]) && $sar[3]) ?
edih_format_money($sar[3]) : ""; // paid amount
731 $svc04 = (isset($sar[4]) && $sar[4]) ?
"<em>NUBC</em> ".$sar[4] : ""; // NUBC revenue code
732 $svc05 = (isset($sar[5]) && $sar[5]) ?
"<em>Units</em> ".$sar[5] : ""; // quantity
735 if (isset($sar[6]) && $sar[6]) {
736 // construct a code source code modifier string
737 if (strpos($sar[6], $ds)) {
738 $scda = explode($ds, $sar[6]);
740 while (list($key, $val) = each($scda)) {
741 if ($key == 0 && $val) {
742 $svc06 = $cd27x->get_271_code('EB13', $val)." ";
752 $svc07 = (isset($sar[7]) && $sar[7]) ?
$sar[7] : ""; // original unis of service
754 $svc_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>Service</em> " . text($svc01) . " <em>Fee</em> " . text($svc02) . " <em>Pmt</em> " . text($svc03 . " " . $svc05 . " " . $svc04) . "</td></tr>".PHP_EOL
;
755 $svc_html .= ($svc06) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>Submitted Svc</em> " . text($svc06) . " <em>Units</em> " . text($svc07) . "</td></tr>".PHP_EOL
: "";
761 if (strncmp('LQ'.$de, $seg, 3) === 0) {
762 $sar = explode($de, $seg);
763 // Health Care Remark Codes
764 $lq01 = (isset($sar[1]) && $sar[1]) ?
$sar[1] : "";
765 if (isset($sar[2])) {
766 $lq02 = ($lq01 == 'HE') ?
$sar[2] : "";
767 //$lq02 = $cd835->get_835_code('RARC', $sar[2]);
768 $rarc_str .= ($rarc_str) ?
' '.$sar[2] : '<em>Service Remarks</em> ' . text($sar[2]);
774 //$lq02 = (isset($sar[2]) && $sar[2] && $lq01 == 'HE') ? $cd835->get_835_code('RARC', $sar[2]) : "";
776 // $svc_html .= ($rarc_str) ? "<tr class='$cls'><td>></td><td colspan=3>$rarc_str</td></tr>".PHP_EOL : "";
782 } // end foreach trans as seg
783 // assemble the html table at end of the inside foreach loop
785 $str_html .= "<table name='" . attr($tblid) . "' class='h835c' columns=4><caption>" . text($capstr) . "</caption>".PHP_EOL
."<thead>".PHP_EOL
;
786 $str_html .= $hdr_html;
787 $str_html .= $sbr_html;
788 $str_html .= $clp_html;
789 $str_html .= ($mia_str) ?
$mia_str : '';
790 $str_html .= $svc_html;
791 $str_html .= ($rarc_str) ?
"<tr class='svc'><td>></td><td colspan=3>$rarc_str</td></tr>".PHP_EOL
: "";
792 if (count($cas_ar)) {
793 foreach ($cas_ar as $key => $cas) {
794 if (!is_array($cas) && !count($cas)) {
798 if ($key == '2100' && count($cas)) {
800 $str_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>Claim Level Adjustments</em></td></tr>".PHP_EOL
;
803 $str_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>Service Level Adjustments</em></td></tr>".PHP_EOL
;
807 foreach ($cas as $ky => $trp) {
808 //echo '==== cas_ar unwind cas as ky trp '.$ky.PHP_EOL;
809 //var_dump ($trp).PHP_EOL;
811 if (!is_array($trp) && !count($trp)) {
815 $cg = $cd835->get_835_code('CAS_GROUP', $ky);
816 foreach ($trp as $tr) {
818 //echo '==== cas_ar unwind trp as tr '.PHP_EOL;
819 //var_dump ($tr).PHP_EOL;
821 $cd = $cr = $ca = $cq = '';
822 foreach ($tr as $k => $c) {
823 //echo '==== cas_ar unwind tr as k c '.$k.PHP_EOL;
824 //var_dump ($c).PHP_EOL;
829 $cr = $cd835->get_835_code('CARC', $c);
832 $ca = ($c) ?
edih_format_money($c) : "";
835 $cq = ($c) ?
$c : "";
841 $str_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($ky . " " . $cg . " " . $cd . " " . $ca . " " . $cq) . "</td></tr>".PHP_EOL
;
842 $str_html .= "<tr class='" . attr($cls) . "'><td style='text-align: center;'>" . text($ky . " " . $cd) . "</td><td colspan=3>" . text($cr) . "</td></tr>".PHP_EOL
;
847 if (count($moa_ar)) {
849 $str_html .= "<tr class='" . attr($cls) . "'><td colspan=4><em>Remarks</em></td></tr>".PHP_EOL
;
850 foreach ($moa_ar as $moa) {
851 $moar = $cd835->get_835_code('RARC', $moa);
852 $str_html .= "<tr class='" . attr($cls) . "'><td style='text-align: center;'>" . text($moa) . "</td><td colspan=3>" . text($moar) . "</td></tr>".PHP_EOL
;
858 $str_html .= ($rarc_str) ?
"<tr class='" . attr($cls) . "'><td colspan=4>$rarc_str</td></tr>".PHP_EOL
: "";
859 foreach ($lq_ar as $lq) {
860 $lqr = $cd835->get_835_code('RARC', $lq);
861 $str_html .= "<tr class='" . attr($cls) . "'><td style='text-align: center;'>$lq</td><td colspan=3>" . text($lqr) . "</td></tr>".PHP_EOL
;
866 $str_html .= "<tr class='remc'><td colspan=4> </td></tr>".PHP_EOL
;
867 // end tags for table
868 $str_html .= "</tbody>".PHP_EOL
."</table>".PHP_EOL
;
878 * Create an HTML rendition of the 835 check payment transaction.
887 * @return string HTML table
889 function edih_835_payment_html($segments, $codes27x, $codes835, $delimiters, $fname = '')
894 if (is_array($segments) && count($segments)) {
895 $trans_ar = $segments;
897 csv_edihist_log("edih_835_payment_html: invalid segments argument");
898 $str_html .= "<p>invalid segments argument</p>".PHP_EOL
;
902 if (is_array($delimiters) && count($delimiters)) {
903 $de = $delimiters['e'];
904 $ds = $delimiters['s'];
905 $dr = $delimiters['r'];
907 csv_edihist_log("edih_835_payment_html: invalid delimiters argument");
908 $str_html .= "<p>invalid delimiters argument</p>".PHP_EOL
;
913 $fn = ($fname) ?
trim($fname) : "";
915 // get the code objects right
916 $cd835 = $cd27x = '';
917 if ('edih_835_codes' == get_class($codes835)) {
919 } elseif ('edih_835_codes' == get_class($codes27x)) {
923 if ('edih_271_codes' == get_class($codes27x)) {
925 } elseif ('edih_271_codes' == get_class($codes835)) {
929 if (!$cd835 ||
!$cd27x) {
930 csv_edihist_log('edih_835_payment_html: invalid code class argument');
931 $str_html .= "<p>invalid code class argument</p>".PHP_EOL
;
936 // collect all strings into this variable
939 $hdr_html = "<thead>".PHP_EOL
;
940 $hdr_html .= "<tr><th>Reference</th><th colspan=2>Information</th><th colspan=2>" . text($fn) . "</th></tr>".PHP_EOL
;
941 $hdr_html .= "</thead>".PHP_EOL
."<tbody>".PHP_EOL
;
949 $acctng = array('pmt'=>0,'fee'=>0,'clmpmt'=>0,'clmadj'=>0, 'ptrsp'=>0, 'svcptrsp'=>0, 'svcfee'=>0,'svcadj'=>0,'plbadj'=>0);
951 foreach ($trans_ar as $trans) {
958 $capstr = "Remittance ";
961 foreach ($trans as $seg) {
963 if (strncmp('ST'.$de, $seg, 3) === 0) {
969 if (strncmp('BPR'.$de, $seg, 4) === 0) {
973 $acctng = array('pmt'=>0, 'fee'=>0, 'clmpmt'=>0, 'clmadj'=>0, 'ptrsp'=>0,
974 'svcptrsp'=>0, 'svcfee'=>0, 'svcpmt'=>0, 'svcadj'=>0, 'plbadj'=>0);
976 $sar = explode($de, $seg);
977 $bpr01 = (isset($sar[1]) && $sar[1]) ?
$cd835->get_835_code('BPR01', $sar[1]) : ''; // handling code
978 $bpr02 = (isset($sar[2]) && $sar[2]) ?
edih_format_money($sar[2]) : ''; // full payment amount
979 $bpr03 = (isset($sar[3]) && $sar[3] == 'D' ) ?
'Debit' : 'Credit'; // credit or debit flag
980 $bpr04 = (isset($sar[4]) && $sar[4]) ?
$sar[4] : ''; // payment method ACH|CHK|NON
981 $bpr05 = (isset($sar[5]) && $sar[5]) ?
$sar[5] : ''; // payment format code CCP|CTX
982 $bpr06 = (isset($sar[6]) && $sar[6]) ?
$sar[6] : ''; // DFI ID qualifier
983 $bpr07 = (isset($sar[7]) && $sar[7]) ?
$sar[7] : ''; // bank ID
984 $bpr08 = (isset($sar[8]) && $sar[8]) ?
$sar[8] : ''; // account no. qualifier DA
985 $bpr09 = (isset($sar[9]) && $sar[9]) ?
$sar[9] : ''; // sender account number
986 $bpr10 = (isset($sar[10]) && $sar[10]) ?
$sar[10] : ''; // originating company ID
987 $bpr11 = (isset($sar[11]) && $sar[11]) ?
$sar[11] : ''; // originating company supplemental ID
988 $bpr12 = (isset($sar[12]) && $sar[12]) ?
$sar[12] : ''; // deposit acount ID
989 $bpr13 = (isset($sar[13]) && $sar[13]) ?
$sar[13] : ''; // deposit bank ID
990 $bpr14 = (isset($sar[14]) && $sar[14]) ?
$sar[14] : ''; // account type DA deposit SG savings
991 $bpr15 = (isset($sar[15]) && $sar[15]) ?
$sar[15] : ''; // account number
992 $bpr16 = (isset($sar[16]) && $sar[16]) ?
edih_format_date($sar[16]) : ''; // check or payment date
994 if ($bpr04 == 'NON') {
995 $pmt_html .= "<tr class='" . attr($cls) . "'><td>" . text($bpr16) . "</td><td>" . text($bpr03 . " " . $bpr04) . "</td><td colspan=2>Non Payment</td></tr>".PHP_EOL
;
997 $pmt_html .= "<tr class='" . attr($cls) . "'><td>" . text($bpr16) . "</td><td>" . text($bpr03 . " " . $bpr04) . "</td><td colspan=2>" . text($bpr02) . " to " . text($bpr13 . " " . $bpr12 . " " . $bpr14) . "</td></tr>".PHP_EOL
;
1000 if (strpos('|ACH|BOP|FWT', $bpr04)) {
1001 $pmt_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($bpr05) . " from: " . text($bpr07 . " " . $bpr09 . " " . $bpr10) . "</td></tr>".PHP_EOL
;
1004 $pmt_html .= ($bpr11) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>Pmt No.</em> " . text($bpr11 . " " . $bpr01) . "</td></tr>".PHP_EOL
: "";
1005 $acctng['pmt'] =(isset($sar[2]) && $sar[2]) ?
(float)$sar[2] : "";
1011 if (strncmp('TRN'.$de, $seg, 4) === 0) {
1012 $sar = explode($de, $seg);
1014 $trn01 = (isset($sar[1]) && $sar[1]) ?
$sar[1] : ''; // trace type code
1015 $trn02 = (isset($sar[2]) && $sar[2]) ?
$sar[2] : ''; // trace number (= BPR11)
1016 $trn03 = (isset($sar[3]) && $sar[3]) ?
$sar[3] : ''; // originator ID
1017 $trn04 = (isset($sar[4]) && $sar[4]) ?
$sar[4] : ''; // originator supplemental ID
1018 if ($trn03[0] == '1') {
1019 $trn03 = substr($trn03, 1);
1020 } // originator ID is '1' prepended to EIN or TIN
1021 // the html ID for the table
1022 $tblid = ($trn02) ?
$trn02 : "";
1023 $capstr .= ($trn02) ?
"Check No: ".$trn02 : "Payment Listing";
1025 $pmt_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>Trace</em> " . text($trn02) . " <em>by</em> " . text($trn03 . " " . $trn04) . "</td></tr>".PHP_EOL
;
1031 if (strncmp('CUR'.$de, $seg, 4) === 0) {
1032 $sar = explode($de, $seg);
1034 $cur01 = (isset($sar[1])) ?
$sar[1] : ''; // entity ID code
1035 $cur02 = (isset($sar[2])) ?
$sar[2] : ''; // currency code
1037 $pmt_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>Trace</em> " . text($cur02) . " by " . text($cur03 . " " . $cur04) . "</td></tr>".PHP_EOL
;
1043 if (strncmp('REF'.$de, $seg, 4) === 0) {
1044 $sar = explode($de, $seg);
1046 $ref01 = (isset($sar[1])) ?
$cd27x->get_271_code('REF', $sar[1]) : ''; // entity ID code
1047 $ref02 = (isset($sar[2])) ?
$sar[2] : ''; // entity ID
1049 if ($loopid == 'header') {
1050 // should not be present for payee receiver
1051 $pmt_html .= "<tr class='" . text($cls) . "'><td>></td><td colspan=3><em>" . text($ref01) . "</em> " . text($ref02) . "</td></tr>".PHP_EOL
;
1052 } elseif ($loopid == '1000A') {
1054 $src_html .="<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>" . text($ref01) . "</em> " . text($ref02) . "</td></tr>".PHP_EOL
;
1055 } elseif ($loopid == '1000B') {
1057 $rcv_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>" . text($ref01) . "</em> " . text($ref02) . "</td></tr>".PHP_EOL
;
1058 } elseif ($loopid == '2100') {
1061 } elseif ($loopid == '2110') {
1070 if (strncmp('DTM'.$de, $seg, 4) === 0) {
1071 $sar = explode($de, $seg);
1072 // DTM in 835 use DTP codes from 271 codes
1073 $dtm01 = (isset($sar[1])) ?
$cd27x->get_271_code('DTP', $sar[1]) : ''; // date qualifier
1074 $dtm02 = (isset($sar[2])) ?
edih_format_date($sar[2]) : ''; // production date
1075 $dtm05 = (isset($sar[5])) ?
$sar[5] : '';
1076 $dtm06 = (isset($sar[6])) ?
edih_format_date($sar[2]) : '';
1078 //if ( $elem02 == 'D8' && $elem03) {
1079 //$dtmar = edih_format_date($elem03);
1080 //} elseif ( $elem02 == 'RD8' && $elem03) {
1081 //$dtmar = edih_format_date( substr($elem03, 0, 8) );
1082 //$dtmar .= ' - '.edih_format_date( substr($elem03, -8) );
1086 if ($loopid == 'header') {
1087 // should not be present for payee or receiver
1088 $pmt_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3><em>" . text($dtm01) . "</em> " . text($dtm02) . "</td></tr>".PHP_EOL
;
1089 } elseif ($loopid == '2100') {
1091 } elseif ($loopid == '2110') {
1100 if (strncmp('N1'.$de, $seg, 3) === 0) {
1101 $sar = explode($de, $seg);
1103 $n101 = (isset($sar[1])) ?
$cd27x->get_271_code('NM101', $sar[1]) : ''; // entity ID code
1104 $n102 = (isset($sar[2])) ?
$sar[2] : ''; // name
1105 $n103 = (isset($sar[3])) ?
$cd27x->get_271_code('NM108', $sar[3]) : ''; // entity ID type code
1106 $n104 = (isset($sar[4])) ?
$sar[4] : '';
1108 if ($loopid == 'header') {
1111 $src_html .= "<tr class='" . attr($cls) . "'><td><em>" . text($n101) . "</em></td><td colspan=3>" . text($n102) . " <em>" . text($n103) . "</em> " . text($n104) . "</td></tr>".PHP_EOL
;
1112 } elseif ($loopid == '1000A') {
1115 $rcv_html .= "<tr class='" . attr() . "'><td><em>" . text($n101) . "</em></td><td colspan=3>" . text($n102) . " <em>" . text($n103) . "</em> " . text($n104) . "</td></tr>".PHP_EOL
;
1123 if (strncmp('N3'.$de, $seg, 3) === 0) {
1124 $sar = explode($de, $seg);
1126 $n301 = (isset($sar[1])) ?
$sar[1] : ''; // address
1127 $n302 = (isset($sar[2])) ?
$sar[2] : ''; // address line 2
1129 if ($loopid == '1000A') {
1130 $src_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($n301 . " " . $n302) . "</td></tr>".PHP_EOL
;
1131 } elseif ($loopid == '1000B') {
1132 $rcv_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($n301 . " " . $n302) . "</td></tr>".PHP_EOL
;
1140 if (strncmp('N4'.$de, $seg, 3) === 0) {
1141 $sar = explode($de, $seg);
1143 $n401 = (isset($sar[1])) ?
$sar[1] : ''; // city
1144 $n402 = (isset($sar[2])) ?
$sar[2] : ''; // state
1145 $n403 = (isset($sar[3])) ?
$sar[3] : ''; // Postal
1146 $n404 = (isset($sar[4])) ?
$sar[4] : ''; // Country
1147 $n407 = (isset($sar[7])) ?
$sar[7] : ''; // Country subdivision
1149 if ($loopid == '1000A') {
1150 $src_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($n401 . " " . $n402 . " " . $n403) . "</td></tr>".PHP_EOL
;
1151 $src_html .= ($n404 ||
$n407) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($n404 . " " . $n405) . "</td></tr>".PHP_EOL
: "";
1152 } elseif ($loopid == '1000B') {
1153 $rcv_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($n401 . " " . $n402 . " " . $n403) . "</td></tr>".PHP_EOL
;
1154 $rcv_html .= ($n404 ||
$n407) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($n404 . " " . $n405) . "</td></tr>".PHP_EOL
: "";
1162 if (strncmp('PER'.$de, $seg, 4) === 0) {
1163 if ($loopid == '2100' ||
$loopid == '2100') {
1169 $sar = explode($de, $seg);
1170 $per01_ar = array('CX'=>'Claims Dept','BL'=>'Technical Dept','IC'=>'Website');
1171 $per01 = $per02 = $per03 = $per04 = $per05 = $per06 = $per07 = $per08 = '';
1172 foreach ($sar as $k => $v) {
1177 $per01 = (isset($per01_ar[$v])) ?
$per01_ar[$v] : $v;
1186 $per04 = ($per03=='TE') ?
edih_format_telephone($v) : $v;
1192 $per06 = ($per03=='TE') ?
edih_format_telephone($v) : $v;
1198 $per08 = ($per03=='TE') ?
edih_format_telephone($v) : $v;
1203 if ($loopid == '1000A') {
1204 $src_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($per01 . " " . $per02 . " " . $per03 . " " . $per04) . " </td></tr>".PHP_EOL
;
1205 $src_html .= ($per05 ||
$per07) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($per05 . " " . $per06 . " " . $per07 . " " . $per08) . "</td></tr>".PHP_EOL
: "";
1206 } elseif ($loopid == '1000B') {
1207 $rcv_html .= "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($per01 . " " . $per02 . " " . $per03 . " " . $per04) . " </td></tr>".PHP_EOL
;
1208 $rcv_html .= ($per05 ||
$per07) ?
"<tr class='" . attr($cls) . "'><td>></td><td colspan=3>" . text($per05 . " " . $per06 . " " . $per07 . " " . $per08) . "</td></tr>".PHP_EOL
: "";
1216 if (strncmp('RDM'.$de, $seg, 4) === 0) {
1217 // remittance delivery method
1218 // loop 1000B -- add to pmt information
1219 $sar = explode($de, $seg);
1221 $rdm01 = (isset($sar[1])) ?
$sar[1] : '';
1222 if ($sar[1] == 'BM') {
1224 } elseif ($sar[1] == 'EM') {
1225 $rdm01 = 'By e-mail';
1226 } elseif ($sar[1] == 'FT') {
1227 $rdm01 = 'By file transfer';
1228 } elseif ($sar[1] == 'OL') {
1229 $rdm01 = 'By online';
1232 $rdm02 = (isset($sar[2])) ?
$sar[2] : ''; // name
1233 $rdm03 = (isset($sar[3])) ?
$sar[3] : ''; // number
1235 $pmt_html .= "<tr class='" . attr($cls) . "'><td>" . text($rdm01) . "</td><td colspan=3>" . text($rdm02 . " " . $rdm03) . "</td></tr>".PHP_EOL
;
1241 if (strncmp('LX'.$de, $seg, 3) === 0) {
1242 // LX can end loop 1000B or a claim grouping
1243 if ($loopid == '1000B') {
1244 // finish off pmt, src, and rcv
1245 $rcv_html .= "</tbody>".PHP_EOL
."</table>".PHP_EOL
;
1246 } elseif ($loopid == '2110') {
1247 if ($lxkey && array_key_exists($lxkey, $lx_ar)) {
1248 // LX claim grouping -- cannot predict detail
1249 // LX can follow loop 2110
1250 if (count($clpsegs)) {
1251 $clp_html .= edih_835_transaction_html($clpsegs, $codes27x, $codes835, $delimiters);
1255 $nlx_html = ($lx_html) ?
"<table name='lx_" . attr($lxkey) . "' class='h835c' columns=4>".PHP_EOL
."<tbody>".PHP_EOL
.$lx_html.PHP_EOL
: "";
1256 $lx_ar[$lxkey]['lx'] = $nlx_html;
1257 $lx_ar[$lxkey]['clp'] = $clp_html;
1264 $sar = explode($de, $seg);
1265 $lxkey = (isset($sar[1]) && $sar[1]) ?
$sar[1] : ''; // identify a grouping for claim info
1266 $lx_ar[$lxkey] = array();
1270 //$lx_ct = count($lx_ar);
1271 $lx_html .= ($lxkey) ?
"<tr class='" . attr($cls) . "'><td colspan=4><em>Claim Group</em> " . text($lxkey) . "</td></tr>".PHP_EOL
: "";
1276 if (strncmp('TS3'.$de, $seg, 4) === 0) {
1277 $sar = explode($de, $seg);
1278 // this looks like a medicare part A or hospital remittance segment
1279 // segment TS2 gives DRG totals -- not read in this sequence. If you need it, code it
1281 $ts301 = (isset($sar[1]) && $sar[1]) ?
$sar[1] : ''; // Provider ID
1282 $ts302 = (isset($sar[2]) && $sar[2]) ?
$cd27x->get_271_code('POS', $sar[2]) : ''; // Facility Code (place of service)
1283 $ts303 = (isset($sar[3]) && $sar[3]) ?
edih_format_date($sar[3]) : ''; // date - last day of provider fiscal year
1284 $ts304 = (isset($sar[4]) && $sar[4]) ?
$sar[4] : ''; // quantity
1285 $ts305 = (isset($sar[5]) && $sar[5]) ?
edih_format_money($sar[5]) : ''; // monetary amount
1287 $lx_html .= "<tr class='" . attr($cls) . "'><td><em>Prv</em> " . text($ts301) . "</td><td colspan=3>" . text($ts302) . " <em>Count</em> " . text($ts304) . " <em>Amount</em> " . text($ts305) . "</td></tr>".PHP_EOL
;
1290 $tr1 = "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>";
1291 $tr2 = "</td></tr>".PHP_EOL
;
1293 $lx_html .= (isset($sar[13]) && $sar[13]) ?
$tr1."Total MSP Payer Amt: " . text(edih_format_money($sar[13])) . $tr2.PHP_EOL
: "";
1294 $lx_html .= (isset($sar[15]) && $sar[15]) ?
$tr1."Total Non-Lab Chrg Amt: " . text(edih_format_money($sar[15])) . $tr2.PHP_EOL
: "";
1295 $lx_html .= (isset($sar[17]) && $sar[17]) ?
$tr1."Total HCPCS Rpt Chrg Amt: " . text(edih_format_money($sar[17])) . $tr2.PHP_EOL
: "";
1296 $lx_html .= (isset($sar[18]) && $sar[18]) ?
$tr1."Total HCPCS Payable Amt: " . text(edih_format_money($sar[18])) . $tr2.PHP_EOL
: "";
1297 $lx_html .= (isset($sar[20]) && $sar[20]) ?
$tr1."Total Prof Cmpnt Amt: " . text(edih_format_money($sar[20])) . $tr2.PHP_EOL
: "";
1298 $lx_html .= (isset($sar[21]) && $sar[21]) ?
$tr1."Total MSP Pt Liab Met Amt: " . text(edih_format_money($sar[21])) . $tr2.PHP_EOL
: "";
1299 $lx_html .= (isset($sar[22]) && $sar[22]) ?
$tr1."Total MSP Pt Reimb Amt: " . text(edih_format_money($sar[22])) . $tr2.PHP_EOL
: "";
1300 $lx_html .= (isset($sar[23]) && $sar[23]) ?
$tr1."Total PIP Claim Count: " . text($sar[23]) . $tr2.PHP_EOL
: "";
1301 $lx_html .= (isset($sar[24]) && $sar[24]) ?
$tr1."Total PIP Claim Count: " . text(edih_format_money($sar[24])) . $tr2.PHP_EOL
: "";
1307 if (strncmp('TS2'.$de, $seg, 4) === 0) {
1308 csv_edihist_log("edih_835_transaction_html: segment TS2 present in $fn");
1310 $tr1 = "<tr class='" . attr($cls) . "'><td>></td><td colspan=3>";
1311 $tr2 = "</td></tr>".PHP_EOL
;
1313 $lx_html .= (isset($sar[1]) && $sar[1]) ?
$tr1."Total DRG Amt: " . text(edih_format_money($sar[1])) . $tr2 : "";
1314 $lx_html .= (isset($sar[2]) && $sar[2]) ?
$tr1."Total Fed Specific Amt: " . text(edih_format_money($sar[2])) . $tr2 : "";
1315 $lx_html .= (isset($sar[3]) && $sar[3]) ?
$tr1."Total Hosp Specific Amt: " . text(edih_format_money($sar[3])) . $tr2 : "";
1316 $lx_html .= (isset($sar[4]) && $sar[4]) ?
$tr1."Total DSP Share Amt: " . text(edih_format_money($sar[4])) . $tr2 : "";
1317 $lx_html .= (isset($sar[5]) && $sar[5]) ?
$tr1."Total Capital Amt: " . text(edih_format_money($sar[5])) . $tr2 : "";
1318 $lx_html .= (isset($sar[6]) && $sar[6]) ?
$tr1."Total Ind Med Edu Amt: " . text(edih_format_money($sar[6])) . $tr2 : "";
1319 $lx_html .= (isset($sar[7]) && $sar[7]) ?
$tr1."Total Outlier Day Amt: " . text(edih_format_money($sar[7])) . $tr2 : "";
1320 $lx_html .= (isset($sar[8]) && $sar[8]) ?
$tr1."Total Day Outlier Day Amt: " . text(edih_format_money($sar[8])) . $tr2 : "";
1321 $lx_html .= (isset($sar[9]) && $sar[9]) ?
$tr1."Total Cost Outlier Day Amt: " . text(edih_format_money($sar[9])) . $tr2 : "";
1322 $lx_html .= (isset($sar[10]) && $sar[10]) ?
$tr1."Avg DRG Length of Stay: " . text($sar[10]) . $tr2 : "";
1323 $lx_html .= (isset($sar[11]) && $sar[11]) ?
$tr1."Total Discharge Count: " . text($sar[11]) . $tr2 : "";
1324 $lx_html .= (isset($sar[12]) && $sar[12]) ?
$tr1."Total Cost Rpt Day Count: " . text($sar[12]) . $tr2 : "";
1325 $lx_html .= (isset($sar[13]) && $sar[13]) ?
$tr1."Total Covered Day Count: " . text($sar[13]) . $tr2 : "";
1326 $lx_html .= (isset($sar[14]) && $sar[14]) ?
$tr1."Total Non Covered Day Count: " . text($sar[14]) . $tr2 : "";
1327 $lx_html .= (isset($sar[15]) && $sar[15]) ?
$tr1."Total MSP Pass-Thru Amt: " . text(edih_format_money($sar[15])) . $tr2 : "";
1328 $lx_html .= (isset($sar[16]) && $sar[16]) ?
$tr1."Avg DRG Weight: " . text($sar[16]) . $tr2 : "";
1329 $lx_html .= (isset($sar[17]) && $sar[17]) ?
$tr1."Total PPS Capital FSP DRG Amt: " . text(edih_format_money($sar[17])) . $tr2 : "";
1330 $lx_html .= (isset($sar[18]) && $sar[18]) ?
$tr1."Total PPS Capital FSP HSP Amt: " . text(edih_format_money($sar[18])) . $tr2 : "";
1331 $lx_html .= (isset($sar[19]) && $sar[19]) ?
$tr1."Total PPS DSH DRG Amt: " . text(edih_format_money($sar[19])) . $tr2 : "";
1336 if (strncmp('PLB'.$de, $seg, 4) === 0) {
1337 // can signal end of claim transaction
1338 $loopid = 'summary';
1340 //if (count($clpsegs)) {
1341 //$clp_html .= edih_835_transaction_html($clpsegs, $codes27x, $codes835, $delimiters);
1342 //$clpsegs = array();
1345 $sar = explode($de, $seg);
1346 // provider ID and fiscal year end date
1347 $plb01 = (isset($sar[1]) && $sar[1]) ?
$sar[1] : "";
1348 $plb02 = (isset($sar[2]) && $sar[2]) ?
edih_format_date($sar[2]) : "";
1350 $pmt_html .= "<tr class='" . attr($cls) . "'><td><em>Provider</em></td><td colspan=3>" . text($plb01 . " " . $plb02) . "</td></tr>".PHP_EOL
;
1352 $plbar = array_slice($sar, 2);
1353 $plbar = array_chunk($plbar, 2);
1354 // reason code and amount
1355 foreach ($plbar as $plb) {
1356 foreach ($plb as $k => $p) {
1357 // PLB 3, 5, 7, 9, 11, 13
1358 // composite element 'code:reference'
1360 if ($p && strpos($p, $ds)) {
1361 $plb_rc = substr($p, 0, strpos($p, $ds)); // code
1362 $plb_tr = substr($p, strpos($p, $ds)+
1); // reference (case #)?
1364 $plb_rc = ($p) ?
$p : "";
1368 $plb_rt = ($plb_rc) ?
$cd835->get_835_code('PLB', $plb_rc) : "";
1370 // PLB 4, 6, 8, 10, 12, 14
1372 $plb_amt = ($p) ?
edih_format_money($p) : "";
1373 $acctng['plbadj'] +
= ($p) ?
(float)$p : 0;
1377 $pmt_html .= "<tr class='" . attr($cls) . "'><td>" . text($plb_tr) . "</td><td colspan=3>" . text($plb_rc . " " . $plb_rt . " " . $plb_amt) . "</td></tr>".PHP_EOL
;
1385 if (strncmp('SE'.$de, $seg, 3) === 0) {
1386 // end of payment transaction, so create the html page
1389 // include our accounting totals
1390 if (is_array($acctng) && count($acctng)) {
1391 array_walk($acctng, 'edih_round_cb');
1392 $bal = ($acctng['fee'] == ($acctng['pmt'] +
$acctng['clmadj'] +
$acctng['svcadj'] +
$acctng['svcptrsp'] +
$acctng['plbadj']) ) ?
"Balanced" : "Not Balanced";
1393 $acct_str = text($bal) . ": <em>Fee</em> " . text($acctng['fee']) . " <em>Pmt</em> " . text($acctng['pmt']) . " ";
1394 $acct_str .= "<em>ClpAdj</em> " . text($acctng['clmadj']) . " <em>SvcAdj</em> " . text($acctng['svcadj']) . " ";
1395 $acct_str .= "<em>PtRsp</em> " . text($acctng['ptrsp']) . " (<em>svcPtRsp</em> " . text($acctng['svcptrsp']) . ") <em>PlbAdj</em> " . text($acctng['plbadj']) . " ";
1397 $pmt_html .= "<tr class='" . attr($cls) . "'><td colspan=4>$acct_str</td></tr>".PHP_EOL
;
1401 // create the html page
1402 $str_html .= "<table id=" . attr($tblid) . " class='h835' columns=4><caption>" . text($capstr) . "</caption>".PHP_EOL
;
1403 $str_html .= $hdr_html;
1405 $str_html .= $pmt_html;
1410 $str_html .= $src_html;
1415 $str_html .= $rcv_html;
1420 if (count($lx_ar)) {
1421 // claim segments are in lx array
1422 // make sure we have current collection
1423 if ($lxkey && array_key_exists($lxkey, $lx_ar)) {
1424 if (count($clpsegs)) {
1425 $clp_html .= edih_835_transaction_html($clpsegs, $codes27x, $codes835, $delimiters);
1429 // note: table ending in CLP if stanza
1430 $nlx_html = "<table name='lx_" . attr($lxkey) . "' class='h835c' columns=4>".PHP_EOL
."<tbody>".PHP_EOL
.$lx_html.PHP_EOL
;
1431 $lx_ar[$lxkey]['lx'] = $nlx_html;
1432 $lx_ar[$lxkey]['clp'] = $clp_html;
1438 // append segments to html
1439 foreach ($lx_ar as $key => $val) {
1440 $str_html .= $val['lx'];
1441 $str_html .= $val['clp'];
1443 } elseif ($lx_html) {
1444 $str_html .= $lx_html;
1449 if (count($clpsegs)) {
1450 // would be captured in LX and lx array
1451 $clp_html .= edih_835_transaction_html($clpsegs, $codes27x, $codes835, $delimiters);
1456 $str_html .= $clp_html;
1461 $str_html .= $trl_html;
1465 //$str_html .= "</tbody>".PHP_EOL."</table>".PHP_EOL;
1470 if (strncmp('CLP'.$de, $seg, 4) === 0) {
1471 if ($loopid == '1000B') {
1472 // end of 1000B (receiver) loop
1473 $rcv_html .= ($clp_ct) ?
"" : "</tbody>".PHP_EOL
."</table>".PHP_EOL
;
1474 } elseif ($loopid == '2000') {
1475 // end of LX header (LX TS3 TS2 claim grouping)
1476 $lx_html .= ($clp_ct) ?
"" : "</tbody>".PHP_EOL
."</table>".PHP_EOL
;
1480 //array('pmt'=>0, 'clmpmt'=>0, 'clmadj'=0, 'prvadj'=>0, 'ptrsp'=>0,'lx'=>array());
1481 $sar = explode($de, $seg);
1482 $acctng['fee'] +
= (isset($sar[3]) && $sar[3]) ?
(float)$sar[3] : 0;
1483 $acctng['clmpmt'] +
= (isset($sar[4]) && $sar[4]) ?
(float)$sar[4] : 0;
1484 $acctng['ptrsp'] +
= (isset($sar[5]) && $sar[5]) ?
(float)$sar[5] : 0;
1486 if (count($clpsegs)) {
1487 $clp_html .= edih_835_transaction_html($clpsegs, $codes27x, $codes835, $delimiters);
1496 if (strncmp('SVC'.$de, $seg, 4) === 0) {
1498 $sar = explode($de, $seg);
1500 foreach ($sar as $k => $v) {
1502 $svcfee = ($v) ?
(float)$v : 0;
1503 } elseif ($k == 3) {
1504 $svcpmt = ($v) ?
(float)$v : 0;
1505 } elseif ($k == 5) {
1506 $pmtm = ($v) ?
(int)$v : 1;
1507 } elseif ($k == 7) {
1508 $pmts = ($v) ?
(int)$v : 1;
1512 $acctng['svcfee'] +
= $svcfee * $pmts;
1513 $acctng['svcpmt'] +
= $svcpmt * $pmtm;
1519 if (strncmp('CAS'.$de, $seg, 4) === 0) {
1520 $sar = explode($de, $seg);
1522 $ctg = (isset($sar[1]) && $sar[1]) ?
$sar[1] : 'CO';
1523 // slice sar array to get triplet elements
1524 // chunk into triplets
1525 $sar1 = array_slice($sar, 2);
1526 $sar1 = array_chunk($sar1, 3);
1528 foreach ($sar1 as $cas) {
1531 foreach ($cas as $k => $v) {
1533 // monetary amount elem 3, 6, 9, 12, 15, 18
1534 $cav = ($v) ?
$v : 0;
1535 } elseif ($k == 2) {
1536 // quantity elem 4, 7, 10, 13, 16, 19
1537 $cq = ($v) ?
$v : "";
1538 if ($cq && strcmp($cq, '1') > 0) {
1545 $acctng['svcptrsp'] +
= ($cav) ?
(float)$cav : 0;
1547 $acctky = ($loopid == '2100') ?
'clmadj' : 'svcadj';
1548 $acctng[$acctky] +
= ($cav) ?
(float)$cav : 0;
1556 // uncaught segments should be routed by this
1557 if ($loopid == '2100' ||
$loopid == '2110') {
1561 } // end foreach(trans as seg)
1562 } // end foreach(trans_ar as trans)
1569 * create a display for an 835 claim payment file or transaction
1571 * @uses csv_check_x12_obj()
1573 * @param string $filename the filename
1574 * @param string TRN02 identifier from 835 check ir EFT
1575 * @param string CLM01 identifier from 837 CLM
1577 * @return string error message or a table with file information
1579 function edih_835_html($filename, $trace = '', $clm01 = '', $summary = false)
1584 if (trim($filename)) {
1585 $obj835 = csv_check_x12_obj($filename, 'f835');
1586 if ($obj835 && 'edih_x12_file' == get_class($obj835)) {
1587 $fn = $obj835->edih_filename();
1588 $delims = $obj835->edih_delimiters();
1589 $env_ar = $obj835->edih_x12_envelopes();
1591 $de = (isset($delims['e'])) ?
$delims['e'] : '';
1592 $ds = (isset($delims['s'])) ?
$delims['s'] : '';
1593 $dr = (isset($delims['r'])) ?
$delims['r'] : '';
1594 // $dr is not used, but just in case
1596 $html_str .= "<p>edih_835_html: invalid file name</p>".PHP_EOL
;
1600 $html_str .= "Error in file name or file parsing <br />".PHP_EOL
;
1601 csv_edihist_log("edih_835_html: error in parsing file $filename");
1606 // note $dr, repetition separator, is not always available
1607 $cd27x = new edih_271_codes($ds, $dr);
1608 $cd835 = new edih_835_codes($ds, $dr);
1610 csv_edihist_log("edih_835_html: Did not get delimiters");
1611 $html_str .= "<p>Did not get delimiters for " . text($fn) . "</p>".PHP_EOL
;
1616 // if given, one only of trace or clm01
1619 $pid = trim((string)$clm01);
1621 $chk = trim((string)$trace);
1626 $clp_ar = $obj835->edih_x12_transaction($pid);
1627 // $clp_ar is array[i][j]
1628 if (count($clp_ar)) {
1630 $html_str .= edih_835_clp_summary($clp_ar, $cd27x, $cd835, $delims, $fn);
1632 // create a table for this transaction for jquery-ui dialog
1633 $html_str .= edih_835_transaction_html($clp_ar, $cd27x, $cd835, $delims, $fn);
1636 csv_edihist_log("edih_835_html: Did not find PtID $pid in $fn");
1637 $html_str .= "<p>Did not find PtID " . text($pid) . " in " . text($fn) . "</p>".PHP_EOL
;
1642 if (isset($env_ar['ST']) && count($env_ar['ST'])) {
1643 $trans_ar = array();
1644 foreach ($env_ar['ST'] as $st) {
1645 if ($st['trace'] != $chk) {
1649 $trans_ar[] = $obj835->edih_x12_slice(array('trace'=>$chk));
1652 csv_edihist_log("edih_835_transaction_html: Did not get envelopes information for $fn");
1653 $html_str .= "<p>Did not get envelopes information for " . text($fn) . "</p>".PHP_EOL
;
1657 if (is_array($trans_ar) && count($trans_ar)) {
1658 // $trans_ar is a slice, array[i]
1659 $html_str .= edih_835_payment_html($trans_ar, $cd27x, $cd835, $delims, $fn);
1661 csv_edihist_log("edih_835_transaction_html: Did not find trace $chk in $fn");
1662 $html_str .= "<p>Did not find trace " . text($chk) . " in " . text($fn) . "</p>".PHP_EOL
;
1667 if (isset($env_ar['ST']) && count($env_ar['ST'])) {
1668 $trans_ar = array();
1669 foreach ($env_ar['ST'] as $st) {
1670 $trans_ar[] = $obj835->edih_x12_slice(array('trace'=>$st['trace']));
1673 csv_edihist_log("edih_835_transaction_html: Did not envelopes information for $fn");
1674 $html_str .= "<p>Did not get envelopes information for " . text($fn) . "</p>".PHP_EOL
;
1678 if (is_array($trans_ar) && count($trans_ar)) {
1679 // $trans_ar is a slice, array[i]
1680 $html_str .= edih_835_payment_html($trans_ar, $cd27x, $cd835, $delims, $fn);
1682 csv_edihist_log("edih_835_transaction_html: Did not get ST envelopes for $fn");
1683 $html_str .= "<p>Did not get ST envelopes for " . text($fn) . "</p>".PHP_EOL
;