bug fix (#7559)
[openemr.git] / library / edihistory / edih_io.php
blob199267ee11c7aaa682d889505cd92985ba95f1c9
1 <?php
3 /*
4 * edih_io.php
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Kevin McCormick Longview, Texas
9 * @author Stephen Waite <stephen.waite@cmsvt.com>
10 * @copyright Copyright (c) 2016 Kevin McCormick Longview, Texas
11 * @copyright Copyright (c) 2021 Stephen Waite <stephen.waite@cmsvt.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 /**
16 * Get some values from php ini functions for interface
18 * @return array json
20 function edih_php_inivals()
22 $ival = array();
23 $td = basename(sys_get_temp_dir());
24 $ival['maxfsize'] = ini_get('upload_max_filesize');
25 $ival['maxfuploads'] = ini_get('max_file_uploads');
26 $ival['postmaxsize'] = ini_get('post_max_size');
27 $ival['tmpdir'] = $td;
28 $json = json_encode($ival);
30 return $json;
33 /**
34 * display the log file selected
36 * @uses csv_log_html()
37 * @return string
39 function edih_disp_log()
41 $lfn = '';
42 if (isset($_GET['log_select'])) {
43 $lfn = filter_input(INPUT_GET, 'log_select', FILTER_DEFAULT);
46 $str_html = csv_log_html($lfn);
47 return $str_html;
50 function edih_disp_logfiles()
52 $str_html = '';
53 $lst = true;
54 if (isset($_GET['loglist'])) {
55 // loglist: 'yes'
56 $lval = filter_input(INPUT_GET, 'loglist', FILTER_DEFAULT);
57 $lst = ($lval == 'yes') ? true : false;
58 } elseif (isset($_GET['archivelog'])) {
59 // archivelog: 'yes'
60 $lval = filter_input(INPUT_GET, 'archivelog', FILTER_DEFAULT);
61 $lst = ($lval == 'yes') ? false : true;
62 } else {
63 csv_edihist_log('edih_disp_logfiles: input parameter error');
64 return "input parameter error<br />";
67 // returns json array
68 $str_html = csv_log_manage($lst);
69 return $str_html;
71 /**
72 * read or write simple notes to a text file
74 * @uses csv_notes_file()
75 * @return string
77 function edih_user_notes()
80 if (isset($_GET['getnotes'])) {
81 $getnt = filter_input(INPUT_GET, 'getnotes', FILTER_DEFAULT);
82 if ($getnt == 'yes') {
83 $str_html = csv_notes_file();
85 } elseif (isset($_POST['notes_hidden']) && isset($_POST['txtnotes'])) {
86 $putnt = filter_input(INPUT_POST, 'putnotes', FILTER_DEFAULT);
87 if ($putnt == 'yes') {
88 $notetext = trim($_POST['txtnotes']);
89 $filtered = filter_var($notetext, FILTER_DEFAULT);
90 //echo $filtered .PHP_EOL;
91 $str_html = csv_notes_file($filtered, false);
93 } else {
94 csv_edihist_log('edih_user_notes: invalid values in request');
95 $str_html = "<p>User Notes: invalid values in request.</p>";
98 return $str_html;
103 * Restore an existing archive
105 * @uses edih_archive_restore()
107 * @return string
109 function edih_disp_archive_restore()
111 //name="archrestore_sel" { archrestore: 'yes', archfile: archf };
112 $fn = (isset($_POST['archrestore_sel'])) ? filter_input(INPUT_POST, 'archrestore_sel', FILTER_DEFAULT) : '';
113 if (strlen($fn)) {
114 $str_html = edih_archive_restore($fn);
115 } else {
116 $str_html = "<p>Invalid archive name for archive resstore function</p>" . PHP_EOL;
119 return $str_html;
123 * Create a report on edi files and csv tables
125 * @uses edih_archive_report()
127 * @return string
129 function edih_disp_archive_report()
132 $str_html = '';
133 $la = filter_input(INPUT_GET, 'archivereport', FILTER_DEFAULT);
134 $pd = (isset($_GET['period'])) ? filter_input(INPUT_GET, 'period', FILTER_DEFAULT) : '';
136 csv_edihist_log("GET archivereport: archivereport $la period $pd");
138 if ($la == 'yes') {
139 $str_html = edih_archive_report($pd);
140 } else {
141 $str_html = "File Information report input parameter error<br />";
145 return $str_html;
150 * Archive of old edi files
152 * @uses edih_archive_main()
154 * @return string
156 function edih_disp_archive()
159 $pd = (isset($_POST['archive_sel'])) ? filter_input(INPUT_POST, 'archive_sel', FILTER_DEFAULT) : '';
161 if ($pd) {
162 $str_html = edih_archive_main($pd);
163 } else {
164 $str_html = "<p>Invalid aging period for archive function</p>" . PHP_EOL;
167 return $str_html;
171 * call new uploaded files process functions
173 * @todo save the newfiles lists to file so they can
174 * be re-displayed if user has to close app before
175 * finishing review (need to have csv_write option)
177 * @uses csv_newfile_list()
178 * @uses edih_parse_select()
179 * @uses edih_csv_write()
180 * @uses edih_csv_process_html()
182 * @return string html format
184 function edih_disp_file_process()
186 // debug
187 if (isset($_GET)) {
188 $dbg_str = 'GET vars ';
189 foreach ($_GET as $k => $v) {
190 $dbg_str .= $k . ' ' . $v . ' ';
193 csv_edihist_log("edih_disp_file_process $dbg_str");
197 if (!isset($_GET['ProcessFiles'])) {
198 // should only be called with this value existing
199 $str_html = "Error: invalid value for Process New <br />" . PHP_EOL;
200 return $str_html;
203 $htm = $er = false;
204 if (isset($_GET['process_html'])) {
205 // show tables for process results
206 $htmval = filter_input(INPUT_GET, 'process_html', FILTER_DEFAULT);
207 $htm = ($htmval == 'htm') ? true : false;
210 if (isset($_GET['process_err'])) {
211 // show only claims with errors (denied, rejected, etc)
212 $errval = filter_input(INPUT_GET, 'process_err', FILTER_DEFAULT);
213 $er = ($errval == 'err') ? true : false;
216 $str_html = "";
217 $p = csv_parameters();
218 $ftype = array_keys($p);
219 $fct = 0;
221 foreach ($ftype as $tp) {
222 $checkdir = false;
223 // check for directory contents
224 $fdir = $p[$tp]['directory'];
225 if (is_dir($fdir)) {
226 $dh = opendir($fdir);
227 if ($dh) {
228 while (($file = readdir($dh)) !== false) {
229 if ($file != '.' && $file != '..' && $file != "process_bills.log") {
230 $checkdir = true;
231 break;
235 closedir($dh);
239 // if false, no files in directory
240 if (!$checkdir) {
241 continue;
245 $upload_ar = csv_newfile_list($tp);
247 if (is_array($upload_ar) && count($upload_ar)) {
248 $dirct = count($upload_ar);
249 if ($htm) {
250 $dtl = ($er) ? "(claims: errors only)" : "(claims: all)";
251 //$hvals = csv_table_header($tp, 'file');
252 //$col_ct = count($hvals);
253 ////csv_table_header(
254 //$str_html .= "<table class='$tp' cols=$col_ct><caption>$tp Files Summary $dtl</caption>".PHP_EOL;
255 //$str_html .= csv_thead_html($tp, 'file');
256 //$str_html .= "<tbody>".PHP_EOL;
257 $str_html .= "<h2 class='prcs'>" . text($tp) . " " . text($dirct) . " files " . text($dtl) . "</h2>" . PHP_EOL;
258 $str_html .= "<dl class='" . attr($tp) . "'>" . PHP_EOL;
261 foreach ($upload_ar as $fn) {
262 $fp = $fdir . DS . $fn;
263 $csvdata = edih_parse_select($fp);
264 $csvchr = edih_csv_write($csvdata);
265 $fct++;
266 if ($htm) {
267 $str_html .= edih_csv_process_html($csvdata, $er);
271 //$str_html .= ($htm) ? "</tbody>".PHP_EOL."</table>".PHP_EOL : "";
272 $str_html .= ($htm) ? "</dl>" . PHP_EOL : "";
273 } else {
274 $str_html .= "<p>No new " . text($tp) . " files</p>";
278 $capt_html = "<p>Process new files (" . text($fct) . " files)</p>" . PHP_EOL;
279 return $capt_html . $str_html;
283 * uploading of new files
285 * @uses edih_upload_files()
286 * @uses edih_sort_upload()
287 * @return string
289 function edih_disp_file_upload()
291 // multiple file upload
292 $str_html = '';
293 if (isset($_FILES) && count($_FILES)) {
294 $f_array = edih_upload_files();
295 if (is_array($f_array) && count($f_array)) {
296 $str_html .= edih_sort_upload($f_array);
297 } else {
298 $str_html .= "no files accepted <br />" . PHP_EOL;
300 } else {
301 $str_html .= "no files submitted <br />" . PHP_EOL;
305 return $str_html;
308 function edih_disp_denied_claims()
311 $fn = isset($_GET['fname']) ? filter_input(INPUT_GET, 'fname', FILTER_DEFAULT) : '';
312 $ft = isset($_GET['ftype']) ? filter_input(INPUT_GET, 'ftype', FILTER_DEFAULT) : '';
313 $trace = isset($_GET['trace']) ? filter_input(INPUT_GET, 'trace', FILTER_DEFAULT) : '';
315 $str_html = edih_list_denied_claims($ft, $fn, $trace);
317 return $str_html;
321 * display the contents of an x12_edi transaction selected from
322 * a csv table or processed files table
324 * @uses csv_file_by_enctr()
325 * @uses csv_file_by_controlnum()
326 * @uses ibr_batch_get_st_block()
327 * @return string
329 function edih_disp_x12trans()
332 // query source ['gtbl'] file claim hist
334 // file: FileName fname=$fn1&ftype=$ft&fmt=htm' filename x12type format
335 // file: Control fname=$fn1&ftype=$ft&icn=$ctl&fmt=seg filename x12type isa13 format
336 // file: Trace trace=$tr&ftype=$typ&fmt=htm trace x12type format
338 // claim: FileName fname=$fn1&ftype=$ft&fmt=htm filename x12type format:html
339 // claim: Control fname=$fn1&ftype=$ft&icn=$ctl&fmt=seg filename x12type icn format:segment text
340 // claim: CLM01 fname=$fn1&ftype=$ft&pid=$pid filename x12type pid-enctr
341 // claim: Status fname=fname=$fn1&ftype=$ft&pid=$pid&summary=yes filename x12type pid-enctr summary
342 // claim: Status fname=$fn1&ftype=$ft&pid=$pid&summary=no' filename x12type pid-enctr detail
343 // claim: Trace (835) fname=$fn1&ftype=$ft&trace=$trc trace filename x12type
344 // claim: Trace (999) trace=$trc&rsptype=$typ&ftype=$ft trace(bht03syn) response-type x12type
345 // claim: Trace (277) trace=$v&ftype=$tp&rsptype=f837&fmt=seg' trace(clm01) response-type {837) x12type
346 // claim: BHT03 (27x) fname=$fn1&ftype=$ft&bht03=$bht03&fmt=htm filename x12type bht03
347 // claim: err_seg fname=$fn1&ftype=$ft&trace=$trc&rsptype=$typ&err=$err filename x12type trace(bht03syn) response_type error_segment
349 // use files (1) x12 display of file segments (2) 835 html RA or Payment Trace (3) trace from 997 or 271/277/278
350 // $fn or $icn & $ft $fn $icn $trace & $ft $trace & $rsptype
351 // claims (1) html of transaction (2) segments of transaction (3) trace to precedent transaction
352 // $fn & $ft $ pid $trace & $rsptype
354 $str_htm = '';
355 if (isset($_GET['gtbl'])) {
356 $qs = filter_input(INPUT_GET, 'gtbl', FILTER_DEFAULT);
359 if (!$qs) {
360 $str_htm .= '<p>edih_disp_x12 error: missing parameter</p>';
361 csv_edihist_log("edih_io_disp_x12: missing parameter, no 'gtbl' value");
362 return $str_htm;
366 $fmt = isset($_GET['fmt']) ? filter_input(INPUT_GET, 'fmt', FILTER_DEFAULT) : '';
368 $fn = isset($_GET['fname']) ? filter_input(INPUT_GET, 'fname', FILTER_DEFAULT) : '';
369 $ft = isset($_GET['ftype']) ? filter_input(INPUT_GET, 'ftype', FILTER_DEFAULT) : '';
370 $icn = isset($_GET['icn']) ? filter_input(INPUT_GET, 'icn', FILTER_DEFAULT) : '';
371 $rsptype = isset($_GET['rsptype']) ? filter_input(INPUT_GET, 'rsptype', FILTER_DEFAULT) : '';
373 $clm01 = isset($_GET['pid']) ? filter_input(INPUT_GET, 'pid', FILTER_DEFAULT) : '';
374 $trace = isset($_GET['trace']) ? filter_input(INPUT_GET, 'trace', FILTER_DEFAULT) : '';
375 $bht03 = isset($_GET['bht03']) ? filter_input(INPUT_GET, 'bht03', FILTER_DEFAULT) : '';
376 $err = isset($_GET['err']) ? filter_input(INPUT_GET, 'err', FILTER_DEFAULT) : '';
377 $summary = isset($_GET['summary']) ? filter_input(INPUT_GET, 'summary', FILTER_DEFAULT) : false;
379 // debug
380 //$str_htm .= "<p>edih_disp_x12trans values: <br />".PHP_EOL;
381 //$str_htm .= "qs $qs fmt $fmt fn $fn ft $ft icn $icn rsptype $rsptype clm01 $clm01 trace $trace bht03 $bht03 err $err summary $summary</p>".PHP_EOL;
383 if ($ft) {
384 $ft = csv_file_type($ft);
388 if ($qs == 'claim') {
389 if ($ft == 'f997') {
390 if ($trace && $rsptype) {
391 $fname = csv_file_by_trace($trace, $ft, $rsptype);
392 if ($fname) {
393 $str_htm .= edih_display_text($fname, $rsptype, $trace, $err);
394 } else {
395 $str_htm .= "<p>Did not find " . text($trace) . " in the " . text($rsptype) . " claims table.</p>";
398 //$fnar = csv_file_by_enctr($trace, $rsptype, $srchtype='ptidn' );
399 //if (is_array($fnar) && count($fnar)) {
400 //foreach($fnar as $fa) {
401 //$fname = $fa['FileName'];
402 //$str_htm .= edih_display_text($fname, $rsptype, $trace, $err);
404 //} else {
405 //$str_htm .= "<p>Did not find $trace in the $rsptype claims table.</p>";
408 } elseif ($ft == 'f837') {
409 // either transaction or file
410 $str_htm .= edih_display_text($fn, $ft, $clm01);
411 } elseif ($ft == 'f835') {
412 if ($fmt == 'seg') {
413 // either transaction or file
414 $str_htm .= edih_display_text($fn, $ft, $clm01);
415 } elseif ($trace) {
416 // the check trace
417 $str_htm .= edih_835_html($fn, $trace);
418 } elseif ($clm01) {
419 // this claim payment
420 $str_htm .= edih_835_html($fn, '', $clm01, $summary);
422 } elseif (strpos('|f270|f271|f276|f277|f278', $ft)) {
423 if ($fmt == 'seg') {
424 if ($trace && $rsptype) {
425 // 270|276|278|837 claim or request segments
426 // here the 'trace' is from trace or clm01
427 //$fnar = csv_file_by_enctr($trace, $rsptype, $srchtype='ptidn' );
428 //if (is_array($fnar) && count($fnar)) {
429 //foreach($fnar as $fa) {
430 //$fname = $fa['FileName'];
431 //$str_htm .= edih_display_text($fname, $rsptype, $trace);
433 $fname = csv_file_by_trace($trace, $ft, $rsptype);
434 if ($fname) {
435 $str_htm .= edih_display_text($fname, $rsptype, $trace);
436 } else {
437 $str_htm .= "<p>Did not find " . text($trace) . " in type " . text($rsptype) . " csv_claims table</p>" . PHP_EOL;
438 csv_edihist_log("edih_disp_x12trans: Did not find $trace in type $rsptype csv_claims table");
440 } else {
441 // entire file or transaction if bht03 has a value
442 $str_htm .= edih_display_text($fn, $ft, $bht03);
444 } else {
445 // html format
446 if ($ft == 'f277') {
447 $str_htm .= edih_277_html($fn, $bht03);
448 } elseif ($ft == 'f271') {
449 $str_htm .= edih_271_html($fn, $bht03);
450 } elseif ($ft == 'f278') {
451 $str_htm .= edih_278_html($fn, $bht03);
452 } else {
453 // html display not available, use segments
454 $str_htm .= edih_display_text($fn, $ft, $bht03);
458 } elseif ($qs == 'hist') {
459 if ($fn && $ft == 'f837') {
460 if ($clm01) {
461 $str_htm .= edih_display_text($fn, $ft, $clm01);
462 } else {
463 $str_htm .= edih_display_text($fn, $ft);
465 } elseif ($fn && $ft == 'f997') {
466 if ($trace && $rsptype && $err) {
467 $str_htm .= edih_display_text($fn, $rsptype, $trace, true, $err);
468 } elseif ($trace && $rsptype) {
469 $str_htm .= edih_display_text($fn, $rsptype);
470 } else {
471 $str_htm .= edih_display_text($fn, $ft);
473 } elseif ($fn && $ft == 'f277') {
474 if ($trace && $rsptype) {
475 $fname = csv_file_by_trace($trace, $ft, $rsptype);
476 if ($fname) {
477 $str_htm .= edih_display_text($fname, $rsptype, $trace);
478 } else {
479 $str_htm .= "<p>Did not find " . text($trace) . " in type " . text($rsptype) . " csv_claims table</p>" . PHP_EOL;
480 csv_edihist_log("edih_disp_x12trans: Did not find $trace in type $rsptype csv_claims table");
482 } elseif ($clm01) {
483 $str_htm .= edih_277_html($fn, $clm01);
484 } elseif ($bht03) {
485 $str_htm .= edih_277_html($fn, $bht03);
486 } else {
487 $str_htm .= edih_display_text($fn, $ft);
489 } elseif ($fn && $ft == 'f835') {
490 if ($clm01) {
491 if ($summary == 'yes') {
492 $str_htm .= edih_835_html($fn, '', $clm01, true);
493 } else {
494 $str_htm .= edih_835_html($fn, '', $clm01);
496 } elseif ($trace) {
497 $str_htm .= edih_835_html($fn, $trace);
500 } else {
501 $str_htm .= 'error: could not process request.';
504 return $str_htm;
508 * display file uploaded from x12 File tab
509 * wrap individual transactions in accordian jquery ui widget
511 * @uses csv_check_x12_obj()
512 * @uses edih_271_transaction_html()
513 * @uses edih_278_transaction_html()
514 * @uses edih_277_transaction_html()
515 * @uses edih_835_html_page()
516 * @uses edih_display_text()
518 * @param string path to x12 file
519 * @return string
521 function edih_disp_x12file()
524 $str_htm = '';
525 $fn = $ft = $icn = $trace = $rsptype = $format = '';
527 if (isset($_POST['x12_html'])) {
528 $htmval = filter_input(INPUT_POST, 'x12_html', FILTER_DEFAULT);
529 $format = ($htmval == 'html') ? 'htm' : 'seg';
530 $upldir = csv_edih_tmpdir();
531 } else {
532 $format = 'seg';
535 // post request from x12 file tab
536 if (count($_FILES) && isset($_FILES['fileUplx12'])) {
537 $fnupl = $_FILES['fileUplx12']['name'];
538 // the upload files validator
539 $f_array = edih_upload_files();
541 if (is_array($f_array) && count($f_array)) {
542 // was file rejected?
543 if (isset($f_array['reject'])) {
544 $fn = (count($f_array['reject'][0])) ? $f_array['reject'][0]['name'] : '';
545 $cmt = (count($f_array['reject'][0])) ? $f_array['reject'][0]['comment'] : '';
546 $str_htm .= "<p>Rejected file:</p>" . PHP_EOL;
547 $str_htm .= "<p>" . text($fn) . "<br />" . PHP_EOL;
548 $str_htm .= " -- " . text($cmt) . "</p>" . PHP_EOL;
550 csv_edihist_log("edih_disp_x12file: rejected file $fn comment: $cmt");
552 return $str_htm;
553 } else {
554 $fnar = reset($f_array); // type filename array
555 $ft = key($f_array); // type
556 $fn1 = $f_array[$ft][0]; //$upldir.DS.
557 $fn = csv_check_filepath($fn1);
558 csv_edihist_log("edih_disp_x12file: submitted POST $format $ft $fn1 $fnupl");
560 if (!$fn) {
561 $str_htm .= "<p>Path error for " . text($fn1) . "</p>" . PHP_EOL;
562 csv_edihist_log("edih_disp_x12file: Path error for $fn1");
563 return $str_htm;
566 } else {
567 $str_htm .= "<p>File not accepted " . text($fnupl) . "</p>" . PHP_EOL;
568 csv_edihist_log("edih_disp_x12file: File not accepted $fnupl");
569 return $str_htm;
571 } elseif (isset($_GET['gtbl']) && $_GET['gtbl'] == 'file') {
572 // this is a GET request from csv files table
573 // assemble variables
574 $fn = isset($_GET['fname']) ? filter_input(INPUT_GET, 'fname', FILTER_DEFAULT) : '';
575 $ft = isset($_GET['ftype']) ? filter_input(INPUT_GET, 'ftype', FILTER_DEFAULT) : '';
576 $icn = isset($_GET['icn']) ? filter_input(INPUT_GET, 'icn', FILTER_DEFAULT) : '';
577 $trace = isset($_GET['trace']) ? filter_input(INPUT_GET, 'trace', FILTER_DEFAULT) : '';
578 $rsptype = isset($_GET['rsptype']) ? filter_input(INPUT_GET, 'rsptype', FILTER_DEFAULT) : '';
579 $format = isset($_GET['fmt']) ? filter_input(INPUT_GET, 'fmt', FILTER_DEFAULT) : '';
581 } else {
582 $str_htm .= "<p>Error: No request received by server</p>" . PHP_EOL;
583 csv_edihist_log("edih_disp_x12file: No request received by server");
584 return $str_htm;
588 if (!$fn) {
589 if ($ft && $icn) {
590 $fnr = csv_file_by_controlnum($ft, $icn);
591 $fn = csv_check_filepath($fnr);
592 } elseif ($ft && $trace && $rsptype) {
593 $fnr = csv_file_by_trace($trace, $ft, $rsptype);
594 $fn = csv_check_filepath($fnr);
595 $ft = $rsptype;
596 $trace = '';
597 } elseif ($ft == 'f835' && $trace) {
598 $fnr = csv_file_by_trace($trace, $ft, $rsptype);
599 $fn = csv_check_filepath($fnr);
600 } elseif ($ft == 'f997' && $trace && $rsptype) {
601 $fnr = csv_file_by_controlnum($rsptype, $trace);
602 $fn = csv_check_filepath($fnr);
603 $ft = $rsptype;
604 $trace = '';
605 if (!$fn) {
606 $str_htm .= "<p>997/999 Trace value " . text($trace) . " not found for type " . text($rsptype) . "</p>" . PHP_EOL;
607 csv_edihist_log("edih_disp_x12file: 997/999 Trace value $trace not found for type $rsptype");
608 return $str_htm;
613 if (!$fn) {
614 $str_htm .= "<p>Name error for file: type " . text($ft) . " icn " . text($icn) . " trace " . text($trace) . " rsp " . text($rsptype) . "</p>" . PHP_EOL;
615 csv_edihist_log("edih_disp_x12file: Name error for file: type $ft icn $icn trace $trace rsp $rsptype");
616 return $str_htm;
620 if ($format == 'seg') {
621 if ($ft == 'f835' && $trace) {
622 $str_htm .= edih_display_text($fn, $ft, $trace, true);
623 } elseif ($icn) {
624 $str_htm .= edih_display_text($fn, $ft, $icn, true);
625 } else {
626 $str_htm .= edih_display_text($fn, $ft);
629 csv_edihist_log("edih_disp_x12file: segments display $fn");
631 return $str_htm;
634 // request is for html display
635 // now go through each file type
636 // 'HB'=>'271', 'HS'=>'270', 'HR'=>'276', 'HI'=>'278','HN'=>'277',
637 // 'HP'=>'835', 'FA'=>'999', 'HC'=>'837');
638 if ($ft == 'f271' || $ft == 'f270') {
639 $str_htm .= edih_271_html($fn);
640 //$str_htm .= "</body>".PHP_EOL."</html>".PHP_EOL;
641 } elseif ($ft == 'f276' || $ft == 'f277') {
642 $str_htm .= edih_277_html($fn);
643 //$str_htm .= "</body>".PHP_EOL."</html>".PHP_EOL;
644 } elseif ($ft == 'f278') {
645 $str_htm .= edih_278_html($fn);
646 //$str_htm .= "</body>".PHP_EOL."</html>".PHP_EOL;
647 } elseif ($ft == 'f835') {
648 $str_htm = edih_835_html($fn, $trace);
649 //$str_htm .= "</body>".PHP_EOL."</html>".PHP_EOL;
650 } else {
651 // no html format for this type
652 // object is created in edih_display_text function
653 // edih_display_text($filepath, $filetype='', $claimid='', $trace=false, $err_info='')
654 $str_htm .= edih_display_text($fn, $ft);
655 //$str_htm .= "</body>".PHP_EOL."</html>".PHP_EOL;
659 return $str_htm;
664 * csv tables filter input and generate table
666 * @uses csv_to_html()
667 * @return string
669 function edih_disp_csvtable()
672 $str_html = '';
673 $prd = (isset($_GET['csv_period'])) ? filter_input(INPUT_GET, 'csv_period', FILTER_DEFAULT) : '';
674 $dts = (isset($_GET['csv_date_start'])) ? filter_input(INPUT_GET, 'csv_date_start', FILTER_SANITIZE_NUMBER_INT) : '';
675 $dte = (isset($_GET['csv_date_end'])) ? filter_input(INPUT_GET, 'csv_date_end', FILTER_SANITIZE_NUMBER_INT) : '';
676 $csvfile = (isset($_GET['csvtables'])) ? filter_input(INPUT_GET, 'csvtables', FILTER_DEFAULT) : '';
678 // debug
679 csv_edihist_log("edih_disp_csvtable: $csvfile period $prd datestart $dts dateend $dte");
681 if ($dts && strpos($dts, '-') != 4) {
682 if (strlen($_GET['csv_date_start']) == 10 && strpos($_GET['csv_date_start'], '/') == 4) {
683 $dts = str_replace('/', '-', $dts);
684 } else {
685 $str_html = "<p>Date " . text($dts) . " must be in YYYY-MM-DD format, no / or . please</p>" . PHP_EOL;
686 csv_edihist_log("invalid date $dts submitted for csv_table filter");
687 return $str_html;
691 if ($dte && strpos($dte, '-') != 4) {
692 if (strlen($_GET['csv_date_end']) == 10 && strpos($_GET['csv_date_end'], '/') == 4) {
693 $dte = str_replace('/', '-', $dte);
694 } else {
695 $dte = '';
699 if (!$csvfile || $csvfile == null || $csvfile === false) {
700 // here we have an error and must quit
701 $str_html = "<p>Error in CSV table name </p>" . PHP_EOL;
702 return $str_html;
703 } else {
704 $tp_ar = explode('_', $csvfile);
705 $tbl_type = ($tp_ar[0] == 'claims') ? 'claim' : 'file';
706 $f_type = strval($tp_ar[1]);
707 if (ctype_digit($f_type)) {
708 $f_type = 'f' . $f_type;
712 $str_html = edih_csv_to_html($f_type, $tbl_type, $prd, $dts, $dte);
714 return $str_html;
718 function edih_disp_clmhist()
721 if (isset($_GET['hist_enctr'])) {
722 $enctr = filter_input(INPUT_GET, 'hist_enctr', FILTER_DEFAULT);
723 if ($enctr) {
724 $str_html = edih_claim_history($enctr);
725 } else {
726 $str_html = "Invalid or unknown encounter number" . PHP_EOL;
728 } else {
729 $str_html = "Invalid or unknown encounter number" . PHP_EOL;
732 return $str_html;
737 * function to check whether an era payment has been processed and applied
739 * @uses sqlQuery()
741 * @return string
743 function edih_disp_era_processed()
746 $str_html = '';
747 $ckno = filter_input(INPUT_GET, 'tracecheck', FILTER_DEFAULT);
748 if ($ckno) {
749 $srchval = 'ePay - ' . $ckno;
750 // reference like '%".$srchval."%'"
751 $row = sqlQuery("SELECT reference, pay_total, global_amount FROM ar_session WHERE reference = ?", array($srchval));
752 if (!empty($row)) {
753 $str_html .= "trace {$row['reference']} total \${$row['pay_total']}";
754 if ($row['global_amount'] === '0' || $row['global_amount'] === '0.00') {
755 $str_html .= " fully allocated";
756 } else {
757 $str_html .= " (" . text($row['global_amount']) . " not allocated)";
759 } else {
760 $str_html .= "trace " . text($ckno) . " not posted";
762 } else {
763 $str_html .= "trace " . text($ckno) . " not found";
766 return $str_html;