more organization of autoloaded files (#424)
[openemr.git] / interface / reports / edi_271.php
bloba57763280d67c48b576a979807a4b9f15f6a978e
1 <?php
2 // Copyright (C) 2010 MMF Systems, Inc>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 //SANITIZE ALL ESCAPES
10 $sanitize_all_escapes=true;
13 //STOP FAKE REGISTER GLOBALS
14 $fake_register_globals=false;
17 // START - INCLUDE STATEMENTS
18 include_once(dirname(__file__)."/../globals.php");
19 include_once("$srcdir/forms.inc");
20 include_once("$srcdir/billing.inc");
21 include_once("$srcdir/patient.inc");
22 include_once("$srcdir/report.inc");
23 include_once("$srcdir/calendar.inc");
24 include_once("$srcdir/classes/Document.class.php");
25 include_once("$srcdir/classes/Note.class.php");
26 include_once("$srcdir/edi.inc");
28 // END - INCLUDE STATEMENTS
31 // File location (URL or server path)
33 $target = $GLOBALS['edi_271_file_path'];
35 if(isset($_FILES) && !empty($_FILES))
38 $target = $target .time().basename( $_FILES['uploaded']['name']);
40 $FilePath = $target;
42 if ($_FILES['uploaded']['size'] > 350000)
44 $message .= htmlspecialchars( xl('Your file is too large'), ENT_NOQUOTES)."<br>";
48 if ($_FILES['uploaded']['type']!="text/plain")
50 $message .= htmlspecialchars( xl('You may only upload .txt files'), ENT_NOQUOTES)."<br>";
52 if(!isset($message))
54 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
56 $message = htmlspecialchars( xl('The following EDI file has been uploaded').': "'. basename( $_FILES['uploaded']['name']).'"', ENT_NOQUOTES);
58 // Stores the content of the file
59 $Response271= file($FilePath);
61 // Counts the number of lines
62 $LineCount = count($Lines);
64 //This will be a two dimensional array
65 //that holds the content nicely organized
67 $DataSegment271 = array();
68 $Segments271 = array();
70 // We will use this as an index
71 $i = 0;
72 $j = 0;
73 $patientId = "";
75 // Loop through each line
76 foreach($Response271 as $Value)
78 // In the array store this line
79 // with values delimited by ^ (tilt)
80 // as separate array values
82 $DataSegment271[$i] = explode("^", $Value);
85 if(count($DataSegment271[$i])<6)
87 $messageEDI = true;
88 $message = "";
89 if(file_exists($target))
91 unlink($target);
94 else
96 foreach ($DataSegment271[$i] as $datastrings)
99 $Segments271[$j] = explode("*", $datastrings);
101 $segment = $Segments271[$j][0];
104 // Switch Case for Segment
106 switch ($segment)
108 case 'ISA':
110 $j = 0;
112 foreach($Segments271[$j] as $segmentVal){
114 if($j == 6)
116 $x12PartnerId = $segmentVal;
119 $j = $j + 1;
122 break;
124 case 'REF':
126 foreach($Segments271[$j] as $segmentVal){
128 if($segmentVal == "EJ")
130 $patientId = $Segments271[$j][2];
134 break;
136 case 'EB':
138 foreach($Segments271[$j] as $segmentVal){
142 break;
144 case 'MSG':
146 foreach($Segments271[$j] as $segmentVal){
148 if($segment != $segmentVal)
150 eligibility_response_save($segmentVal,$x12PartnerId);
152 eligibility_verification_save($segmentVal,$x12PartnerId,$patientId);
156 break;
164 // Increase the line index
165 $j++;
168 //Increase the line index
169 $i++;
173 else
175 $message .= htmlspecialchars( xl('Sorry, there was a problem uploading your file'), ENT_NOQUOTES). "<br><br>";
180 <html>
181 <head>
182 <?php html_header_show();?>
183 <title><?php echo htmlspecialchars( xl('EDI-271 Response File Upload'), ENT_NOQUOTES); ?></title>
184 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
185 <style type="text/css">
187 /* specifically include & exclude from printing */
188 @media print {
189 #report_parameters {
190 visibility: hidden;
191 display: none;
193 #report_parameters_daterange {
194 visibility: visible;
195 display: inline;
197 #report_results table {
198 margin-top: 0px;
202 /* specifically exclude some from the screen */
203 @media screen {
204 #report_parameters_daterange {
205 visibility: hidden;
206 display: none;
210 </style>
212 <script type="text/javascript" src="../../library/textformat.js"></script>
213 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
214 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script>
216 <script type="text/javascript">
217 function edivalidation(){
219 var mypcc = "<?php echo htmlspecialchars( xl('Required Field Missing: Please choose the EDI-271 file to upload'), ENT_QUOTES);?>";
221 if(document.getElementById('uploaded').value == ""){
222 alert(mypcc);
223 return false;
225 else
227 $("#theform").submit();
231 </script>
233 </head>
234 <body class="body_top">
236 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
237 <?php if(isset($message) && !empty($message))
240 <div style="margin-left:25%;width:50%;color:RED;text-align:center;font-family:arial;font-size:15px;background:#ECECEC;border:1px solid;" ><?php echo $message; ?></div>
241 <?php
242 $message = "";
244 if(isset($messageEDI))
247 <div style="margin-left:25%;width:50%;color:RED;text-align:center;font-family:arial;font-size:15px;background:#ECECEC;border:1px solid;" >
248 <?php echo htmlspecialchars( xl('Please choose the proper formatted EDI-271 file'), ENT_NOQUOTES); ?>
249 </div>
250 <?php
251 $messageEDI = "";
255 <div>
257 <span class='title'><?php echo htmlspecialchars( xl('EDI-271 File Upload'), ENT_NOQUOTES); ?></span>
259 <form enctype="multipart/form-data" name="theform" id="theform" action="edi_271.php" method="POST" onsubmit="return top.restoreSession()">
261 <div id="report_parameters">
262 <table>
263 <tr>
264 <td width='550px'>
265 <div style='float:left'>
266 <table class='text'>
267 <tr>
268 <td style='width:125px;' class='label'> <?php echo htmlspecialchars( xl('Select EDI-271 file'), ENT_NOQUOTES); ?>: </td>
269 <td> <input name="uploaded" id="uploaded" type="file" size=37 /></td>
270 </tr>
271 </table>
272 </div>
273 </td>
274 <td align='left' valign='middle' height="100%">
275 <table style='border-left:1px solid; width:100%; height:100%' >
276 <tr>
277 <td>
278 <div style='margin-left:15px'>
279 <a href='#' class='css_button' onclick='return edivalidation(); '><span><?php echo htmlspecialchars( xl('Upload'), ENT_NOQUOTES); ?></span>
280 </a>
281 </div>
282 </td>
283 </tr>
284 </table>
285 </td>
286 </tr>
287 </table>
288 </div>
291 <input type="hidden" name="form_orderby" value="<?php echo htmlspecialchars( $form_orderby, ENT_QUOTES); ?>" />
292 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
294 </form>
295 </body>
296 </html>