dump db version
[openemr.git] / interface / billing / edih_main.php
blob777f254014e20271068de9e14f12009553361894
1 <?php
2 /*
3 * edi_history_main.php
5 * Copyright 2012 Kevin McCormick Longview, Texas
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; version 3 or later. You should have
16 * received a copy of the GNU General Public License along with this program;
17 * if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * <http://opensource.org/licenses/gpl-license.php>
22 * @author Kevin McCormick
23 * @link: http://www.open-emr.org
24 * @package OpenEMR
25 * @subpackage ediHistory
28 /* these lines for OpenEMR
32 require_once(dirname(__FILE__) . "/../globals.php");
34 /**
35 * this define is used to prevent direct access to the included scripts
36 * which have the corresponding definition commented for now
38 define('SITE_IN', 1);
40 // define constants
41 // since enounter digits are sequential, digit length should rarely change
42 // however for a startup they may, or a "mask" value of 1000 or 10000
43 // would be a good idea if there are problems with deciphering the pid-encounter
44 // same idea for pid value, but since encounter is unique and always last, it is essential
45 // possibly check the mask value in OpenEMR globals to set this
48 // Try to prevent search for too short encounter value
49 if (!defined("ENCOUNTER_MIN_DIGIT_LENGTH")) {
50 define("ENCOUNTER_MIN_DIGIT_LENGTH", 1);
53 // these delimiters are hardcoded into OpenEMR batch files
54 if (!defined("SEG_ELEM_DELIM")) {
55 define("SEG_ELEM_DELIM", "*");
58 if (!defined("SEG_TERM_DELIM")) {
59 define("SEG_TERM_DELIM", "~");
62 //clearinghouse practice
63 if (!defined("IBR_DELIMITER")) {
64 define("IBR_DELIMITER", "|");
68 if (!defined("DS")) {
69 define("DS", DIRECTORY_SEPARATOR);
73 // path will be "$srcdir/edihistory/filename.php"
74 require_once("$srcdir/edihistory/edih_csv_inc.php"); //dirname(__FILE__) . "/edihist/csv_record_include.php");
75 require_once("$srcdir/edihistory/edih_io.php"); //dirname(__FILE__) . "/edihist/ibr_io.php");
76 require_once("$srcdir/edihistory/edih_x12file_class.php");
77 require_once("$srcdir/edihistory/edih_uploads.php"); //dirname(__FILE__) . "/edihist/ibr_uploads.php");
78 require_once("$srcdir/edihistory/edih_csv_parse.php"); //dirname(__FILE__) . "/edihist/ibr_997_read.php");
79 require_once("$srcdir/edihistory/edih_csv_data.php"); //dirname(__FILE__) . "/edihist/ibr_277_read.php");
80 require_once("$srcdir/edihistory/edih_997_error.php");
81 require_once("$srcdir/edihistory/edih_segments.php");
82 require_once("$srcdir/edihistory/edih_archive.php"); //dirname(__FILE__) . "/edihist/ibr_batch_read.php");
83 require_once("$srcdir/edihistory/edih_271_html.php"); //dirname(__FILE__) . "/edihist/ibr_ack_read.php");
84 require_once("$srcdir/edihistory/edih_277_html.php");
85 require_once("$srcdir/edihistory/edih_278_html.php");
86 require_once("$srcdir/edihistory/edih_835_html.php"); //dirname(__FILE__) . "/edihist/ibr_era_read.php");
87 require_once("$srcdir/edihistory/codes/edih_271_code_class.php"); //dirname(__FILE__) . "/edihist/ibr_code_arrays.php");
88 require_once("$srcdir/edihistory/codes/edih_835_code_class.php"); //dirname(__FILE__) . "/edihist/ibr_status_code_arrays.php");
89 require_once("$srcdir/edihistory/codes/edih_997_codes.php");
91 // php may output line endings with included files
92 ob_clean();
94 if (isset($GLOBALS['OE_SITE_DIR'])) {
95 $edih_base_dir = csv_edih_basedir();
96 $edih_tmp_dir = csv_edih_tmpdir();
97 } else {
98 die("EDI History: Did not get directory path information!");
101 // if we are not set up, create directories and csv files
102 //if (!is_dir(dirname(__FILE__) . '/edihist' . IBR_HISTORY_DIR) ) {
103 if (!is_dir($edih_tmp_dir)) {
105 //echo "setup with base directory: $edih_base_dir <br />" .PHP_EOL;
106 if (csv_setup() == true) {
107 $html_str = '';
108 if (is_dir($edih_tmp_dir)) {
109 csv_clear_tmpdir();
111 } else {
112 print $html_str;
113 exit;
117 // avoid unitialized variable error
118 $html_str = '';
119 // debug
120 if (count($_GET)) {
121 $dbg_str = "_GET request ".PHP_EOL;
122 foreach ($_GET as $k => $v) {
123 $dbg_str .= " $k => $v ";
126 csv_edihist_log($dbg_str);
129 if (count($_POST)) {
130 $dbg_str = "_POST request ".PHP_EOL;
131 foreach ($_POST as $k => $v) {
132 $dbg_str .= " $k => $v ";
135 csv_edihist_log($dbg_str);
139 /* ******* remove functions to separate file ******* */
141 * functions called in the if stanzas are now in edih_io.php
143 if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
144 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
145 csrfNotVerified();
149 // === log user access on POST requests ===========
150 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
151 // =====================================
152 if (isset($_POST['NewFiles']) && isset($_FILES['fileUplMulti'])) {
153 // process new files button clicked
154 $html_str = edih_disp_file_upload();
155 } elseif (isset($_POST['viewx12Files']) && isset($_FILES['fileUplx12'])) {
156 // process new files button clicked
157 $html_str = edih_disp_x12file();
158 } elseif (isset($_POST['notes_hidden'])) {
159 // user notes
160 $html_str = edih_user_notes();
161 } elseif (isset($_POST['ArchiveRequest'])) {
162 // request to archive edi files
163 $req = filter_input(INPUT_POST, 'ArchiveRequest', FILTER_DEFAULT);
164 if ($req == 'requested') {
165 $html_str = edih_disp_archive();
166 } else {
167 $html_str .= "<p>Input Error: for edi files archive function</p>".PHP_EOL;
169 } elseif (isset($_POST['ArchiveRestore'])) {
170 // request to restore an archive of edi files
171 $req = filter_input(INPUT_POST, 'ArchiveRestore', FILTER_DEFAULT);
172 if ($req == 'restore') {
173 $html_str = edih_disp_archive_restore();
174 } else {
175 $html_str .= "<p>Input Error: for edi files archive restore function</p>".PHP_EOL;
177 } else {
178 // ========= log user access for user commands ===========
179 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
180 // ===========
181 $html_str .= "<p>Error: unrecognized value in request</p>".PHP_EOL;
182 // debug
183 $bg_str = "Unknown POST value: ".PHP_EOL;
184 foreach ($_POST as $ky => $val) {
185 $bg_str .= "$ky : $val ".PHP_EOL;
188 csv_edihist_log($bg_str);
189 } // end if (strtolower($_SERVER['REQUEST_METHOD']) == 'post')
191 } elseif (strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
192 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
193 csrfNotVerified();
197 if (isset($_GET['srvinfo']) && $_GET['srvinfo'] == 'yes') {
198 // initial ajax request
199 $html_str = edih_php_inivals();
200 } elseif (isset($_GET['csvtbllist'])) {
201 // list of available csv tables
202 $tbl = filter_input(INPUT_GET, 'csvtbllist', FILTER_DEFAULT);
204 if ($tbl == 'yes') {
205 $html_str = csv_table_select_list();
206 } else {
207 $html_str = json_encode('error');
208 csv_edihist_log("GET error: missing parameter for csv table list");
209 return $html_str;
211 } elseif (isset($_GET['archlist'])) {
212 // list of csv archive files
213 $tbl = filter_input(INPUT_GET, 'archlist', FILTER_DEFAULT);
214 if ($tbl == 'yes') {
215 $html_str = csv_archive_select_list();
216 } else {
217 $html_str = json_encode('error');
218 csv_edihist_log("GET error: missing parameter for csv archive list");
219 return $html_str;
221 } elseif (isset($_GET['loglist'])) {
222 // initial setup -- populate log file select { loglist: 'yes' },
223 $la = filter_input(INPUT_GET, 'loglist', FILTER_DEFAULT);
224 $html_str = edih_disp_logfiles();
225 } elseif (isset($_GET['archivelog'])) {
226 // Notes tab [archive log files if older than 7 days]
227 // ========= log user access for user commands ===========
228 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
229 // =====================================
230 $html_str = edih_disp_logfiles();
231 } elseif (isset($_GET['logshowfile'])) {
232 // New Files tab [ Process New ]
233 // ========= log user access for user commands ===========
234 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
235 // =====================================
236 $html_str = edih_disp_log();
237 } elseif (isset($_GET['ProcessFiles'])) {
238 // New Files tab [ Process New ]
239 // ========= log user access for user commands ===========
240 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
241 // =====================================
242 $html_str = edih_disp_file_process();
243 } elseif (isset($_GET['gtbl'])) {
244 // get from a csv_table
245 // ========= log user access for user commands ===========
246 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
247 // ======================================
248 $gtb = filter_input(INPUT_GET, 'gtbl', FILTER_DEFAULT);
250 if ($gtb == 'file') {
251 $html_str = edih_disp_x12file();
252 } elseif ($gtb == 'claim') {
253 $html_str = edih_disp_x12trans();
254 } elseif ($gtb == 'hist') {
255 $chkd = (isset($_GET['chkdenied'])) ? filter_input(INPUT_GET, 'chkdenied', FILTER_DEFAULT) : '';
256 if ($chkd == 'yes') {
257 $html_str = edih_disp_denied_claims();
258 } else {
259 $html_str = edih_disp_x12trans();
261 } else {
262 $html_str = '<p>Input error: missing parameter</p>';
263 csv_edihist_log("GET error: missing parameter, no 'gtbl' value");
265 } elseif (isset($_GET['csvShowTable'])) {
266 // view a csv table
267 // ========= log user access for user commands ===========
268 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
269 // =======================================
270 $html_str = edih_disp_csvtable();
271 } elseif (isset($_GET['hist_enctr'])) {
272 // history for encounter
273 // ========= log user access for user commands ===========
274 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
275 // =======================================
276 $html_str = edih_disp_clmhist();
277 } elseif (isset($_GET['ckprocessed'])) {
278 // whether 835 payment file has been applied to pt balance
279 // ========= log user access for user commands ===========
280 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
281 // =======================================
282 $la = filter_input(INPUT_GET, 'ckprocessed', FILTER_DEFAULT);
283 if ($la == 'yes') {
284 // ajax request on page load
285 $html_str = edih_disp_era_processed();
286 $html_str = "alert('$html_str')";
288 } elseif (isset($_GET['chkdenied'])) {
289 // files csv table
290 // ========= log user access for user commands ===========
291 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
292 // =====================================
293 $chkd = filter_input(INPUT_GET, 'chkdenied', FILTER_DEFAULT);
294 if ($chkd == 'yes') {
295 $html_str = edih_disp_denied_claims();
296 } else {
297 $html_str = '<p>Input error: invalid parameter</p>';
298 csv_edihist_log("GET error: missing parameter, invalid 'chkdenied' value");
300 } elseif (isset($_GET['showlog'])) {
301 // show the edi_history log
302 // ========= log user access for user commands ===========
303 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
304 // =======================================
305 $lgnm = (isset($_GET['log_select'])) ? filter_input(INPUT_GET, 'log_select', FILTER_DEFAULT) : '';
306 $la = (isset($_GET['logshowfile'])) ? filter_input(INPUT_GET, 'logshowfile', FILTER_DEFAULT) : '';
307 if ($la == 'getlog' && $lgnm) {
308 $html_str = csv_log_html($lgnm);
309 } else {
310 $html_str = "Show Log: input parameter error<br />" ;
312 } elseif (isset($_GET['getnotes'])) {
313 // ========= log user access for user commands ===========
314 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
315 // =======================================
316 $la = filter_input(INPUT_GET, 'getnotes', FILTER_DEFAULT);
317 $html_str = ($la) ? edih_user_notes() : "input parameter error<br />";
318 } elseif (isset($_GET['archivereport'])) {
319 // ========= log user access for user commands ===========
320 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
321 // =======================================
322 // data: { period: prd, archivereport: 'yes'),
323 $html_str = edih_disp_archive_report();
324 } else {
325 // ========= log user access for user commands ===========
326 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
327 // =======================================
328 $html_str = "Error: unknown parameter in request<br />" .PHP_EOL;
329 $bg_str = "Error GET unknown value ";
330 foreach ($_GET as $ky => $val) {
331 $bg_str .= "$ky : $val ".PHP_EOL;
334 csv_edihist_log($bg_str);
335 //$html_str .= var_dump($_GET) . PHP_EOL;
337 } else {
338 die("EDI History: invalid input method <br />");
342 $isclear = csv_clear_tmpdir();
343 if (!$isclear) {
344 //echo "file contents remain in $edih_tmp_dir <br />".PHP_EOL;
345 csv_edihist_log("file contents remain in $edih_tmp_dir");
349 if (!$html_str) {
350 csv_edihist_log("no html output!");
351 die("No content in response <br />" . PHP_EOL);
355 print $html_str;