some session fixes (#1659)
[openemr.git] / interface / patient_file / encounter / forms.php
bloba84d45e0c6cdd35f3e63f9a7309115ba8c667ebe
1 <?php
2 /**
3 * forms.php
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Brady Miller <brady.g.miller@gmail.com>
8 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../../globals.php");
14 require_once("$srcdir/encounter.inc");
15 require_once("$srcdir/group.inc");
16 require_once("$srcdir/calendar.inc");
17 require_once("$srcdir/acl.inc");
18 require_once("$srcdir/patient.inc");
19 require_once("$srcdir/amc.php");
20 require_once $GLOBALS['srcdir'].'/ESign/Api.php';
21 require_once("$srcdir/../controllers/C_Document.class.php");
23 use ESign\Api;
24 use OpenEMR\Core\Header;
26 $reviewMode = false;
27 if (!empty($_REQUEST['review_id'])) {
28 $reviewMode = true;
29 $encounter=sanitizeNumber($_REQUEST['review_id']);
32 $is_group = ($attendant_type == 'gid') ? true : false;
33 if ($attendant_type == 'gid') {
34 $groupId = $therapy_group;
36 $attendant_id = $attendant_type == 'pid' ? $pid : $therapy_group;
37 if ($is_group && !acl_check("groups", "glog", false, array('view','write'))) {
38 echo xlt("access not allowed");
39 exit();
43 <html>
45 <head>
47 <?php require $GLOBALS['srcdir'] . '/js/xl/dygraphs.js.php'; ?>
49 <?php Header::setupHeader(['common','esign','dygraphs']); ?>
51 <?php
52 $esignApi = new Api();
55 <?php // if the track_anything form exists, then include the styling and js functions for graphing
56 if (file_exists(dirname(__FILE__) . "/../../forms/track_anything/style.css")) { ?>
57 <script type="text/javascript" src="<?php echo $GLOBALS['web_root']?>/interface/forms/track_anything/report.js"></script>
58 <link rel="stylesheet" href="<?php echo $GLOBALS['web_root']?>/interface/forms/track_anything/style.css" type="text/css">
59 <?php } ?>
61 <?php
62 // If the user requested attachment of any orphaned procedure orders, do it.
63 if (!empty($_GET['attachid'])) {
64 $attachid = explode(',', $_GET['attachid']);
65 foreach ($attachid as $aid) {
66 $aid = intval($aid);
67 if (!$aid) {
68 continue;
70 $tmp = sqlQuery(
71 "SELECT COUNT(*) AS count FROM procedure_order WHERE " .
72 "procedure_order_id = ? AND patient_id = ? AND encounter_id = 0 AND activity = 1",
73 array($aid, $pid)
75 if (!empty($tmp['count'])) {
76 sqlStatement(
77 "UPDATE procedure_order SET encounter_id = ? WHERE " .
78 "procedure_order_id = ? AND patient_id = ? AND encounter_id = 0 AND activity = 1",
79 array($encounter, $aid, $pid)
81 addForm($encounter, "Procedure Order", $aid, "procedure_order", $pid, $userauthorized);
87 <script type="text/javascript">
88 $.noConflict();
89 jQuery(document).ready( function($) {
90 var formConfig = <?php echo $esignApi->formConfigToJson(); ?>;
91 $(".esign-button-form").esign(
92 formConfig,
94 afterFormSuccess : function( response ) {
95 if ( response.locked ) {
96 var editButtonId = "form-edit-button-"+response.formDir+"-"+response.formId;
97 $("#"+editButtonId).replaceWith( response.editButtonHtml );
100 var logId = "esign-signature-log-"+response.formDir+"-"+response.formId;
101 $.post( formConfig.logViewAction, response, function( html ) {
102 $("#"+logId).replaceWith( html );
108 var encounterConfig = <?php echo $esignApi->encounterConfigToJson(); ?>;
109 $(".esign-button-encounter").esign(
110 encounterConfig,
112 afterFormSuccess : function( response ) {
113 // If the response indicates a locked encounter, replace all
114 // form edit buttons with a "disabled" button, and "disable" left
115 // nav visit form links
116 if ( response.locked ) {
117 // Lock the form edit buttons
118 $(".form-edit-button").replaceWith( response.editButtonHtml );
119 // Disable the new-form capabilities in left nav
120 top.window.parent.left_nav.syncRadios();
121 // Disable the new-form capabilities in top nav of the encounter
122 $(".encounter-form-category-li").remove();
125 var logId = "esign-signature-log-encounter-"+response.encounterId;
126 $.post( encounterConfig.logViewAction, response, function( html ) {
127 $("#"+logId).replaceWith( html );
133 $("#prov_edu_res").click(function() {
134 if ( $('#prov_edu_res').prop('checked') ) {
135 var mode = "add";
137 else {
138 var mode = "remove";
140 top.restoreSession();
141 $.post( "../../../library/ajax/amc_misc_data.php",
142 { amc_id: "patient_edu_amc",
143 complete: true,
144 mode: mode,
145 patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
146 object_category: "form_encounter",
147 object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
152 $("#provide_sum_pat_flag").click(function() {
153 if ( $('#provide_sum_pat_flag').prop('checked') ) {
154 var mode = "add";
156 else {
157 var mode = "remove";
159 top.restoreSession();
160 $.post( "../../../library/ajax/amc_misc_data.php",
161 { amc_id: "provide_sum_pat_amc",
162 complete: true,
163 mode: mode,
164 patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
165 object_category: "form_encounter",
166 object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
171 $("#trans_trand_care").click(function() {
172 if ( $('#trans_trand_care').prop('checked') ) {
173 var mode = "add";
174 // Enable the reconciliation checkbox
175 $("#med_reconc_perf").removeAttr("disabled");
176 $("#soc_provided").removeAttr("disabled");
178 else {
179 var mode = "remove";
180 //Disable the reconciliation checkbox (also uncheck it if applicable)
181 $("#med_reconc_perf").attr("disabled", true);
182 $("#med_reconc_perf").prop("checked",false);
183 $("#soc_provided").attr("disabled",true);
184 $("#soc_provided").prop("checked",false);
186 top.restoreSession();
187 $.post( "../../../library/ajax/amc_misc_data.php",
188 { amc_id: "med_reconc_amc",
189 complete: false,
190 mode: mode,
191 patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
192 object_category: "form_encounter",
193 object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
198 $("#med_reconc_perf").click(function() {
199 if ( $('#med_reconc_perf').prop('checked') ) {
200 var mode = "complete";
202 else {
203 var mode = "uncomplete";
205 top.restoreSession();
206 $.post( "../../../library/ajax/amc_misc_data.php",
207 { amc_id: "med_reconc_amc",
208 complete: true,
209 mode: mode,
210 patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
211 object_category: "form_encounter",
212 object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
216 $("#soc_provided").click(function(){
217 if($('#soc_provided').prop('checked')){
218 var mode = "soc_provided";
220 else{
221 var mode = "no_soc_provided";
223 top.restoreSession();
224 $.post( "../../../library/ajax/amc_misc_data.php",
225 { amc_id: "med_reconc_amc",
226 complete: true,
227 mode: mode,
228 patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
229 object_category: "form_encounter",
230 object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
235 $(".deleteme").click(function(evt) { deleteme(); evt.stopPropogation(); });
237 <?php
238 // If the user was not just asked about orphaned orders, build javascript for that.
239 if (!isset($_GET['attachid'])) {
240 $ares = sqlStatement(
241 "SELECT procedure_order_id, date_ordered " .
242 "FROM procedure_order WHERE " .
243 "patient_id = ? AND encounter_id = 0 AND activity = 1 " .
244 "ORDER BY procedure_order_id",
245 array($pid)
247 echo " // Ask about attaching orphaned orders to this encounter.\n";
248 echo " var attachid = '';\n";
249 while ($arow = sqlFetchArray($ares)) {
250 $orderid = $arow['procedure_order_id'];
251 $orderdate = $arow['date_ordered'];
252 echo " if (confirm('" . xls('There is a lab order') . " $orderid " .
253 xls('dated') . " $orderdate " .
254 xls('for this patient not yet assigned to any encounter.') . " " .
255 xls('Assign it to this one?') . "')) attachid += '$orderid,';\n";
257 echo " if (attachid) location.href = 'forms.php?attachid=' + attachid;\n";
261 <?php if ($reviewMode) { ?>
262 $("body table:first").hide();
263 $(".encounter-summary-column").hide();
264 $(".css_button").hide();
265 $(".css_button_small").hide();
266 $(".encounter-summary-column:first").show();
267 $(".title:first").text("<?php echo xls("Review"); ?> " + $(".title:first").text() + " ( <?php echo addslashes($encounter); ?> )");
268 <?php } ?>
271 // Process click on Delete link.
272 function deleteme() {
273 dlgopen('../deleter.php?encounterid=<?php echo $encounter; ?>', '_blank', 500, 200, '', '', {
274 buttons: [
275 {text: '<?php echo xla('Done'); ?>', close: true, style: 'primary btn-sm'}
277 allowResize: false,
278 allowDrag: true,
280 return false;
283 // Called by the deleter.php window on a successful delete.
284 function imdeleted(EncounterId) {
285 top.window.parent.left_nav.removeOptionSelected(EncounterId);
286 top.window.parent.left_nav.clearEncounter();
287 if (top.tab_mode) {
288 top.encounterList();
289 } else {
290 top.window.parent.left_nav.loadFrame('ens1', window.parent.name, 'patient_file/history/encounters.php');
294 // Called to open the data entry form a specified encounter form instance.
295 function openEncounterForm(formdir, formname, formid) {
296 var url = '<?php echo "$rootdir/patient_file/encounter/view_form.php?formname=" ?>' +
297 formdir + '&id=' + formid;
298 if (formdir == 'newpatient' || !parent.twAddFrameTab) {
299 top.restoreSession();
300 location.href = url;
302 else {
303 parent.twAddFrameTab('enctabs', formname, url);
305 return false;
308 // Called when an encounter form may changed something that requires a refresh here.
309 function refreshVisitDisplay() {
310 location.href = '<?php echo $rootdir; ?>/patient_file/encounter/forms.php';
313 </script>
315 <script language="javascript">
316 function expandcollapse(atr) {
317 for (var i = 1; i < 15; ++i) {
318 var mydivid="divid_" + i; var myspanid = "spanid_" + i;
319 var ele = document.getElementById(mydivid);
320 var text = document.getElementById(myspanid);
321 if (!ele) continue;
322 if (atr == "expand") {
323 ele.style.display = "block"; text.innerHTML = "<?php xl('Collapse', 'e'); ?>";
325 else {
326 ele.style.display = "none" ; text.innerHTML = "<?php xl('Expand', 'e'); ?>";
331 function divtoggle(spanid, divid) {
332 var ele = document.getElementById(divid);
333 var text = document.getElementById(spanid);
334 if(ele.style.display == "block") {
335 ele.style.display = "none";
336 text.innerHTML = "<?php xl('Expand', 'e'); ?>";
338 else {
339 ele.style.display = "block";
340 text.innerHTML = "<?php xl('Collapse', 'e'); ?>";
343 </script>
345 <style type="text/css">
346 div.tab {
347 min-height: 50px;
348 padding:8px;
351 div.form_header {
352 float:left;
353 min-width:300pt;
356 div.form_header_controls {
357 float:left;
358 margin-bottom:2px;
359 margin-left:6px;
362 div.formname {
363 float:left;
364 min-width:120pt;
365 font-weight:bold;
366 padding:0px;
367 margin:0px;
370 .encounter-summary-container {
371 float:left;
372 width:100%;
375 .encounter-summary-column {
376 width: 33.3%;
377 float:left;
378 display:inline;
379 margin-top:10px;
381 </style>
383 <!-- *************** -->
384 <!-- Form menu start -->
385 <script language="JavaScript">
387 function openNewForm(sel, label) {
388 top.restoreSession();
389 var FormNameValueArray = sel.split('formname=');
390 if (FormNameValueArray[1] == 'newpatient') {
391 // TBD: Make this work when it's not the first frame.
392 parent.frames[0].location.href = sel;
394 else {
395 parent.twAddFrameTab('enctabs', label, sel);
399 function toggleFrame1(fnum) {
400 top.frames['left_nav'].document.forms[0].cb_top.checked=false;
401 top.window.parent.left_nav.toggleFrame(fnum);
403 </script>
404 <style type="text/css">
405 #sddm
406 { margin: 0;
407 padding: 0;
408 z-index: 30;
411 </style>
412 <script type="text/javascript" language="javascript">
414 var timeout = 500;
415 var closetimer = 0;
416 var ddmenuitem = 0;
417 var oldddmenuitem = 0;
418 var flag = 0;
420 // open hidden layer
421 function mopen(id)
423 // cancel close timer
424 //mcancelclosetime();
426 flag=10;
428 // close old layer
429 //if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
430 //if(ddmenuitem) ddmenuitem.style.display = 'none';
432 // get new layer and show it
433 oldddmenuitem = ddmenuitem;
434 ddmenuitem = document.getElementById(id);
435 if((ddmenuitem.style.visibility == '')||(ddmenuitem.style.visibility == 'hidden')){
436 if(oldddmenuitem) oldddmenuitem.style.visibility = 'hidden';
437 if(oldddmenuitem) oldddmenuitem.style.display = 'none';
438 ddmenuitem.style.visibility = 'visible';
439 ddmenuitem.style.display = 'block';
440 }else{
441 ddmenuitem.style.visibility = 'hidden';
442 ddmenuitem.style.display = 'none';
445 // close showed layer
446 function mclose()
448 if(flag==10)
450 flag=11;
451 return;
453 if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
454 if(ddmenuitem) ddmenuitem.style.display = 'none';
457 // close layer when click-out
458 document.onclick = mclose;
459 //=================================================
460 function findPosX(id)
462 obj=document.getElementById(id);
463 var curleft = 0;
464 if(obj.offsetParent)
465 while(1)
467 curleft += obj.offsetLeft;
468 if(!obj.offsetParent)
469 break;
470 obj = obj.offsetParent;
472 else if(obj.x)
473 curleft += obj.x;
474 PropertyWidth=document.getElementById(id).offsetWidth;
475 if(PropertyWidth>curleft)
477 document.getElementById(id).style.left=0;
481 function findPosY(obj)
483 var curtop = 0;
484 if(obj.offsetParent)
485 while(1)
487 curtop += obj.offsetTop;
488 if(!obj.offsetParent)
489 break;
490 obj = obj.offsetParent;
492 else if(obj.y)
493 curtop += obj.y;
494 return curtop;
496 </script>
498 </head>
499 <body class="bgcolor2">
500 <dl>
501 <?php //DYNAMIC FORM RETREIVAL
502 include_once("$srcdir/registry.inc");
504 function myGetRegistered($state = "1", $limit = "unlimited", $offset = "0")
506 global $attendant_type;
507 $sql = "SELECT category, nickname, name, state, directory, id, sql_run, " .
508 "unpackaged, date, aco_spec FROM registry WHERE ";
509 // select different forms for groups
510 if ($attendant_type == 'pid') {
511 $sql .= "patient_encounter = 1 AND ";
512 } else {
513 $sql .= "therapy_group_encounter = 1 AND ";
515 $sql .= "state LIKE \"$state\" ORDER BY category, priority, name";
516 if ($limit != "unlimited") {
517 $sql .= " limit $limit, $offset";
519 $res = sqlStatement($sql);
520 if ($res) {
521 for ($iter=0; $row=sqlFetchArray($res); $iter++) {
522 $all[$iter] = $row;
524 } else {
525 return false;
527 return $all;
530 $reg = myGetRegistered();
531 $old_category = '';
533 $DivId=1;
535 // To see if the encounter is locked. If it is, no new forms can be created
536 $encounterLocked = false;
537 if ($esignApi->lockEncounters() &&
538 isset($GLOBALS['encounter']) &&
539 !empty($GLOBALS['encounter']) ) {
540 $esign = $esignApi->createEncounterESign($GLOBALS['encounter']);
541 if ($esign->isLocked()) {
542 $encounterLocked = true;
546 if (!empty($reg)) {
547 $StringEcho= '<ul id="sddm">';
548 if ($encounterLocked === false) {
549 foreach ($reg as $entry) {
550 // Check permission to create forms of this type.
551 $tmp = explode('|', $entry['aco_spec']);
552 if (!empty($tmp[1])) {
553 if (!acl_check($tmp[0], $tmp[1], '', 'write') && !acl_check($tmp[0], $tmp[1], '', 'addonly')) {
554 continue;
557 $new_category = trim($entry['category']);
558 $new_nickname = trim($entry['nickname']);
559 if ($new_category == '') {
560 $new_category = htmlspecialchars(xl('Miscellaneous'), ENT_QUOTES);
561 } else {
562 $new_category = htmlspecialchars(xl($new_category), ENT_QUOTES);
564 if ($new_nickname != '') {
565 $nickname = $new_nickname;
566 } else {
567 $nickname = trim($entry['name']);
569 if ($old_category != $new_category) {
570 $new_category_ = $new_category;
571 $new_category_ = str_replace(' ', '_', $new_category_);
572 if ($old_category != '') {
573 $StringEcho .= "</table></div></li>";
575 $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'>";
576 $old_category = $new_category;
577 $DivId++;
579 $StringEcho .= "<tr><td style='border-top: 1px solid #000000;padding:0px;'><a onclick=\"openNewForm('" .
580 $rootdir . "/patient_file/encounter/load_form.php?formname=" . urlencode($entry['directory']) .
581 "', '" . addslashes(xl_form_title($nickname)) . "')\" href='JavaScript:void(0);'>" .
582 text(xl_form_title($nickname)) . "</a></td></tr>";
585 $StringEcho.= '</table></div></li>';
588 if ($StringEcho) {
589 $StringEcho2= '<div style="clear:both"></div>';
590 } else {
591 $StringEcho2="";
594 // This shows Layout Based Form names just like the above.
596 if ($encounterLocked === false) {
597 $lres = sqlStatement("SELECT grp_form_id AS option_id, grp_title AS title, grp_aco_spec " .
598 "FROM layout_group_properties WHERE " .
599 "grp_form_id LIKE 'LBF%' AND grp_group_id = '' AND grp_activity = 1 " .
600 "ORDER BY grp_seq, grp_title");
602 if (sqlNumRows($lres)) {
603 if (!$StringEcho) {
604 $StringEcho= '<ul id="sddm">';
606 $StringEcho.= "<li class=\"encounter-form-category-li\"><a href='JavaScript:void(0);' onClick=\"mopen('lbf');\" >" .
607 xl('Layout Based') . "</a><div id='lbf' ><table border='0' cellspacing='0' cellpadding='0'>";
608 while ($lrow = sqlFetchArray($lres)) {
609 $option_id = $lrow['option_id']; // should start with LBF
610 $title = $lrow['title'];
611 // Check ACO attribute, if any, of this LBF.
612 if (!empty($lrow['grp_aco_spec'])) {
613 $tmp = explode('|', $lrow['grp_aco_spec']);
614 if (!acl_check($tmp[0], $tmp[1], '', 'write') && !acl_check($tmp[0], $tmp[1], '', 'addonly')) {
615 continue;
618 $StringEcho .= "<tr><td style='border-top: 1px solid #000000;padding:0px;'><a onclick=\"openNewForm('" .
619 $rootdir . "/patient_file/encounter/load_form.php?formname=" . urlencode($option_id) .
620 "', '" . addslashes(xl_form_title($title)) . "')\" href='JavaScript:void(0);'>" .
621 text(xl_form_title($title)) . "</a></td></tr>";
626 <!-- DISPLAYING HOOKS STARTS HERE -->
627 <?php
628 $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
629 obj_name=enabled_hooks AND ms.mod_id=msh.mod_id LEFT OUTER JOIN modules AS m ON m.mod_id=ms.mod_id
630 WHERE fld_type=3 AND mod_active=1 AND sql_run=1 AND attached_to='encounter' ORDER BY mod_id");
631 $DivId = 'mod_installer';
632 if (sqlNumRows($module_query)) {
633 $jid = 0;
634 $modid = '';
635 while ($modulerow = sqlFetchArray($module_query)) {
636 $DivId = 'mod_'.$modulerow['mod_id'];
637 $new_category = $modulerow['mod_ui_name'];
638 $modulePath = "";
639 $added = "";
640 if ($modulerow['type'] == 0) {
641 $modulePath = $GLOBALS['customModDir'];
642 $added = "";
643 } else {
644 $added = "index";
645 $modulePath = $GLOBALS['zendModDir'];
647 $relative_link = "../../modules/".$modulePath."/".$modulerow['path'];
648 $nickname = $modulerow['menu_name'] ? $modulerow['menu_name'] : 'Noname';
649 if ($jid==0 || ($modid!=$modulerow['mod_id'])) {
650 if ($modid!='') {
651 $StringEcho.= '</table></div></li>';
653 $StringEcho.= "<li><a href='JavaScript:void(0);' onClick=\"mopen('$DivId');\" >$new_category</a><div id='$DivId' ><table border='0' cellspacing='0' cellpadding='0'>";
655 $jid++;
656 $modid = $modulerow['mod_id'];
657 $StringEcho.= "<tr><td style='border-top: 1px solid #000000;padding:0px;'><a onclick=" .
658 "\"openNewForm('$relative_link', '" . addslashes(xl_form_title($nickname)) . "')\" " .
659 "href='JavaScript:void(0);'>" . xl_form_title($nickname) . "</a></td></tr>";
663 <!-- DISPLAYING HOOKS ENDS HERE -->
664 <?php
665 if ($StringEcho) {
666 $StringEcho.= "</table></div></li></ul>".$StringEcho2;
669 <table cellspacing="0" cellpadding="0" align="center">
670 <tr>
671 <td valign="top"><?php echo $StringEcho; ?></td>
672 </tr>
673 </table>
674 </dl>
675 <!-- Form menu stop -->
676 <!-- *************** -->
678 <div id="encounter_forms">
680 <?php
681 $dateres = getEncounterDateByEncounter($encounter);
682 $encounter_date = date("Y-m-d", strtotime($dateres["date"]));
683 $providerIDres = getProviderIdOfEncounter($encounter);
684 $providerNameRes = getProviderName($providerIDres);
687 <div class='encounter-summary-container'>
688 <div class='encounter-summary-column'>
689 <div>
690 <?php
691 $pass_sens_squad = true;
693 //fetch acl for category of given encounter
694 $pc_catid = fetchCategoryIdByEncounter($encounter);
695 $postCalendarCategoryACO = fetchPostCalendarCategoryACO($pc_catid);
696 if ($postCalendarCategoryACO) {
697 $postCalendarCategoryACO = explode('|', $postCalendarCategoryACO);
698 $authPostCalendarCategory = acl_check($postCalendarCategoryACO[0], $postCalendarCategoryACO[1]);
699 $authPostCalendarCategoryWrite = acl_check($postCalendarCategoryACO[0], $postCalendarCategoryACO[1], '', 'write');
700 } else { // if no aco is set for category
701 $authPostCalendarCategory = true;
702 $authPostCalendarCategoryWrite = true;
705 if ($attendant_type == 'pid' && is_numeric($pid)) {
706 echo '<span class="title">' . text(oeFormatShortDate($encounter_date)) . " " . xlt("Encounter") . '</span>';
708 // Check for no access to the patient's squad.
709 $result = getPatientData($pid, "fname,lname,squad");
710 echo htmlspecialchars(xl('for', '', ' ', ' ') . $result['fname'] . " " . $result['lname']);
711 if ($result['squad'] && ! acl_check('squads', $result['squad'])) {
712 $pass_sens_squad = false;
715 // Check for no access to the encounter's sensitivity level.
716 $result = sqlQuery("SELECT sensitivity FROM form_encounter WHERE " .
717 "pid = '$pid' AND encounter = '$encounter' LIMIT 1");
718 if (($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) || !$authPostCalendarCategory) {
719 $pass_sens_squad = false;
721 // for therapy group
722 } else {
723 echo '<span class="title">' . text(oeFormatShortDate($encounter_date)) . " " . xlt("Group Encounter") . '</span>';
724 // Check for no access to the patient's squad.
725 $result = getGroup($groupId);
726 echo htmlspecialchars(xl('for ', '', ' ', ' ') . $result['group_name']);
727 if ($result['squad'] && ! acl_check('squads', $result['squad'])) {
728 $pass_sens_squad = false;
730 // Check for no access to the encounter's sensitivity level.
731 $result = sqlQuery("SELECT sensitivity FROM form_groups_encounter WHERE " .
732 "group_id = ? AND encounter = ? LIMIT 1", array($groupId, $encounter));
733 if (($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) || !$authPostCalendarCategory) {
734 $pass_sens_squad = false;
738 </div>
739 <div style='margin-top:8px;'>
740 <?php
741 // ESign for entire encounter
742 $esign = $esignApi->createEncounterESign($encounter);
743 if ($esign->isButtonViewable()) {
744 echo $esign->buttonHtml();
747 <?php if (acl_check('admin', 'super')) { ?>
748 <a href='#' class='css_button' onclick='return deleteme()'><span><?php echo xl('Delete') ?></span></a>
749 <?php } ?>
750 &nbsp;&nbsp;&nbsp;<a href="#" onClick='expandcollapse("expand");' style="font-size:80%;"><?php xl('Expand All', 'e'); ?></a>
751 &nbsp;&nbsp;&nbsp;<a style="font-size:80%;" href="#" onClick='expandcollapse("collapse");'><?php xl('Collapse All', 'e'); ?></a>
752 </div>
753 </div>
755 <div class='encounter-summary-column'>
756 <?php if ($esign->isLogViewable()) {
757 $esign->renderLog();
758 } ?>
759 </div>
761 <div class='encounter-summary-column'>
762 <?php if ($GLOBALS['enable_amc_prompting']) { ?>
763 <div style='float:right;margin-right:25px;border-style:solid;border-width:1px;'>
764 <div style='float:left;margin:5px 5px 5px 5px;'>
765 <table>
766 <tr>
767 <td>
768 <?php // Display the education resource checkbox (AMC prompting)
769 $itemAMC = amcCollect("patient_edu_amc", $pid, 'form_encounter', $encounter);
771 <?php if (!(empty($itemAMC))) { ?>
772 <input type="checkbox" id="prov_edu_res" checked>
773 <?php } else { ?>
774 <input type="checkbox" id="prov_edu_res">
775 <?php } ?>
776 </td>
777 <td>
778 <span class="text"><?php echo xl('Provided Education Resource(s)?') ?></span>
779 </td>
780 </tr>
781 <tr>
782 <td>
783 <?php // Display the Provided Clinical Summary checkbox (AMC prompting)
784 $itemAMC = amcCollect("provide_sum_pat_amc", $pid, 'form_encounter', $encounter);
786 <?php if (!(empty($itemAMC))) { ?>
787 <input type="checkbox" id="provide_sum_pat_flag" checked>
788 <?php } else { ?>
789 <input type="checkbox" id="provide_sum_pat_flag">
790 <?php } ?>
791 </td>
792 <td>
793 <span class="text"><?php echo xl('Provided Clinical Summary?') ?></span>
794 </td>
795 </tr>
796 <?php // Display the medication reconciliation checkboxes (AMC prompting)
797 $itemAMC = amcCollect("med_reconc_amc", $pid, 'form_encounter', $encounter);
799 <?php if (!(empty($itemAMC))) { ?>
800 <tr>
801 <td>
802 <input type="checkbox" id="trans_trand_care" checked>
803 </td>
804 <td>
805 <span class="text"><?php echo xl('Transition/Transfer of Care?') ?></span>
806 </td>
807 </tr>
808 </table>
809 <table style="margin-left:2em;">
810 <tr>
811 <td>
812 <?php if (!(empty($itemAMC['date_completed']))) { ?>
813 <input type="checkbox" id="med_reconc_perf" checked>
814 <?php } else { ?>
815 <input type="checkbox" id="med_reconc_perf">
816 <?php } ?>
817 </td>
818 <td>
819 <span class="text"><?php echo xl('Medication Reconciliation Performed?') ?></span>
820 </td>
821 </tr>
822 <tr>
823 <td>
824 <?php if (!(empty($itemAMC['soc_provided']))) { ?>
825 <input type="checkbox" id="soc_provided" checked>
826 <?php } else { ?>
827 <input type="checkbox" id="soc_provided">
828 <?php } ?>
829 </td>
830 <td>
831 <span class="text"><?php echo xl('Summary Of Care Provided?') ?></span>
832 </td>
833 </tr>
834 </table>
835 <?php } else { ?>
836 <tr>
837 <td>
838 <input type="checkbox" id="trans_trand_care">
839 </td>
840 <td>
841 <span class="text"><?php echo xl('Transition/Transfer of Care?') ?></span>
842 </td>
843 </tr>
844 </table>
845 <table style="margin-left:2em;">
846 <tr>
847 <td>
848 <input type="checkbox" id="med_reconc_perf" DISABLED>
849 </td>
850 <td>
851 <span class="text"><?php echo xl('Medication Reconciliation Performed?') ?></span>
852 </td>
853 </tr>
854 <tr>
855 <td>
856 <input type="checkbox" id="soc_provided" DISABLED>
857 </td>
858 <td>
859 <span class="text"><?php echo xl('Summary of Care Provided?') ?></span>
860 </td>
861 </tr>
862 </table>
863 <?php } ?>
864 </div>
865 </div>
866 <?php } ?>
867 </div>
869 </div>
871 <!-- Get the documents tagged to this encounter and display the links and notes as the tooltip -->
872 <?php
873 if ($attendant_type == 'pid') {
874 $docs_list = getDocumentsByEncounter($pid, $_SESSION['encounter']);
875 } else {
876 // already doesn't exist document for therapy groups
877 $docs_list = array();
879 if (!empty($docs_list) && count($docs_list) > 0) {
881 <div class='enc_docs'>
882 <span class="bold"><?php echo xlt("Document(s)"); ?>:</span>
883 <?php
884 $doc = new C_Document();
885 foreach ($docs_list as $doc_iter) {
886 $doc_url = $doc->_tpl_vars[CURRENT_ACTION]. "&view&patient_id=".attr($pid)."&document_id=" . attr($doc_iter[id]) . "&";
887 // Get notes for this document.
888 $queryString = "SELECT GROUP_CONCAT(note ORDER BY date DESC SEPARATOR '|') AS docNotes, GROUP_CONCAT(date ORDER BY date DESC SEPARATOR '|') AS docDates
889 FROM notes WHERE foreign_id = ? GROUP BY foreign_id";
890 $noteData = sqlQuery($queryString, array($doc_iter[id]));
891 $note = '';
892 if ($noteData) {
893 $notes = array();
894 $notes = explode("|", $noteData['docNotes']);
895 $dates = explode("|", $noteData['docDates']);
896 for ($i = 0; $i < count($notes); $i++) {
897 $note .= oeFormatShortDate(date('Y-m-d', strtotime($dates[$i]))) . " : " . $notes[$i] . "\n";
901 <br>
902 <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>
903 <?php if ($note != '') {?>
904 <a href="javascript:void(0);" title="<?php echo attr($note);?>"><img src="../../../images/info.png"/></a>
905 <?php }?>
906 <?php } ?>
907 </div>
908 <?php } ?>
909 <br/>
911 <?php
912 if ($pass_sens_squad &&
913 ($result = getFormByEncounter(
914 $attendant_id,
915 $encounter,
916 "id, date, form_id, form_name, formdir, user, deleted",
918 "FIND_IN_SET(formdir,'newpatient') DESC, form_name, date DESC"
919 ))) {
920 echo "<table width='100%' id='partable'>";
921 $divnos = 1;
922 foreach ($result as $iter) {
923 $formdir = $iter['formdir'];
925 // skip forms whose 'deleted' flag is set to 1
926 if ($iter['deleted'] == 1) {
927 continue;
930 $aco_spec = false;
932 if (substr($formdir, 0, 3) == 'LBF') {
933 // Skip LBF forms that we are not authorized to see.
934 $lrow = sqlQuery(
935 "SELECT grp_aco_spec " .
936 "FROM layout_group_properties WHERE " .
937 "grp_form_id = ? AND grp_group_id = '' AND grp_activity = 1",
938 array($formdir)
940 if (!empty($lrow)) {
941 if (!empty($lrow['grp_aco_spec'])) {
942 $aco_spec = explode('|', $lrow['grp_aco_spec']);
943 if (!acl_check($aco_spec[0], $aco_spec[1])) {
944 continue;
948 } else {
949 // Skip non-LBF forms that we are not authorized to see.
950 $tmp = getRegistryEntryByDirectory($formdir, 'aco_spec');
951 if (!empty($tmp['aco_spec'])) {
952 $aco_spec = explode('|', $tmp['aco_spec']);
953 if (!acl_check($aco_spec[0], $aco_spec[1])) {
954 continue;
959 // $form_info = getFormInfoById($iter['id']);
960 if (strtolower(substr($iter['form_name'], 0, 5)) == 'camos') {
961 //CAMOS generates links from report.php and these links should
962 //be clickable without causing view.php to come up unexpectedly.
963 //I feel that the JQuery code in this file leading to a click
964 //on the report.php content to bring up view.php steps on a
965 //form's autonomy to generate it's own html content in it's report
966 //but until any other form has a problem with this, I will just
967 //make an exception here for CAMOS and allow it to carry out this
968 //functionality for all other forms. --Mark
969 echo '<tr title="' . xl('Edit form') . '" '.
970 'id="'.$formdir.'~'.$iter['form_id'].'">';
971 } else {
972 echo '<tr id="' . $formdir . '~' . $iter['form_id'] . '" class="text onerow">';
975 $acl_groups = acl_check("groups", "glog", false, 'write') ? true : false;
976 $user = getNameFromUsername($iter['user']);
978 $form_name = ($formdir == 'newpatient') ? xl('Visit Summary') : xl_form_title($iter['form_name']);
980 // Create the ESign instance for this form
981 $esign = $esignApi->createFormESign($iter['id'], $formdir, $encounter);
983 // echo "<tr>"; // Removed as bug fix.
985 echo "<td style='border-bottom:1px solid'>";
987 // Figure out the correct author (encounter authors are the '$providerNameRes', while other
988 // form authors are the '$user['fname'] . " " . $user['lname']').
989 if ($formdir == 'newpatient') {
990 $form_author = $providerNameRes;
991 } else {
992 $form_author = $user['fname'] . " " . $user['lname'];
994 echo "<div class='form_header'>";
995 echo "<a href='#' onclick='divtoggle(\"spanid_$divnos\",\"divid_$divnos\");' class='small' id='aid_$divnos'>" .
996 "<div class='formname'>" . text($form_name) . "</div> " .
997 xlt('by') . " " . text($form_author) . " " .
998 "(<span id=spanid_$divnos class=\"indicator\">" . ($divnos == 1 ? xlt('Collapse') : xlt('Expand')) . "</span>)</a>";
999 echo "</div>";
1001 // a link to edit the form
1002 echo "<div class='form_header_controls'>";
1004 // If the form is locked, it is no longer editable
1005 if ($esign->isLocked()) {
1006 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>";
1007 } else {
1008 if ((!$aco_spec || acl_check($aco_spec[0], $aco_spec[1], '', 'write') and $is_group == 0 and $authPostCalendarCategoryWrite)
1009 or (((!$aco_spec || acl_check($aco_spec[0], $aco_spec[1], '', 'write')) and $is_group and acl_check("groups", "glog", false, 'write')) and $authPostCalendarCategoryWrite)) {
1010 echo "<a class='css_button_small form-edit-button' " .
1011 "id='form-edit-button-" . attr($formdir) . "-" . attr($iter['id']) . "' " .
1012 "href='#' " .
1013 "title='" . xla('Edit this form') . "' " .
1014 "onclick=\"return openEncounterForm('" . attr($formdir) . "', '" .
1015 attr($form_name) . "', '" . attr($iter['form_id']) . "')\">";
1016 echo "<span>" . xlt('Edit') . "</span></a>";
1020 if (($esign->isButtonViewable() and $is_group == 0 and $authPostCalendarCategoryWrite) or ($esign->isButtonViewable() and $is_group and acl_check("groups", "glog", false, 'write') and $authPostCalendarCategoryWrite)) {
1021 if (!$aco_spec || acl_check($aco_spec[0], $aco_spec[1], '', 'write')) {
1022 echo $esign->buttonHtml();
1026 if (substr($formdir, 0, 3) == 'LBF') {
1027 // A link for a nice printout of the LBF
1028 echo "<a target='_blank' " .
1029 "href='$rootdir/forms/LBF/printable.php?" .
1030 "formname=" . urlencode($formdir) .
1031 "&formid=" . urlencode($iter['form_id']) .
1032 "&visitid=" . urlencode($encounter) .
1033 "&patientid=" . urlencode($pid) .
1034 "' class='css_button_small' title='" . xl('Print this form') .
1035 "' onclick='top.restoreSession()'><span>" . xlt('Print') . "</span></a>";
1038 if (acl_check('admin', 'super')) {
1039 if ($formdir != 'newpatient' && $formdir != 'newGroupEncounter') {
1040 // a link to delete the form from the encounter
1041 echo "<a href='$rootdir/patient_file/encounter/delete_form.php?" .
1042 "formname=" . $formdir .
1043 "&id=" . $iter['id'] .
1044 "&encounter=". $encounter.
1045 "&pid=".$pid.
1046 "' class='css_button_small' title='" . xl('Delete this form') . "' onclick='top.restoreSession()'><span>" . xl('Delete') . "</span></a>";
1047 } else {
1048 ?><a href='javascript:;' class='css_button_small' style='color:gray'><span><?php xl('Delete', 'e'); ?></span></a><?php
1051 echo "</div>\n"; // Added as bug fix.
1053 echo "</td>\n";
1054 echo "</tr>";
1055 echo "<tr>";
1056 echo "<td valign='top' class='formrow'><div class='tab' id='divid_$divnos' ";
1057 echo "style='display:" . ($divnos == 1 ? 'block' : 'none') . "'>";
1059 // Use the form's report.php for display. Forms with names starting with LBF
1060 // are list-based forms sharing a single collection of code.
1062 if (substr($formdir, 0, 3) == 'LBF') {
1063 include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
1065 call_user_func("lbf_report", $attendant_id, $encounter, 2, $iter['form_id'], $formdir, true);
1066 } else {
1067 include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
1068 call_user_func($formdir . "_report", $attendant_id, $encounter, 2, $iter['form_id']);
1071 if ($esign->isLogViewable()) {
1072 $esign->renderLog();
1075 echo "</div></td></tr>";
1076 $divnos=$divnos+1;
1078 echo "</table>";
1080 if (!$pass_sens_squad) {
1081 echo xlt("Not authorized to view this encounter");
1085 </div> <!-- end large encounter_forms DIV -->
1086 </body>
1087 </html>