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