Portal Updates for Usability study, UI/UX and bug fixes. (#7556)
[openemr.git] / interface / de_identification_forms / de_identification_screen2.php
blobe07ff707fcf42a69cdc158f300c22e2797e5d099
1 <?php
3 /**
4 * de_identification script 2
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author ViCarePlus, Visolve <vicareplus_engg@visolve.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2010 ViCarePlus, Visolve <vicareplus_engg@visolve.com>
11 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/lists.inc.php");
17 require_once("$srcdir/patient.inc.php");
18 require_once("$srcdir/options.inc.php");
20 use OpenEMR\Common\Acl\AclMain;
21 use OpenEMR\Common\Csrf\CsrfUtils;
22 use OpenEMR\Common\Twig\TwigContainer;
23 use OpenEMR\Core\Header;
25 if (!AclMain::aclCheckCore('admin', 'super')) {
26 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("De Identification")]);
27 exit;
30 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
31 CsrfUtils::csrfNotVerified();
34 /*executes the De Identification process, using the parameters chosen from the
35 de_identification_screen1.php */
36 $begin_date = $_POST["begin_date"];
37 $end_date = $_POST["end_date"];
39 if ($_POST["unstructured"]) {
40 $include_unstructured = 1;
41 } else {
42 $include_unstructured = 0;
45 if ($_POST["all"]) {
46 $include_tables = "all";
47 } else {
48 if ($_POST["history_data"]) {
49 $include_tables = $include_tables . $_POST["history_data"] . "#";
52 if ($_POST["prescriptions"]) {
53 $include_tables = $include_tables . $_POST["prescriptions"] . "#";
56 if ($_POST["immunization"]) {
57 $include_tables = $include_tables . $_POST["immunization"] . "#";
60 if ($_POST["lists"]) {
61 $include_tables = $include_tables . $_POST["lists"] . "#";
64 if ($_POST["transactions"]) {
65 $include_tables = $include_tables . $_POST["transactions"] . "#";
68 if ($_POST["insurance_data"]) {
69 $include_tables = $include_tables . $_POST["insurance_data"] . "#";
72 if ($_POST["billing_data"]) {
73 $include_tables = $include_tables . "billing#payments";
77 $diagnosis_text = $_POST["diagnosis_text"];
78 $drug_text = $_POST["drug_text"];
79 $immunization_text = $_POST["immunization_text"];
81 $query = "select status from de_identification_status";
82 $res = sqlStatement($query);
83 if ($row = sqlFetchArray($res)) {
84 $deIdentificationStatus = $row['status'];
85 /* $deIdentificationStatus:
86 * 0 - There is no De Identification in progress. (start new De Identification process)
87 * 1 - A De Identification process is currently in progress.
88 * 2 - The De Identification process completed and xls file is ready to download
89 * 3 - The De Identification process completed with error
93 if ($deIdentificationStatus == 0) {
94 //0 - There is no De Identification in progress. (start new De Identification process)
96 <html>
97 <head>
98 <title>De Identification</title>
100 <?php Header::setupHeader(); ?>
102 <style>
103 .style1 {
104 text-align: center;
106 </style>
107 </head>
108 <body class="body_top">
109 <strong>De Identification</strong>
110 <form name="De Identification1" id="De Identification1" method="post"><br />
111 <?php
113 $query = "SELECT count(*) as count FROM metadata_de_identification";
114 $res = sqlStatement($query);
115 if ($row = sqlFetchArray($res)) {
116 $no_of_items = $row['count'];
117 if ($no_of_items == 0) {
118 $cmd = "cp " . escapeshellarg($GLOBALS['fileroot'] . "/sql/metadata_de_identification.txt") . " " . escapeshellarg($GLOBALS['temporary_files_dir'] . "/metadata_de_identification.txt");
119 $output3 = shell_exec($cmd);
120 $query = "LOAD DATA INFILE '" . add_escape_custom($GLOBALS['temporary_files_dir']) . "/metadata_de_identification.txt' INTO TABLE metadata_de_identification FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'";
121 $res = sqlStatement($query);
125 //create transaction tables
126 $query = "call create_transaction_tables()";
127 $res = sqlStatement($query);
129 //write input to data base
130 $query = "delete from param_include_tables";
131 $res = sqlStatement($query);
133 $query = "insert into param_include_tables values (?, ?)";
134 $res = sqlStatement($query, array($include_tables, $include_unstructured));
136 $query = "delete from param_filter_pid";
137 $res = sqlStatement($query);
139 $query = "insert into param_filter_pid values (?, ?, ?, ?, ?)";
140 $res = sqlStatement($query, array($begin_date, $end_date, $diagnosis_text, $drug_text, $immunization_text));
142 //process running
143 $query = "update de_identification_status set status = 1";
144 $res = sqlStatement($query);
146 try {
147 //call procedure - execute in background
148 $sh_cmd = './de_identification_procedure.sh ' . escapeshellarg($sqlconf["host"]) . ' ' . escapeshellarg($sqlconf["login"]) . ' ' . escapeshellarg($sqlconf["pass"]) . ' ' . escapeshellarg($sqlconf["dbase"]) . ' &';
149 system($sh_cmd);
152 $query = "SELECT status FROM de_identification_status ";
153 $res = sqlStatement($query);
154 if ($row = sqlFetchArray($res)) {
155 $de_identification_status = $row['status'];
156 if ($de_identification_status == 2 || $de_identification_status == 3) {
157 //2 - The De Identification process completed and xls file is ready to download
158 //3 - The De Identification process completed with error
159 $query = "SELECT count(*) as count FROM de_identified_data ";
160 $res = sqlStatement($query);
161 if ($row = sqlFetchArray($res)) {
162 $no_of_items = $row['count'];
163 if ($no_of_items <= 1) {
165 <table>
166 <tr>
167 <td>&nbsp;</td>
168 <td>&nbsp;</td>
169 </tr>
170 <tr>
171 <td>&nbsp;</td>
172 <td>&nbsp;</td>
173 </tr>
174 </table>
175 <table class="de_identification_status_message" align="center">
176 <tr valign="top">
178 <td>&nbsp;</td>
179 <td rowspan="3"><br />
180 <?php echo xlt('No Patient record found for given Selection criteria');
181 echo "<br /><br />";
182 echo xlt('Please start new De Identification process');
183 echo "<br />"; ?> <br />
184 </td>
185 <td>&nbsp;</td>
186 </tr>
187 <tr>
188 <td>&nbsp;</td>
189 <td>&nbsp;</td>
190 </tr>
191 <tr>
192 <td>&nbsp;</td>
193 <td>&nbsp;</td>
194 </tr>
195 </table>
196 <table align="center">
197 <tr>
198 <td>&nbsp;</td>
199 <td>&nbsp;</td>
200 </tr>
201 </table>
203 <?php
204 } else { //delete old de_identified_data.xls file
205 $timestamp = 0;
206 $query = "select now() as timestamp";
207 $res = sqlStatement($query);
208 if ($row = sqlFetchArray($res)) {
209 $timestamp = $row['timestamp'];
212 $timestamp = str_replace(" ", "_", $timestamp);
213 $de_identified_file = $GLOBALS['temporary_files_dir'] . "/de_identified_data" . $timestamp . ".xls";
214 $query = "update de_identification_status set last_available_de_identified_data_file = ?";
215 $res = sqlStatement($query, array($de_identified_file));
216 $query = "select * from de_identified_data into outfile '" . add_escape_custom($de_identified_file) . "' ";
217 $res = sqlStatement($query);
219 <table>
220 <tr>
221 <td>&nbsp;</td>
222 <td>&nbsp;</td>
223 </tr>
224 <tr>
225 <td>&nbsp;</td>
226 <td>&nbsp;</td>
227 </tr>
228 </table>
229 <table class="de_identification_status_message" align="center">
230 <tr valign="top">
231 <td>&nbsp;</td>
232 <td rowspan="3"><br />
233 <?php echo xlt('De Identification Process is ongoing');
234 echo "<br /><br />";
235 echo xlt('Please visit De Identification screen after some time');
236 echo "<br />"; ?> <br />
237 </td>
238 <td>&nbsp;</td>
239 </tr>
240 <tr>
241 <td>&nbsp;</td>
242 <td>&nbsp;</td>
243 </tr>
244 <tr>
245 <td>&nbsp;</td>
246 <td>&nbsp;</td>
247 </tr>
248 </table>
249 <table align="center">
250 <tr>
251 <td>&nbsp;</td>
252 <td>&nbsp;</td>
253 </tr>
254 </table>
255 <?php
260 } catch (Exception $e) {
261 //error status
262 $query = "update de_identification_status set status = 3";
263 $res = sqlStatement($query);
265 } elseif ($deIdentificationStatus == 2 or $deIdentificationStatus == 3) {
266 //2 - The De Identification process completed and xls file is ready to download
267 //3 - The De Identification process completed with error
268 $query = "select last_available_de_identified_data_file from de_identification_status";
269 $res = sqlStatement($query);
270 if ($row = sqlFetchArray($res)) {
271 $filename = $row['last_available_de_identified_data_file'];
274 ob_end_clean();
275 if (file_exists($filename)) {
276 header('Content-Description: File Transfer');
277 header('Content-Type: application/octet-stream');
278 header('Content-Disposition: attachment; filename=' . basename($filename));
279 header('Content-Transfer-Encoding: binary');
280 header('Content-Type: application/vnd.ms-excel;'); // This should work for IE & Opera
281 header("Content-type: application/x-msexcel"); // This should work for the rest
282 header('Expires: 0');
283 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
284 header('Pragma: public');
285 header('Content-Length: ' . filesize($filename));
286 ob_clean();
287 flush();
288 readfile($filename);
291 //xls file downloaded complete
292 $query = "update de_identification_status set status = 0";
293 $res = sqlStatement($query);
296 </body>
297 </html>