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
25 * @subpackage ediHistory
28 /* these lines for OpenEMR
32 require_once(dirname(__FILE__
) . "/../globals.php");
35 * this define is used to prevent direct access to the included scripts
36 * which have the corresponding definition commented for now
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", "|");
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
94 if (isset($GLOBALS['OE_SITE_DIR'])) {
95 $edih_base_dir = csv_edih_basedir();
96 $edih_tmp_dir = csv_edih_tmpdir();
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) {
108 if (is_dir($edih_tmp_dir)) {
117 // avoid unitialized variable error
121 $dbg_str = "_GET request ".PHP_EOL
;
122 foreach ($_GET as $k => $v) {
123 $dbg_str .= " $k => $v ";
126 csv_edihist_log($dbg_str);
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') {
145 // === log user access on POST requests ===========
146 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
147 // =====================================
148 if (isset($_POST['NewFiles']) && isset($_FILES['fileUplMulti'])) {
149 // process new files button clicked
150 $html_str = edih_disp_file_upload();
151 } elseif (isset($_POST['viewx12Files']) && isset($_FILES['fileUplx12'])) {
152 // process new files button clicked
153 $html_str = edih_disp_x12file();
154 } elseif (isset($_POST['notes_hidden'])) {
156 $html_str = edih_user_notes();
157 } elseif (isset($_POST['ArchiveRequest'])) {
158 // request to archive edi files
159 $req = filter_input(INPUT_POST
, 'ArchiveRequest', FILTER_DEFAULT
);
160 if ($req == 'requested') {
161 $html_str = edih_disp_archive();
163 $html_str .= "<p>Input Error: for edi files archive function</p>".PHP_EOL
;
165 } elseif (isset($_POST['ArchiveRestore'])) {
166 // request to restore an archive of edi files
167 $req = filter_input(INPUT_POST
, 'ArchiveRestore', FILTER_DEFAULT
);
168 if ($req == 'restore') {
169 $html_str = edih_disp_archive_restore();
171 $html_str .= "<p>Input Error: for edi files archive restore function</p>".PHP_EOL
;
174 // ========= log user access for user commands ===========
175 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
177 $html_str .= "<p>Error: unrecognized value in request</p>".PHP_EOL
;
179 $bg_str = "Unknown POST value: ".PHP_EOL
;
180 foreach ($_POST as $ky => $val) {
181 $bg_str .= "$ky : $val ".PHP_EOL
;
184 csv_edihist_log($bg_str);
185 } // end if (strtolower($_SERVER['REQUEST_METHOD']) == 'post')
187 } elseif (strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
189 if (isset($_GET['srvinfo']) && $_GET['srvinfo'] == 'yes') {
190 // initial ajax request
191 $html_str = edih_php_inivals();
192 } elseif (isset($_GET['csvtbllist'])) {
193 // list of available csv tables
194 $tbl = filter_input(INPUT_GET
, 'csvtbllist', FILTER_DEFAULT
);
197 $html_str = csv_table_select_list();
199 $html_str = json_encode('error');
200 csv_edihist_log("GET error: missing parameter for csv table list");
203 } elseif (isset($_GET['archlist'])) {
204 // list of csv archive files
205 $tbl = filter_input(INPUT_GET
, 'archlist', FILTER_DEFAULT
);
207 $html_str = csv_archive_select_list();
209 $html_str = json_encode('error');
210 csv_edihist_log("GET error: missing parameter for csv archive list");
213 } elseif (isset($_GET['loglist'])) {
214 // initial setup -- populate log file select { loglist: 'yes' },
215 $la = filter_input(INPUT_GET
, 'loglist', FILTER_DEFAULT
);
216 $html_str = edih_disp_logfiles();
217 } elseif (isset($_GET['archivelog'])) {
218 // Notes tab [archive log files if older than 7 days]
219 // ========= log user access for user commands ===========
220 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
221 // =====================================
222 $html_str = edih_disp_logfiles();
223 } elseif (isset($_GET['logshowfile'])) {
224 // New Files tab [ Process New ]
225 // ========= log user access for user commands ===========
226 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
227 // =====================================
228 $html_str = edih_disp_log();
229 } elseif (isset($_GET['ProcessFiles'])) {
230 // New Files tab [ Process New ]
231 // ========= log user access for user commands ===========
232 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
233 // =====================================
234 $html_str = edih_disp_file_process();
235 } elseif (isset($_GET['gtbl'])) {
236 // get from a csv_table
237 // ========= log user access for user commands ===========
238 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
239 // ======================================
240 $gtb = filter_input(INPUT_GET
, 'gtbl', FILTER_DEFAULT
);
242 if ($gtb == 'file') {
243 $html_str = edih_disp_x12file();
244 } elseif ($gtb == 'claim') {
245 $html_str = edih_disp_x12trans();
246 } elseif ($gtb == 'hist') {
247 $chkd = (isset($_GET['chkdenied'])) ?
filter_input(INPUT_GET
, 'chkdenied', FILTER_DEFAULT
) : '';
248 if ($chkd == 'yes') {
249 $html_str = edih_disp_denied_claims();
251 $html_str = edih_disp_x12trans();
254 $html_str = '<p>Input error: missing parameter</p>';
255 csv_edihist_log("GET error: missing parameter, no 'gtbl' value");
257 } elseif (isset($_GET['csvShowTable'])) {
259 // ========= log user access for user commands ===========
260 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
261 // =======================================
262 $html_str = edih_disp_csvtable();
263 } elseif (isset($_GET['hist_enctr'])) {
264 // history for encounter
265 // ========= log user access for user commands ===========
266 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
267 // =======================================
268 $html_str = edih_disp_clmhist();
269 } elseif (isset($_GET['ckprocessed'])) {
270 // whether 835 payment file has been applied to pt balance
271 // ========= log user access for user commands ===========
272 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
273 // =======================================
274 $la = filter_input(INPUT_GET
, 'ckprocessed', FILTER_DEFAULT
);
276 // ajax request on page load
277 $html_str = edih_disp_era_processed();
278 $html_str = "alert('$html_str')";
280 } elseif (isset($_GET['chkdenied'])) {
282 // ========= log user access for user commands ===========
283 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
284 // =====================================
285 $chkd = filter_input(INPUT_GET
, 'chkdenied', FILTER_DEFAULT
);
286 if ($chkd == 'yes') {
287 $html_str = edih_disp_denied_claims();
289 $html_str = '<p>Input error: invalid parameter</p>';
290 csv_edihist_log("GET error: missing parameter, invalid 'chkdenied' value");
292 } elseif (isset($_GET['showlog'])) {
293 // show the edi_history log
294 // ========= log user access for user commands ===========
295 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
296 // =======================================
297 $lgnm = (isset($_GET['log_select'])) ?
filter_input(INPUT_GET
, 'log_select', FILTER_DEFAULT
) : '';
298 $la = (isset($_GET['logshowfile'])) ?
filter_input(INPUT_GET
, 'logshowfile', FILTER_DEFAULT
) : '';
299 if ($la == 'getlog' && $lgnm) {
300 $html_str = csv_log_html($lgnm);
302 $html_str = "Show Log: input parameter error<br />" ;
304 } elseif (isset($_GET['getnotes'])) {
305 // ========= log user access for user commands ===========
306 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
307 // =======================================
308 $la = filter_input(INPUT_GET
, 'getnotes', FILTER_DEFAULT
);
309 $html_str = ($la) ?
edih_user_notes() : "input parameter error<br />";
310 } elseif (isset($_GET['archivereport'])) {
311 // ========= log user access for user commands ===========
312 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
313 // =======================================
314 // data: { period: prd, archivereport: 'yes'),
315 $html_str = edih_disp_archive_report();
317 // ========= log user access for user commands ===========
318 csv_edihist_log("User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a"));
319 // =======================================
320 $html_str = "Error: unknown parameter in request<br />" .PHP_EOL
;
321 $bg_str = "Error GET unknown value ";
322 foreach ($_GET as $ky => $val) {
323 $bg_str .= "$ky : $val ".PHP_EOL
;
326 csv_edihist_log($bg_str);
327 //$html_str .= var_dump($_GET) . PHP_EOL;
330 die("EDI History: invalid input method <br />");
334 $isclear = csv_clear_tmpdir();
336 //echo "file contents remain in $edih_tmp_dir <br />".PHP_EOL;
337 csv_edihist_log("file contents remain in $edih_tmp_dir");
342 csv_edihist_log("no html output!");
343 die("No content in response <br />" . PHP_EOL
);