bug-fix: new encounter cancel not returning in tabs ui. (#1324)
[openemr.git] / interface / patient_file / encounter / forms.php
blob132fe95dd14c908f88be1c90256e280a8e318bed
1 <?php
2 use ESign\Api;
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../../globals.php");
10 require_once("$srcdir/encounter.inc");
11 require_once("$srcdir/group.inc");
12 require_once("$srcdir/calendar.inc");
13 require_once("$srcdir/acl.inc");
14 require_once("$srcdir/patient.inc");
15 require_once("$srcdir/amc.php");
16 require_once $GLOBALS['srcdir'].'/ESign/Api.php';
17 require_once("$srcdir/../controllers/C_Document.class.php");
19 $reviewMode = false;
20 if (!empty($_REQUEST['review_id'])) {
21 $reviewMode = true;
22 $encounter=sanitizeNumber($_REQUEST['review_id']);
25 $is_group = ($attendant_type == 'gid') ? true : false;
26 if ($attendant_type == 'gid') {
27 $groupId = $therapy_group;
29 $attendant_id = $attendant_type == 'pid' ? $pid : $therapy_group;
30 if ($is_group && !acl_check("groups", "glog", false, array('view','write'))) {
31 echo xlt("access not allowed");
32 exit();
36 <html>
38 <head>
40 <?php require $GLOBALS['srcdir'] . '/js/xl/dygraphs.js.php'; ?>
42 <?php html_header_show();?>
43 <link href="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap-3-3-4/dist/css/bootstrap.min.css" rel="stylesheet" />
44 <?php if ($_SESSION['language_direction'] == 'rtl') { ?>
45 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative'] ?>/bootstrap-rtl-3-3-4/dist/css/bootstrap-rtl.min.css">
46 <?php } ?>
47 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
48 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/ESign/css/esign.css" />
49 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/modified/dygraphs-2-0-0/dygraph.css" type="text/css"></script>
51 <!-- supporting javascript code -->
52 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
53 <script src="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap-3-3-4/dist/js/bootstrap.min.js" type="text/javascript"></script>
54 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
55 <script type="text/javascript" src="../../../library/textformat.js"></script>
56 <script type="text/javascript" src="../../../library/js/common.js"></script>
57 <script src="<?php echo $GLOBALS['webroot'] ?>/library/ESign/js/jquery.esign.js"></script>
58 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/modified/dygraphs-2-0-0/dygraph.js?v=<?php echo $v_js_includes; ?>"></script>
60 <?php
61 $esignApi = new Api();
64 <?php // if the track_anything form exists, then include the styling and js functions for graphing
65 if (file_exists(dirname(__FILE__) . "/../../forms/track_anything/style.css")) { ?>
66 <script type="text/javascript" src="<?php echo $GLOBALS['web_root']?>/interface/forms/track_anything/report.js"></script>
67 <link rel="stylesheet" href="<?php echo $GLOBALS['web_root']?>/interface/forms/track_anything/style.css" type="text/css">
68 <?php } ?>
70 <?php
71 // If the user requested attachment of any orphaned procedure orders, do it.
72 if (!empty($_GET['attachid'])) {
73 $attachid = explode(',', $_GET['attachid']);
74 foreach ($attachid as $aid) {
75 $aid = intval($aid);
76 if (!$aid) {
77 continue;
79 $tmp = sqlQuery(
80 "SELECT COUNT(*) AS count FROM procedure_order WHERE " .
81 "procedure_order_id = ? AND patient_id = ? AND encounter_id = 0 AND activity = 1",
82 array($aid, $pid)
84 if (!empty($tmp['count'])) {
85 sqlStatement(
86 "UPDATE procedure_order SET encounter_id = ? WHERE " .
87 "procedure_order_id = ? AND patient_id = ? AND encounter_id = 0 AND activity = 1",
88 array($encounter, $aid, $pid)
90 addForm($encounter, "Procedure Order", $aid, "procedure_order", $pid, $userauthorized);
96 <script type="text/javascript">
97 $.noConflict();
98 jQuery(document).ready( function($) {
99 var formConfig = <?php echo $esignApi->formConfigToJson(); ?>;
100 $(".esign-button-form").esign(
101 formConfig,
103 afterFormSuccess : function( response ) {
104 if ( response.locked ) {
105 var editButtonId = "form-edit-button-"+response.formDir+"-"+response.formId;
106 $("#"+editButtonId).replaceWith( response.editButtonHtml );
109 var logId = "esign-signature-log-"+response.formDir+"-"+response.formId;
110 $.post( formConfig.logViewAction, response, function( html ) {
111 $("#"+logId).replaceWith( html );
117 var encounterConfig = <?php echo $esignApi->encounterConfigToJson(); ?>;
118 $(".esign-button-encounter").esign(
119 encounterConfig,
121 afterFormSuccess : function( response ) {
122 // If the response indicates a locked encounter, replace all
123 // form edit buttons with a "disabled" button, and "disable" left
124 // nav visit form links
125 if ( response.locked ) {
126 // Lock the form edit buttons
127 $(".form-edit-button").replaceWith( response.editButtonHtml );
128 // Disable the new-form capabilities in left nav
129 top.window.parent.left_nav.syncRadios();
130 // Disable the new-form capabilities in top nav of the encounter
131 $(".encounter-form-category-li").remove();
134 var logId = "esign-signature-log-encounter-"+response.encounterId;
135 $.post( encounterConfig.logViewAction, response, function( html ) {
136 $("#"+logId).replaceWith( html );
142 $("#prov_edu_res").click(function() {
143 if ( $('#prov_edu_res').prop('checked') ) {
144 var mode = "add";
146 else {
147 var mode = "remove";
149 top.restoreSession();
150 $.post( "../../../library/ajax/amc_misc_data.php",
151 { amc_id: "patient_edu_amc",
152 complete: true,
153 mode: mode,
154 patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
155 object_category: "form_encounter",
156 object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
161 $("#provide_sum_pat_flag").click(function() {
162 if ( $('#provide_sum_pat_flag').prop('checked') ) {
163 var mode = "add";
165 else {
166 var mode = "remove";
168 top.restoreSession();
169 $.post( "../../../library/ajax/amc_misc_data.php",
170 { amc_id: "provide_sum_pat_amc",
171 complete: true,
172 mode: mode,
173 patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
174 object_category: "form_encounter",
175 object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
180 $("#trans_trand_care").click(function() {
181 if ( $('#trans_trand_care').prop('checked') ) {
182 var mode = "add";
183 // Enable the reconciliation checkbox
184 $("#med_reconc_perf").removeAttr("disabled");
185 $("#soc_provided").removeAttr("disabled");
187 else {
188 var mode = "remove";
189 //Disable the reconciliation checkbox (also uncheck it if applicable)
190 $("#med_reconc_perf").attr("disabled", true);
191 $("#med_reconc_perf").prop("checked",false);
192 $("#soc_provided").attr("disabled",true);
193 $("#soc_provided").prop("checked",false);
195 top.restoreSession();
196 $.post( "../../../library/ajax/amc_misc_data.php",
197 { amc_id: "med_reconc_amc",
198 complete: false,
199 mode: mode,
200 patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
201 object_category: "form_encounter",
202 object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
207 $("#med_reconc_perf").click(function() {
208 if ( $('#med_reconc_perf').prop('checked') ) {
209 var mode = "complete";
211 else {
212 var mode = "uncomplete";
214 top.restoreSession();
215 $.post( "../../../library/ajax/amc_misc_data.php",
216 { amc_id: "med_reconc_amc",
217 complete: true,
218 mode: mode,
219 patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
220 object_category: "form_encounter",
221 object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
225 $("#soc_provided").click(function(){
226 if($('#soc_provided').prop('checked')){
227 var mode = "soc_provided";
229 else{
230 var mode = "no_soc_provided";
232 top.restoreSession();
233 $.post( "../../../library/ajax/amc_misc_data.php",
234 { amc_id: "med_reconc_amc",
235 complete: true,
236 mode: mode,
237 patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
238 object_category: "form_encounter",
239 object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
244 $(".deleteme").click(function(evt) { deleteme(); evt.stopPropogation(); });
246 <?php
247 // If the user was not just asked about orphaned orders, build javascript for that.
248 if (!isset($_GET['attachid'])) {
249 $ares = sqlStatement(
250 "SELECT procedure_order_id, date_ordered " .
251 "FROM procedure_order WHERE " .
252 "patient_id = ? AND encounter_id = 0 AND activity = 1 " .
253 "ORDER BY procedure_order_id",
254 array($pid)
256 echo " // Ask about attaching orphaned orders to this encounter.\n";
257 echo " var attachid = '';\n";
258 while ($arow = sqlFetchArray($ares)) {
259 $orderid = $arow['procedure_order_id'];
260 $orderdate = $arow['date_ordered'];
261 echo " if (confirm('" . xls('There is a lab order') . " $orderid " .
262 xls('dated') . " $orderdate " .
263 xls('for this patient not yet assigned to any encounter.') . " " .
264 xls('Assign it to this one?') . "')) attachid += '$orderid,';\n";
266 echo " if (attachid) location.href = 'forms.php?attachid=' + attachid;\n";
270 <?php if ($reviewMode) { ?>
271 $("body table:first").hide();
272 $(".encounter-summary-column").hide();
273 $(".css_button").hide();
274 $(".css_button_small").hide();
275 $(".encounter-summary-column:first").show();
276 $(".title:first").text("<?php echo xls("Review"); ?> " + $(".title:first").text() + " ( <?php echo addslashes($encounter); ?> )");
277 <?php } ?>
280 // Process click on Delete link.
281 function deleteme() {
282 dlgopen('../deleter.php?encounterid=<?php echo $encounter; ?>', '_blank', 500, 200, '', '', {
283 buttons: [
284 {text: '<?php echo xla('Done'); ?>', close: true, style: 'primary btn-sm'}
286 allowResize: false,
287 allowDrag: true,
289 return false;
292 // Called by the deleter.php window on a successful delete.
293 function imdeleted(EncounterId) {
294 top.window.parent.left_nav.removeOptionSelected(EncounterId);
295 top.window.parent.left_nav.clearEncounter();
296 if (top.tab_mode) {
297 top.encounterList();
298 } else {
299 top.window.parent.left_nav.loadFrame('ens1', window.parent.name, 'patient_file/history/encounters.php');
303 // Called to open the data entry form a specified encounter form instance.
304 function openEncounterForm(formdir, formname, formid) {
305 var url = '<?php echo "$rootdir/patient_file/encounter/view_form.php?formname=" ?>' +
306 formdir + '&id=' + formid;
307 if (formdir == 'newpatient' || !parent.twAddFrameTab) {
308 location.href = url;
310 else {
311 parent.twAddFrameTab('enctabs', formname, url);
313 return false;
316 // Called when an encounter form may changed something that requires a refresh here.
317 function refreshVisitDisplay() {
318 location.href = '<?php echo $rootdir; ?>/patient_file/encounter/forms.php';
321 </script>
323 <script language="javascript">
324 function expandcollapse(atr) {
325 for (var i = 1; i < 15; ++i) {
326 var mydivid="divid_" + i; var myspanid = "spanid_" + i;
327 var ele = document.getElementById(mydivid);
328 var text = document.getElementById(myspanid);
329 if (!ele) continue;
330 if (atr == "expand") {
331 ele.style.display = "block"; text.innerHTML = "<?php xl('Collapse', 'e'); ?>";
333 else {
334 ele.style.display = "none" ; text.innerHTML = "<?php xl('Expand', 'e'); ?>";
339 function divtoggle(spanid, divid) {
340 var ele = document.getElementById(divid);
341 var text = document.getElementById(spanid);
342 if(ele.style.display == "block") {
343 ele.style.display = "none";
344 text.innerHTML = "<?php xl('Expand', 'e'); ?>";
346 else {
347 ele.style.display = "block";
348 text.innerHTML = "<?php xl('Collapse', 'e'); ?>";
351 </script>
353 <style type="text/css">
354 div.tab {
355 min-height: 50px;
356 padding:8px;
359 div.form_header {
360 float:left;
361 min-width:300pt;
364 div.form_header_controls {
365 float:left;
366 margin-bottom:2px;
367 margin-left:6px;
370 div.formname {
371 float:left;
372 min-width:120pt;
373 font-weight:bold;
374 padding:0px;
375 margin:0px;
378 .encounter-summary-container {
379 float:left;
380 width:100%;
383 .encounter-summary-column {
384 width: 33.3%;
385 float:left;
386 display:inline;
387 margin-top:10px;
389 </style>
391 <!-- *************** -->
392 <!-- Form menu start -->
393 <script language="JavaScript">
395 function openNewForm(sel, label) {
396 top.restoreSession();
397 var FormNameValueArray = sel.split('formname=');
398 if (FormNameValueArray[1] == 'newpatient') {
399 // TBD: Make this work when it's not the first frame.
400 parent.frames[0].location.href = sel;
402 else {
403 parent.twAddFrameTab('enctabs', label, sel);
407 function toggleFrame1(fnum) {
408 top.frames['left_nav'].document.forms[0].cb_top.checked=false;
409 top.window.parent.left_nav.toggleFrame(fnum);
411 </script>
412 <style type="text/css">
413 #sddm
414 { margin: 0;
415 padding: 0;
416 z-index: 30;
419 </style>
420 <script type="text/javascript" language="javascript">
422 var timeout = 500;
423 var closetimer = 0;
424 var ddmenuitem = 0;
425 var oldddmenuitem = 0;
426 var flag = 0;
428 // open hidden layer
429 function mopen(id)
431 // cancel close timer
432 //mcancelclosetime();
434 flag=10;
436 // close old layer
437 //if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
438 //if(ddmenuitem) ddmenuitem.style.display = 'none';
440 // get new layer and show it
441 oldddmenuitem = ddmenuitem;
442 ddmenuitem = document.getElementById(id);
443 if((ddmenuitem.style.visibility == '')||(ddmenuitem.style.visibility == 'hidden')){
444 if(oldddmenuitem) oldddmenuitem.style.visibility = 'hidden';
445 if(oldddmenuitem) oldddmenuitem.style.display = 'none';
446 ddmenuitem.style.visibility = 'visible';
447 ddmenuitem.style.display = 'block';
448 }else{
449 ddmenuitem.style.visibility = 'hidden';
450 ddmenuitem.style.display = 'none';
453 // close showed layer
454 function mclose()
456 if(flag==10)
458 flag=11;
459 return;
461 if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
462 if(ddmenuitem) ddmenuitem.style.display = 'none';
465 // close layer when click-out
466 document.onclick = mclose;
467 //=================================================
468 function findPosX(id)
470 obj=document.getElementById(id);
471 var curleft = 0;
472 if(obj.offsetParent)
473 while(1)
475 curleft += obj.offsetLeft;
476 if(!obj.offsetParent)
477 break;
478 obj = obj.offsetParent;
480 else if(obj.x)
481 curleft += obj.x;
482 PropertyWidth=document.getElementById(id).offsetWidth;
483 if(PropertyWidth>curleft)
485 document.getElementById(id).style.left=0;
489 function findPosY(obj)
491 var curtop = 0;
492 if(obj.offsetParent)
493 while(1)
495 curtop += obj.offsetTop;
496 if(!obj.offsetParent)
497 break;
498 obj = obj.offsetParent;
500 else if(obj.y)
501 curtop += obj.y;
502 return curtop;
504 </script>
506 </head>
507 <body class="bgcolor2">
508 <dl>
509 <?php //DYNAMIC FORM RETREIVAL
510 include_once("$srcdir/registry.inc");
512 function myGetRegistered($state = "1", $limit = "unlimited", $offset = "0")
514 global $attendant_type;
515 $sql = "SELECT category, nickname, name, state, directory, id, sql_run, " .
516 "unpackaged, date, aco_spec FROM registry WHERE ";
517 // select different forms for groups
518 if ($attendant_type == 'pid') {
519 $sql .= "patient_encounter = 1 AND ";
520 } else {
521 $sql .= "therapy_group_encounter = 1 AND ";
523 $sql .= "state LIKE \"$state\" ORDER BY category, priority, name";
524 if ($limit != "unlimited") {
525 $sql .= " limit $limit, $offset";
527 $res = sqlStatement($sql);
528 if ($res) {
529 for ($iter=0; $row=sqlFetchArray($res); $iter++) {
530 $all[$iter] = $row;
532 } else {
533 return false;
535 return $all;
538 $reg = myGetRegistered();
539 $old_category = '';
541 $DivId=1;
543 // To see if the encounter is locked. If it is, no new forms can be created
544 $encounterLocked = false;
545 if ($esignApi->lockEncounters() &&
546 isset($GLOBALS['encounter']) &&
547 !empty($GLOBALS['encounter']) ) {
548 $esign = $esignApi->createEncounterESign($GLOBALS['encounter']);
549 if ($esign->isLocked()) {
550 $encounterLocked = true;
554 if (!empty($reg)) {
555 $StringEcho= '<ul id="sddm">';
556 if ($encounterLocked === false) {
557 foreach ($reg as $entry) {
558 // Check permission to create forms of this type.
559 $tmp = explode('|', $entry['aco_spec']);
560 if (!empty($tmp[1])) {
561 if (!acl_check($tmp[0], $tmp[1], '', 'write') && !acl_check($tmp[0], $tmp[1], '', 'addonly')) {
562 continue;
565 $new_category = trim($entry['category']);
566 $new_nickname = trim($entry['nickname']);
567 if ($new_category == '') {
568 $new_category = htmlspecialchars(xl('Miscellaneous'), ENT_QUOTES);
569 } else {
570 $new_category = htmlspecialchars(xl($new_category), ENT_QUOTES);
572 if ($new_nickname != '') {
573 $nickname = $new_nickname;
574 } else {
575 $nickname = trim($entry['name']);
577 if ($old_category != $new_category) {
578 $new_category_ = $new_category;
579 $new_category_ = str_replace(' ', '_', $new_category_);
580 if ($old_category != '') {
581 $StringEcho .= "</table></div></li>";
583 $StringEcho .= "<li class=\"encounter-form-category-li\"><a href='JavaScript:void(0);' onClick=\"mopen('$DivId');\" >$new_category</a><div id='$DivId' ><table border='0' cellspacing='0' cellpadding='0'>";
584 $old_category = $new_category;
585 $DivId++;
587 $StringEcho .= "<tr><td style='border-top: 1px solid #000000;padding:0px;'><a onclick=\"openNewForm('" .
588 $rootdir . "/patient_file/encounter/load_form.php?formname=" . urlencode($entry['directory']) .
589 "', '" . addslashes(xl_form_title($nickname)) . "')\" href='JavaScript:void(0);'>" .
590 text(xl_form_title($nickname)) . "</a></td></tr>";
593 $StringEcho.= '</table></div></li>';
596 if ($StringEcho) {
597 $StringEcho2= '<div style="clear:both"></div>';
598 } else {
599 $StringEcho2="";
602 // This shows Layout Based Form names just like the above.
604 if ($encounterLocked === false) {
605 $lres = sqlStatement("SELECT grp_form_id AS option_id, grp_title AS title, grp_aco_spec " .
606 "FROM layout_group_properties WHERE " .
607 "grp_form_id LIKE 'LBF%' AND grp_group_id = '' AND grp_activity = 1 " .
608 "ORDER BY grp_seq, grp_title");
610 if (sqlNumRows($lres)) {
611 if (!$StringEcho) {
612 $StringEcho= '<ul id="sddm">';
614 $StringEcho.= "<li class=\"encounter-form-category-li\"><a href='JavaScript:void(0);' onClick=\"mopen('lbf');\" >" .
615 xl('Layout Based') . "</a><div id='lbf' ><table border='0' cellspacing='0' cellpadding='0'>";
616 while ($lrow = sqlFetchArray($lres)) {
617 $option_id = $lrow['option_id']; // should start with LBF
618 $title = $lrow['title'];
619 // Check ACO attribute, if any, of this LBF.
620 if (!empty($lrow['grp_aco_spec'])) {
621 $tmp = explode('|', $lrow['grp_aco_spec']);
622 if (!acl_check($tmp[0], $tmp[1], '', 'write') && !acl_check($tmp[0], $tmp[1], '', 'addonly')) {
623 continue;
626 $StringEcho .= "<tr><td style='border-top: 1px solid #000000;padding:0px;'><a onclick=\"openNewForm('" .
627 $rootdir . "/patient_file/encounter/load_form.php?formname=" . urlencode($option_id) .
628 "', '" . addslashes(xl_form_title($title)) . "')\" href='JavaScript:void(0);'>" .
629 text(xl_form_title($title)) . "</a></td></tr>";
634 <!-- DISPLAYING HOOKS STARTS HERE -->
635 <?php
636 $module_query = sqlStatement("SELECT msh.*,ms.menu_name,ms.path,m.mod_ui_name,m.type FROM modules_hooks_settings AS msh LEFT OUTER JOIN modules_settings AS ms ON
637 obj_name=enabled_hooks AND ms.mod_id=msh.mod_id LEFT OUTER JOIN modules AS m ON m.mod_id=ms.mod_id
638 WHERE fld_type=3 AND mod_active=1 AND sql_run=1 AND attached_to='encounter' ORDER BY mod_id");
639 $DivId = 'mod_installer';
640 if (sqlNumRows($module_query)) {
641 $jid = 0;
642 $modid = '';
643 while ($modulerow = sqlFetchArray($module_query)) {
644 $DivId = 'mod_'.$modulerow['mod_id'];
645 $new_category = $modulerow['mod_ui_name'];
646 $modulePath = "";
647 $added = "";
648 if ($modulerow['type'] == 0) {
649 $modulePath = $GLOBALS['customModDir'];
650 $added = "";
651 } else {
652 $added = "index";
653 $modulePath = $GLOBALS['zendModDir'];
655 $relative_link = "../../modules/".$modulePath."/".$modulerow['path'];
656 $nickname = $modulerow['menu_name'] ? $modulerow['menu_name'] : 'Noname';
657 if ($jid==0 || ($modid!=$modulerow['mod_id'])) {
658 if ($modid!='') {
659 $StringEcho.= '</table></div></li>';
661 $StringEcho.= "<li><a href='JavaScript:void(0);' onClick=\"mopen('$DivId');\" >$new_category</a><div id='$DivId' ><table border='0' cellspacing='0' cellpadding='0'>";
663 $jid++;
664 $modid = $modulerow['mod_id'];
665 $StringEcho.= "<tr><td style='border-top: 1px solid #000000;padding:0px;'><a onclick=" .
666 "\"openNewForm('$relative_link', '" . addslashes(xl_form_title($nickname)) . "')\" " .
667 "href='JavaScript:void(0);'>" . xl_form_title($nickname) . "</a></td></tr>";
671 <!-- DISPLAYING HOOKS ENDS HERE -->
672 <?php
673 if ($StringEcho) {
674 $StringEcho.= "</table></div></li></ul>".$StringEcho2;
677 <table cellspacing="0" cellpadding="0" align="center">
678 <tr>
679 <td valign="top"><?php echo $StringEcho; ?></td>
680 </tr>
681 </table>
682 </dl>
683 <!-- Form menu stop -->
684 <!-- *************** -->
686 <div id="encounter_forms">
688 <?php
689 $dateres = getEncounterDateByEncounter($encounter);
690 $encounter_date = date("Y-m-d", strtotime($dateres["date"]));
691 $providerIDres = getProviderIdOfEncounter($encounter);
692 $providerNameRes = getProviderName($providerIDres);
695 <div class='encounter-summary-container'>
696 <div class='encounter-summary-column'>
697 <div>
698 <?php
699 $pass_sens_squad = true;
701 //fetch acl for category of given encounter
702 $pc_catid = fetchCategoryIdByEncounter($encounter);
703 $postCalendarCategoryACO = fetchPostCalendarCategoryACO($pc_catid);
704 if ($postCalendarCategoryACO) {
705 $postCalendarCategoryACO = explode('|', $postCalendarCategoryACO);
706 $authPostCalendarCategory = acl_check($postCalendarCategoryACO[0], $postCalendarCategoryACO[1]);
707 $authPostCalendarCategoryWrite = acl_check($postCalendarCategoryACO[0], $postCalendarCategoryACO[1], '', 'write');
708 } else { // if no aco is set for category
709 $authPostCalendarCategory = true;
710 $authPostCalendarCategoryWrite = true;
713 if ($attendant_type == 'pid' && is_numeric($pid)) {
714 echo '<span class="title">' . text(oeFormatShortDate($encounter_date)) . " " . xlt("Encounter") . '</span>';
716 // Check for no access to the patient's squad.
717 $result = getPatientData($pid, "fname,lname,squad");
718 echo htmlspecialchars(xl('for', '', ' ', ' ') . $result['fname'] . " " . $result['lname']);
719 if ($result['squad'] && ! acl_check('squads', $result['squad'])) {
720 $pass_sens_squad = false;
723 // Check for no access to the encounter's sensitivity level.
724 $result = sqlQuery("SELECT sensitivity FROM form_encounter WHERE " .
725 "pid = '$pid' AND encounter = '$encounter' LIMIT 1");
726 if (($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) || !$authPostCalendarCategory) {
727 $pass_sens_squad = false;
729 // for therapy group
730 } else {
731 echo '<span class="title">' . text(oeFormatShortDate($encounter_date)) . " " . xlt("Group Encounter") . '</span>';
732 // Check for no access to the patient's squad.
733 $result = getGroup($groupId);
734 echo htmlspecialchars(xl('for ', '', ' ', ' ') . $result['group_name']);
735 if ($result['squad'] && ! acl_check('squads', $result['squad'])) {
736 $pass_sens_squad = false;
738 // Check for no access to the encounter's sensitivity level.
739 $result = sqlQuery("SELECT sensitivity FROM form_groups_encounter WHERE " .
740 "group_id = ? AND encounter = ? LIMIT 1", array($groupId, $encounter));
741 if (($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) || !$authPostCalendarCategory) {
742 $pass_sens_squad = false;
746 </div>
747 <div style='margin-top:8px;'>
748 <?php
749 // ESign for entire encounter
750 $esign = $esignApi->createEncounterESign($encounter);
751 if ($esign->isButtonViewable()) {
752 echo $esign->buttonHtml();
755 <?php if (acl_check('admin', 'super')) { ?>
756 <a href='#' class='css_button' onclick='return deleteme()'><span><?php echo xl('Delete') ?></span></a>
757 <?php } ?>
758 &nbsp;&nbsp;&nbsp;<a href="#" onClick='expandcollapse("expand");' style="font-size:80%;"><?php xl('Expand All', 'e'); ?></a>
759 &nbsp;&nbsp;&nbsp;<a style="font-size:80%;" href="#" onClick='expandcollapse("collapse");'><?php xl('Collapse All', 'e'); ?></a>
760 </div>
761 </div>
763 <div class='encounter-summary-column'>
764 <?php if ($esign->isLogViewable()) {
765 $esign->renderLog();
766 } ?>
767 </div>
769 <div class='encounter-summary-column'>
770 <?php if ($GLOBALS['enable_amc_prompting']) { ?>
771 <div style='float:right;margin-right:25px;border-style:solid;border-width:1px;'>
772 <div style='float:left;margin:5px 5px 5px 5px;'>
773 <table>
774 <tr>
775 <td>
776 <?php // Display the education resource checkbox (AMC prompting)
777 $itemAMC = amcCollect("patient_edu_amc", $pid, 'form_encounter', $encounter);
779 <?php if (!(empty($itemAMC))) { ?>
780 <input type="checkbox" id="prov_edu_res" checked>
781 <?php } else { ?>
782 <input type="checkbox" id="prov_edu_res">
783 <?php } ?>
784 </td>
785 <td>
786 <span class="text"><?php echo xl('Provided Education Resource(s)?') ?></span>
787 </td>
788 </tr>
789 <tr>
790 <td>
791 <?php // Display the Provided Clinical Summary checkbox (AMC prompting)
792 $itemAMC = amcCollect("provide_sum_pat_amc", $pid, 'form_encounter', $encounter);
794 <?php if (!(empty($itemAMC))) { ?>
795 <input type="checkbox" id="provide_sum_pat_flag" checked>
796 <?php } else { ?>
797 <input type="checkbox" id="provide_sum_pat_flag">
798 <?php } ?>
799 </td>
800 <td>
801 <span class="text"><?php echo xl('Provided Clinical Summary?') ?></span>
802 </td>
803 </tr>
804 <?php // Display the medication reconciliation checkboxes (AMC prompting)
805 $itemAMC = amcCollect("med_reconc_amc", $pid, 'form_encounter', $encounter);
807 <?php if (!(empty($itemAMC))) { ?>
808 <tr>
809 <td>
810 <input type="checkbox" id="trans_trand_care" checked>
811 </td>
812 <td>
813 <span class="text"><?php echo xl('Transition/Transfer of Care?') ?></span>
814 </td>
815 </tr>
816 </table>
817 <table style="margin-left:2em;">
818 <tr>
819 <td>
820 <?php if (!(empty($itemAMC['date_completed']))) { ?>
821 <input type="checkbox" id="med_reconc_perf" checked>
822 <?php } else { ?>
823 <input type="checkbox" id="med_reconc_perf">
824 <?php } ?>
825 </td>
826 <td>
827 <span class="text"><?php echo xl('Medication Reconciliation Performed?') ?></span>
828 </td>
829 </tr>
830 <tr>
831 <td>
832 <?php if (!(empty($itemAMC['soc_provided']))) { ?>
833 <input type="checkbox" id="soc_provided" checked>
834 <?php } else { ?>
835 <input type="checkbox" id="soc_provided">
836 <?php } ?>
837 </td>
838 <td>
839 <span class="text"><?php echo xl('Summary Of Care Provided?') ?></span>
840 </td>
841 </tr>
842 </table>
843 <?php } else { ?>
844 <tr>
845 <td>
846 <input type="checkbox" id="trans_trand_care">
847 </td>
848 <td>
849 <span class="text"><?php echo xl('Transition/Transfer of Care?') ?></span>
850 </td>
851 </tr>
852 </table>
853 <table style="margin-left:2em;">
854 <tr>
855 <td>
856 <input type="checkbox" id="med_reconc_perf" DISABLED>
857 </td>
858 <td>
859 <span class="text"><?php echo xl('Medication Reconciliation Performed?') ?></span>
860 </td>
861 </tr>
862 <tr>
863 <td>
864 <input type="checkbox" id="soc_provided" DISABLED>
865 </td>
866 <td>
867 <span class="text"><?php echo xl('Summary of Care Provided?') ?></span>
868 </td>
869 </tr>
870 </table>
871 <?php } ?>
872 </div>
873 </div>
874 <?php } ?>
875 </div>
877 </div>
879 <!-- Get the documents tagged to this encounter and display the links and notes as the tooltip -->
880 <?php
881 if ($attendant_type == 'pid') {
882 $docs_list = getDocumentsByEncounter($pid, $_SESSION['encounter']);
883 } else {
884 // already doesn't exist document for therapy groups
885 $docs_list = array();
887 if (count($docs_list) > 0) {
889 <div class='enc_docs'>
890 <span class="bold"><?php echo xlt("Document(s)"); ?>:</span>
891 <?php
892 $doc = new C_Document();
893 foreach ($docs_list as $doc_iter) {
894 $doc_url = $doc->_tpl_vars[CURRENT_ACTION]. "&view&patient_id=".attr($pid)."&document_id=" . attr($doc_iter[id]) . "&";
895 // Get notes for this document.
896 $queryString = "SELECT GROUP_CONCAT(note ORDER BY date DESC SEPARATOR '|') AS docNotes, GROUP_CONCAT(date ORDER BY date DESC SEPARATOR '|') AS docDates
897 FROM notes WHERE foreign_id = ? GROUP BY foreign_id";
898 $noteData = sqlQuery($queryString, array($doc_iter[id]));
899 $note = '';
900 if ($noteData) {
901 $notes = array();
902 $notes = explode("|", $noteData['docNotes']);
903 $dates = explode("|", $noteData['docDates']);
904 for ($i = 0; $i < count($notes); $i++) {
905 $note .= oeFormatShortDate(date('Y-m-d', strtotime($dates[$i]))) . " : " . $notes[$i] . "\n";
909 <br>
910 <a href="<?php echo $doc_url;?>" style="font-size:small;" onsubmit="return top.restoreSession()"><?php echo text(oeFormatShortDate($doc_iter[docdate])) . ": " . text(basename($doc_iter[url]));?></a>
911 <?php if ($note != '') {?>
912 <a href="javascript:void(0);" title="<?php echo attr($note);?>"><img src="../../../images/info.png"/></a>
913 <?php }?>
914 <?php } ?>
915 </div>
916 <?php } ?>
917 <br/>
919 <?php
920 if ($pass_sens_squad &&
921 ($result = getFormByEncounter(
922 $attendant_id,
923 $encounter,
924 "id, date, form_id, form_name, formdir, user, deleted",
926 "FIND_IN_SET(formdir,'newpatient') DESC, form_name, date DESC"
927 ))) {
928 echo "<table width='100%' id='partable'>";
929 $divnos = 1;
930 foreach ($result as $iter) {
931 $formdir = $iter['formdir'];
933 // skip forms whose 'deleted' flag is set to 1
934 if ($iter['deleted'] == 1) {
935 continue;
938 $aco_spec = false;
940 if (substr($formdir, 0, 3) == 'LBF') {
941 // Skip LBF forms that we are not authorized to see.
942 $lrow = sqlQuery(
943 "SELECT grp_aco_spec " .
944 "FROM layout_group_properties WHERE " .
945 "grp_form_id = ? AND grp_group_id = '' AND grp_activity = 1",
946 array($formdir)
948 if (!empty($lrow)) {
949 if (!empty($lrow['grp_aco_spec'])) {
950 $aco_spec = explode('|', $lrow['grp_aco_spec']);
951 if (!acl_check($aco_spec[0], $aco_spec[1])) {
952 continue;
956 } else {
957 // Skip non-LBF forms that we are not authorized to see.
958 $tmp = getRegistryEntryByDirectory($formdir, 'aco_spec');
959 if (!empty($tmp['aco_spec'])) {
960 $aco_spec = explode('|', $tmp['aco_spec']);
961 if (!acl_check($aco_spec[0], $aco_spec[1])) {
962 continue;
967 // $form_info = getFormInfoById($iter['id']);
968 if (strtolower(substr($iter['form_name'], 0, 5)) == 'camos') {
969 //CAMOS generates links from report.php and these links should
970 //be clickable without causing view.php to come up unexpectedly.
971 //I feel that the JQuery code in this file leading to a click
972 //on the report.php content to bring up view.php steps on a
973 //form's autonomy to generate it's own html content in it's report
974 //but until any other form has a problem with this, I will just
975 //make an exception here for CAMOS and allow it to carry out this
976 //functionality for all other forms. --Mark
977 echo '<tr title="' . xl('Edit form') . '" '.
978 'id="'.$formdir.'~'.$iter['form_id'].'">';
979 } else {
980 echo '<tr id="' . $formdir . '~' . $iter['form_id'] . '" class="text onerow">';
983 $acl_groups = acl_check("groups", "glog", false, 'write') ? true : false;
984 $user = getNameFromUsername($iter['user']);
986 $form_name = ($formdir == 'newpatient') ? xl('Visit Summary') : xl_form_title($iter['form_name']);
988 // Create the ESign instance for this form
989 $esign = $esignApi->createFormESign($iter['id'], $formdir, $encounter);
991 // echo "<tr>"; // Removed as bug fix.
993 echo "<td style='border-bottom:1px solid'>";
995 // Figure out the correct author (encounter authors are the '$providerNameRes', while other
996 // form authors are the '$user['fname'] . " " . $user['lname']').
997 if ($formdir == 'newpatient') {
998 $form_author = $providerNameRes;
999 } else {
1000 $form_author = $user['fname'] . " " . $user['lname'];
1002 echo "<div class='form_header'>";
1003 echo "<a href='#' onclick='divtoggle(\"spanid_$divnos\",\"divid_$divnos\");' class='small' id='aid_$divnos'>" .
1004 "<div class='formname'>" . text($form_name) . "</div> " .
1005 xlt('by') . " " . text($form_author) . " " .
1006 "(<span id=spanid_$divnos class=\"indicator\">" . ($divnos == 1 ? xlt('Collapse') : xlt('Expand')) . "</span>)</a>";
1007 echo "</div>";
1009 // a link to edit the form
1010 echo "<div class='form_header_controls'>";
1012 // If the form is locked, it is no longer editable
1013 if ($esign->isLocked()) {
1014 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>";
1015 } else {
1016 if ((!$aco_spec || acl_check($aco_spec[0], $aco_spec[1], '', 'write') and $is_group == 0 and $authPostCalendarCategoryWrite)
1017 or (((!$aco_spec || acl_check($aco_spec[0], $aco_spec[1], '', 'write')) and $is_group and acl_check("groups", "glog", false, 'write')) and $authPostCalendarCategoryWrite)) {
1018 echo "<a class='css_button_small form-edit-button' " .
1019 "id='form-edit-button-" . attr($formdir) . "-" . attr($iter['id']) . "' " .
1020 "href='#' " .
1021 "title='" . xla('Edit this form') . "' " .
1022 "onclick=\"return openEncounterForm('" . attr($formdir) . "', '" .
1023 attr($form_name) . "', '" . attr($iter['form_id']) . "')\">";
1024 echo "<span>" . xlt('Edit') . "</span></a>";
1028 if (($esign->isButtonViewable() and $is_group == 0 and $authPostCalendarCategoryWrite) or ($esign->isButtonViewable() and $is_group and acl_check("groups", "glog", false, 'write') and $authPostCalendarCategoryWrite)) {
1029 if (!$aco_spec || acl_check($aco_spec[0], $aco_spec[1], '', 'write')) {
1030 echo $esign->buttonHtml();
1034 if (substr($formdir, 0, 3) == 'LBF') {
1035 // A link for a nice printout of the LBF
1036 echo "<a target='_blank' " .
1037 "href='$rootdir/forms/LBF/printable.php?" .
1038 "formname=" . urlencode($formdir) .
1039 "&formid=" . urlencode($iter['form_id']) .
1040 "&visitid=" . urlencode($encounter) .
1041 "&patientid=" . urlencode($pid) .
1042 "' class='css_button_small' title='" . xl('Print this form') .
1043 "' onclick='top.restoreSession()'><span>" . xlt('Print') . "</span></a>";
1046 if (acl_check('admin', 'super')) {
1047 if ($formdir != 'newpatient' && $formdir != 'newGroupEncounter') {
1048 // a link to delete the form from the encounter
1049 echo "<a href='$rootdir/patient_file/encounter/delete_form.php?" .
1050 "formname=" . $formdir .
1051 "&id=" . $iter['id'] .
1052 "&encounter=". $encounter.
1053 "&pid=".$pid.
1054 "' class='css_button_small' title='" . xl('Delete this form') . "' onclick='top.restoreSession()'><span>" . xl('Delete') . "</span></a>";
1055 } else {
1056 ?><a href='javascript:;' class='css_button_small' style='color:gray'><span><?php xl('Delete', 'e'); ?></span></a><?php
1059 echo "</div>\n"; // Added as bug fix.
1061 echo "</td>\n";
1062 echo "</tr>";
1063 echo "<tr>";
1064 echo "<td valign='top' class='formrow'><div class='tab' id='divid_$divnos' ";
1065 echo "style='display:" . ($divnos == 1 ? 'block' : 'none') . "'>";
1067 // Use the form's report.php for display. Forms with names starting with LBF
1068 // are list-based forms sharing a single collection of code.
1070 if (substr($formdir, 0, 3) == 'LBF') {
1071 include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
1073 call_user_func("lbf_report", $attendant_id, $encounter, 2, $iter['form_id'], $formdir, true);
1074 } else {
1075 include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
1076 call_user_func($formdir . "_report", $attendant_id, $encounter, 2, $iter['form_id']);
1079 if ($esign->isLogViewable()) {
1080 $esign->renderLog();
1083 echo "</div></td></tr>";
1084 $divnos=$divnos+1;
1086 echo "</table>";
1088 if (!$pass_sens_squad) {
1089 echo xlt("Not authorized to view this encounter");
1093 </div> <!-- end large encounter_forms DIV -->
1094 </body>
1095 </html>