Add back popup dialogs for tabs U.I. (#1434)
[openemr.git] / interface / de_identification_forms / de_identification_screen2.php
blob6ba6928718709225f2b658c7eb8abdf213be541f
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;
37 if ($_POST["all"]) {
38 $include_tables = "all";
39 } else {
40 if ($_POST["history_data"]) {
41 $include_tables = $include_tables . $_POST["history_data"]. "#";
44 if ($_POST["prescriptions"]) {
45 $include_tables = $include_tables . $_POST["prescriptions"]. "#";
48 if ($_POST["immunization"]) {
49 $include_tables = $include_tables . $_POST["immunization"]. "#";
52 if ($_POST["lists"]) {
53 $include_tables = $include_tables . $_POST["lists"]. "#";
56 if ($_POST["transactions"]) {
57 $include_tables = $include_tables . $_POST["transactions"]. "#";
60 if ($_POST["insurance_data"]) {
61 $include_tables = $include_tables . $_POST["insurance_data"]. "#";
64 if ($_POST["billing_data"]) {
65 $include_tables = $include_tables . "billing#payments";
69 $diagnosis_text = $_POST["diagnosis_text"];
70 $drug_text = $_POST["drug_text"];
71 $immunization_text = $_POST["immunization_text"];
73 $query = "select status from de_identification_status";
74 $res = sqlStatement($query);
75 if ($row = sqlFetchArray($res)) {
76 $deIdentificationStatus = addslashes($row['status']);
77 /* $deIdentificationStatus:
78 * 0 - There is no De Identification in progress. (start new De Identification process)
79 * 1 - A De Identification process is currently in progress.
80 * 2 - The De Identification process completed and xls file is ready to download
81 * 3 - The De Identification process completed with error
85 if ($deIdentificationStatus == 0) {
86 //0 - There is no De Identification in progress. (start new De Identification process)
88 <html>
89 <head>
90 <title>De Identification</title>
91 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
92 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
93 <style type="text/css">
94 .style1 {
95 text-align: center;
97 </style>
98 </head>
99 <body class="body_top">
100 <strong>De Identification</strong>
101 <form name="De Identification1" id="De Identification1" method="post"><br />
102 <?php
104 $query = "SELECT count(*) as count FROM metadata_de_identification";
105 $res = sqlStatement($query);
106 if ($row = sqlFetchArray($res)) {
107 $no_of_items = addslashes($row['count']);
108 if ($no_of_items == 0) {
109 $cmd="cp ".$GLOBALS['webserver_root']."/sql/metadata_de_identification.txt ".$GLOBALS['temporary_files_dir']."/metadata_de_identification.txt";
110 $output3=shell_exec($cmd);
111 $query = "LOAD DATA INFILE '".$GLOBALS['temporary_files_dir']."/metadata_de_identification.txt' INTO TABLE metadata_de_identification FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'";
112 $res = sqlStatement($query);
116 //create transaction tables
117 $query = "call create_transaction_tables()";
118 $res = sqlStatement($query);
120 //write input to data base
121 $query = "delete from param_include_tables";
122 $res = sqlStatement($query);
124 $query = "insert into param_include_tables values ('$include_tables','$include_unstructured')";
125 $res = sqlStatement($query);
127 $query = "delete from param_filter_pid";
128 $res = sqlStatement($query);
130 $query = "insert into param_filter_pid values ('$begin_date', '$end_date', '$diagnosis_text', '$drug_text', '$immunization_text')";
131 $res = sqlStatement($query);
133 //process running
134 $query = "update de_identification_status set status = 1";
135 $res = sqlStatement($query);
137 try {
138 //call procedure - execute in background
139 $sh_cmd='./de_identification_procedure.sh '.$sqlconf["host"].' '.$sqlconf["login"].' '.$sqlconf["pass"].' '.$sqlconf["dbase"].' &';
140 system($sh_cmd);
143 $query = "SELECT status FROM de_identification_status ";
144 $res = sqlStatement($query);
145 if ($row = sqlFetchArray($res)) {
146 $de_identification_status = addslashes($row['status']);
147 if ($de_identification_status == 2 || $de_identification_status == 3) {
148 //2 - The De Identification process completed and xls file is ready to download
149 //3 - The De Identification process completed with error
150 $query = "SELECT count(*) as count FROM de_identified_data ";
151 $res = sqlStatement($query);
152 if ($row = sqlFetchArray($res)) {
153 $no_of_items = addslashes($row['count']);
154 if ($no_of_items <= 1) {
156 <table>
157 <tr>
158 <td>&nbsp;</td>
159 <td>&nbsp;</td>
160 </tr>
161 <tr>
162 <td>&nbsp;</td>
163 <td>&nbsp;</td>
164 </tr>
165 </table>
166 <table class="de_identification_status_message" align="center">
167 <tr valign="top">
169 <td>&nbsp;</td>
170 <td rowspan="3"><br>
171 <?php echo xl('No Patient record found for given Selection criteria');
172 echo "</br></br>";
173 echo xl('Please start new De Identification process');
174 echo "</br>"; ?> </br>
175 </td>
176 <td>&nbsp;</td>
177 </tr>
178 <tr>
179 <td>&nbsp;</td>
180 <td>&nbsp;</td>
181 </tr>
182 <tr>
183 <td>&nbsp;</td>
184 <td>&nbsp;</td>
185 </tr>
186 </table>
187 <table align="center">
188 <tr>
189 <td>&nbsp;</td>
190 <td>&nbsp;</td>
191 </tr>
192 </table>
194 <?php
195 } else { //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)) {
200 $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
251 } catch (Exception $e) {
252 //error status
253 $query = "update de_identification_status set status = 3";
254 $res = sqlStatement($query);
256 } else if ($deIdentificationStatus == 2 or $deIdentificationStatus == 3) {
257 //2 - The De Identification process completed and xls file is ready to download
258 //3 - The De Identification process completed with error
259 $query = "select last_available_de_identified_data_file from de_identification_status";
260 $res = sqlStatement($query);
261 if ($row = sqlFetchArray($res)) {
262 $filename = addslashes($row['last_available_de_identified_data_file']);
265 ob_end_clean();
266 if (file_exists($filename)) {
267 header('Content-Description: File Transfer');
268 header('Content-Type: application/octet-stream');
269 header('Content-Disposition: attachment; filename='.basename($filename));
270 header('Content-Transfer-Encoding: binary');
271 header('Content-Type: application/vnd.ms-excel;'); // This should work for IE & Opera
272 header("Content-type: application/x-msexcel"); // This should work for the rest
273 header('Expires: 0');
274 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
275 header('Pragma: public');
276 header('Content-Length: ' . filesize($filename));
277 ob_clean();
278 flush();
279 readfile($filename);
282 //xls file downloaded complete
283 $query = "update de_identification_status set status = 0";
284 $res = sqlStatement($query);
287 </body>
288 </html>