Fix bug in the careplan list endpoint
[openemr.git] / library / edihistory / edih_271_html.php
blobfb17ff38596630448932f924f6669f1600807a18
1 <?php
3 /*
4 * edih_271_html.php
6 * Copyright 2016 Kevin McCormick <kevin@kt61p>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301, USA.
27 // require_once("$srcdir/edihistory/codes/edih_271_code_class.php");
30 /**
31 * Produce an html display of information in
32 * the x12 edi 271 eligibility report for a particular patient
34 * @uses edih_271_codes()
35 * @uses edih_format_money()
36 * @uses edih_format_date()
37 * @uses edih_format_percent()
39 * @param object edih_x12_file type 271
40 * @param string bht03 or clm01 reference for transaction
41 * @return string
43 function edih_271_transaction_html($obj271, $bht03)
46 $trans = $obj271->edih_x12_transaction($bht03);
47 if (empty($trans) || !count($trans)) {
48 $str_html = "<p>Did not find transaction " . text($bht03) . " in " . text($obj271->edih_filename()) . "</p>";
49 return $str_html;
52 $de = $obj271->edih_delimiters()['e'];
53 $ds = $obj271->edih_delimiters()['s'];
54 $dr = $obj271->edih_delimiters()['r'];
55 $fn = $obj271->edih_filename();
57 $cd271 = new edih_271_codes($ds, $dr);
59 $str_html = "";
61 $hdr_html = "<table id=" . attr($bht03) . " class='h271' columns=4><caption>Eligibility Benefit Response</caption>" . PHP_EOL;
62 $hdr_html .= "<thead>" . PHP_EOL;
63 $hdr_html .= "<tr><th>Reference</th><th colspan=2>Information</th><th colspan=2>" . text($fn) . "</th></tr>" . PHP_EOL;
64 $hdr_html .= "</thead>" . PHP_EOL . "<tbody>" . PHP_EOL;
65 $src_html = "";
66 $rcv_html = "";
67 $sbr_nm1_html = "";
68 $dep_nm1_html = "";
69 $sbr_ref_html = "";
70 $dep_ref_html = "";
71 $sbr_eb_html = "";
72 $dep_eb_html = "";
74 $ebct = 0;
76 $trns_ct = count($trans);
77 for ($i = 0; $i < $trns_ct; $i++) {
78 foreach ($trans[$i] as $seg) {
80 $idtype = '';
81 $name = '';
82 $var = '';
83 $rej_reason = '';
84 $follow = '';
85 $addr = '';
87 if (strncmp('BHT' . $de, $seg, 4) === 0) {
88 $loopid = 'Heading';
89 $sar = explode($de, $seg);
90 $bht01 = ( isset($sar[1]) && $sar[1] == '022') ? "Src, Rcv, Sbr, Dep" : "Order unspecified";
91 $bht02 = ( isset($sar[2]) && $sar[2] == '11') ? "Response" : "Confirmation";
92 $bht03 = ( isset($sar[3]) && $sar[3]) ? $sar[3] : "";
93 $bht04 = ( isset($sar[4]) && $sar[4]) ? edih_format_date($sar[4]) : "";
95 $hdr_html .= "<tr><td><em>Reference:</em> " . text($bht03) . "</td><td><em>Date:</em> " . text($bht04) . "</td><td><em>Type:</em> " . text($bht02) . "</td><td>" . text($bht01) . "</td></tr>" . PHP_EOL;
96 continue;
100 if (strncmp('HL' . $de, $seg, 3) === 0) {
101 $sar = explode($de, $seg);
102 if ($sar[3] == '20') { // level code
103 $loopid = '2000A'; // info source (payer)
104 $src_html .= "<tr><td colspan=4><b>Information Source</b></td></tr>" . PHP_EOL;
105 } elseif ($sar[3] == '21') {
106 $loopid = '2000B'; // info receiver (clinic)
107 $rcv_html .= "<tr><td colspan=4><b>Information Receiver</b></td></tr>" . PHP_EOL;
108 } elseif ($sar[3] == '22') {
109 $loopid = '2000C'; // subscriber
110 $has_eb = false;
111 $sbr_nm1_html .= "<tr><td colspan=4><b>Subscriber</b></td></tr>" . PHP_EOL;
112 } elseif ($sar[3] == '23') {
113 $loopid = '2000D'; // dependent
114 $has_eb = false;
115 $dep_nm1_html .= "<tr><td colspan=4><b>Dependent</b></td></tr>" . PHP_EOL;
119 $ebct = 0;
120 continue;
124 if (strncmp('AAA' . $de, $seg, 4) === 0) {
125 // rejection
126 $sar = explode($de, $seg);
127 $rej_reason = $cd271->get_271_code('AAA03', $sar[3]);
128 $follow = $cd271->get_271_code('AAA04', $sar[4]);
129 if ($loopid == '2000A') {
130 $src_html .= "<tr><td><em><b>Rejection:</b></em></td><td colspan=3 title='" . attr($follow) . "'>" . text($rej_reason) . "</td></tr>" . PHP_EOL;
131 } elseif ($loopid == '2000B') {
132 $rcv_html .= "<tr><td><em><b>Rejection:</b></em></td><td colspan=3 title='" . attr($follow) . "'>" . text($rej_reason) . "</td></tr>" . PHP_EOL;
133 } elseif ($loopid == '2000C') {
134 $sbr_nm1_html .= "<tr><td><em><b>Rejection:</b></em></td><td colspan=3 title='" . attr($follow) . "'>" . text($rej_reason) . "</td></tr>" . PHP_EOL;
135 } elseif ($loopid == '2000D') {
136 $dep_nm1_html .= "<tr><td><em><b>Rejection:</b></em></td><td colspan=3 title='" . attr($follow) . "'>" . text($rej_reason) . "</td></tr>" . PHP_EOL;
137 } elseif ($loopid == '2110C') {
138 $sbr_eb_html .= "<tr class=$cls><td><em><b>Rejection:</b></em></td><td colspan=3 title='" . attr($follow) . "'>" . text($rej_reason) . "</td></tr>" . PHP_EOL;
139 } elseif ($loopid == '2110D') {
140 $dep_eb_html .= "<tr class=$cls><td><em><b>Rejection:</b></em></td><td colspan=3 title='" . attr($follow) . "'>" . text($rej_reason) . "</td></tr>" . PHP_EOL;
141 } else {
142 $hdr_html .= "<tr><td>$loopid <em><b>Rejection:</b></em></td><td colspan=3 title='" . attr($follow) . "'>" . text($rej_reason) . "</td></tr>" . PHP_EOL;
145 continue;
148 if (strncmp('NM1' . $de, $seg, 4) === 0) {
149 $sar = explode($de, $seg);
151 $descr = (isset($sar[1]) && $sar[1] ) ? $cd271->get_271_code('NM101', $sar[1]) : "";
153 $name = (isset($sar[3]) && $sar[3] ) ? $sar[3] : "";
154 $name .= (isset($sar[7]) && $sar[7]) ? " {$sar[7]}" : "";
155 $name .= (isset($sar[4]) && $sar[4]) ? ", {$sar[4]}" : "";
156 $name .= (isset($sar[5]) && $sar[5]) ? " {$sar[5]}" : "";
157 $name .= (isset($sar[7]) && $sar[7]) ? " {$sar[7]}" : "";
159 $idtype = (isset($sar[8]) && $sar[8] ) ? $cd271->get_271_code('NM108', $sar[8]) : "";
160 $nm109 = (isset($sar[9]) && $sar[9]) ? $sar[9] : "";
162 if ($loopid == '2000A') {
163 $src_html .= "<tr><td title='" . attr($idtype) . "'>" . text($nm109) . "</td><td colspan=3 title='" . attr($descr) . "'>" . text($name) . "</td></tr>" . PHP_EOL;
164 $loopid = '2100A';
165 } elseif ($loopid == '2000B') {
166 $rcv_html .= "<tr><td title='" . attr($idtype) . "'>" . text($nm109) . "</td><td colspan=3 title='" . attr($descr) . "'>" . text($name) . "</td></tr>" . PHP_EOL;
167 $loopid = '2100B';
168 } elseif ($loopid == '2000C') {
169 $sbr_nm1_html .= "<tr><td title='" . attr($idtype) . "'>" . text($nm109) . "</td><td colspan=3 title='" . attr($descr) . "'>" . text($name) . "</td></tr>" . PHP_EOL;
170 $loopid = '2100C';
171 } elseif ($loopid == '2000D') {
172 $dep_nm1_html .= "<tr><td title='" . attr($idtype) . "'>" . text($nm109) . "</td><td colspan=3 title='" . attr($descr) . "'>" . text($name) . "</td></tr>" . PHP_EOL;
173 $loopid = '2100D';
174 } elseif ($loopid == '2120C') {
175 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td title='" . attr($idtype) . "'>" . text($nm109) . "</td><td colspan=2 title='" . attr($descr) . "'>" . text($descr . " " . $name) . "</td></tr>" . PHP_EOL;
176 } elseif ($loopid == '2120D') {
177 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td title='" . attr($idtype) . "'>" . text($nm109) . "</td><td colspan=2 title='" . attr($descr) . "'>" . text($descr . " " . $name) . "</td></tr>" . PHP_EOL;
181 continue;
185 if (strncmp('PER' . $de, $seg, 4) === 0) {
186 $sar = explode($de, $seg);
187 $per02 = (isset($sar[2]) && $sar[2]) ? $sar[2] : '';
188 $idtype = (isset($sar[3]) && $sar[3]) ? $cd271->get_271_code('PER03', $sar[3]) : "";
189 $per04 = (isset($sar[4]) && $sar[2]) ? $sar[4] : '';
190 if ($loopid == '2100A') {
191 $src_html .= "<tr><td colspan=3>$per02</td><td title='" . attr($idtype) . "'>$per04</td></tr>" . PHP_EOL;
192 } elseif ($loopid == '2120C') {
193 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td title='" . attr($idtype) . "'>" . text($per04) . "</td><td colspan=2>" . text($per02) . "</td></tr>" . PHP_EOL;
194 } elseif ($loopid == '2120D') {
195 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td title='" . attr($idtype) . "'>" . text($per04) . "</td><td colspan=2>" . text($per02) . "</td></tr>" . PHP_EOL;
199 continue;
203 if (strncmp('N3' . $de, $seg, 3) === 0) {
204 $sar = explode($de, $seg);
205 $addr = (isset($sar[1])) ? $sar[1] : "";
206 $addr .= (isset($sar[2])) ? " {$sar[2]}" : "";
207 if ($loopid == '2100C') {
208 $sbr_nm1_html .= "<tr><td>&gt;</td><td colspan=3>" . text($addr) . "</td></tr>" . PHP_EOL;
209 } elseif ($loopid == '2100D') {
210 $dep_nm1_html .= "<tr><td>&gt;</td><td colspan=3>" . text($addr) . "</td></tr>" . PHP_EOL;
211 } elseif ($loopid == '2120C') {
212 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($addr) . "</td></tr>" . PHP_EOL;
213 } elseif ($loopid == '2120D') {
214 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($addr) . "</td></tr>" . PHP_EOL;
217 continue;
221 if (strncmp('N4' . $de, $seg, 3) === 0) {
222 $sar = explode($de, $seg);
223 if ($loopid == '2100C') {
224 $sbr_nm1_html .= "<tr><td>&gt;</td><td colspan=3>" . text($sar[1] . " " . $sar[2] . " " . $sar[3]) . "</td></tr>" . PHP_EOL;
225 } elseif ($loopid == '2100D') {
226 $dep_nm1_html .= "<tr><td>&gt;</td><td colspan=3>" . text($sar[1] . " " . $sar[2] . " " . $sar[3]) . "</td></tr>" . PHP_EOL;
227 } elseif ($loopid == '2120C') {
228 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($sar[1] . " " . $sar[2] . " " . $sar[3]) . "</td></tr>" . PHP_EOL;
229 } elseif ($loopid == '2120D') {
230 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($sar[1] . " " . $sar[2] . " " . $sar[3]) . "</td></tr>" . PHP_EOL;
233 continue;
237 if (strncmp('PRV' . $de, $seg, 4) === 0) {
238 $sar = explode($de, $seg);
239 $idtype = ($sar[1]) ? $cd271->get_271_code('PRV', $sar[1]) : "";
240 if ($loopid == '2100B') {
241 $src_html .= "<tr><td colspan=3>" . text($sar[2]) . "</td><td title='" . attr($idtype) . "'>" . text($sar[3]) . "</td></tr>" . PHP_EOL;
242 } elseif ($loopid == '2100C') {
243 $sbr_nm1_html .= "<tr><td title='" . attr($idtype) . "'>" . text($sar[3]) . "</td><td colspan=3>" . text($sar[2]) . "</td></tr>" . PHP_EOL;
244 } elseif ($loopid == '2100D') {
245 $dep_nm1_html .= "<tr><td title='" . attr($idtype) . "'>" . text($sar[3]) . "</td><td colspan=3>" . text($sar[2]) . "</td></tr>" . PHP_EOL;
246 } elseif ($loopid == '2120C') {
247 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td title='" . attr($idtype) . "'>" . text($sar[3]) . "</td><td colspan=2>" . text($sar[2]) . "</td></tr>" . PHP_EOL;
248 } elseif ($loopid == '2120D') {
249 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td title='" . attr($idtype) . "'>" . text($sar[3]) . "</td><td colspan=2>" . text($sar[2]) . "</td></tr>" . PHP_EOL;
253 continue;
257 if (strncmp('DMG' . $de, $seg, 4) === 0) {
258 $sar = explode($de, $seg);
259 $dmg02 = (isset($sar[2]) && $sar[2]) ? edih_format_date($sar[2]) : "";
260 if (isset($sar[3]) && $sar[3]) {
261 if ($sar[3] == 'M') {
262 $dmg03 = "Male";
263 } elseif ($sar[3] == 'F') {
264 $dmg03 = "Female";
265 } else {
266 $dmg03 = "Unknown";
270 if ($loopid == '2100C') {
271 $sbr_nm1_html .= "<tr><td>&gt;</td><td>" . text($dmg03) . "</td><td colspan=2><em>Date of Birth</em> " . text($dmg02) . "</td></tr>" . PHP_EOL;
272 } elseif ($loopid == '2100D') {
273 $dep_nm1_html .= "<tr><td>&gt;</td><td>" . text($dmg03) . "</td><td colspan=2><em>Date of Birth</em> " . text($dmg02) . "</td></tr>" . PHP_EOL;
276 continue;
279 if (strncmp('INS' . $de, $seg, 4) === 0) {
280 $sar = explode($de, $seg);
281 $ins01 = (isset($sar[1]) && $sar[1] == 'Y') ? "Subscriber" : "Dependent";
282 $ins02 = (isset($sar[2]) && $sar[2]) ? $cd271->get_271_code('INS02', $sar[2]) : "";
283 $ins03 = (isset($sar[3]) && $sar[3]) ? $sar[3] : "";
284 $ins04 = (isset($sar[4]) && $sar[4] == '25') ? "<b>Information changed</b>" : "";
285 $ins17 = (isset($sar[17]) && $sar[17]) ? $sar[17] : "";
287 if ($loopid == '2100C') {
288 $sbr_nm1_html .= "<tr><td>&gt;</td><td>" . text($ins01 . " " . $ins17) . "</td><td>" . text($ins02) . "</td><td>" . text($ins03) . " " . $ins04 . "</td></tr>" . PHP_EOL;
289 } elseif ($loopid == '2100D') {
290 $dep_nm1_html .= "<tr><td>&gt;</td><td>" . text($ins01 . " " . $ins17) . "</td><td>" . text($ins02) . "</td><td>" . text($ins03) . " " . $ins04 . "</td></tr>" . PHP_EOL;
293 continue;
296 if (strncmp('DTP' . $de, $seg, 4) === 0) {
298 $sar = explode($de, $seg);
299 $var = '';
300 $dtp01 = (isset($sar[1])) ? $sar[1] : '';
301 $dtp02 = (isset($sar[2])) ? $sar[2] : '';
302 $dtp03 = (isset($sar[3])) ? $sar[3] : '';
304 $idtype = ($dtp01) ? $cd271->get_271_code('DTP', $dtp01) : "";
305 if ($dtp02 == 'D8' && $dtp03) {
306 $var = edih_format_date($dtp03);
307 } elseif ($dtp02 == 'RD8' && $dtp03) {
308 $var = edih_format_date(substr($dtp03, 0, 8));
309 $var .= ' - ' . edih_format_date(substr($dtp03, -8));
312 if ($loopid == '2100C') {
313 $sbr_nm1_html .= "<tr><td>&gt;</td><td>" . text($idtype) . "</td><td colspan=2>" . text($var) . "</td></tr>" . PHP_EOL;
314 } elseif ($loopid == '2100D') {
315 $dep_nm1_html .= "<tr><td>&gt;</td><td>" . text($idtype) . "</td><td colspan=2>" . text($var) . "</td></tr>" . PHP_EOL;
316 } elseif ($loopid == '2110C') {
317 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td>" . text($idtype) . "</td><td colspan=2>" . text($var) . "</td></tr>" . PHP_EOL;
318 } elseif ($loopid == '2110D') {
319 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td>" . text($idtype) . "</td><td colspan=2>" . text($var) . "</td></tr>" . PHP_EOL;
322 continue;
326 if (strncmp('MPI' . $de, $seg, 4) === 0) {
327 $sar = explode($de, $seg);
328 $idtype = (isset($sar[1]) && $sar[1]) ? $cd271->get_271_code('MPI', $sar[1]) : "";
329 $idtype .= (isset($sar[2]) && $sar[2]) ? $cd271->get_271_code('MPI', $sar[2]) : "";
330 $idtype .= (isset($sar[3]) && $sar[3]) ? $cd271->get_271_code('MPI', 'SB' . $sar[3]) : "";
331 if (isset($sar[7]) && isset($sar[8])) {
332 if ($sar[7] == 'D8') {
333 $var = edih_format_date($sar[8]);
334 } elseif ($sar[7] == 'RD8') {
335 $var = edih_format_date(substr($sar[8], 0, 8));
336 $var .= ' - ' . edih_format_date(substr($sar[8], -8));
340 if ($loopid == '2100C') {
341 $sbr_nm1_html .= "<tr><td colspan=3>" . text($idtype) . "</td><td>" . text($var) . "</td></tr>" . PHP_EOL;
342 } elseif ($loopid == '2100D') {
343 $dep_nm1_html .= "<tr><td colspan=3>" . text($idtype) . "</td><td>" . text($var) . "</td></tr>" . PHP_EOL;
346 continue;
350 if (strncmp('EB' . $de, $seg, 3) === 0) {
352 $ebct++;
353 $cls = ($ebct % 2) ? 'ebe' : 'ebo';
354 $sar = explode($de, $seg);
356 $eb01 = $cd271->get_271_code('EB01', $sar[1]); // eligibility or benefit
357 $eb02 = (isset($sar[2]) && $sar[2]) ? $cd271->get_271_code('EB02', $sar[2]) : ''; // coverage level
358 $eb03 = (isset($sar[3]) && $sar[3]) ? $cd271->get_271_code('EB03', $sar[3]) : ''; // service type
359 $eb04 = (isset($sar[4]) && $sar[4]) ? $cd271->get_271_code('EB04', $sar[4]) : ''; // insurance type
360 $eb05 = (isset($sar[5]) && $sar[5]) ? $sar[5] : ''; // descriptive (plan name)
361 $eb06 = (isset($sar[6]) && $sar[6]) ? $cd271->get_271_code('EB06', $sar[6]) : ''; // time qualifier
362 $eb07 = (isset($sar[7]) && strlen($sar[7])) ? edih_format_money($sar[7]) : ''; // monetary amount
363 $eb08 = (isset($sar[8]) && $sar[8]) ? edih_format_percent($sar[8]) : ''; // percentage amount
364 $eb09 = (isset($sar[9]) && $sar[9]) ? $cd271->get_271_code('EB09', $sar[9]) : ''; // Quantity qualifier
365 $eb10 = (isset($sar[10]) && $sar[10]) ? $sar[10] : ''; // quantity
366 $eb11 = (isset($sar[11]) && $sar[11]) ? $cd271->get_271_code('EB11', $sar[11]) : ''; // authorization required?
367 $eb12 = (isset($sar[12]) && $sar[12]) ? $cd271->get_271_code('EB12', $sar[12]) : ''; // in network?
368 $eb13 = "";
369 if (isset($sar[13]) && strpos($sar[13], $ds)) { // composite procedure ID
370 $eb13ar = explode($ds, $sar[13]);
371 reset($eb13ar);
372 while (list($k, $v) = each($eb13ar)) {
373 if ($k == 0) {
374 $eb13 = text($cd271->get_271_code('EB13', $v));
375 } else {
376 $eb13 .= " " . text($v);
379 } else {
380 $eb13 = ($sar[13]) ? "<em>Procedure</em> " . text($eb13) : "";
383 $eb14 = "";
384 if (isset($sar[14])) {
385 if (strpos($sar[14], $ds)) { // composite diagnosis pointer
386 $eb14 = str_replace($ds, " | ", $sar[14]) ;
387 } else {
388 $eb14 = $sar[14];
391 $eb14 = ($eb14) ? "<em>Pointers</em> " . text($eb14) : "";
394 // if LS - LE segments loop should be 2110C or 2110D
395 if ($loopid == '2100C' || $loopid == '2110C') {
396 $loopid = '2110C';
397 if (strpos('|A|B', $sar[1]) !== false) {
398 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>" . text($eb01) . "</td><td>" . text($eb07 . " " . $eb08) . "</td><td colspan=2>" . text($eb02 . " " . $eb03 . " " . $eb04 . " " . $eb06) . "</td></tr>" . PHP_EOL;
399 } elseif (strpos('|C|G|J|Y', $sar[1]) !== false) {
400 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>" . text($eb01) . "</td><td>" . text($eb02) . "</td><td>" . text($eb06 . " " . $eb07) . "</td><td>" . text($eb03 . " " . $eb04) . "</td></tr>" . PHP_EOL;
401 } elseif (strpos('|E|F|', $sar[1]) !== false) {
402 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>" . text($eb01) . "</td><td>" . text($eb02) . "</td><td colspan=2>" . text($eb03 . " " . $eb04 . " " . $eb06) . "</td></tr>" . PHP_EOL;
403 } else {
404 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>" . text($eb01) . "</td><td>" . text($eb02) . "</td><td colspan=3>" . text($eb07 . " " . $eb08 . " " . $eb03 . " " . $eb04 . " " . $eb06) . "</td></tr>" . PHP_EOL;
407 $sbr_eb_html .= ($eb09 || $eb10 || $eb11 || $eb12) ? "<tr class=" . attr($cls) . "><td colspan=2>&gt;</td><td colspan=2>" . text($eb09 . " " . $eb10 . " " . $eb11 . " " . $eb12) . "</td></tr>" . PHP_EOL : "";
408 $sbr_eb_html .= ($eb13 || $eb14) ? "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . $eb13 . " " . $eb14 . "</td></tr>" . PHP_EOL : "";
409 $sbr_eb_html .= ($eb05) ? "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($eb05) . "</td></tr>" . PHP_EOL : "";
410 } elseif ($loopid == '2100D' || $loopid == '2110D') {
411 $loopid = '2110D';
412 if (strpos('|A|B', $eb01) && !$eb02) {
413 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>" . text($eb01) . "</td><td>" . text($ebo7 . " " . $eb08) . "</td><td colspan=2>" . text($eb03 . " " . $eb04 . " " . $eb06) . "</td></tr>" . PHP_EOL;
414 } elseif (strpos('|C|G|J|Y', $eb01)) {
415 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>" . text($eb01) . "</td><td>" . text($eb02) . "</td><td>" . text($eb07 . " " . $eb08) . "</td><td>" . text($eb11 . " " . $eb12) . "</td></tr>" . PHP_EOL;
416 } elseif (strpos('|E|F|', $eb01)) {
417 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>" . text($eb01) . "</td><td>" . text($eb02) . "</td><td colspan=2>" . text($eb03 . " " . $eb04 . " " . $eb06) . "</td></tr>" . PHP_EOL;
418 } else {
419 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>" . text($eb01) . "</td><td>" . text($eb02) . "</td><td colspan=3>" . text($eb07 . " " . $eb08 . " " . $eb03 . " " . $eb04 . " " . $eb06) . "</td></tr>" . PHP_EOL;
422 $dep_eb_html .= ($eb09 || $eb10 || $eb11 || $eb12) ? "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($eb09 . " " . $eb10 . " " . $eb11 . " " . $eb12) . "</td></tr>" . PHP_EOL : "";
423 $dep_eb_html .= ($eb13 || $eb14) ? "<tr class=$cls><td>&gt;</td><td colspan=3>" . $eb13 . " " . $eb14 . "</td></tr>" . PHP_EOL : "";
424 $dep_eb_html .= ($eb05) ? "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($eb05) . "</td></tr>" . PHP_EOL : "";
427 continue;
431 if (strncmp('HSD' . $de, $seg, 4) === 0) {
432 $sar = explode($de, $seg);
434 $hsd01 = (isset($sar[1]) && $sar[1]) ? $cd271->get_271_code('HSD01', $sar[1]) : ''; // quantity qualifier
435 $hsd02 = (isset($sar[2]) && $sar[2]) ? $sar[2] : ''; // numeric quantity
436 $hsd03 = (isset($sar[3]) && $sar[3]) ? $cd271->get_271_code('HSD01', $sar[3]) : ''; // measurement unit
437 $hsd04 = (isset($sar[4]) && $sar[4]) ? $sar[4] : ''; // sample selection modulus
438 $hsd05 = (isset($sar[5]) && $sar[5]) ? $cd271->get_271_code('EB06', $sar[5]) : ''; // time period qualifier
439 $hsd06 = (isset($sar[6]) && $sar[6]) ? $sar[6] : ''; // number of periods
440 $hsd07 = (isset($sar[7]) && $sar[7]) ? $cd271->get_271_code('HSD07', $sar[7]) : ''; // delivery
441 $hsd08 = (isset($sar[8]) && $sar[8]) ? $cd271->get_271_code('HSD08', $sar[8]) : ''; // delivery
443 if ($loopid == '2110C') {
444 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td>" . text($hsd01 . " : " . $hsd02) . "</td><td>" . text($hsd03 . " : " . $hsd04) . "</td><td>" . text($hsd05 . " : " . $hsd06) . "</td></tr>" . PHP_EOL;
445 $sbr_eb_html .= ($hsd07 || $hsd08) ? "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($hsd07 . " " . $hsd08) . "</td></tr>" . PHP_EOL : '';
446 } elseif ($loopid == '2110D') {
447 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td>" . text($hsd01 . " : " . $hsd02) . "</td><td>" . text($hsd03 . " : " . $hsd04) . "</td><td>" . text($hsd05 . " : " . $hsd06) . "</td></tr>" . PHP_EOL;
448 $dep_eb_html .= ($hsd07 || $hsd08) ? "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($hsd07 . " " . $hsd08) . "</td></tr>" . PHP_EOL : '';
451 continue;
454 if (strncmp('REF' . $de, $seg, 4) === 0) {
455 $sar = explode($de, $seg);
457 $ref01 = (isset($sar[1]) && $sar[1]) ? $cd271->get_271_code('REF', $sar[1]) : ''; // identification qualifier
458 $ref02 = (isset($sar[2]) && $sar[2]) ? $sar[2] : ''; // identification value
459 $ref03 = (isset($sar[3]) && $sar[3]) ? $sar[3] : ''; // description
461 if ($loopid == '2100C') {
462 $sbr_ref_html .= "<tr><td>&gt;</td><td colspan=2>" . text($ref03) . "</td><td>" . text($ref01 . " " . $ref02) . "</td></tr>" . PHP_EOL;
463 } elseif ($loopid == '2100D') {
464 $dep_ref_html .= "<tr><td>&gt;</td><td colspan=2>" . text($ref03) . "</td><td>" . text($ref01 . " " . $ref02) . "</td></tr>" . PHP_EOL;
465 } elseif ($loopid == '2110C') {
466 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=2>" . text($ref03) . "</td><td>" . text($ref01 . " " . $ref02) . "</td></tr>" . PHP_EOL;
467 } elseif ($loopid == '2110D') {
468 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=2>" . text($ref03) . "</td><td>" . text($ref01 . " " . $ref02) . "</td></tr>" . PHP_EOL;
471 continue;
474 if (strncmp('MSG' . $de, $seg, 4) === 0) {
475 $sar = explode($de, $seg);
476 $msg01 = (isset($sar[1]) && $sar[1]) ? $sar[1] : '';
477 if ($msg01 && $loopid == '2110C') {
478 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($msg01) . "</td></tr>" . PHP_EOL;
479 } elseif ($msg01 && $loopid == '2110D') {
480 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($msg01) . "</td></tr>" . PHP_EOL;
483 continue;
486 if (strncmp('III' . $de, $seg, 4) === 0 && ($loopid == '2110C' || $loopid == '2110D')) {
487 $sar = explode($de, $seg);
488 if (isset($sar[1]) && ($sar[1] == 'GR' || $sar[1] == 'NI')) {
489 $iii02 = (isset($sar[2]) && $sar[2]) ? $cd271->get_271_code('IIIGR', $sar[2]) : '';
490 } else {
491 $iii02 = (isset($sar[2]) && $sar[2]) ? $cd271->get_271_code('POS', $sar[2]) : '';
494 $iii03 = (isset($sar[3]) && $sar[3]) ? $sar[3] : '';
496 if ($loopid == '2110C') {
497 $sbr_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($iii02) . "</td></tr>" . PHP_EOL;
498 $sbr_eb_html .= ($iii03) ? "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($iii03) . "</td></tr>" . PHP_EOL : '';
499 } elseif ($loopid == '2110D') {
500 $dep_eb_html .= "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($iii02) . "</td></tr>" . PHP_EOL;
501 $dep_eb_html .= ($iii03) ? "<tr class=" . attr($cls) . "><td>&gt;</td><td colspan=3>" . text($iii03) . "</td></tr>" . PHP_EOL : '';
504 continue;
508 if (strncmp('LS' . $de, $seg, 3) === 0) {
509 if ($loopid == '2110C') {
510 $loopid = '2120C';
513 if ($loopid == '2110D') {
514 $loopid = '2120D';
517 continue;
520 if (strncmp('LE' . $de, $seg, 3) === 0) {
521 if ($loopid == '2120C') {
522 $loopid = '2100C';
525 if ($loopid == '2120D') {
526 $loopid = '2100D';
529 continue;
536 $str_html .= $hdr_html;
537 $str_html .= ($src_html) ? $src_html : "";
538 $str_html .= ($rcv_html) ? $rcv_html : "";
539 $str_html .= ($sbr_nm1_html) ? $sbr_nm1_html : "";
540 $str_html .= $sbr_ref_html;
541 $str_html .= $sbr_eb_html;
542 $str_html .= ($dep_nm1_html) ? $dep_nm1_html : "";
543 $str_html .= $dep_ref_html;
544 $str_html .= $dep_eb_html;
545 $str_html .= "<tr><td colspan=4>&nbsp;</td></tr>" . PHP_EOL;
546 $str_html .= "</tbody>" . PHP_EOL . "</table>" . PHP_EOL;
550 return $str_html;
554 * create a display for an individual claim status response
556 * @uses csv_check_x12_obj()
557 * @uses edih_271_transaction_html()
559 * @param string $filename the filename
560 * @param string $bht03 identifier from 837 CLM or BHT segment
562 * @return string either an error message or an html table
564 function edih_271_html($filename, $bht03 = '')
566 // create a display for an individual 277 response
567 $html_str = '';
569 if ($filename) {
570 $obj271 = csv_check_x12_obj($filename, 'f271');
571 if ('edih_x12_file' == get_class($obj271)) {
572 if ($bht03) {
573 // particular transaction
574 $html_str .= edih_271_transaction_html($obj271, $bht03);
575 } else {
576 // file contents
577 $env_ar = $obj271->edih_envelopes();
578 if (!isset($env_ar['ST'])) {
579 $html_str .= "<p>edih_271_html: file parse error, envelope error</p>" . PHP_EOL;
580 $html_str .= text($obj271->edih_message());
581 return $html_str;
582 } else {
583 $html_str .= "<div id='accordion'>" . PHP_EOL;
586 foreach ($env_ar['ST'] as $st) {
587 foreach ($env_ar['GS'] as $gs) {
588 if ($gs['icn'] != $st['icn']) {
589 continue;
592 if ($gs['gsn'] == $st['gsn']) {
593 $gs_date = edih_format_date($gs['date']);
594 $gs_sender = $gs['sender'];
595 break;
600 // get each transaction
601 foreach ($st['bht03'] as $bht) {
602 $html_str .= "<h3>" . text($bht) . " Benefit Eligibility</h3>" . PHP_EOL;
603 $html_str .= "<div id='ac_" . attr($bht) . "'>" . PHP_EOL;
605 $html_str .= edih_271_transaction_html($obj271, $bht);
607 $html_str .= "</div>" . PHP_EOL;
610 $html_str .= "</div>" . PHP_EOL;
613 } else {
614 $html_str .= "<p>edih_271_html: file parse error</p>" . PHP_EOL;
616 } else {
617 csv_edihist_log("edih_271_html: error in file arguments");
618 $html_str .= "Error: invalid file name<br />" . PHP_EOL;
619 return $html_str;
623 return $html_str;