added new datepicker to amendments gui
[openemr.git] / interface / de_identification_forms / de_identification_screen2.php
blob58d1210872f6dd2228bd1a1b08704e53b2827e0d
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");
25 <?php
26 /*executes the De Identification process, using the parameters chosen from the
27 de_identification_screen1.php */
28 $begin_date = $_POST["begin_date"];
29 $end_date = $_POST["end_date"];
31 if ($_POST["unstructured"])
32 $include_unstructured = 1;
33 else
34 $include_unstructured = 0;
36 if ($_POST["all"])
37 $include_tables = "all";
38 else
40 if ($_POST["history_data"])
41 $include_tables = $include_tables . $_POST["history_data"]. "#";
42 if ($_POST["prescriptions"])
43 $include_tables = $include_tables . $_POST["prescriptions"]. "#";
44 if ($_POST["immunization"])
45 $include_tables = $include_tables . $_POST["immunization"]. "#";
46 if ($_POST["lists"])
47 $include_tables = $include_tables . $_POST["lists"]. "#";
48 if ($_POST["transactions"])
49 $include_tables = $include_tables . $_POST["transactions"]. "#";
50 if ($_POST["insurance_data"])
51 $include_tables = $include_tables . $_POST["insurance_data"]. "#";
52 if ($_POST["billing_data"])
53 $include_tables = $include_tables . "billing#payments";
56 $diagnosis_text = $_POST["diagnosis_text"];
57 $drug_text = $_POST["drug_text"];
58 $immunization_text = $_POST["immunization_text"];
60 $query = "select status from de_identification_status";
61 $res = sqlStatement($query);
62 if ($row = sqlFetchArray($res))
64 $deIdentificationStatus = addslashes($row['status']);
65 /* $deIdentificationStatus:
66 * 0 - There is no De Identification in progress. (start new De Identification process)
67 * 1 - A De Identification process is currently in progress.
68 * 2 - The De Identification process completed and xls file is ready to download
69 * 3 - The De Identification process completed with error
73 if($deIdentificationStatus == 0)
75 //0 - There is no De Identification in progress. (start new De Identification process)
77 <html>
78 <head>
79 <title>De Identification</title>
80 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
81 <link rel="stylesheet"
82 href='<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css'
83 type='text/css'>
84 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
85 <style type="text/css">
86 .style1 {
87 text-align: center;
89 </style>
90 </head>
91 <body class="body_top">
92 <strong>De Identification</strong>
93 <form name="De Identification1" id="De Identification1" method="post"><br />
94 <?php
96 $query = "SELECT count(*) as count FROM metadata_de_identification";
97 $res = sqlStatement($query);
98 if ($row = sqlFetchArray($res))
100 $no_of_items = addslashes($row['count']);
101 if($no_of_items == 0)
103 $cmd="cp ".$GLOBALS['webserver_root']."/sql/metadata_de_identification.txt ".$GLOBALS['temporary_files_dir']."/metadata_de_identification.txt";
104 $output3=shell_exec($cmd);
105 $query = "LOAD DATA INFILE '".$GLOBALS['temporary_files_dir']."/metadata_de_identification.txt' INTO TABLE metadata_de_identification FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'";
106 $res = sqlStatement($query);
109 //create transaction tables
110 $query = "call create_transaction_tables()";
111 $res = sqlStatement($query);
113 //write input to data base
114 $query = "delete from param_include_tables";
115 $res = sqlStatement($query);
117 $query = "insert into param_include_tables values ('$include_tables','$include_unstructured')";
118 $res = sqlStatement($query);
120 $query = "delete from param_filter_pid";
121 $res = sqlStatement($query);
123 $query = "insert into param_filter_pid values ('$begin_date', '$end_date', '$diagnosis_text', '$drug_text', '$immunization_text')";
124 $res = sqlStatement($query);
126 //process running
127 $query = "update de_identification_status set status = 1";
128 $res = sqlStatement($query);
132 //call procedure - execute in background
133 $sh_cmd='./de_identification_procedure.sh '.$sqlconf["host"].' '.$sqlconf["login"].' '.$sqlconf["pass"].' '.$sqlconf["dbase"].' &';
134 system ($sh_cmd);
137 $query = "SELECT status FROM de_identification_status ";
138 $res = sqlStatement($query);
139 if ($row = sqlFetchArray($res))
141 $de_identification_status = addslashes($row['status']);
142 if($de_identification_status == 2 || $de_identification_status == 3)
144 //2 - The De Identification process completed and xls file is ready to download
145 //3 - The De Identification process completed with error
146 $query = "SELECT count(*) as count FROM de_identified_data ";
147 $res = sqlStatement($query);
148 if ($row = sqlFetchArray($res))
150 $no_of_items = addslashes($row['count']);
151 if($no_of_items <= 1)
154 <table>
155 <tr>
156 <td>&nbsp;</td>
157 <td>&nbsp;</td>
158 </tr>
159 <tr>
160 <td>&nbsp;</td>
161 <td>&nbsp;</td>
162 </tr>
163 </table>
164 <table class="de_identification_status_message" align="center">
165 <tr valign="top">
167 <td>&nbsp;</td>
168 <td rowspan="3"><br>
169 <?php echo xl('No Patient record found for given Selection criteria');
170 echo "</br></br>";
171 echo xl('Please start new De Identification process');
172 echo "</br>"; ?> </br>
173 </td>
174 <td>&nbsp;</td>
175 </tr>
176 <tr>
177 <td>&nbsp;</td>
178 <td>&nbsp;</td>
179 </tr>
180 <tr>
181 <td>&nbsp;</td>
182 <td>&nbsp;</td>
183 </tr>
184 </table>
185 <table align="center">
186 <tr>
187 <td>&nbsp;</td>
188 <td>&nbsp;</td>
189 </tr>
190 </table>
192 <?php
194 else
195 { //delete old de_identified_data.xls file
196 $timestamp=0;
197 $query = "select now() as timestamp";
198 $res = sqlStatement($query);
199 if ($row = sqlFetchArray($res))
201 $timestamp = addslashes($row['timestamp']);
203 $timestamp = str_replace(" ","_",$timestamp);
204 $de_identified_file = $GLOBALS['temporary_files_dir']."/de_identified_data".$timestamp.".xls";
205 $query = "update de_identification_status set last_available_de_identified_data_file = '" . $de_identified_file . "'";
206 $res = sqlStatement($query);
207 $query = "select * from de_identified_data into outfile '$de_identified_file' ";
208 $res = sqlStatement($query);
210 <table>
211 <tr>
212 <td>&nbsp;</td>
213 <td>&nbsp;</td>
214 </tr>
215 <tr>
216 <td>&nbsp;</td>
217 <td>&nbsp;</td>
218 </tr>
219 </table>
220 <table class="de_identification_status_message" align="center">
221 <tr valign="top">
222 <td>&nbsp;</td>
223 <td rowspan="3"><br>
224 <?php echo xl('De Identification Process is ongoing');
225 echo "</br></br>";
226 echo xl('Please visit De Identification screen after some time');
227 echo "</br>"; ?> </br>
228 </td>
229 <td>&nbsp;</td>
230 </tr>
231 <tr>
232 <td>&nbsp;</td>
233 <td>&nbsp;</td>
234 </tr>
235 <tr>
236 <td>&nbsp;</td>
237 <td>&nbsp;</td>
238 </tr>
239 </table>
240 <table align="center">
241 <tr>
242 <td>&nbsp;</td>
243 <td>&nbsp;</td>
244 </tr>
245 </table>
246 <?php
252 catch (Exception $e)
254 //error status
255 $query = "update de_identification_status set status = 3";
256 $res = sqlStatement($query);
259 else if($deIdentificationStatus == 2 or $deIdentificationStatus == 3)
261 //2 - The De Identification process completed and xls file is ready to download
262 //3 - The De Identification process completed with error
263 $query = "select last_available_de_identified_data_file from de_identification_status";
264 $res = sqlStatement($query);
265 if ($row = sqlFetchArray($res))
267 $filename = addslashes($row['last_available_de_identified_data_file']);
269 ob_end_clean();
270 if (file_exists($filename)) {
272 header('Content-Description: File Transfer');
273 header('Content-Type: application/octet-stream');
274 header('Content-Disposition: attachment; filename='.basename($filename));
275 header('Content-Transfer-Encoding: binary');
276 header('Content-Type: application/vnd.ms-excel;'); // This should work for IE & Opera
277 header("Content-type: application/x-msexcel"); // This should work for the rest
278 header('Expires: 0');
279 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
280 header('Pragma: public');
281 header('Content-Length: ' . filesize($filename));
282 ob_clean();
283 flush();
284 readfile($filename);
288 //xls file downloaded complete
289 $query = "update de_identification_status set status = 0";
290 $res = sqlStatement($query);
293 </body>
294 </html>