Added a new billing widget and following related changes:
[openemr.git] / interface / de_identification_forms / de_identification_screen2.php
blobf63aac1a5a3283833a0698c53df5424d9606b363
1 <?php
2 /********************************************************************************\
3 * Copyright (C) ViCarePlus, Visolve (vicareplus_engg@visolve.com) *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 \********************************************************************************/
19 require_once("../globals.php");
20 require_once("$srcdir/lists.inc");
21 require_once("$srcdir/patient.inc");
22 require_once("$srcdir/acl.inc");
23 require_once("$srcdir/options.inc.php");
24 require_once("$srcdir/translation.inc.php");
25 require_once("../../library/sqlconf.php");
27 <?php
28 /*executes the De Identification process, using the parameters chosen from the
29 de_identification_screen1.php */
30 $begin_date = $_POST["begin_date"];
31 $end_date = $_POST["end_date"];
33 if ($_POST["unstructured"])
34 $include_unstructured = 1;
35 else
36 $include_unstructured = 0;
38 if ($_POST["all"])
39 $include_tables = "all";
40 else
42 if ($_POST["history_data"])
43 $include_tables = $include_tables . $_POST["history_data"]. "#";
44 if ($_POST["prescriptions"])
45 $include_tables = $include_tables . $_POST["prescriptions"]. "#";
46 if ($_POST["immunization"])
47 $include_tables = $include_tables . $_POST["immunization"]. "#";
48 if ($_POST["lists"])
49 $include_tables = $include_tables . $_POST["lists"]. "#";
50 if ($_POST["transactions"])
51 $include_tables = $include_tables . $_POST["transactions"]. "#";
52 if ($_POST["insurance_data"])
53 $include_tables = $include_tables . $_POST["insurance_data"]. "#";
54 if ($_POST["billing_data"])
55 $include_tables = $include_tables . "billing#payments";
58 $diagnosis_text = $_POST["diagnosis_text"];
59 $drug_text = $_POST["drug_text"];
60 $immunization_text = $_POST["immunization_text"];
62 $query = "select status from de_identification_status";
63 $res = sqlStatement($query);
64 if ($row = sqlFetchArray($res))
66 $deIdentificationStatus = addslashes($row['status']);
67 /* $deIdentificationStatus:
68 * 0 - There is no De Identification in progress. (start new De Identification process)
69 * 1 - A De Identification process is currently in progress.
70 * 2 - The De Identification process completed and xls file is ready to download
71 * 3 - The De Identification process completed with error
72 */
75 if($deIdentificationStatus == 0)
77 //0 - There is no De Identification in progress. (start new De Identification process)
79 <html>
80 <head>
81 <title>De Identification</title>
82 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
83 <link rel="stylesheet"
84 href='<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css'
85 type='text/css'>
86 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
87 <style type="text/css">
88 .style1 {
89 text-align: center;
91 </style>
92 </head>
93 <body class="body_top">
94 <strong>De Identification</strong>
95 <form name="De Identification1" id="De Identification1" method="post"><br />
97 $query = "SELECT count(*) as count FROM metadata_de_identification";
98 $res = sqlStatement($query);
99 if ($row = sqlFetchArray($res))
101 $no_of_items = addslashes($row['count']);
102 if($no_of_items == 0)
104 $cmd="cp ".$GLOBALS['webserver_root']."/sql/metadata_de_identification.txt ".$GLOBALS['temporary_files_dir']."/metadata_de_identification.txt";
105 $output3=shell_exec($cmd);
106 $query = "LOAD DATA INFILE '".$GLOBALS['temporary_files_dir']."/metadata_de_identification.txt' INTO TABLE metadata_de_identification FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'";
107 $res = sqlStatement($query);
110 //create transaction tables
111 $query = "call create_transaction_tables()";
112 $res = sqlStatement($query);
114 //write input to data base
115 $query = "delete from param_include_tables";
116 $res = sqlStatement($query);
118 $query = "insert into param_include_tables values ('$include_tables','$include_unstructured')";
119 $res = sqlStatement($query);
121 $query = "delete from param_filter_pid";
122 $res = sqlStatement($query);
124 $query = "insert into param_filter_pid values ('$begin_date', '$end_date', '$diagnosis_text', '$drug_text', '$immunization_text')";
125 $res = sqlStatement($query);
127 //process running
128 $query = "update de_identification_status set status = 1";
129 $res = sqlStatement($query);
133 //call procedure - execute in background
134 $sh_cmd='./de_identification_procedure.sh '.$sqlconf["host"].' '.$sqlconf["login"].' '.$sqlconf["pass"].' '.$sqlconf["dbase"].' &';
135 system ($sh_cmd);
138 $query = "SELECT status FROM de_identification_status ";
139 $res = sqlStatement($query);
140 if ($row = sqlFetchArray($res))
142 $de_identification_status = addslashes($row['status']);
143 if($de_identification_status == 2 || $de_identification_status == 3)
145 //2 - The De Identification process completed and xls file is ready to download
146 //3 - The De Identification process completed with error
147 $query = "SELECT count(*) as count FROM de_identified_data ";
148 $res = sqlStatement($query);
149 if ($row = sqlFetchArray($res))
151 $no_of_items = addslashes($row['count']);
152 if($no_of_items <= 1)
155 <table>
156 <tr>
157 <td>&nbsp;</td>
158 <td>&nbsp;</td>
159 </tr>
160 <tr>
161 <td>&nbsp;</td>
162 <td>&nbsp;</td>
163 </tr>
164 </table>
165 <table class="de_identification_status_message" align="center">
166 <tr valign="top">
168 <td>&nbsp;</td>
169 <td rowspan="3"><br>
170 <?php echo xl('No Patient record found for given Selection criteria');
171 echo "</br></br>";
172 echo xl('Please start new De Identification process');
173 echo "</br>"; ?> </br>
174 </td>
175 <td>&nbsp;</td>
176 </tr>
177 <tr>
178 <td>&nbsp;</td>
179 <td>&nbsp;</td>
180 </tr>
181 <tr>
182 <td>&nbsp;</td>
183 <td>&nbsp;</td>
184 </tr>
185 </table>
186 <table align="center">
187 <tr>
188 <td>&nbsp;</td>
189 <td>&nbsp;</td>
190 </tr>
191 </table>
193 <?php
195 else
196 { //delete old de_identified_data.xls file
197 $timestamp=0;
198 $query = "select now() as timestamp";
199 $res = sqlStatement($query);
200 if ($row = sqlFetchArray($res))
202 $timestamp = addslashes($row['timestamp']);
204 $timestamp = str_replace(" ","_",$timestamp);
205 $de_identified_file = $GLOBALS['temporary_files_dir']."/de_identified_data".$timestamp.".xls";
206 $query = "update de_identification_status set last_available_de_identified_data_file = '" . $de_identified_file . "'";
207 $res = sqlStatement($query);
208 $query = "select * from de_identified_data into outfile '$de_identified_file' ";
209 $res = sqlStatement($query);
211 <table>
212 <tr>
213 <td>&nbsp;</td>
214 <td>&nbsp;</td>
215 </tr>
216 <tr>
217 <td>&nbsp;</td>
218 <td>&nbsp;</td>
219 </tr>
220 </table>
221 <table class="de_identification_status_message" align="center">
222 <tr valign="top">
223 <td>&nbsp;</td>
224 <td rowspan="3"><br>
225 <?php echo xl('De Identification Process is ongoing');
226 echo "</br></br>";
227 echo xl('Please visit De Identification screen after some time');
228 echo "</br>"; ?> </br>
229 </td>
230 <td>&nbsp;</td>
231 </tr>
232 <tr>
233 <td>&nbsp;</td>
234 <td>&nbsp;</td>
235 </tr>
236 <tr>
237 <td>&nbsp;</td>
238 <td>&nbsp;</td>
239 </tr>
240 </table>
241 <table align="center">
242 <tr>
243 <td>&nbsp;</td>
244 <td>&nbsp;</td>
245 </tr>
246 </table>
247 <?php
253 catch (Exception $e)
255 //error status
256 $query = "update de_identification_status set status = 3";
257 $res = sqlStatement($query);
260 else if($deIdentificationStatus == 2 or $deIdentificationStatus == 3)
262 //2 - The De Identification process completed and xls file is ready to download
263 //3 - The De Identification process completed with error
264 $query = "select last_available_de_identified_data_file from de_identification_status";
265 $res = sqlStatement($query);
266 if ($row = sqlFetchArray($res))
268 $filename = addslashes($row['last_available_de_identified_data_file']);
270 ob_end_clean();
271 if (file_exists($filename)) {
273 header('Content-Description: File Transfer');
274 header('Content-Type: application/octet-stream');
275 header('Content-Disposition: attachment; filename='.basename($filename));
276 header('Content-Transfer-Encoding: binary');
277 header('Content-Type: application/vnd.ms-excel;'); // This should work for IE & Opera
278 header("Content-type: application/x-msexcel"); // This should work for the rest
279 header('Expires: 0');
280 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
281 header('Pragma: public');
282 header('Content-Length: ' . filesize($filename));
283 ob_clean();
284 flush();
285 readfile($filename);
289 //xls file downloaded complete
290 $query = "update de_identification_status set status = 0";
291 $res = sqlStatement($query);
294 </body>
295 </html>