4 * Functions to globally validate and prepare data for sql database insertion.
7 * @link http://www.open-emr.org
8 * @author MMF Systems, Inc
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @author Jerry Padgett <sjpadgett@gmail.com>
11 * @copyright Copyright (c) 2010 MMF Systems, Inc
12 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2019-2020 Jerry Padgett <sjpadgett@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once(dirname(__file__
) . "/../globals.php");
18 require_once("$srcdir/forms.inc.php");
19 require_once("$srcdir/patient.inc.php");
20 require_once("$srcdir/report.inc.php");
21 require_once("$srcdir/calendar.inc.php");
23 use OpenEMR\Billing\EDI270
;
24 use OpenEMR\Common\Crypto\CryptoGen
;
25 use OpenEMR\Common\Csrf\CsrfUtils
;
26 use OpenEMR\Core\Header
;
29 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
30 CsrfUtils
::csrfNotVerified();
34 // File location (URL or server path)
35 $target = $GLOBALS['edi_271_file_path'];
38 if (isset($_FILES) && !empty($_FILES)) {
39 $target = $target . time() . basename($_FILES['uploaded']['name']);
41 if ($_FILES['uploaded']['size'] > 350000) {
42 $message .= xlt('Your file is too large') . "<br />";
44 if (mime_content_type($_FILES['uploaded']['tmp_name']) != "text/plain") {
45 $message .= xlt('You may only upload .txt files') . "<br />";
47 if (preg_match("/(.*)\.(inc|php|php7|php8)$/i", $_FILES['uploaded']['name']) !== 0) {
48 $message .= xlt('Invalid file type.') . "<br />";
50 if (!isset($message)) {
51 $cryptoGen = new CryptoGen();
52 $uploadedFile = file_get_contents($_FILES['uploaded']['tmp_name']);
53 if ($GLOBALS['drive_encryption']) {
54 $uploadedFile = $cryptoGen->encryptStandard($uploadedFile, null, 'database');
56 if (file_put_contents($target, $uploadedFile)) {
57 $message = xlt('The following EDI file has been uploaded') . ': "' . text(basename($_FILES['uploaded']['name'])) . '"';
58 $Response271 = file_get_contents($target);
59 if ($cryptoGen->cryptCheckStandard($Response271)) {
60 $Response271 = $cryptoGen->decryptStandard($Response271, null, 'database');
63 $batch_log = EDI270
::parseEdi271($Response271);
65 $message = xlt('The following EDI file upload failed to open') . ': "' . text(basename($_FILES['uploaded']['name'])) . '"';
68 $message = xlt('The following EDI file failed save to archive') . ': "' . text(basename($_FILES['uploaded']['name'])) . '"';
71 $message .= xlt('Sorry, there was a problem uploading your file') . "<br /><br />";
74 if ($batch_log && !$GLOBALS['disable_eligibility_log']) {
76 'elig-batch_log_%s.txt',
79 $batch_log = str_replace('~', "~\r", $batch_log);
80 while (@ob_end_flush
()) {
82 header('Content-Type: text/plain');
83 header("Content-Length: " . strlen($batch_log));
84 header('Content-Disposition: attachment; filename="' . $fn . '"');
92 <title
><?php
echo xlt('EDI-271 Response File Upload'); ?
></title
>
94 <?php Header
::setupHeader(); ?
>
97 /* specifically include & exclude from printing */
103 #report_parameters_daterange {
107 #report_results table {
111 /* specifically exclude some from the screen */
113 #report_parameters_daterange {
120 function edivalidation() {
121 var mypcc
= <?php
echo xlj('Required Field Missing: Please choose the EDI-271 file to upload'); ?
>;
122 if (document
.getElementById('uploaded').value
== "") {
126 $
("#theform").trigger("submit");
131 <body
class="body_top">
132 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
133 <?php
if (isset($message) && !empty($message)) { ?
>
134 <div
class="text-danger text-center bg-light w-50" style
="margin-left:25%; font-family: 'Arial', sans-serif; font-size:15px; border:1px solid;"><?php
echo $message; ?
></div
>
138 if (isset($messageEDI)) { ?
>
139 <div
class="text-danger text-center bg-light w-50" style
="margin-left:25%; font-family: 'Arial', sans-serif; font-size:15px; border:1px solid;">
140 <?php
echo xlt('Please choose the proper formatted EDI-271 file'); ?
>
146 <span
class='title'><?php
echo xlt('EDI-271 File Upload'); ?
></span
>
147 <form enctype
="multipart/form-data" name
="theform" id
="theform" action
="edi_271.php" method
="POST" onsubmit
="return top.restoreSession()">
148 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
149 <div id
="report_parameters">
153 <div
class='float-left'>
156 <td style
='width:125px;' class='label_custom'> <?php
echo xlt('Select EDI-271 file'); ?
>: </td
>
157 <td
> <input name
="uploaded" id
="uploaded" type
="file" size
="37" /></td
>
162 <td align
='left' valign
='middle' height
="100%">
163 <table
class='w-100 h-100' style
='border-left:1px solid;'>
166 <div style
='margin-left:15px'>
167 <a href
='#' class='btn btn-primary' onclick
='return edivalidation(); '><span
><?php
echo xlt('Upload'); ?
></span
>
177 <input type
="hidden" name
="form_orderby" value
="<?php echo attr($form_orderby ?? ''); ?>" />
178 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>