incremented patch version 5
[openemr.git] / interface / billing / freebtest.php
blobf343870629cf413382d71264a2fc9690a155b4a7
1 <?php
3 include_once("../globals.php");
4 set_time_limit(0);
5 $format = $_GET['format'];
6 $billkey = escapeshellarg($_GET['billkey']);
8 $command = "perl /usr/share/freeb/formatbin/" . $format . ".pl";
9 $command = escapeshellcmd($command);
12 $logfile = "/tmp/log-" . date("Ymd") . "-" . rand() . ".log";
14 $execstring = $command . " " . $billkey . " " . $logfile;
15 echo xl("Running Command: ")."$execstring\n<br>";
16 echo "<p>";
17 echo xl("Please note that this can take a very long time, up to several minutes, your web browser may not appear very active during this time but generating a bill is a
18 complicated process and your web browser is merely waiting for more information.");
19 echo "</p>";
20 echo "<p>";
21 echo xl("You should be running this test if this claim appeared to generate successfully but the actual claim file does not contain any data or only an unfinished portion
22 of the amount of data it is supposed to contain. It is obvious with HCFA claims because they are human readable, with X12 claims it is a more difficult process to determine
23 if the claim is properly complete.");
24 echo xl(" Pecularities in many browsers may mean that the output below enters your screen in sudden jerks and that there are long pauses of several seconds where it
25 appears as though things may have crashed. That is not the case, you will eventually see output coming out line by line. There may be sequential numbers appearing
26 below, this is to indicate that even though nothing else may be displaying there is activity going on. These numbers will be interspersed with the content of the
27 billing and that is normal.");
28 echo "</p>";
29 echo "<p>";
30 echo xl("Depending on the type of bill you are testing you will see HCFA like output on a blank page for HCFA bills, you will see many lines of somewhat garbled text
31 and information if you are testing an X12 claim. That garbled text is the X12 EDI 4010A format. Occasionally you will see odd characters that look like dominoes or
32 squiglies, these are control characters such as page feeds and are normal.");
33 echo "</p>";
34 echo "<p>";
35 echo xl("Please do NOT use your browsers stop or reload button while this page is running unless more than 10 minutes have elapsed, this will not cause the process to
36 stop on the server and will consume uneccesary resources.");
37 echo "</p>";
38 flush();
39 ob_flush;
40 $descriptorspec = array(
41 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
42 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
43 2 => array("pipe", "w") // stderr is a file to write to
46 $process = proc_open($execstring, $descriptorspec, $pipes);
47 if (is_resource($process)) {
48 // $pipes now looks like this:
49 // 0 => writeable handle connected to child stdin
50 // 1 => readable handle connected to child stdout
51 // Any error output will be appended to /tmp/error-output.txt
52 stream_set_blocking($pipes[1],false);
53 stream_set_blocking($pipes[2],false);
55 echo "<pre>";
56 $loop = true;
57 $p1 = true;
58 $p2 = true;
59 $counter = 0;
60 while($loop) {
61 echo sprintf("%04d",$counter) . " ";
62 flush();
64 if (!feof($pipes[1])) {
65 fflush($pipes[1]);
66 $val = fgets($pipes[1], 1024);
67 if (!empty($val)) {
68 echo $val;
69 flush();
72 else {
73 $p1 = false;
75 if (!feof($pipes[2])) {
76 fflush($pipes[2]);
77 $val = fgets($pipes[2], 1024);
78 if (!empty($val)) {
79 echo $val;
80 flush();
83 else {
84 $p2 = false;
86 if (!$p1 && !$p2) {
87 $loop = false;
89 $counter++;
90 usleep(1500000);
92 fclose($pipes[0]);
93 fclose($pipes[1]);
94 fclose($pipes[2]);
95 echo "</pre>";
96 // It is important that you close any pipes before calling
97 // proc_close in order to avoid a deadlock
98 $return_value = proc_close($process);
100 echo "<br>".xl("Claim test has completed running")."\n";