fix: fix ci (#7614)
[openemr.git] / interface / billing / edih_main.php
blob7c7d5ccf9a170306fc3f213bbf536bae9c29a199
1 <?php
3 /**
4 * edi_history_main.php
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Kevin McCormick Longview, Texas
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2012 Kevin McCormick Longview, Texas
11 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once(dirname(__FILE__) . "/../globals.php");
17 use OpenEMR\Common\Csrf\CsrfUtils;
19 /**
20 * this define is used to prevent direct access to the included scripts
21 * which have the corresponding definition commented for now
23 define('SITE_IN', 1);
25 // define constants
26 // since enounter digits are sequential, digit length should rarely change
27 // however for a startup they may, or a "mask" value of 1000 or 10000
28 // would be a good idea if there are problems with deciphering the pid-encounter
29 // same idea for pid value, but since encounter is unique and always last, it is essential
30 // possibly check the mask value in OpenEMR globals to set this
33 // Try to prevent search for too short encounter value
34 if (!defined("ENCOUNTER_MIN_DIGIT_LENGTH")) {
35 define("ENCOUNTER_MIN_DIGIT_LENGTH", 1);
38 // these delimiters are hardcoded into OpenEMR batch files
39 if (!defined("SEG_ELEM_DELIM")) {
40 define("SEG_ELEM_DELIM", "*");
43 if (!defined("SEG_TERM_DELIM")) {
44 define("SEG_TERM_DELIM", "~");
47 //clearinghouse practice
48 if (!defined("IBR_DELIMITER")) {
49 define("IBR_DELIMITER", "|");
53 if (!defined("DS")) {
54 define("DS", DIRECTORY_SEPARATOR);
58 // path will be "$srcdir/edihistory/filename.php"
59 require_once("$srcdir/edihistory/edih_csv_inc.php"); //dirname(__FILE__) . "/edihist/csv_record_include.php");
60 require_once("$srcdir/edihistory/edih_io.php"); //dirname(__FILE__) . "/edihist/ibr_io.php");
61 require_once("$srcdir/edihistory/edih_x12file_class.php");
62 require_once("$srcdir/edihistory/edih_uploads.php"); //dirname(__FILE__) . "/edihist/ibr_uploads.php");
63 require_once("$srcdir/edihistory/edih_csv_parse.php"); //dirname(__FILE__) . "/edihist/ibr_997_read.php");
64 require_once("$srcdir/edihistory/edih_csv_data.php"); //dirname(__FILE__) . "/edihist/ibr_277_read.php");
65 require_once("$srcdir/edihistory/edih_997_error.php");
66 require_once("$srcdir/edihistory/edih_segments.php");
67 require_once("$srcdir/edihistory/edih_archive.php"); //dirname(__FILE__) . "/edihist/ibr_batch_read.php");
68 require_once("$srcdir/edihistory/edih_271_html.php"); //dirname(__FILE__) . "/edihist/ibr_ack_read.php");
69 require_once("$srcdir/edihistory/edih_277_html.php");
70 require_once("$srcdir/edihistory/edih_278_html.php");
71 require_once("$srcdir/edihistory/edih_835_html.php"); //dirname(__FILE__) . "/edihist/ibr_era_read.php");
72 require_once("$srcdir/edihistory/codes/edih_271_code_class.php"); //dirname(__FILE__) . "/edihist/ibr_code_arrays.php");
73 require_once("$srcdir/edihistory/codes/edih_835_code_class.php"); //dirname(__FILE__) . "/edihist/ibr_status_code_arrays.php");
74 require_once("$srcdir/edihistory/codes/edih_997_codes.php");
76 // php may output line endings with included files
77 ob_clean();
79 if (isset($GLOBALS['OE_SITE_DIR'])) {
80 $edih_base_dir = csv_edih_basedir();
81 $edih_tmp_dir = csv_edih_tmpdir();
82 } else {
83 die("EDI History: Did not get directory path information!");
86 // if we are not set up, create directories and csv files
87 //if (!is_dir(dirname(__FILE__) . '/edihist' . IBR_HISTORY_DIR) ) {
88 if (!is_dir($edih_tmp_dir)) {
90 //echo "setup with base directory: $edih_base_dir <br />" .PHP_EOL;
91 if (csv_setup() == true) {
92 $html_str = '';
93 if (is_dir($edih_tmp_dir)) {
94 csv_clear_tmpdir();
96 } else {
97 print $html_str;
98 exit;
102 // avoid unitialized variable error
103 $html_str = '';
104 // debug
105 if (count($_GET)) {
106 $dbg_str = "_GET request " . PHP_EOL;
107 foreach ($_GET as $k => $v) {
108 $dbg_str .= " $k => $v ";
111 csv_edihist_log($dbg_str);
114 if (count($_POST)) {
115 $dbg_str = "_POST request " . PHP_EOL;
116 foreach ($_POST as $k => $v) {
117 $dbg_str .= " $k => $v ";
120 csv_edihist_log($dbg_str);
124 /* ******* remove functions to separate file ******* */
126 * functions called in the if stanzas are now in edih_io.php
128 if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
129 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
130 CsrfUtils::csrfNotVerified();
134 // === log user access on POST requests ===========
135 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
136 // =====================================
137 if (isset($_POST['NewFiles']) && isset($_FILES['fileUplMulti'])) {
138 // process new files button clicked
139 $html_str = edih_disp_file_upload();
140 } elseif (isset($_POST['viewx12Files']) && isset($_FILES['fileUplx12'])) {
141 // process new files button clicked
142 $html_str = edih_disp_x12file();
143 } elseif (isset($_POST['notes_hidden'])) {
144 // user notes
145 $html_str = edih_user_notes();
146 } elseif (isset($_POST['ArchiveRequest'])) {
147 // request to archive edi files
148 $req = filter_input(INPUT_POST, 'ArchiveRequest', FILTER_DEFAULT);
149 if ($req == 'requested') {
150 $html_str = edih_disp_archive();
151 } else {
152 $html_str .= "<p>Input Error: for edi files archive function</p>" . PHP_EOL;
154 } elseif (isset($_POST['ArchiveRestore'])) {
155 // request to restore an archive of edi files
156 $req = filter_input(INPUT_POST, 'ArchiveRestore', FILTER_DEFAULT);
157 if ($req == 'restore') {
158 $html_str = edih_disp_archive_restore();
159 } else {
160 $html_str .= "<p>Input Error: for edi files archive restore function</p>" . PHP_EOL;
162 } else {
163 // ========= log user access for user commands ===========
164 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
165 // ===========
166 $html_str .= "<p>Error: unrecognized value in request</p>" . PHP_EOL;
167 // debug
168 $bg_str = "Unknown POST value: " . PHP_EOL;
169 foreach ($_POST as $ky => $val) {
170 $bg_str .= "$ky : $val " . PHP_EOL;
173 csv_edihist_log($bg_str);
174 } // end if (strtolower($_SERVER['REQUEST_METHOD']) == 'post')
176 } elseif (strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
177 if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
178 CsrfUtils::csrfNotVerified();
182 if (isset($_GET['srvinfo']) && $_GET['srvinfo'] == 'yes') {
183 // initial ajax request
184 $html_str = edih_php_inivals();
185 } elseif (isset($_GET['csvtbllist'])) {
186 // list of available csv tables
187 $tbl = filter_input(INPUT_GET, 'csvtbllist', FILTER_DEFAULT);
189 if ($tbl == 'yes') {
190 $html_str = csv_table_select_list();
191 } else {
192 $html_str = json_encode('error');
193 csv_edihist_log("GET error: missing parameter for csv table list");
194 return $html_str;
196 } elseif (isset($_GET['archlist'])) {
197 // list of csv archive files
198 $tbl = filter_input(INPUT_GET, 'archlist', FILTER_DEFAULT);
199 if ($tbl == 'yes') {
200 $html_str = csv_archive_select_list();
201 } else {
202 $html_str = json_encode('error');
203 csv_edihist_log("GET error: missing parameter for csv archive list");
204 return $html_str;
206 } elseif (isset($_GET['loglist'])) {
207 // initial setup -- populate log file select { loglist: 'yes' },
208 $la = filter_input(INPUT_GET, 'loglist', FILTER_DEFAULT);
209 $html_str = edih_disp_logfiles();
210 } elseif (isset($_GET['archivelog'])) {
211 // Notes tab [archive log files if older than 7 days]
212 // ========= log user access for user commands ===========
213 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
214 // =====================================
215 $html_str = edih_disp_logfiles();
216 } elseif (isset($_GET['logshowfile'])) {
217 // New Files tab [ Process New ]
218 // ========= log user access for user commands ===========
219 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
220 // =====================================
221 $html_str = edih_disp_log();
222 } elseif (isset($_GET['ProcessFiles'])) {
223 // New Files tab [ Process New ]
224 // ========= log user access for user commands ===========
225 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
226 // =====================================
227 $html_str = edih_disp_file_process();
228 } elseif (isset($_GET['gtbl'])) {
229 // get from a csv_table
230 // ========= log user access for user commands ===========
231 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
232 // ======================================
233 $gtb = filter_input(INPUT_GET, 'gtbl', FILTER_DEFAULT);
235 if ($gtb == 'file') {
236 $html_str = edih_disp_x12file();
237 } elseif ($gtb == 'claim') {
238 $html_str = edih_disp_x12trans();
239 } elseif ($gtb == 'hist') {
240 $chkd = (isset($_GET['chkdenied'])) ? filter_input(INPUT_GET, 'chkdenied', FILTER_DEFAULT) : '';
241 if ($chkd == 'yes') {
242 $html_str = edih_disp_denied_claims();
243 } else {
244 $html_str = edih_disp_x12trans();
246 } else {
247 $html_str = '<p>Input error: missing parameter</p>';
248 csv_edihist_log("GET error: missing parameter, no 'gtbl' value");
250 } elseif (isset($_GET['csvShowTable'])) {
251 // view a csv table
252 // ========= log user access for user commands ===========
253 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
254 // =======================================
255 $html_str = edih_disp_csvtable();
256 } elseif (isset($_GET['hist_enctr'])) {
257 // history for encounter
258 // ========= log user access for user commands ===========
259 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
260 // =======================================
261 $html_str = edih_disp_clmhist();
262 } elseif (isset($_GET['ckprocessed'])) {
263 // whether 835 payment file has been applied to pt balance
264 // ========= log user access for user commands ===========
265 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
266 // =======================================
267 $la = filter_input(INPUT_GET, 'ckprocessed', FILTER_DEFAULT);
268 if ($la == 'yes') {
269 // ajax request on page load
270 $html_str = edih_disp_era_processed();
271 $html_str = "alert('$html_str')";
273 } elseif (isset($_GET['chkdenied'])) {
274 // files csv table
275 // ========= log user access for user commands ===========
276 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
277 // =====================================
278 $chkd = filter_input(INPUT_GET, 'chkdenied', FILTER_DEFAULT);
279 if ($chkd == 'yes') {
280 $html_str = edih_disp_denied_claims();
281 } else {
282 $html_str = '<p>Input error: invalid parameter</p>';
283 csv_edihist_log("GET error: missing parameter, invalid 'chkdenied' value");
285 } elseif (isset($_GET['showlog'])) {
286 // show the edi_history log
287 // ========= log user access for user commands ===========
288 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
289 // =======================================
290 $lgnm = (isset($_GET['log_select'])) ? filter_input(INPUT_GET, 'log_select', FILTER_DEFAULT) : '';
291 $la = (isset($_GET['logshowfile'])) ? filter_input(INPUT_GET, 'logshowfile', FILTER_DEFAULT) : '';
292 if ($la == 'getlog' && $lgnm) {
293 $html_str = csv_log_html($lgnm);
294 } else {
295 $html_str = "Show Log: input parameter error<br />" ;
297 } elseif (isset($_GET['getnotes'])) {
298 // ========= log user access for user commands ===========
299 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
300 // =======================================
301 $la = filter_input(INPUT_GET, 'getnotes', FILTER_DEFAULT);
302 $html_str = ($la) ? edih_user_notes() : "input parameter error<br />";
303 } elseif (isset($_GET['archivereport'])) {
304 // ========= log user access for user commands ===========
305 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
306 // =======================================
307 // data: { period: prd, archivereport: 'yes'),
308 $html_str = edih_disp_archive_report();
309 } else {
310 // ========= log user access for user commands ===========
311 csv_edihist_log("User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a"));
312 // =======================================
313 $html_str = "Error: unknown parameter in request<br />" . PHP_EOL;
314 $bg_str = "Error GET unknown value ";
315 foreach ($_GET as $ky => $val) {
316 $bg_str .= "$ky : $val " . PHP_EOL;
319 csv_edihist_log($bg_str);
320 //$html_str .= var_dump($_GET) . PHP_EOL;
322 } else {
323 die("EDI History: invalid input method <br />");
327 $isclear = csv_clear_tmpdir();
328 if (!$isclear) {
329 //echo "file contents remain in $edih_tmp_dir <br />".PHP_EOL;
330 csv_edihist_log("file contents remain in $edih_tmp_dir");
334 if (!$html_str) {
335 csv_edihist_log("no html output!");
336 die("No content in response <br />" . PHP_EOL);
340 print $html_str;