Added ESign api and implemantion of ESign on forms and encounters
[openemr.git] / interface / patient_file / encounter / forms.php
blobdfca6bb7ed2d0000ab547c3a8203615e40e69406
1 <?php
2 use ESign\Api;
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 require_once("../../globals.php");
9 require_once("$srcdir/forms.inc");
10 require_once("$srcdir/calendar.inc");
11 require_once("$srcdir/acl.inc");
12 require_once("$srcdir/formatting.inc.php");
13 require_once("$srcdir/patient.inc");
14 require_once("$srcdir/amc.php");
15 require_once $GLOBALS['srcdir'].'/ESign/Api.php';
17 <html>
19 <head>
20 <?php html_header_show();?>
21 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
22 <link rel="stylesheet" type="text/css" href="../../../library/js/fancybox-2.1.5/source/jquery.fancybox.css" media="screen" />
23 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
25 <!-- supporting javascript code -->
26 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.9.1.min.js"></script>
27 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
28 <script type="text/javascript" src="../../../library/textformat.js"></script>
29 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
30 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
31 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
32 <script type="text/javascript" src="../../../library/js/common.js"></script>
33 <script type="text/javascript" src="../../../library/js/fancybox-2.1.5/source/jquery.fancybox.js"></script>
34 <script src="<?php echo $GLOBALS['webroot'] ?>/library/ESign/js/jquery.esign.js"></script>
35 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/ESign/css/esign.css" />
36 <?php
37 $esignApi = new Api();
39 <script type="text/javascript">
40 $(document).ready( function() {
41 var formConfig = <?php echo $esignApi->formConfigToJson(); ?>;
42 $(".esign-button-form").esign(
43 formConfig,
45 afterFormSuccess : function( response ) {
46 if ( response.locked ) {
47 var editButtonId = "form-edit-button-"+response.formDir+"-"+response.formId;
48 $("#"+editButtonId).replaceWith( response.editButtonHtml );
51 var logId = "esign-signature-log-"+response.formDir+"-"+response.formId;
52 $.post( formConfig.logViewAction, response, function( html ) {
53 $("#"+logId).replaceWith( html );
54 });
59 var encounterConfig = <?php echo $esignApi->encounterConfigToJson(); ?>;
60 $(".esign-button-encounter").esign(
61 encounterConfig,
63 afterFormSuccess : function( response ) {
64 // If the response indicates a locked encounter, replace all
65 // form edit buttons with a "disabled" button, and "disable" left
66 // nav visit form links
67 if ( response.locked ) {
68 // Lock the form edit buttons
69 $(".form-edit-button").replaceWith( response.editButtonHtml );
70 // Disable the new-form capabilities in left nav
71 top.window.parent.left_nav.syncRadios();
72 // Disable the new-form capabilities in top nav of the encounter
73 $(".encounter-form-category-li").remove();
76 var logId = "esign-signature-log-encounter-"+response.encounterId;
77 $.post( encounterConfig.logViewAction, response, function( html ) {
78 $("#"+logId).replaceWith( html );
79 });
83 });
85 // Process click on Delete link.
86 function deleteme() {
87 dlgopen('../deleter.php?encounterid=<?php echo $encounter; ?>', '_blank', 500, 450);
88 return false;
91 // Called by the deleter.php window on a successful delete.
92 function imdeleted(EncounterId) {
93 <?php if ($GLOBALS['concurrent_layout']) { ?>
94 top.window.parent.left_nav.removeOptionSelected(EncounterId);
95 top.window.parent.left_nav.clearEncounter();
96 <?php } else { ?>
97 top.restoreSession();
98 top.Title.location.href = '../patient_file/encounter/encounter_title.php';
99 top.Main.location.href = '../patient_file/encounter/patient_encounter.php?mode=new';
100 <?php } ?>
103 </script>
105 <script language="javascript">
106 function expandcollapse(atr){
107 if(atr == "expand") {
108 for(i=1;i<15;i++){
109 var mydivid="divid_"+i;var myspanid="spanid_"+i;
110 var ele = document.getElementById(mydivid); var text = document.getElementById(myspanid);
111 ele.style.display = "block";text.innerHTML = "<?php xl('Collapse','e'); ?>";
114 else {
115 for(i=1;i<15;i++){
116 var mydivid="divid_"+i;var myspanid="spanid_"+i;
117 var ele = document.getElementById(mydivid); var text = document.getElementById(myspanid);
118 ele.style.display = "none"; text.innerHTML = "<?php xl('Expand','e'); ?>";
124 function divtoggle(spanid, divid) {
125 var ele = document.getElementById(divid);
126 var text = document.getElementById(spanid);
127 if(ele.style.display == "block") {
128 ele.style.display = "none";
129 text.innerHTML = "<?php xl('Expand','e'); ?>";
131 else {
132 ele.style.display = "block";
133 text.innerHTML = "<?php xl('Collapse','e'); ?>";
136 </script>
138 <style type="text/css">
139 div.tab {
140 min-height: 50px;
141 padding:8px;
144 div.form_header_controls {
145 float:left;margin-bottom:2px;
148 div.form_header {
149 float:left;
150 margin-left:6px;
153 .encounter-summary-container {
154 float:left;
155 width:100%;
158 .encounter-summary-column {
159 width: 33.3%;
160 float:left;
161 display:inline;
162 margin-top:10px;
164 </style>
166 </head>
167 <?php
168 $hide=1;
169 require_once("$incdir/patient_file/encounter/new_form.php");
171 <body class="body_top">
173 <div id="encounter_forms">
176 <?php
177 $dateres = getEncounterDateByEncounter($encounter);
178 $encounter_date = date("Y-m-d",strtotime($dateres["date"]));
179 $providerIDres = getProviderIdOfEncounter($encounter);
180 $providerNameRes = getProviderName($providerIDres);
183 <div class='encounter-summary-container'>
184 <div class='encounter-summary-column'>
185 <div>
186 <span class="title"><?php echo oeFormatShortDate($encounter_date) . " " . xl("Encounter"); ?> </span>
187 <?php
188 $auth_notes_a = acl_check('encounters', 'notes_a');
189 $auth_notes = acl_check('encounters', 'notes');
190 $auth_relaxed = acl_check('encounters', 'relaxed');
192 if (is_numeric($pid)) {
193 // Check for no access to the patient's squad.
194 $result = getPatientData($pid, "fname,lname,squad");
195 echo htmlspecialchars( xl('for','',' ',' ') . $result['fname'] . " " . $result['lname'] );
196 if ($result['squad'] && ! acl_check('squads', $result['squad'])) {
197 $auth_notes_a = $auth_notes = $auth_relaxed = 0;
199 // Check for no access to the encounter's sensitivity level.
200 $result = sqlQuery("SELECT sensitivity FROM form_encounter WHERE " .
201 "pid = '$pid' AND encounter = '$encounter' LIMIT 1");
202 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
203 $auth_notes_a = $auth_notes = $auth_relaxed = 0;
207 </div>
208 <div style='margin-top:8px;'>
209 <?php
210 // ESign for entire encounter
211 $esign = $esignApi->createEncounterESign( $encounter );
212 if ( $esign->isButtonViewable() ) {
213 echo $esign->buttonHtml();
216 <?php if (acl_check('admin', 'super')) { ?>
217 <a href='toggledivs(this.id,this.id);' class='css_button' onclick='return deleteme()'><span><?php echo xl('Delete') ?></span></a>
218 <?php } ?>
219 &nbsp;&nbsp;&nbsp;<a href="#" onClick='expandcollapse("expand");' style="font-size:80%;"><?php xl('Expand All','e'); ?></a>
220 &nbsp;&nbsp;&nbsp;<a style="font-size:80%;" href="#" onClick='expandcollapse("collapse");'><?php xl('Collapse All','e'); ?></a>
221 </div>
222 </div>
224 <div class='encounter-summary-column'>
225 <?php if ( $esign->isLogViewable() ) {
226 $esign->renderLog();
227 } ?>
228 </div>
230 <div class='encounter-summary-column'>
231 <?php if ($GLOBALS['enable_amc_prompting']) { ?>
232 <div style='float:right;margin-right:25px;border-style:solid;border-width:1px;'>
233 <div style='float:left;margin:5px 5px 5px 5px;'>
234 <table>
235 <tr>
236 <td>
237 <?php // Display the education resource checkbox (AMC prompting)
238 $itemAMC = amcCollect("patient_edu_amc", $pid, 'form_encounter', $encounter);
240 <?php if (!(empty($itemAMC))) { ?>
241 <input type="checkbox" id="prov_edu_res" checked>
242 <?php } else { ?>
243 <input type="checkbox" id="prov_edu_res">
244 <?php } ?>
245 </td>
246 <td>
247 <span class="text"><?php echo xl('Provided Education Resource(s)?') ?></span>
248 </td>
249 </tr>
250 <tr>
251 <td>
252 <?php // Display the Provided Clinical Summary checkbox (AMC prompting)
253 $itemAMC = amcCollect("provide_sum_pat_amc", $pid, 'form_encounter', $encounter);
255 <?php if (!(empty($itemAMC))) { ?>
256 <input type="checkbox" id="provide_sum_pat_flag" checked>
257 <?php } else { ?>
258 <input type="checkbox" id="provide_sum_pat_flag">
259 <?php } ?>
260 </td>
261 <td>
262 <span class="text"><?php echo xl('Provided Clinical Summary?') ?></span>
263 </td>
264 </tr>
265 <?php // Display the medication reconciliation checkboxes (AMC prompting)
266 $itemAMC = amcCollect("med_reconc_amc", $pid, 'form_encounter', $encounter);
268 <?php if (!(empty($itemAMC))) { ?>
269 <tr>
270 <td>
271 <input type="checkbox" id="trans_trand_care" checked>
272 </td>
273 <td>
274 <span class="text"><?php echo xl('Transition/Transfer of Care?') ?></span>
275 </td>
276 </tr>
277 </table>
278 <table style="margin-left:2em;">
279 <tr>
280 <td>
281 <?php if (!(empty($itemAMC['date_completed']))) { ?>
282 <input type="checkbox" id="med_reconc_perf" checked>
283 <?php } else { ?>
284 <input type="checkbox" id="med_reconc_perf">
285 <?php } ?>
286 </td>
287 <td>
288 <span class="text"><?php echo xl('Medication Reconciliation Performed?') ?></span>
289 </td>
290 </tr>
291 </table>
292 <?php } else { ?>
293 <tr>
294 <td>
295 <input type="checkbox" id="trans_trand_care">
296 </td>
297 <td>
298 <span class="text"><?php echo xl('Transition/Transfer of Care?') ?></span>
299 </td>
300 </tr>
301 </table>
302 <table style="margin-left:2em;">
303 <tr>
304 <td>
305 <input type="checkbox" id="med_reconc_perf" DISABLED>
306 </td>
307 <td>
308 <span class="text"><?php echo xl('Medication Reconciliation Performed?') ?></span>
309 </td>
310 </tr>
311 </table>
312 <?php } ?>
313 </div>
314 </div>
315 <?php } ?>
316 </div>
318 </div>
320 <br/>
321 <br/>
323 <?php
324 if ($result = getFormByEncounter($pid, $encounter, "id, date, form_id, form_name, formdir, user, deleted")) {
325 echo "<table width='100%' id='partable'>";
326 $divnos=1;
327 foreach ($result as $iter) {
328 $formdir = $iter['formdir'];
330 // skip forms whose 'deleted' flag is set to 1
331 if ($iter['deleted'] == 1) continue;
333 // Skip forms that we are not authorized to see.
334 if (($auth_notes_a) ||
335 ($auth_notes && $iter['user'] == $_SESSION['authUser']) ||
336 ($auth_relaxed && ($formdir == 'sports_fitness' || $formdir == 'podiatry'))) ;
337 else continue;
339 // $form_info = getFormInfoById($iter['id']);
340 if (strtolower(substr($iter['form_name'],0,5)) == 'camos') {
341 //CAMOS generates links from report.php and these links should
342 //be clickable without causing view.php to come up unexpectedly.
343 //I feel that the JQuery code in this file leading to a click
344 //on the report.php content to bring up view.php steps on a
345 //form's autonomy to generate it's own html content in it's report
346 //but until any other form has a problem with this, I will just
347 //make an exception here for CAMOS and allow it to carry out this
348 //functionality for all other forms. --Mark
349 echo '<tr title="' . xl('Edit form') . '" '.
350 'id="'.$formdir.'~'.$iter['form_id'].'">';
351 } else {
352 echo '<tr title="' . xl('Edit form') . '" '.
353 'id="'.$formdir.'~'.$iter['form_id'].'" class="text onerow">';
355 $user = getNameFromUsername($iter['user']);
357 $form_name = ($formdir == 'newpatient') ? xl('Patient Encounter') : xl_form_title($iter['form_name']);
359 // Create the ESign instance for this form
360 $esign = $esignApi->createFormESign( $iter['id'], $formdir, $encounter );
361 echo "<tr>";
362 echo "<td style='border-bottom:1px solid'>";
363 // a link to edit the form
364 echo "<div class='form_header_controls'>";
366 // If the form is locked, it is no longer editable
367 if ( $esign->isLocked() ) {
368 echo "<a href=# class='css_button_small form-edit-button-locked' id='form-edit-button-".attr($formdir)."-".attr($iter['id'])."'><span>".xlt('Locked')."</span></a>";
369 } else {
370 echo "<a class='css_button_small form-edit-button' id='form-edit-button-".attr($formdir)."-".attr($iter['id'])."' target='".
371 ($GLOBALS['concurrent_layout'] ? "_parent" : "Main") .
372 "' href='$rootdir/patient_file/encounter/view_form.php?" .
373 "formname=" . attr($formdir) . "&id=" . attr($iter['form_id']) .
374 "' onclick='top.restoreSession()'>";
375 echo "<span>" . xlt('Edit') . "</span></a>";
378 if ( $esign->isButtonViewable() ) {
379 echo $esign->buttonHtml();
382 if (acl_check('admin', 'super') ) {
383 if ( $formdir != 'newpatient') {
384 // a link to delete the form from the encounter
385 echo "<a target='".
386 ($GLOBALS['concurrent_layout'] ? "_parent" : "Main") .
387 "' href='$rootdir/patient_file/encounter/delete_form.php?" .
388 "formname=" . $formdir .
389 "&id=" . $iter['id'] .
390 "&encounter=". $encounter.
391 "&pid=".$pid.
392 "' class='css_button_small' title='" . xl('Delete this form') . "' onclick='top.restoreSession()'><span>" . xl('Delete') . "</span></a>";
393 } else {
394 ?><a href='javascript:;' class='css_button_small' style='color:gray'><span><?php xl('Delete','e'); ?></span></a><?php
398 echo "<div class='form_header'>";
400 // Figure out the correct author (encounter authors are the '$providerNameRes', while other
401 // form authors are the '$user['fname'] . " " . $user['lname']').
402 if ($formdir == 'newpatient') {
403 $form_author = $providerNameRes;
405 else {
406 $form_author = $user['fname'] . " " . $user['lname'];
408 echo "<a href='#' onclick='divtoggle(\"spanid_$divnos\",\"divid_$divnos\");' class='small' id='aid_$divnos'><b>$form_name</b> <span class='text'>by " . htmlspecialchars( $form_author ) . "</span> (<span id=spanid_$divnos class=\"indicator\">" . xl('Collapse') . "</span>)</a></div>";
410 echo "</td>\n";
411 echo "</tr>";
412 echo "<tr>";
413 echo "<td valign='top' class='formrow'><div class='tab' id='divid_$divnos' style='display:block'>";
415 // Use the form's report.php for display. Forms with names starting with LBF
416 // are list-based forms sharing a single collection of code.
418 if (substr($formdir,0,3) == 'LBF') {
419 include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
420 call_user_func("lbf_report", $pid, $encounter, 2, $iter['form_id'], $formdir);
422 else {
423 include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
424 call_user_func($formdir . "_report", $pid, $encounter, 2, $iter['form_id']);
427 if ( $esign->isLogViewable() ) {
428 $esign->renderLog();
431 echo "</div></td></tr>";
432 $divnos=$divnos+1;
434 echo "</table>";
438 <?php if ($GLOBALS['athletic_team'] && $GLOBALS['concurrent_layout'] == 2) { ?>
439 <script language='JavaScript'>
440 // If this is the top frame then show the encounters list in the bottom frame.
441 // var n = parent.parent.left_nav;
442 var n = top.left_nav;
443 var nf = n.document.forms[0];
444 if (parent.window.name == 'RTop' && nf.cb_bot.checked) {
445 var othername = 'RBot';
446 n.setRadio(othername, 'ens');
447 n.loadFrame('ens1', othername, 'patient_file/history/encounters.php');
449 </script>
450 <?php } ?>
452 </div> <!-- end large encounter_forms DIV -->
453 </body>
455 <script language="javascript">
456 // jQuery stuff to make the page a little easier to use
458 $(document).ready(function(){
459 $(".onerow").mouseover(function() { $(this).toggleClass("highlight"); });
460 $(".onerow").mouseout(function() { $(this).toggleClass("highlight"); });
461 $(".onerow").click(function() { GotoForm(this); });
463 $("#prov_edu_res").click(function() {
464 if ( $('#prov_edu_res').attr('checked') ) {
465 var mode = "add";
467 else {
468 var mode = "remove";
470 top.restoreSession();
471 $.post( "../../../library/ajax/amc_misc_data.php",
472 { amc_id: "patient_edu_amc",
473 complete: true,
474 mode: mode,
475 patient_id: <?php echo htmlspecialchars($pid,ENT_NOQUOTES); ?>,
476 object_category: "form_encounter",
477 object_id: <?php echo htmlspecialchars($encounter,ENT_NOQUOTES); ?>
482 $("#provide_sum_pat_flag").click(function() {
483 if ( $('#provide_sum_pat_flag').attr('checked') ) {
484 var mode = "add";
486 else {
487 var mode = "remove";
489 top.restoreSession();
490 $.post( "../../../library/ajax/amc_misc_data.php",
491 { amc_id: "provide_sum_pat_amc",
492 complete: true,
493 mode: mode,
494 patient_id: <?php echo htmlspecialchars($pid,ENT_NOQUOTES); ?>,
495 object_category: "form_encounter",
496 object_id: <?php echo htmlspecialchars($encounter,ENT_NOQUOTES); ?>
501 $("#trans_trand_care").click(function() {
502 if ( $('#trans_trand_care').attr('checked') ) {
503 var mode = "add";
504 // Enable the reconciliation checkbox
505 $("#med_reconc_perf").removeAttr("disabled");
507 else {
508 var mode = "remove";
509 //Disable the reconciliation checkbox (also uncheck it if applicable)
510 $("#med_reconc_perf").attr("disabled", true);
511 $("#med_reconc_perf").removeAttr("checked");
513 top.restoreSession();
514 $.post( "../../../library/ajax/amc_misc_data.php",
515 { amc_id: "med_reconc_amc",
516 complete: false,
517 mode: mode,
518 patient_id: <?php echo htmlspecialchars($pid,ENT_NOQUOTES); ?>,
519 object_category: "form_encounter",
520 object_id: <?php echo htmlspecialchars($encounter,ENT_NOQUOTES); ?>
525 $("#med_reconc_perf").click(function() {
526 if ( $('#med_reconc_perf').attr('checked') ) {
527 var mode = "complete";
529 else {
530 var mode = "uncomplete";
532 top.restoreSession();
533 $.post( "../../../library/ajax/amc_misc_data.php",
534 { amc_id: "med_reconc_amc",
535 complete: true,
536 mode: mode,
537 patient_id: <?php echo htmlspecialchars($pid,ENT_NOQUOTES); ?>,
538 object_category: "form_encounter",
539 object_id: <?php echo htmlspecialchars($encounter,ENT_NOQUOTES); ?>
544 // $(".deleteme").click(function(evt) { deleteme(); evt.stopPropogation(); });
546 var GotoForm = function(obj) {
547 var parts = $(obj).attr("id").split("~");
548 top.restoreSession();
549 <?php if ($GLOBALS['concurrent_layout']): ?>
550 parent.location.href = "<?php echo $rootdir; ?>/patient_file/encounter/view_form.php?formname="+parts[0]+"&id="+parts[1];
551 <?php else: ?>
552 top.Main.location.href = "<?php echo $rootdir; ?>/patient_file/encounter/view_form.php?formname="+parts[0]+"&id="+parts[1];
553 <?php endif; ?>
557 </script>
559 </html>