switch to explode since split deprecated
[openemr.git] / interface / reports / edi_271.php
blobb6bd08fba455aa3096d5a3d5865b9d86efb526ea
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/sqlconf.php");
27 include_once("$srcdir/edi.inc");
29 // END - INCLUDE STATEMENTS
32 // File location (URL or server path)
34 $target = $GLOBALS['edi_271_file_path'];
36 if(isset($_FILES) && !empty($_FILES))
39 $target = $target .time().basename( $_FILES['uploaded']['name']);
41 $FilePath = $target;
43 if ($_FILES['uploaded']['size'] > 350000)
45 $message .= htmlspecialchars( xl('Your file is too large'), ENT_NOQUOTES)."<br>";
49 if ($_FILES['uploaded']['type']!="text/plain")
51 $message .= htmlspecialchars( xl('You may only upload .txt files'), ENT_NOQUOTES)."<br>";
53 if(!isset($message))
55 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
57 $message = htmlspecialchars( xl('The following EDI file has been uploaded').': "'. basename( $_FILES['uploaded']['name']).'"', ENT_NOQUOTES);
59 // Stores the content of the file
60 $Response271= file($FilePath);
62 // Counts the number of lines
63 $LineCount = count($Lines);
65 //This will be a two dimensional array
66 //that holds the content nicely organized
68 $DataSegment271 = array();
69 $Segments271 = array();
71 // We will use this as an index
72 $i = 0;
73 $j = 0;
74 $patientId = "";
76 // Loop through each line
77 foreach($Response271 as $Value)
79 // In the array store this line
80 // with values delimited by ^ (tilt)
81 // as separate array values
83 $DataSegment271[$i] = explode("^", $Value);
86 if(count($DataSegment271[$i])<6)
88 $messageEDI = true;
89 $message = "";
90 if(file_exists($target))
92 unlink($target);
95 else
97 foreach ($DataSegment271[$i] as $datastrings)
100 $Segments271[$j] = explode("*", $datastrings);
102 $segment = $Segments271[$j][0];
105 // Switch Case for Segment
107 switch ($segment)
109 case 'ISA':
111 $j = 0;
113 foreach($Segments271[$j] as $segmentVal){
115 if($j == 6)
117 $x12PartnerId = $segmentVal;
120 $j = $j + 1;
123 break;
125 case 'REF':
127 foreach($Segments271[$j] as $segmentVal){
129 if($segmentVal == "EJ")
131 $patientId = $Segments271[$j][2];
135 break;
137 case 'EB':
139 foreach($Segments271[$j] as $segmentVal){
143 break;
145 case 'MSG':
147 foreach($Segments271[$j] as $segmentVal){
149 if($segment != $segmentVal)
151 eligibility_response_save($segmentVal,$x12PartnerId);
153 eligibility_verification_save($segmentVal,$x12PartnerId,$patientId);
157 break;
165 // Increase the line index
166 $j++;
169 //Increase the line index
170 $i++;
174 else
176 $message .= htmlspecialchars( xl('Sorry, there was a problem uploading your file'), ENT_NOQUOTES). "<br><br>";
181 <html>
182 <head>
183 <?php html_header_show();?>
184 <title><?php echo htmlspecialchars( xl('EDI-271 Response File Upload'), ENT_NOQUOTES); ?></title>
185 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
186 <style type="text/css">
188 /* specifically include & exclude from printing */
189 @media print {
190 #report_parameters {
191 visibility: hidden;
192 display: none;
194 #report_parameters_daterange {
195 visibility: visible;
196 display: inline;
198 #report_results table {
199 margin-top: 0px;
203 /* specifically exclude some from the screen */
204 @media screen {
205 #report_parameters_daterange {
206 visibility: hidden;
207 display: none;
211 </style>
213 <script type="text/javascript" src="../../library/textformat.js"></script>
214 <script type="text/javascript" src="../../library/dialog.js"></script>
215 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
217 <script type="text/javascript">
218 function edivalidation(){
220 var mypcc = "<?php echo htmlspecialchars( xl('Required Field Missing: Please choose the EDI-271 file to upload'), ENT_QUOTES);?>";
222 if(document.getElementById('uploaded').value == ""){
223 alert(mypcc);
224 return false;
226 else
228 $("#theform").submit();
232 </script>
234 </head>
235 <body class="body_top">
237 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
238 <?php if(isset($message) && !empty($message))
241 <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>
242 <?php
243 $message = "";
245 if(isset($messageEDI))
248 <div style="margin-left:25%;width:50%;color:RED;text-align:center;font-family:arial;font-size:15px;background:#ECECEC;border:1px solid;" >
249 <?php echo htmlspecialchars( xl('Please choose the proper formatted EDI-271 file'), ENT_NOQUOTES); ?>
250 </div>
251 <?php
252 $messageEDI = "";
256 <div>
258 <span class='title'><?php echo htmlspecialchars( xl('EDI-271 File Upload'), ENT_NOQUOTES); ?></span>
260 <form enctype="multipart/form-data" name="theform" id="theform" action="edi_271.php" method="POST" onsubmit="return top.restoreSession()">
262 <div id="report_parameters">
263 <table>
264 <tr>
265 <td width='550px'>
266 <div style='float:left'>
267 <table class='text'>
268 <tr>
269 <td style='width:125px;' class='label'> <?php echo htmlspecialchars( xl('Select EDI-271 file'), ENT_NOQUOTES); ?>: </td>
270 <td> <input name="uploaded" id="uploaded" type="file" size=37 /></td>
271 </tr>
272 </table>
273 </div>
274 </td>
275 <td align='left' valign='middle' height="100%">
276 <table style='border-left:1px solid; width:100%; height:100%' >
277 <tr>
278 <td>
279 <div style='margin-left:15px'>
280 <a href='#' class='css_button' onclick='return edivalidation(); '><span><?php echo htmlspecialchars( xl('Upload'), ENT_NOQUOTES); ?></span>
281 </a>
282 </div>
283 </td>
284 </tr>
285 </table>
286 </td>
287 </tr>
288 </table>
289 </div>
292 <input type="hidden" name="form_orderby" value="<?php echo htmlspecialchars( $form_orderby, ENT_QUOTES); ?>" />
293 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
295 </form>
296 </body>
297 </html>