Merge pull request #7535 from stephenwaite/bug_fix_w1
[openemr.git] / interface / de_identification_forms / de_identification_screen1.php
blobb2a4ae80f97516d9a713e52c89bbda352fe688f3
1 <?php
3 /**
4 * de_identification script
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) 2017-2019 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;
32 <html>
33 <head>
34 <title><?php echo xlt('De Identification'); ?></title>
35 <?php Header::setupHeader('datetime-picker'); ?>
36 <style>
37 .style1 {
38 text-align: center;
39 }</style>
41 <script>
42 //get value from popup window
43 function set_related(s,type) {
44 var list;
45 if(type == "diagnosis")
46 list = "diagnosis_list";
47 else if(type == "drugs")
48 list = "drug_list";
49 else if(type == "immunizations")
50 list = "immunization_list";
52 var p=s.split("#");
53 var elSel = document.getElementById(list);
54 var i,k;
55 for (i=0;p[i]!=null;i++)
57 for(k=0;k<elSel.length;k++)
59 if((elSel.options[k].value)==p[i])
60 p[i]= " ";
62 if(p[i]!= " ")
64 var elOptNew = document.createElement('option');
65 elOptNew.text = p[i];
66 elOptNew.value = p[i];
67 try {
68 elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
70 catch(ex) {
71 elSel.add(elOptNew); // IE only
75 show_value(type);
78 function get_values(type)
80 if(type == "diagnosis")
81 dlgopen('find_code_popup.php', '_blank', 500, 400,true);
82 else if(type == "drugs")
83 dlgopen('find_drug_popup.php', '_blank', 500, 400,true);
84 else if(type == "immunizations")
85 dlgopen('find_immunization_popup.php', '_blank', 500, 400,true);
88 //remove item selected from list
89 function remove_selected(type)
91 var list;
92 if(type == "diagnosis")
93 list = "diagnosis_list";
94 else if(type == "drugs")
95 list = "drug_list";
96 else if(type == "immunizations")
97 list = "immunization_list";
98 var elSel = document.getElementById(list);
99 var i;
100 for (i = elSel.length - 1; i>=0; i--) {
101 if (elSel.options[i].selected)
103 elSel.remove(i);
106 show_value(type);
109 function show_value(type)
111 var list,text,radio;
112 if(type == "diagnosis")
113 { radio = "diagnosis"; list = "diagnosis_list"; text="diagnosis_text"; }
114 else if(type == "drugs")
115 { radio = "drugs"; list = "drug_list"; text="drug_text"; }
116 else if(type == "immunizations")
117 { radio = "immunizations"; list = "immunization_list"; text="immunization_text"; }
118 if(document.getElementById(radio) == "all")
120 document.getElementById(text).value="all";
122 else
124 var str;
125 var elSel = document.getElementById(list);
126 var i;
127 for (i = elSel.length - 1; i>=0; i--)
129 if(!str)
130 str = elSel.options[i].value;
131 else
132 str = str +"#"+elSel.options[i].value;
135 document.getElementById(text).value=str;
139 //disable - enable other checkbox when all checkbox is clicked
140 function disable_other_chkbox()
142 var value = document.forms[0].all.checked;
143 if(value == 1)
145 document.forms[0].history_data.disabled = true;
146 document.forms[0].prescriptions.disabled = true;
147 document.forms[0].lists.disabled = true;
148 document.forms[0].immunization.disabled = true;
149 document.forms[0].transactions.disabled = true;
150 document.forms[0].billing_data.disabled = true;
151 document.forms[0].insurance_data.disabled = true;
153 else
155 document.forms[0].history_data.disabled = false;
156 document.forms[0].prescriptions.disabled = false;
157 document.forms[0].lists.disabled = false;
158 document.forms[0].immunization.disabled = false;
159 document.forms[0].transactions.disabled = false;
160 document.forms[0].billing_data.disabled = false;
161 document.forms[0].insurance_data.disabled = false;
165 //disable list,add button,remove button when all option is selected
166 function disable_controls(type)
168 var list,button1,button2;
169 if(type == "diagnosis")
170 { button1 = "add_diagnosis"; button2 = "remove_diagnosis"; list = "diagnosis_list"; text="diagnosis_text"; }
171 else if(type == "drugs")
172 { button1 = "add_drug"; button2 = "remove_drug"; list = "drug_list"; text="drug_text";}
173 else if(type == "immunizations")
174 { button1 = "add_immunization"; button2 = "remove_immunization"; list = "immunization_list"; text="immunization_text"; }
175 document.getElementById(button1).disabled = true;
176 document.getElementById(button2).disabled = true;
177 document.getElementById(list).disabled = true;
178 document.getElementById(text).value = "all";
181 function enable_controls(type)
183 var list,button1,button2;
184 if(type == "diagnosis")
185 { button1 = "add_diagnosis"; button2 = "remove_diagnosis"; list = "diagnosis_list"; }
186 else if(type == "drugs")
187 { button1 = "add_drug"; button2 = "remove_drug"; list = "drug_list"; }
188 else if(type == "immunizations")
189 { button1 = "add_immunization"; button2 = "remove_immunization"; list = "immunization_list";
191 document.getElementById(button1).disabled = false;
192 document.getElementById(button2).disabled = false;
193 document.getElementById(list).disabled = false;
194 show_value(type);
198 function form_validate()
200 if(document.forms[0].begin_date.value >= document.forms[0].end_date.value)
202 alert(<?php echo xlj('End date should be greater than Begin date'); ?>);
203 return false;
206 if(document.forms[0].all.checked == false &&
207 document.forms[0].history_data.checked == false &&
208 document.forms[0].prescriptions.checked == false &&
209 document.forms[0].immunization.checked == false &&
210 document.forms[0].lists.checked == false &&
211 document.forms[0].transactions.checked == false &&
212 document.forms[0].billing_data.checked == false &&
213 document.forms[0].insurance_data.checked == false)
215 alert(<?php echo xlj('Select Data Required for De Identification'); ?>);
216 return false;
219 if(document.forms[0].diagnosis_text.value == "undefined" || document.forms[0].diagnosis_text.value == "")
221 alert(<?php echo xlj('Select Diagnosis for De Identification request'); ?>);
222 return false;
224 if(document.forms[0].drug_text.value == "undefined" || document.forms[0].drug_text.value == "")
226 alert(<?php echo xlj('Select Drugs for De Identification request'); ?>);
227 return false;
229 if(document.forms[0].immunization_text.value == "undefined" || document.forms[0].immunization_text.value == "")
231 alert(<?php echo xlj('Select Immunizations for De Identification request'); ?>);
232 return false;
234 alert(<?php echo xlj('De Identification process is started and running in background'); ?> + '\n' + <?php echo xlj('Please visit the screen after some time'); ?>);
235 top.restoreSession();
236 return true;
239 function download_file()
241 alert(<?php echo xlj('De-identification files will be saved in'); ?> + ' `' + <?php echo js_escape($GLOBALS['temporary_files_dir']); ?> + '` ' + <?php echo xlj('location of the openemr machine and may contain sensitive data, so it is recommended to manually delete the files after its use'); ?>);
242 document.de_identification.submit();
245 $(function () {
246 $('.datepicker').datetimepicker({
247 <?php $datetimepicker_timepicker = false; ?>
248 <?php $datetimepicker_showseconds = false; ?>
249 <?php $datetimepicker_formatInput = false; ?>
250 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
251 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
255 </script>
256 </head>
257 <body class="body_top">
258 <form name="de_identification" id="de_identification" action="de_identification_screen2.php" method="post" onsubmit="return form_validate();">
259 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
260 <strong><?php echo xlt('De Identification'); ?></strong>
261 <?php
262 $row = sqlQuery("SHOW TABLES LIKE 'de_identification_status'");
263 if (empty($row)) {
265 <table> <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
266 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
267 </table>
268 <table class="de_identification_status_message" align="center" >
269 <tr valign="top">
270 <td>&nbsp;</td>
271 <td rowspan="3">
272 <br />
273 <?php echo xlt('Please upgrade OpenEMR Database to include De Identification procedures, function, tables'); ?>
274 <br /><br /><a target="Blank" href="../../contrib/util/de_identification_upgrade.php"><?php echo xlt('Click here');?></a>
275 <?php echo xlt('to run');
276 echo " de_identification_upgrade.php<br />";?><br />
277 </td>
278 <td>&nbsp;</td>
279 </tr>
280 <tr>
281 <td>&nbsp;</td>
282 <td>&nbsp;</td>
283 </tr>
284 <tr>
285 <td>&nbsp;</td>
286 <td>&nbsp;</td>
287 </tr>
288 </table>
289 <?php
290 } else {
291 $query = "select status from de_identification_status";
292 $res = sqlStatement($query);
293 if ($row = sqlFetchArray($res)) {
294 $deIdentificationStatus = $row['status'];
295 /* $deIdentificationStatus:
296 * 0 - There is no De Identification in progress. (start new De Identification process)
297 * 1 - A De Identification process is currently in progress.
298 * 2 - The De Identification process completed and xls file is ready to download
299 * 3 - The De Identification process completed with error
303 if ($deIdentificationStatus == 1) {
304 //1 - A De Identification process is currently in progress.
306 <table> <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
307 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
308 </table>
309 <table class="de_identification_status_message" align="center" >
310 <tr valign="top">
311 <td>&nbsp;</td>
312 <td rowspan="3">
313 <br />
314 <?php echo xlt('De Identification Process is ongoing');
315 echo "<br /><br />";
316 echo xlt('Please visit De Identification screen after some time');
317 echo "<br />"; ?> <br />
318 </td>
319 <td>&nbsp;</td>
320 </tr>
321 <tr>
322 <td>&nbsp;</td>
323 <td>&nbsp;</td>
324 </tr>
325 <tr>
326 <td>&nbsp;</td>
327 <td>&nbsp;</td>
328 </tr>
329 </table>
330 <?php
331 } elseif ($deIdentificationStatus == 2) {
332 //2 - The De Identification process completed and xls file is ready to download
333 $query = "SELECT count(*) as count FROM de_identified_data ";
334 $res = sqlStatement($query);
335 if ($row = sqlFetchArray($res)) {
336 $no_of_items = $row['count'];
339 if ($no_of_items <= 1) {
340 //start new search - no patient record fount
341 $query = "update de_identification_status set status = 0";
342 $res = sqlStatement($query);
344 <table> <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
345 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
346 </table>
347 <table class="de_identification_status_message" align="center" >
348 <tr valign="top">
350 <td>&nbsp;</td>
351 <td rowspan="3">
352 <br />
353 <?php echo xlt('No Patient record found for given Selection criteria');
354 echo "<br /><br />";
355 echo xlt('Please start new De Identification process');
356 echo "<br />"; ?> <br />
357 </td>
358 <td>&nbsp;</td>
359 </tr>
360 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
362 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
363 </table>
365 <table align="center">
366 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
367 </table>
368 <?php
369 } else {
371 <table> <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
372 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
373 </table>
374 <table class="de_identification_status_message" align="center" >
375 <tr valign="top">
376 <td>&nbsp;</td>
377 <td rowspan="3">
378 <br />
379 <?php echo xlt('De Identification Process is completed');
380 echo "<br /><br />";
381 echo xlt('Please Click download button to download the De Identified data');
382 echo "<br />"; ?> <br />
383 </td>
384 <td>&nbsp;</td>
385 </tr>
386 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
387 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
388 </table>
389 <table align="center">
390 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
391 <tr>
392 <td colspan="2" class="style1">
393 <input type="button" name="Download" value=<?php echo xla("Download");?> onclick="download_file()" ></td>
394 </tr>
395 </table>
396 <?php
398 } elseif ($deIdentificationStatus == 3) {
399 //3 - The De Identification process completed with error
401 <table> <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
402 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
403 </table>
404 <table class="de_identification_status_message" align="center" >
405 <tr valign="top">
406 <td>&nbsp;</td>
407 <td rowspan="3">
408 <br />
409 <?php echo xlt('Some error has occured during De Identification Process');
410 echo "<br /><br />";
411 echo xlt('De Identified data may not be complete');
412 echo "<br /><br />";
413 ?><span class="text"><?php echo xlt('Please view De Identification error log table for more details');
414 echo "<br />"; ?></span> <br />
415 </td>
416 <td>&nbsp;</td>
417 </tr>
418 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
419 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
420 </table>
421 <table align="center">
422 <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr>
423 <tr>
424 <td colspan="2" class="style1">
425 <input type="button" name="Download" value=<?php echo xla("Download Anyway");?> onclick="download_file()"></td>
426 </tr>
427 </table>
428 </tr>
429 </table>
431 <?php
434 if ($deIdentificationStatus == 0) {
435 //0 - There is no De Identification in progress. (start new De Identification process)
437 <div id="overDiv" style="position: absolute; visibility: hidden; z-index: 1000;">
438 </div>
439 <table style="width: 74%" border=0>
440 <tr rowspan=2>
441 <td>&nbsp;</td>
442 <td><span class="text"><?php echo xlt('Begin Date'); ?></span>
443 <input type="text" size="10" class="datepicker" name="begin_date" id="begin_date" value="<?php echo $viewmode ? attr(substr($result['date'], 0, 10)) : date('Y-m-d'); ?>" title="<?php echo xla('yyyy-mm-dd Date of service'); ?>" />
444 </td>
445 <td><span class="text"><?php xl('End Date', 'e'); ?></span>
446 <input type="text" size="10" class="datepicker" name="end_date" id="end_date" value="<?php echo $viewmode ? attr(substr($result['date'], 0, 10)) : date('Y-m-d'); ?>" title="<?php echo xla('yyyy-mm-dd Date of service'); ?>" />
447 </td>
448 <td>&nbsp;</td>
449 <td>&nbsp;</td>
450 </tr>
451 <tr>
452 <td>&nbsp;</td> </tr>
453 <tr><td>&nbsp;</td>
454 <td colspan=2 class="de_identification_input_controls_box"><input type="checkbox" name="unstructured" id="unstructured" value=<?php echo xla("unstructured");?>><span class="text"><?php echo xlt('Include Unstructured data'); ?></span></td>
455 <td>&nbsp;</td></tr>
456 <tr>
457 <td>&nbsp;</td>
458 <td colspan="2">
459 <table class="de_identification_input_controls_box">
460 <tr>
461 <td><span class="text"><?php echo xlt('Select data to be included in De Identified data'); ?></span> <br />
462 <input type="checkbox" name="all" id ="all" value='all' onclick="disable_other_chkbox()"><span class="text"><?php echo xlt('All'); ?> </span><br />
463 <input type="checkbox" name="history_data" id="history_data" value='history_data'><span class="text"><?php echo xlt('History Data'); ?></span> <br />
464 <input type="checkbox" name="immunization" id="immunization" value="immunizations"><span class="text"><?php echo xlt('Immunizations'); ?></span>
465 <br />
466 <input type="checkbox" name="prescriptions" id="prescriptions" value="prescriptions"><span class="text"><?php echo xlt('Prescriptions'); ?></span>
468 &nbsp;</td> <br />
469 <td><br />
470 <input type="checkbox" name="lists" id="lists" value="lists"><span class="text"><?php echo xlt('Issues'); ?> </span><br />
471 <input type="checkbox" name="transactions" id="transactions" value="transactions"><span class="text"><?php echo xlt('Transactions'); ?></span>
472 <br />
473 <input type="checkbox" name="insurance_data" id="insurance_data" value="insurance_data"><span class="text"><?php echo xlt('Insurance Data'); ?> </span><br />
474 <input type="checkbox" name="billing_data" id="billing_data" value="billing_data"><span class="text"><?php echo xlt('Billing Data'); ?></span> <br />
476 &nbsp;</td>
477 </tr>
478 </table>
479 </td>
480 <td>&nbsp;</td>
481 </tr>
482 <tr>
483 <td>&nbsp;</td>
484 <td colspan="2"><br />
485 </td>
486 <td>&nbsp;</td>
487 </tr>
488 <tr>
489 <td>&nbsp;</td>
490 <td colspan="3">
491 <table style="width: 100%">
492 <tr valign="top">
493 <!--diagnosis--><td style="width:50%;" class="style1"><span class="text"><?php echo xlt('Enter Diagnosis'); ?></span>
494 <input type="radio" id="diagnosis" name="diagnosis" value="all" onclick="disable_controls('diagnosis');" /><span class="text"> <?php echo xlt('All'); ?></span>
495 <input type="radio" id="diagnosis" name="diagnosis" value="select_diagnosis" onclick="enable_controls('diagnosis');" />
496 <span class="text"><?php echo xlt('Select Diagnosis'); ?></span>
497 <select id="diagnosis_list" name="diagnosis_list" size="10" style="width: 60%">
498 </select>
500 </td>
501 <td style="width:50%;" class="style1">
502 <!--drugs--><span class="text"><?php echo xlt('Enter Drugs'); ?></span>
503 <input type="radio" id="drugs" name="drugs" value="all"); onclick="disable_controls('drugs')"/><span class="text"> <?php echo xlt('All'); ?></span>
504 <input type="radio" id="drugs" name="drugs" value="select_drug" onclick="enable_controls('drugs')" />
505 <span class="text"><?php echo xlt('Select Drugs'); ?> <br /></span>
506 <select id="drug_list" name="drug_list" size="10" style="width: 60%">
507 </select>
509 </td>
510 </tr>
511 <tr> <td class="style1">
512 <input type="button" name="add_diagnosis" id = "add_diagnosis" value=<?php echo xla("Add Diagnosis"); ?> onclick="get_values('diagnosis')">
513 <input type="button" name="remove_diagnosis" id="remove_diagnosis"value=<?php echo xla("Remove"); ?> onclick="remove_selected('diagnosis')">&nbsp; </td> <td class="style1">
514 <input type="button" name="add_drug" id="add_drug" value=<?php echo xla("Add Drug"); ?> onclick="get_values('drugs')">
515 <input type="button" name="remove_drug" id="remove_drug" value=<?php echo xla("Remove"); ?> onclick="remove_selected('drugs')">
516 </td> </tr>
517 </table>
518 </td>
519 <td>&nbsp;</td>
520 </tr>
521 <tr>
522 <td>&nbsp;</td>
523 <td colspan="2" class="style1">
524 <!--immunizations--><br />
525 <span class="text"><?php echo xlt('Enter Immunizations'); ?></span>
526 <input type="radio" id="immunizations" name="immunizations" value="all" onclick="disable_controls('immunizations')"/><span class="text"> <?php echo xlt('All'); ?></span>
527 <input type="radio" id="immunizations" name="immunizations" value="select_immunization" onclick="enable_controls('immunizations')" />
528 <span class="text"><?php echo xlt('Select Immunizations'); ?></span> <br />
529 <select id="immunization_list" name="immunization_list" size="10" width="300" style="width: 30%">
530 </select> <br />
531 <input type="button" name="add_immunization" id="add_immunization" value="<?php echo xla("Add Immunization"); ?>" onclick="get_values('immunizations')">
532 <input type="button" name="remove_immunization" id="remove_immunization" value="<?php echo xla("Remove"); ?>" onclick="remove_selected('immunizations')">
533 <br />
534 &nbsp;</td>
535 <td>&nbsp;</td>
536 </tr>
537 <tr>
538 <td>&nbsp;</td>
539 <td colspan="2" class="style1">
540 <input type="submit" name="Submit" value="<?php echo xla("Submit"); ?>" ></td>
541 <td>&nbsp;</td>
542 </tr>
544 <input type="hidden" name="diagnosis_text" id="diagnosis_text"><br />
545 <input type="hidden" name="drug_text" id="drug_text"><br />
546 <input type="hidden" name="immunization_text" id="immunization_text">
547 </table>
548 <?php
553 </form>
554 </body>
555 </html>