fix: quick fix to enforce support of x509 database connection on install (#6157)
[openemr.git] / interface / billing / edi_271.php
blob5e4d73902f9b4e9c51bbf679998a07f13a0c90db
1 <?php
3 /**
4 * Functions to globally validate and prepare data for sql database insertion.
6 * @package OpenEMR
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;
28 if (!empty($_POST)) {
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'];
36 $batch_log = '';
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');
62 if ($Response271) {
63 $batch_log = EDI270::parseEdi271($Response271);
64 } else {
65 $message = xlt('The following EDI file upload failed to open') . ': "' . text(basename($_FILES['uploaded']['name'])) . '"';
67 } else {
68 $message = xlt('The following EDI file failed save to archive') . ': "' . text(basename($_FILES['uploaded']['name'])) . '"';
70 } else {
71 $message .= xlt('Sorry, there was a problem uploading your file') . "<br /><br />";
74 if ($batch_log && !$GLOBALS['disable_eligibility_log']) {
75 $fn = sprintf(
76 'elig-batch_log_%s.txt',
77 date("Y-m-d:H:i:s")
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 . '"');
85 ob_start();
86 echo $batch_log;
87 exit();
90 <html>
91 <head>
92 <title><?php echo xlt('EDI-271 Response File Upload'); ?></title>
94 <?php Header::setupHeader(); ?>
96 <style>
97 /* specifically include & exclude from printing */
98 @media print {
99 #report_parameters {
100 visibility: hidden;
101 display: none;
103 #report_parameters_daterange {
104 visibility: visible;
105 display: inline;
107 #report_results table {
108 margin-top: 0px;
111 /* specifically exclude some from the screen */
112 @media screen {
113 #report_parameters_daterange {
114 visibility: hidden;
115 display: none;
118 </style>
119 <script>
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 == "") {
123 alert(mypcc);
124 return false;
125 } else {
126 $("#theform").trigger("submit");
129 </script>
130 </head>
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>
135 <?php
136 $message = "";
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'); ?>
141 </div>
142 <?php
143 $messageEDI = "";
144 } ?>
145 <div>
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">
150 <table>
151 <tr>
152 <td width='550px'>
153 <div class='float-left'>
154 <table class='text'>
155 <tr>
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>
158 </tr>
159 </table>
160 </div>
161 </td>
162 <td align='left' valign='middle' height="100%">
163 <table class='w-100 h-100' style='border-left:1px solid;'>
164 <tr>
165 <td>
166 <div style='margin-left:15px'>
167 <a href='#' class='btn btn-primary' onclick='return edivalidation(); '><span><?php echo xlt('Upload'); ?></span>
168 </a>
169 </div>
170 </td>
171 </tr>
172 </table>
173 </td>
174 </tr>
175 </table>
176 </div>
177 <input type="hidden" name="form_orderby" value="<?php echo attr($form_orderby ?? ''); ?>" />
178 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
179 </form>
180 </body>
181 </html>