final mu2 changes by Visolve for certification, take 2.
[openemr.git] / interface / logview / logview.php
blob1d5d74bc8728dc1a4cc9658a402658d4becce962
1 <?php
2 include_once("../globals.php");
3 include_once("$srcdir/log.inc");
4 include_once("$srcdir/formdata.inc.php");
5 require_once("$srcdir/formatting.inc.php");
6 ?>
7 <html>
8 <head>
9 <?php html_header_show();?>
10 <link rel="stylesheet" href='<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css' type='text/css'>
11 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
12 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
13 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
14 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
16 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
17 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
18 <style>
19 #logview {
20 width: 100%;
22 #logview table {
23 width:100%;
24 border-collapse: collapse;
26 #logview th {
27 background-color: #cccccc;
28 cursor: pointer; cursor: hand;
29 padding: 5px 5px;
30 align: left;
31 text-align: left;
34 #logview td {
35 background-color: #ffffff;
36 border-bottom: 1px solid #808080;
37 cursor: default;
38 padding: 5px 5px;
39 vertical-align: top;
41 .highlight {
42 background-color: #336699;
43 color: #336699;
45 </style>
46 <script>
47 //function to disable the event type field if the event name is disclosure
48 function eventTypeChange(eventname)
50 if (eventname == "disclosure") {
51 document.theform.type_event.disabled = true;
53 else {
54 document.theform.type_event.disabled = false;
58 // VicarePlus :: This invokes the find-patient popup.
59 function sel_patient() {
60 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
63 // VicarePlus :: This is for callback by the find-patient popup.
64 function setpatient(pid, lname, fname, dob) {
65 var f = document.theform;
66 f.form_patient.value = lname + ', ' + fname;
67 f.form_pid.value = pid;
70 </script>
71 </head>
72 <body class="body_top">
73 <font class="title"><?php xl('Logs Viewer','e'); ?></font>
74 <br>
75 <?php
76 $err_message=0;
77 if ($_GET["start_date"])
78 $start_date = formData('start_date','G');
80 if ($_GET["end_date"])
81 $end_date = formData('end_date','G');
83 if ($_GET["form_patient"])
84 $form_patient = formData('form_patient','G');
87 * Start date should not be greater than end date - Date Validation
89 if ($start_date && $end_date)
91 if($start_date > $end_date){
92 echo "<table><tr class='alert'><td colspan=7>"; xl('Start Date should not be greater than End Date',e);
93 echo "</td></tr></table>";
94 $err_message=1;
99 <?php
100 $form_user = formData('form_user','R');
101 $form_pid = formData('form_pid','R');
102 if ($form_patient == '' ) $form_pid = '';
104 $res = sqlStatement("select distinct LEFT(date,10) as date from log order by date desc limit 30");
105 for($iter=0;$row=sqlFetchArray($res);$iter++) {
106 $ret[$iter] = $row;
109 // Get the users list.
110 $sqlQuery = "SELECT username, fname, lname FROM users " .
111 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) ";
113 $ures = sqlStatement($sqlQuery);
116 <?php
117 $get_sdate=$start_date ? $start_date : date("Y-m-d H:i:s");
118 $get_edate=$end_date ? $end_date : date("Y-m-d H:i:s");
122 <br>
123 <FORM METHOD="GET" name="theform" id="theform">
124 <?php
126 $sortby = formData('sortby','G') ;
127 $direction = formData('direction','G') ;
129 <input type="hidden" name="direction" id="direction" value="<?php echo !empty($direction) ? $direction : 'asc'; ?>">
130 <input type="hidden" name="sortby" id="sortby" value="<?php echo $sortby; ?>">
131 <input type=hidden name=csum value="">
132 <table>
133 <tr><td>
134 <span class="text"><?php xl('Start Date','e'); ?>: </span>
135 </td><td>
136 <input type="text" size="18" name="start_date" id="start_date" value="<?php echo $start_date ? $start_date : (date("Y-m-d") . " 00:00:00"); ?>" title="<?php xl('yyyy-mm-dd H:m Start Date','e'); ?>" onkeyup="datekeyup(this,mypcc,true)" onblur="dateblur(this,mypcc,true)" />
137 <img src="../pic/show_calendar.gif" align="absbottom" width="24" height="22" id="img_begin_date" border="0" alt="[?]" style="cursor: pointer; cursor: hand" title="<?php xl('Click here to choose date time','e'); ?>">&nbsp;
138 </td>
139 <td>
140 <span class="text"><?php xl('End Date','e'); ?>: </span>
141 </td><td>
142 <input type="text" size="18" name="end_date" id="end_date" value="<?php echo $end_date ? $end_date : (date("Y-m-d") . " 23:59:00"); ?>" title="<?php xl('yyyy-mm-dd H:m End Date','e'); ?>" onkeyup="datekeyup(this,mypcc,true)" onblur="dateblur(this,mypcc,true)" />
143 <img src="../pic/show_calendar.gif" align="absbottom" width="24" height="22" id="img_end_date" border="0" alt="[?]" style="cursor: pointer; cursor: hand" title="<?php xl('Click here to choose date time','e'); ?>">&nbsp;
144 </td>
145 <!--VicarePlus :: Feature For Generating Log For The Selected Patient --!>
146 <td>
147 &nbsp;&nbsp;<span class='text'><?php echo htmlspecialchars(xl('Patient'),ENT_NOQUOTES); ?>: </span>
148 </td>
149 <td>
150 <input type='text' size='20' name='form_patient' style='width:100%;cursor:pointer;cursor:hand' value='<?php echo $form_patient ? $form_patient : htmlspecialchars(xl('Click To Select'),ENT_QUOTES); ?>' onclick='sel_patient()' title='<?php echo htmlspecialchars(xl('Click to select patient'),ENT_QUOTES); ?>' />
151 <input type='hidden' name='form_pid' value='<?php echo $form_pid; ?>' />
152 </td>
153 </tr>
154 <tr><td>
155 <span class='text'><?php xl('User','e'); ?>: </span>
156 </td>
157 <td>
158 <?php
159 echo "<select name='form_user'>\n";
160 echo " <option value=''>" . xl('All') . "</option>\n";
161 while ($urow = sqlFetchArray($ures)) {
162 if (!trim($urow['username'])) continue;
163 echo " <option value='" . $urow['username'] . "'";
164 if ($urow['username'] == $form_user) echo " selected";
165 echo ">" . $urow['lname'];
166 if ($urow['fname']) echo ", " . $urow['fname'];
167 echo "</option>\n";
169 echo "</select>\n";
171 </td>
172 <td>
173 <!-- list of events name -->
174 <span class='text'><?php xl('Name of Events','e'); ?>: </span>
175 </td>
176 <td>
177 <?php
178 $res = sqlStatement("select distinct event from log order by event ASC");
179 $ename_list=array(); $j=0;
180 while ($erow = sqlFetchArray($res)) {
181 if (!trim($erow['event'])) continue;
182 $data = explode('-', $erow['event']);
183 $data_c = count($data);
184 $ename=$data[0];
185 for($i=1;$i<($data_c-1);$i++)
187 $ename.="-".$data[$i];
189 $ename_list[$j]=$ename;
190 $j=$j+1;
192 $res1 = sqlStatement("select distinct event from extended_log order by event ASC");
193 // $j=0; // This can't be right! -- Rod 2013-08-23
194 while ($row = sqlFetchArray($res1)) {
195 if (!trim($row['event'])) continue;
196 $new_event = explode('-', $row['event']);
197 $no = count($new_event);
198 $events=$new_event[0];
199 for($i=1;$i<($no-1);$i++)
201 $events.="-".$new_event[$i];
203 if ($events=="disclosure")
204 $ename_list[$j]=$events;
205 $j=$j+1;
207 $ename_list=array_unique($ename_list);
208 $ename_list=array_merge($ename_list);
209 $ecount=count($ename_list);
210 echo "<select name='eventname' onchange='eventTypeChange(this.options[this.selectedIndex].value);'>\n";
211 echo " <option value=''>" . xl('All') . "</option>\n";
212 for($k=0;$k<$ecount;$k++) {
213 echo " <option value='" .$ename_list[$k]. "'";
214 if ($ename_list[$k] == $eventname && $ename_list[$k]!= "") echo " selected";
215 echo ">" . $ename_list[$k];
216 echo "</option>\n";
218 echo "</select>\n";
220 </td>
221 <!-- type of events ends -->
222 <td>
223 &nbsp;&nbsp;<span class='text'><?php xl('Type of Events','e'); ?>: </span>
224 </td><td>
225 <?php
226 $event_types=array("select", "update", "insert", "delete", "replace");
227 $lcount=count($event_types);
228 if($eventname=="disclosure"){
229 echo "<select name='type_event' disabled='disabled'>\n";
230 echo " <option value=''>" . xl('All') . "</option>\n";
231 echo "</option>\n";
233 else{
234 echo "<select name='type_event'>\n";}
235 echo " <option value=''>" . xl('All') . "</option>\n";
236 for($k=0;$k<$lcount;$k++) {
237 echo " <option value='" .$event_types[$k]. "'";
238 if ($event_types[$k] == $type_event && $event_types[$k]!= "") echo " selected";
239 echo ">" . preg_replace('/^select$/','Query',$event_types[$k]); // Convert select to Query for MU2 requirement
240 echo "</option>\n";
242 echo "</select>\n";
244 </td>
245 <tr><td>
246 <span class='text'><?php xl('Include Checksum','e'); ?>: </span>
247 </td><td>
248 <?php
250 $check_sum = formData('check_sum','G');
252 <input type="checkbox" name="check_sum" " <?php if ($check_sum == 'on') echo "checked"; ?>"></input>
253 </td>
254 <td>
255 <input type=hidden name="event" value=<?php echo $event ; ?>>
256 <a href="javascript:document.theform.submit();" class='link_submit'>[<?php xl('Refresh','e'); ?>]</a>
257 </td>
258 <td>
259 <div id='valid_button'>
260 <input type=button id='validate_log' onclick='validatelog();' value='<?php echo xla('Validate Log'); ?>'></input>
261 </div>
262 <div id='log_loading' style="display: none">
263 <img src='../../images/loading.gif'/>
264 </div>
265 </td>
266 </tr>
267 </table>
268 </FORM>
271 <?php if ($start_date && $end_date && $err_message!=1) { ?>
272 <div id="logview">
273 <table>
274 <tr>
275 <!-- <TH><?php xl('Date', 'e'); ?><TD> -->
276 <th id="sortby_date" class="text sortby" title="<?php xl('Sort by date/time','e'); ?>"><?php xl('Date','e'); ?></th>
277 <th id="sortby_event" class="text sortby" title="<?php xl('Sort by Event','e'); ?>"><?php xl('Event','e'); ?></th>
278 <th id="sortby_category" class="text sortby" title="<?php xl('Sort by Category','e'); ?>"><?php xl('Category','e'); ?></th>
279 <th id="sortby_user" class="text sortby" title="<?php xl('Sort by User','e'); ?>"><?php xl('User','e'); ?></th>
280 <th id="sortby_cuser" class="text sortby" title="<?php xl('Sort by Crt User','e'); ?>"><?php xl('Certificate User','e'); ?></th>
281 <th id="sortby_group" class="text sortby" title="<?php xl('Sort by Group','e'); ?>"><?php xl('Group','e'); ?></th>
282 <th id="sortby_pid" class="text sortby" title="<?php xl('Sort by PatientID','e'); ?>"><?php xl('PatientID','e'); ?></th>
283 <th id="sortby_success" class="text sortby" title="<?php xl('Sort by Success','e'); ?>"><?php xl('Success','e'); ?></th>
284 <th id="sortby_comments" class="text sortby" title="<?php xl('Sort by Comments','e'); ?>"><?php xl('Comments','e'); ?></th>
285 <?php if($check_sum) {?>
286 <th id="sortby_checksum" class="text sortby" title="<?php xl('Sort by Checksum','e'); ?>"><?php xl('Checksum','e'); ?></th>
287 <?php } ?>
288 </tr>
289 <?php
291 $eventname = formData('eventname','G');
292 $type_event = formData('type_event','G');
294 <input type=hidden name=event value=<?php echo $eventname."-".$type_event ?>>
295 <?php
297 $tevent=""; $gev="";
298 if($eventname != "" && $type_event != "")
300 $getevent=$eventname."-".$type_event;
303 if(($eventname == "") && ($type_event != ""))
304 { $tevent=$type_event;
306 else if($type_event =="" && $eventname != "")
307 {$gev=$eventname;}
308 else if ($eventname == "")
309 {$gev = "";}
310 else
311 {$gev = $getevent;}
313 if ($ret = getEvents(array('sdate' => $get_sdate,'edate' => $get_edate, 'user' => $form_user, 'patient' => $form_pid, 'sortby' => $_GET['sortby'], 'levent' =>$gev, 'tevent' =>$tevent,'direction' => $_GET['direction']))) {
316 foreach ($ret as $iter) {
317 //translate comments
318 $patterns = array ('/^success/','/^failure/','/ encounter/');
319 $replace = array ( xl('success'), xl('failure'), xl('encounter','',' '));
321 $log_id = $iter['id'];
322 $commentEncrStatus = "No";
323 $logEncryptData = logCommentEncryptData($log_id);
324 if(count($logEncryptData) > 0){
325 $commentEncrStatus = $logEncryptData['encrypt'];
328 //July 1, 2014: Ensoftek: Decrypt comment data if encrypted
329 if($commentEncrStatus == "Yes"){
330 $trans_comments = preg_replace($patterns, $replace, aes256Decrypt($iter["comments"]));
331 }else{
332 $trans_comments = preg_replace($patterns, $replace, $iter["comments"]);
336 <TR class="oneresult">
337 <TD class="text"><?php echo oeFormatShortDate(substr($iter["date"], 0, 10)) . substr($iter["date"], 10) ?></TD>
338 <TD class="text"><?php echo preg_replace('/select$/','Query',$iter["event"]); //Convert select term to Query for MU2 requirements ?></TD>
339 <TD class="text"><?php echo $iter["category"]?></TD>
340 <TD class="text"><?php echo $iter["user"]?></TD>
341 <TD class="text"><?php echo $iter["crt_user"]?></TD>
342 <TD class="text"><?php echo $iter["groupname"]?></TD>
343 <TD class="text"><?php echo $iter["patient_id"]?></TD>
344 <TD class="text"><?php echo $iter["success"]?></TD>
345 <TD class="text"><?php echo nl2br(text(preg_replace('/^select/i','Query',$trans_comments))); //Convert select term to Query for MU2 requirements ?></TD>
346 <?php if($check_sum) { ?>
347 <TD class="text"><?php echo $iter["checksum"]?></TD>
348 <?php } ?>
349 </TR>
351 <?php
355 if (($eventname=="disclosure") || ($gev == ""))
357 $eventname="disclosure";
358 if ($ret = getEvents(array('sdate' => $get_sdate,'edate' => $get_edate, 'user' => $form_user, 'patient' => $form_pid, 'sortby' => $_GET['sortby'], 'event' =>$eventname))) {
359 foreach ($ret as $iter) {
360 $comments=xl('Recipient Name').":".$iter["recipient"].";".xl('Disclosure Info').":".$iter["description"];
362 <TR class="oneresult">
363 <TD class="text"><?php echo htmlspecialchars(oeFormatShortDate(substr($iter["date"], 0, 10)) . substr($iter["date"], 10),ENT_NOQUOTES); ?></TD>
364 <TD class="text"><?php echo htmlspecialchars(xl($iter["event"]),ENT_NOQUOTES);?></TD>
365 <TD class="text"><?php echo htmlspecialchars(xl($iter["category"]),ENT_NOQUOTES);?></TD>
366 <TD class="text"><?php echo htmlspecialchars($iter["user"],ENT_NOQUOTES);?></TD>
367 <TD class="text"><?php echo htmlspecialchars($iter["crt_user"],ENT_NOQUOTES);?></TD>
368 <TD class="text"><?php echo htmlspecialchars($iter["groupname"],ENT_NOQUOTES);?></TD>
369 <TD class="text"><?php echo htmlspecialchars($iter["patient_id"],ENT_NOQUOTES);?></TD>
370 <TD class="text"><?php echo htmlspecialchars($iter["success"],ENT_NOQUOTES);?></TD>
371 <TD class="text"><?php echo htmlspecialchars($comments,ENT_NOQUOTES);?></TD>
372 <?php if($check_sum) { ?>
373 <TD class="text"><?php echo htmlspecialchars($iter["checksum"],ENT_NOQUOTES);?></TD>
374 <?php } ?>
375 </TR>
376 <?php
381 </table>
382 </div>
384 <?php } ?>
386 </body>
388 <script language="javascript">
390 // jQuery stuff to make the page a little easier to use
391 $(document).ready(function(){
392 // funny thing here... good learning experience
393 // the TR has TD children which have their own background and text color
394 // toggling the TR color doesn't change the TD color
395 // so we need to change all the TR's children (the TD's) just as we did the TR
396 // thus we have two calls to toggleClass:
397 // 1 - for the parent (the TR)
398 // 2 - for each of the children (the TDs)
399 $(".oneresult").mouseover(function() { $(this).toggleClass("highlight"); $(this).children().toggleClass("highlight"); });
400 $(".oneresult").mouseout(function() { $(this).toggleClass("highlight"); $(this).children().toggleClass("highlight"); });
402 // click-able column headers to sort the list
403 $('.sortby')
404 $("#sortby_date").click(function() { set_sort_direction(); $("#sortby").val("date"); $("#theform").submit(); });
405 $("#sortby_event").click(function() { set_sort_direction(); $("#sortby").val("event"); $("#theform").submit(); });
406 $("#sortby_category").click(function() { set_sort_direction(); $("#sortby").val("category"); $("#theform").submit(); });
407 $("#sortby_user").click(function() { set_sort_direction(); $("#sortby").val("user"); $("#theform").submit(); });
408 $("#sortby_cuser").click(function() { set_sort_direction(); $("#sortby").val("user"); $("#theform").submit(); });
409 $("#sortby_group").click(function() { set_sort_direction(); $("#sortby").val("groupname"); $("#theform").submit(); });
410 $("#sortby_pid").click(function() { set_sort_direction(); $("#sortby").val("patient_id"); $("#theform").submit(); });
411 $("#sortby_success").click(function() { set_sort_direction(); $("#sortby").val("success"); $("#theform").submit(); });
412 $("#sortby_comments").click(function() { set_sort_direction(); $("#sortby").val("comments"); $("#theform").submit(); });
413 $("#sortby_checksum").click(function() { set_sort_direction(); $("#sortby").val("checksum"); $("#theform").submit(); });
416 function set_sort_direction(){
417 if($('#direction').val() == 'asc')
418 $('#direction').val('desc');
419 else
420 $('#direction').val('asc');
425 /* required for popup calendar */
426 Calendar.setup({inputField:"start_date", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_begin_date", showsTime:true});
427 Calendar.setup({inputField:"end_date", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_end_date", showsTime:true});
429 function validatelog(){
430 var img = document.getElementById('log_loading');
431 var btn = document.getElementById('valid_button');
432 if(img){
433 if(img.style.display == "block"){
434 return false;
436 img.style.display = "block";
437 if(btn){btn.style.display = "none"}
439 $.ajax({
440 url:"../../library/log_validation.php",
441 asynchronous : true,
442 method: "post",
443 success :function(response){
444 if(img){
445 img.style.display="none";
446 if(btn){btn.style.display="block";}
448 alert(response);
450 failure :function(){
451 if(img){
452 img.style.display="none";
453 if(btn){btn.style.display="block";}
455 alert('<?php echo xls("Audit Log Validation Failed"); ?>');
460 </script>
462 </html>