2 /********************************************************************************\
3 * Copyright (C) ViCarePlus, Visolve (vicareplus_engg@visolve.com) *
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. *
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. *
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 \********************************************************************************/
21 require_once("../globals.php");
22 require_once("$srcdir/lists.inc");
23 require_once("$srcdir/patient.inc");
24 require_once("$srcdir/acl.inc");
25 require_once("$srcdir/options.inc.php");
27 if (!acl_check('admin', 'super')) {
28 die(xlt('Not authorized'));
31 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
35 /*executes the De Identification process, using the parameters chosen from the
36 de_identification_screen1.php */
37 $begin_date = $_POST["begin_date"];
38 $end_date = $_POST["end_date"];
40 if ($_POST["unstructured"]) {
41 $include_unstructured = 1;
43 $include_unstructured = 0;
47 $include_tables = "all";
49 if ($_POST["history_data"]) {
50 $include_tables = $include_tables . $_POST["history_data"]. "#";
53 if ($_POST["prescriptions"]) {
54 $include_tables = $include_tables . $_POST["prescriptions"]. "#";
57 if ($_POST["immunization"]) {
58 $include_tables = $include_tables . $_POST["immunization"]. "#";
61 if ($_POST["lists"]) {
62 $include_tables = $include_tables . $_POST["lists"]. "#";
65 if ($_POST["transactions"]) {
66 $include_tables = $include_tables . $_POST["transactions"]. "#";
69 if ($_POST["insurance_data"]) {
70 $include_tables = $include_tables . $_POST["insurance_data"]. "#";
73 if ($_POST["billing_data"]) {
74 $include_tables = $include_tables . "billing#payments";
78 $diagnosis_text = $_POST["diagnosis_text"];
79 $drug_text = $_POST["drug_text"];
80 $immunization_text = $_POST["immunization_text"];
82 $query = "select status from de_identification_status";
83 $res = sqlStatement($query);
84 if ($row = sqlFetchArray($res)) {
85 $deIdentificationStatus = $row['status'];
86 /* $deIdentificationStatus:
87 * 0 - There is no De Identification in progress. (start new De Identification process)
88 * 1 - A De Identification process is currently in progress.
89 * 2 - The De Identification process completed and xls file is ready to download
90 * 3 - The De Identification process completed with error
94 if ($deIdentificationStatus == 0) {
95 //0 - There is no De Identification in progress. (start new De Identification process)
99 <title
>De Identification
</title
>
100 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
101 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
102 <style type
="text/css">
108 <body
class="body_top">
109 <strong
>De Identification
</strong
>
110 <form name
="De Identification1" id
="De Identification1" method
="post"><br
/>
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['webserver_root']."/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));
143 $query = "update de_identification_status set status = 1";
144 $res = sqlStatement($query);
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"]) . ' &';
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) {
175 <table
class="de_identification_status_message" align
="center">
180 <?php
echo xlt('No Patient record found for given Selection criteria');
182 echo xlt('Please start new De Identification process');
183 echo "</br>"; ?
> </br
>
196 <table align
="center">
204 } else { //delete old de_identified_data.xls file
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);
229 <table
class="de_identification_status_message" align
="center">
233 <?php
echo xlt('De Identification Process is ongoing');
235 echo xlt('Please visit De Identification screen after some time');
236 echo "</br>"; ?
> </br
>
249 <table align
="center">
260 } catch (Exception
$e) {
262 $query = "update de_identification_status set status = 3";
263 $res = sqlStatement($query);
265 } else if ($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'];
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));
291 //xls file downloaded complete
292 $query = "update de_identification_status set status = 0";
293 $res = sqlStatement($query);