PageRenderTime 1609ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/interface/de_identification_forms/de_identification_screen2.php

https://github.com/md-tech/openemr
PHP | 297 lines | 241 code | 20 blank | 36 comment | 29 complexity | 934c0ed8ee5d4bd9cdd49e9742924be3 MD5 | raw file
  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");
  26. ?>
  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"];
  32. if ($_POST["unstructured"])
  33. $include_unstructured = 1;
  34. else
  35. $include_unstructured = 0;
  36. if ($_POST["all"])
  37. $include_tables = "all";
  38. else
  39. {
  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";
  54. }
  55. $diagnosis_text = $_POST["diagnosis_text"];
  56. $drug_text = $_POST["drug_text"];
  57. $immunization_text = $_POST["immunization_text"];
  58. $query = "select status from de_identification_status";
  59. $res = sqlStatement($query);
  60. if ($row = sqlFetchArray($res))
  61. {
  62. $deIdentificationStatus = addslashes($row['status']);
  63. /* $deIdentificationStatus:
  64. * 0 - There is no De Identification in progress. (start new De Identification process)
  65. * 1 - A De Identification process is currently in progress.
  66. * 2 - The De Identification process completed and xls file is ready to download
  67. * 3 - The De Identification process completed with error
  68. */
  69. }
  70. if($deIdentificationStatus == 0)
  71. {
  72. //0 - There is no De Identification in progress. (start new De Identification process)
  73. ?>
  74. <html>
  75. <head>
  76. <title>De Identification</title>
  77. <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
  78. <link rel="stylesheet"
  79. href='<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css'
  80. type='text/css'>
  81. <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
  82. <style type="text/css">
  83. .style1 {
  84. text-align: center;
  85. }
  86. </style>
  87. </head>
  88. <body class="body_top">
  89. <strong>De Identification</strong>
  90. <form name="De Identification1" id="De Identification1" method="post"><br />
  91. <?php
  92. $query = "SELECT count(*) as count FROM metadata_de_identification";
  93. $res = sqlStatement($query);
  94. if ($row = sqlFetchArray($res))
  95. {
  96. $no_of_items = addslashes($row['count']);
  97. if($no_of_items == 0)
  98. {
  99. $cmd="cp ".$GLOBALS['webserver_root']."/sql/metadata_de_identification.txt ".$GLOBALS['temporary_files_dir']."/metadata_de_identification.txt";
  100. $output3=shell_exec($cmd);
  101. $query = "LOAD DATA INFILE '".$GLOBALS['temporary_files_dir']."/metadata_de_identification.txt' INTO TABLE metadata_de_identification FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'";
  102. $res = sqlStatement($query);
  103. }
  104. }
  105. //create transaction tables
  106. $query = "call create_transaction_tables()";
  107. $res = sqlStatement($query);
  108. //write input to data base
  109. $query = "delete from param_include_tables";
  110. $res = sqlStatement($query);
  111. $query = "insert into param_include_tables values ('$include_tables','$include_unstructured')";
  112. $res = sqlStatement($query);
  113. $query = "delete from param_filter_pid";
  114. $res = sqlStatement($query);
  115. $query = "insert into param_filter_pid values ('$begin_date', '$end_date', '$diagnosis_text', '$drug_text', '$immunization_text')";
  116. $res = sqlStatement($query);
  117. //process running
  118. $query = "update de_identification_status set status = 1";
  119. $res = sqlStatement($query);
  120. try
  121. {
  122. //call procedure - execute in background
  123. $sh_cmd='./de_identification_procedure.sh '.$sqlconf["host"].' '.$sqlconf["login"].' '.$sqlconf["pass"].' '.$sqlconf["dbase"].' &';
  124. system ($sh_cmd);
  125. $query = "SELECT status FROM de_identification_status ";
  126. $res = sqlStatement($query);
  127. if ($row = sqlFetchArray($res))
  128. {
  129. $de_identification_status = addslashes($row['status']);
  130. if($de_identification_status == 2 || $de_identification_status == 3)
  131. {
  132. //2 - The De Identification process completed and xls file is ready to download
  133. //3 - The De Identification process completed with error
  134. $query = "SELECT count(*) as count FROM de_identified_data ";
  135. $res = sqlStatement($query);
  136. if ($row = sqlFetchArray($res))
  137. {
  138. $no_of_items = addslashes($row['count']);
  139. if($no_of_items <= 1)
  140. {
  141. ?>
  142. <table>
  143. <tr>
  144. <td>&nbsp;</td>
  145. <td>&nbsp;</td>
  146. </tr>
  147. <tr>
  148. <td>&nbsp;</td>
  149. <td>&nbsp;</td>
  150. </tr>
  151. </table>
  152. <table class="de_identification_status_message" align="center">
  153. <tr valign="top">
  154. <td>&nbsp;</td>
  155. <td rowspan="3"><br>
  156. <?php echo xl('No Patient record found for given Selection criteria');
  157. echo "</br></br>";
  158. echo xl('Please start new De Identification process');
  159. echo "</br>"; ?> </br>
  160. </td>
  161. <td>&nbsp;</td>
  162. </tr>
  163. <tr>
  164. <td>&nbsp;</td>
  165. <td>&nbsp;</td>
  166. </tr>
  167. <tr>
  168. <td>&nbsp;</td>
  169. <td>&nbsp;</td>
  170. </tr>
  171. </table>
  172. <table align="center">
  173. <tr>
  174. <td>&nbsp;</td>
  175. <td>&nbsp;</td>
  176. </tr>
  177. </table>
  178. <?php
  179. }
  180. else
  181. { //delete old de_identified_data.xls file
  182. $timestamp=0;
  183. $query = "select now() as timestamp";
  184. $res = sqlStatement($query);
  185. if ($row = sqlFetchArray($res))
  186. {
  187. $timestamp = addslashes($row['timestamp']);
  188. }
  189. $timestamp = str_replace(" ","_",$timestamp);
  190. $de_identified_file = $GLOBALS['temporary_files_dir']."/de_identified_data".$timestamp.".xls";
  191. $query = "update de_identification_status set last_available_de_identified_data_file = '" . $de_identified_file . "'";
  192. $res = sqlStatement($query);
  193. $query = "select * from de_identified_data into outfile '$de_identified_file' ";
  194. $res = sqlStatement($query);
  195. ?>
  196. <table>
  197. <tr>
  198. <td>&nbsp;</td>
  199. <td>&nbsp;</td>
  200. </tr>
  201. <tr>
  202. <td>&nbsp;</td>
  203. <td>&nbsp;</td>
  204. </tr>
  205. </table>
  206. <table class="de_identification_status_message" align="center">
  207. <tr valign="top">
  208. <td>&nbsp;</td>
  209. <td rowspan="3"><br>
  210. <?php echo xl('De Identification Process is ongoing');
  211. echo "</br></br>";
  212. echo xl('Please visit De Identification screen after some time');
  213. echo "</br>"; ?> </br>
  214. </td>
  215. <td>&nbsp;</td>
  216. </tr>
  217. <tr>
  218. <td>&nbsp;</td>
  219. <td>&nbsp;</td>
  220. </tr>
  221. <tr>
  222. <td>&nbsp;</td>
  223. <td>&nbsp;</td>
  224. </tr>
  225. </table>
  226. <table align="center">
  227. <tr>
  228. <td>&nbsp;</td>
  229. <td>&nbsp;</td>
  230. </tr>
  231. </table>
  232. <?php
  233. }
  234. }
  235. }
  236. }
  237. }
  238. catch (Exception $e)
  239. {
  240. //error status
  241. $query = "update de_identification_status set status = 3";
  242. $res = sqlStatement($query);
  243. }
  244. }
  245. else if($deIdentificationStatus == 2 or $deIdentificationStatus == 3)
  246. {
  247. //2 - The De Identification process completed and xls file is ready to download
  248. //3 - The De Identification process completed with error
  249. $query = "select last_available_de_identified_data_file from de_identification_status";
  250. $res = sqlStatement($query);
  251. if ($row = sqlFetchArray($res))
  252. {
  253. $filename = addslashes($row['last_available_de_identified_data_file']);
  254. }
  255. ob_end_clean();
  256. if (file_exists($filename)) {
  257. header('Content-Description: File Transfer');
  258. header('Content-Type: application/octet-stream');
  259. header('Content-Disposition: attachment; filename='.basename($filename));
  260. header('Content-Transfer-Encoding: binary');
  261. header('Content-Type: application/vnd.ms-excel;'); // This should work for IE & Opera
  262. header("Content-type: application/x-msexcel"); // This should work for the rest
  263. header('Expires: 0');
  264. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  265. header('Pragma: public');
  266. header('Content-Length: ' . filesize($filename));
  267. ob_clean();
  268. flush();
  269. readfile($filename);
  270. }
  271. //xls file downloaded complete
  272. $query = "update de_identification_status set status = 0";
  273. $res = sqlStatement($query);
  274. }
  275. ?>
  276. </body>
  277. </html>