bug fixes in patient_files summary directory (#1964)
[openemr.git] / interface / patient_file / encounter / forms.php
blobc477a01f616c42005589c06aa3a30103c0b9872c
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 js_escape($pid); ?>,
146 object_category: "form_encounter",
147 object_id: <?php echo js_escape($encounter); ?>,
148 csrf_token_form: <?php echo js_escape(collectCsrfToken()); ?>
153 $("#provide_sum_pat_flag").click(function() {
154 if ( $('#provide_sum_pat_flag').prop('checked') ) {
155 var mode = "add";
157 else {
158 var mode = "remove";
160 top.restoreSession();
161 $.post( "../../../library/ajax/amc_misc_data.php",
162 { amc_id: "provide_sum_pat_amc",
163 complete: true,
164 mode: mode,
165 patient_id: <?php echo js_escape($pid); ?>,
166 object_category: "form_encounter",
167 object_id: <?php echo js_escape($encounter); ?>,
168 csrf_token_form: <?php echo js_escape(collectCsrfToken()); ?>
173 $("#trans_trand_care").click(function() {
174 if ( $('#trans_trand_care').prop('checked') ) {
175 var mode = "add";
176 // Enable the reconciliation checkbox
177 $("#med_reconc_perf").removeAttr("disabled");
178 $("#soc_provided").removeAttr("disabled");
180 else {
181 var mode = "remove";
182 //Disable the reconciliation checkbox (also uncheck it if applicable)
183 $("#med_reconc_perf").attr("disabled", true);
184 $("#med_reconc_perf").prop("checked",false);
185 $("#soc_provided").attr("disabled",true);
186 $("#soc_provided").prop("checked",false);
188 top.restoreSession();
189 $.post( "../../../library/ajax/amc_misc_data.php",
190 { amc_id: "med_reconc_amc",
191 complete: false,
192 mode: mode,
193 patient_id: <?php echo js_escape($pid); ?>,
194 object_category: "form_encounter",
195 object_id: <?php echo js_escape($encounter); ?>,
196 csrf_token_form: <?php echo js_escape(collectCsrfToken()); ?>
201 $("#med_reconc_perf").click(function() {
202 if ( $('#med_reconc_perf').prop('checked') ) {
203 var mode = "complete";
205 else {
206 var mode = "uncomplete";
208 top.restoreSession();
209 $.post( "../../../library/ajax/amc_misc_data.php",
210 { amc_id: "med_reconc_amc",
211 complete: true,
212 mode: mode,
213 patient_id: <?php echo js_escape($pid); ?>,
214 object_category: "form_encounter",
215 object_id: <?php echo js_escape($encounter); ?>,
216 csrf_token_form: <?php echo js_escape(collectCsrfToken()); ?>
220 $("#soc_provided").click(function(){
221 if($('#soc_provided').prop('checked')){
222 var mode = "soc_provided";
224 else{
225 var mode = "no_soc_provided";
227 top.restoreSession();
228 $.post( "../../../library/ajax/amc_misc_data.php",
229 { amc_id: "med_reconc_amc",
230 complete: true,
231 mode: mode,
232 patient_id: <?php echo js_escape($pid); ?>,
233 object_category: "form_encounter",
234 object_id: <?php echo js_escape($encounter); ?>,
235 csrf_token_form: <?php echo js_escape(collectCsrfToken()); ?>
240 $(".deleteme").click(function(evt) { deleteme(); evt.stopPropogation(); });
242 <?php
243 // If the user was not just asked about orphaned orders, build javascript for that.
244 if (!isset($_GET['attachid'])) {
245 $ares = sqlStatement(
246 "SELECT procedure_order_id, date_ordered " .
247 "FROM procedure_order WHERE " .
248 "patient_id = ? AND encounter_id = 0 AND activity = 1 " .
249 "ORDER BY procedure_order_id",
250 array($pid)
252 echo " // Ask about attaching orphaned orders to this encounter.\n";
253 echo " var attachid = '';\n";
254 while ($arow = sqlFetchArray($ares)) {
255 $orderid = $arow['procedure_order_id'];
256 $orderdate = $arow['date_ordered'];
257 echo " if (confirm(" . xlj('There is a lab order') . " + ' ' + " . js_escape($orderid). " + ' ' + " .
258 xlj('dated') . " + ' ' + " . js_escape($orderdate) . " + ' ' + " .
259 xlj('for this patient not yet assigned to any encounter.') . " + ' ' + " .
260 xlj('Assign it to this one?') . ")) attachid += " . js_escape($orderid.",") . ";\n";
262 echo " if (attachid) location.href = 'forms.php?attachid=' + encodeURIComponent(attachid);\n";
266 <?php if ($reviewMode) { ?>
267 $("body table:first").hide();
268 $(".encounter-summary-column").hide();
269 $(".css_button").hide();
270 $(".css_button_small").hide();
271 $(".encounter-summary-column:first").show();
272 $(".title:first").text(<?php echo xlj("Review"); ?> + " " + $(".title:first").text() + " ( " + <?php echo js_escape($encounter); ?> + " )");
273 <?php } ?>
276 // Process click on Delete link.
277 function deleteme() {
278 dlgopen('../deleter.php?encounterid=' + <?php echo js_escape($encounter); ?>, '_blank', 500, 200, '', '', {
279 buttons: [
280 {text: <?php echo xlj('Done'); ?>, close: true, style: 'primary btn-sm'}
282 allowResize: false,
283 allowDrag: true,
285 return false;
288 // Called by the deleter.php window on a successful delete.
289 function imdeleted(EncounterId) {
290 top.window.parent.left_nav.removeOptionSelected(EncounterId);
291 top.window.parent.left_nav.clearEncounter();
292 if (top.tab_mode) {
293 top.encounterList();
294 } else {
295 top.window.parent.left_nav.loadFrame('ens1', window.parent.name, 'patient_file/history/encounters.php');
299 // Called to open the data entry form a specified encounter form instance.
300 function openEncounterForm(formdir, formname, formid) {
301 var url = <?php echo js_escape($rootdir); ?> + '/patient_file/encounter/view_form.php?formname=' +
302 encodeURIComponent(formdir) + '&id=' + encodeURIComponent(formid);
303 if (formdir == 'newpatient' || !parent.twAddFrameTab) {
304 top.restoreSession();
305 location.href = url;
307 else {
308 parent.twAddFrameTab('enctabs', formname, url);
310 return false;
313 // Called when an encounter form may changed something that requires a refresh here.
314 function refreshVisitDisplay() {
315 location.href = <?php echo js_escape($rootdir); ?> + '/patient_file/encounter/forms.php';
318 </script>
320 <script language="javascript">
321 function expandcollapse(atr) {
322 for (var i = 1; i < 15; ++i) {
323 var mydivid="divid_" + i; var myspanid = "spanid_" + i;
324 var ele = document.getElementById(mydivid);
325 var text = document.getElementById(myspanid);
326 if (!ele) continue;
327 if (atr == "expand") {
328 ele.style.display = "block"; text.innerHTML = <?php echo xlj('Collapse'); ?>;
330 else {
331 ele.style.display = "none" ; text.innerHTML = <?php echo xlj('Expand'); ?>;
336 function divtoggle(spanid, divid) {
337 var ele = document.getElementById(divid);
338 var text = document.getElementById(spanid);
339 if(ele.style.display == "block") {
340 ele.style.display = "none";
341 text.innerHTML = <?php echo xlj('Expand'); ?>;
343 else {
344 ele.style.display = "block";
345 text.innerHTML = <?php echo xlj('Collapse'); ?>;
348 </script>
350 <style type="text/css">
351 div.tab {
352 min-height: 50px;
353 padding:8px;
356 div.form_header {
357 float:left;
358 min-width:300pt;
361 div.form_header_controls {
362 float:left;
363 margin-bottom:2px;
364 margin-left:6px;
367 div.formname {
368 float:left;
369 min-width:120pt;
370 font-weight:bold;
371 padding:0px;
372 margin:0px;
375 .encounter-summary-container {
376 float:left;
377 width:100%;
380 .encounter-summary-column {
381 width: 33.3%;
382 float:left;
383 display:inline;
384 margin-top:10px;
386 </style>
388 <!-- *************** -->
389 <!-- Form menu start -->
390 <script language="JavaScript">
392 function openNewForm(sel, label) {
393 top.restoreSession();
394 var FormNameValueArray = sel.split('formname=');
395 if (FormNameValueArray[1] == 'newpatient') {
396 // TBD: Make this work when it's not the first frame.
397 parent.frames[0].location.href = sel;
399 else {
400 parent.twAddFrameTab('enctabs', label, sel);
404 function toggleFrame1(fnum) {
405 top.frames['left_nav'].document.forms[0].cb_top.checked=false;
406 top.window.parent.left_nav.toggleFrame(fnum);
408 </script>
409 <style type="text/css">
410 #sddm
411 { margin: 0;
412 padding: 0;
413 z-index: 30;
416 </style>
417 <script type="text/javascript" language="javascript">
419 var timeout = 500;
420 var closetimer = 0;
421 var ddmenuitem = 0;
422 var oldddmenuitem = 0;
423 var flag = 0;
425 // open hidden layer
426 function mopen(id)
428 // cancel close timer
429 //mcancelclosetime();
431 flag=10;
433 // close old layer
434 //if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
435 //if(ddmenuitem) ddmenuitem.style.display = 'none';
437 // get new layer and show it
438 oldddmenuitem = ddmenuitem;
439 ddmenuitem = document.getElementById(id);
440 if((ddmenuitem.style.visibility == '')||(ddmenuitem.style.visibility == 'hidden')){
441 if(oldddmenuitem) oldddmenuitem.style.visibility = 'hidden';
442 if(oldddmenuitem) oldddmenuitem.style.display = 'none';
443 ddmenuitem.style.visibility = 'visible';
444 ddmenuitem.style.display = 'block';
445 }else{
446 ddmenuitem.style.visibility = 'hidden';
447 ddmenuitem.style.display = 'none';
450 // close showed layer
451 function mclose()
453 if(flag==10)
455 flag=11;
456 return;
458 if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
459 if(ddmenuitem) ddmenuitem.style.display = 'none';
462 // close layer when click-out
463 document.onclick = mclose;
464 //=================================================
465 function findPosX(id)
467 obj=document.getElementById(id);
468 var curleft = 0;
469 if(obj.offsetParent)
470 while(1)
472 curleft += obj.offsetLeft;
473 if(!obj.offsetParent)
474 break;
475 obj = obj.offsetParent;
477 else if(obj.x)
478 curleft += obj.x;
479 PropertyWidth=document.getElementById(id).offsetWidth;
480 if(PropertyWidth>curleft)
482 document.getElementById(id).style.left=0;
486 function findPosY(obj)
488 var curtop = 0;
489 if(obj.offsetParent)
490 while(1)
492 curtop += obj.offsetTop;
493 if(!obj.offsetParent)
494 break;
495 obj = obj.offsetParent;
497 else if(obj.y)
498 curtop += obj.y;
499 return curtop;
501 </script>
503 </head>
504 <body class="bgcolor2">
505 <dl>
506 <?php //DYNAMIC FORM RETREIVAL
507 include_once("$srcdir/registry.inc");
509 function myGetRegistered($state = "1", $limit = "unlimited", $offset = "0")
511 global $attendant_type;
512 $sql = "SELECT category, nickname, name, state, directory, id, sql_run, " .
513 "unpackaged, date, aco_spec FROM registry WHERE ";
514 // select different forms for groups
515 if ($attendant_type == 'pid') {
516 $sql .= "patient_encounter = 1 AND ";
517 } else {
518 $sql .= "therapy_group_encounter = 1 AND ";
520 $sql .= "state LIKE ? ORDER BY category, priority, name";
521 if ($limit != "unlimited") {
522 $sql .= " limit " . escape_limit($limit) . ", " . escape_limit($offset);
524 $res = sqlStatement($sql, array($state));
525 if ($res) {
526 for ($iter=0; $row=sqlFetchArray($res); $iter++) {
527 $all[$iter] = $row;
529 } else {
530 return false;
532 return $all;
535 $reg = myGetRegistered();
536 $old_category = '';
538 $DivId=1;
540 // To see if the encounter is locked. If it is, no new forms can be created
541 $encounterLocked = false;
542 if ($esignApi->lockEncounters() &&
543 isset($GLOBALS['encounter']) &&
544 !empty($GLOBALS['encounter']) ) {
545 $esign = $esignApi->createEncounterESign($GLOBALS['encounter']);
546 if ($esign->isLocked()) {
547 $encounterLocked = true;
551 if (!empty($reg)) {
552 $StringEcho= '<ul id="sddm">';
553 if ($encounterLocked === false) {
554 foreach ($reg as $entry) {
555 // Check permission to create forms of this type.
556 $tmp = explode('|', $entry['aco_spec']);
557 if (!empty($tmp[1])) {
558 if (!acl_check($tmp[0], $tmp[1], '', 'write') && !acl_check($tmp[0], $tmp[1], '', 'addonly')) {
559 continue;
562 $new_category = trim($entry['category']);
563 $new_nickname = trim($entry['nickname']);
564 if ($new_category == '') {
565 $new_category = xl('Miscellaneous');
566 } else {
567 $new_category = xl($new_category);
569 if ($new_nickname != '') {
570 $nickname = $new_nickname;
571 } else {
572 $nickname = trim($entry['name']);
574 if ($old_category != $new_category) {
575 $new_category_ = $new_category;
576 $new_category_ = str_replace(' ', '_', $new_category_);
577 if ($old_category != '') {
578 $StringEcho .= "</table></div></li>";
580 $StringEcho .= "<li class=\"encounter-form-category-li\"><a href='JavaScript:void(0);' onClick=\"mopen(" . attr_js($DivId) . ");\" >" . text($new_category) . "</a><div id='" . attr($DivId) . "' ><table border='0' cellspacing='0' cellpadding='0'>";
581 $old_category = $new_category;
582 $DivId++;
584 $StringEcho .= "<tr><td style='border-top: 1px solid #000000;padding:0px;'><a onclick=\"openNewForm(" .
585 attr_js($rootdir."/patient_file/encounter/load_form.php?formname=".urlencode($entry['directory'])) .
586 ", " . attr_js(xl_form_title($nickname)) . ")\" href='JavaScript:void(0);'>" .
587 text(xl_form_title($nickname)) . "</a></td></tr>";
590 $StringEcho.= '</table></div></li>';
593 if ($StringEcho) {
594 $StringEcho2= '<div style="clear:both"></div>';
595 } else {
596 $StringEcho2="";
599 // This shows Layout Based Form names just like the above.
601 if ($encounterLocked === false) {
602 $lres = sqlStatement("SELECT grp_form_id AS option_id, grp_title AS title, grp_aco_spec " .
603 "FROM layout_group_properties WHERE " .
604 "grp_form_id LIKE 'LBF%' AND grp_group_id = '' AND grp_activity = 1 " .
605 "ORDER BY grp_seq, grp_title");
607 if (sqlNumRows($lres)) {
608 if (!$StringEcho) {
609 $StringEcho= '<ul id="sddm">';
611 $StringEcho.= "<li class=\"encounter-form-category-li\"><a href='JavaScript:void(0);' onClick=\"mopen('lbf');\" >" .
612 xlt('Layout Based') . "</a><div id='lbf' ><table border='0' cellspacing='0' cellpadding='0'>";
613 while ($lrow = sqlFetchArray($lres)) {
614 $option_id = $lrow['option_id']; // should start with LBF
615 $title = $lrow['title'];
616 // Check ACO attribute, if any, of this LBF.
617 if (!empty($lrow['grp_aco_spec'])) {
618 $tmp = explode('|', $lrow['grp_aco_spec']);
619 if (!acl_check($tmp[0], $tmp[1], '', 'write') && !acl_check($tmp[0], $tmp[1], '', 'addonly')) {
620 continue;
623 $StringEcho .= "<tr><td style='border-top: 1px solid #000000;padding:0px;'><a onclick=\"openNewForm(" .
624 attr_js($rootdir."/patient_file/encounter/load_form.php?formname=".urlencode($option_id)) .
625 ", " . attr_js(xl_form_title($title)) . ")\" href='JavaScript:void(0);'>" .
626 text(xl_form_title($title)) . "</a></td></tr>";
631 <!-- DISPLAYING HOOKS STARTS HERE -->
632 <?php
633 $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
634 obj_name=enabled_hooks AND ms.mod_id=msh.mod_id LEFT OUTER JOIN modules AS m ON m.mod_id=ms.mod_id
635 WHERE fld_type=3 AND mod_active=1 AND sql_run=1 AND attached_to='encounter' ORDER BY mod_id");
636 $DivId = 'mod_installer';
637 if (sqlNumRows($module_query)) {
638 $jid = 0;
639 $modid = '';
640 while ($modulerow = sqlFetchArray($module_query)) {
641 $DivId = 'mod_'.$modulerow['mod_id'];
642 $new_category = $modulerow['mod_ui_name'];
643 $modulePath = "";
644 $added = "";
645 if ($modulerow['type'] == 0) {
646 $modulePath = $GLOBALS['customModDir'];
647 $added = "";
648 } else {
649 $added = "index";
650 $modulePath = $GLOBALS['zendModDir'];
652 $relative_link = "../../modules/".$modulePath."/".$modulerow['path'];
653 $nickname = $modulerow['menu_name'] ? $modulerow['menu_name'] : 'Noname';
654 if ($jid==0 || ($modid!=$modulerow['mod_id'])) {
655 if ($modid!='') {
656 $StringEcho.= '</table></div></li>';
658 $StringEcho.= "<li><a href='JavaScript:void(0);' onClick=\"mopen(" . attr_js($DivId) . ");\" >" . text($new_category) . "</a><div id='" . attr($DivId) . "' ><table border='0' cellspacing='0' cellpadding='0'>";
660 $jid++;
661 $modid = $modulerow['mod_id'];
662 $StringEcho.= "<tr><td style='border-top: 1px solid #000000;padding:0px;'><a onclick=" .
663 "\"openNewForm(" . attr_js($relative_link) . ", " . attr_js(xl_form_title($nickname)) . ")\" " .
664 "href='JavaScript:void(0);'>" . text(xl_form_title($nickname)) . "</a></td></tr>";
668 <!-- DISPLAYING HOOKS ENDS HERE -->
669 <?php
670 if ($StringEcho) {
671 $StringEcho.= "</table></div></li></ul>".$StringEcho2;
674 <table cellspacing="0" cellpadding="0" align="center">
675 <tr>
676 <td valign="top"><?php echo $StringEcho; ?></td>
677 </tr>
678 </table>
679 </dl>
680 <!-- Form menu stop -->
681 <!-- *************** -->
683 <div id="encounter_forms">
685 <?php
686 $dateres = getEncounterDateByEncounter($encounter);
687 $encounter_date = date("Y-m-d", strtotime($dateres["date"]));
688 $providerIDres = getProviderIdOfEncounter($encounter);
689 $providerNameRes = getProviderName($providerIDres);
692 <div class='encounter-summary-container'>
693 <div class='encounter-summary-column'>
694 <div>
695 <?php
696 $pass_sens_squad = true;
698 //fetch acl for category of given encounter
699 $pc_catid = fetchCategoryIdByEncounter($encounter);
700 $postCalendarCategoryACO = fetchPostCalendarCategoryACO($pc_catid);
701 if ($postCalendarCategoryACO) {
702 $postCalendarCategoryACO = explode('|', $postCalendarCategoryACO);
703 $authPostCalendarCategory = acl_check($postCalendarCategoryACO[0], $postCalendarCategoryACO[1]);
704 $authPostCalendarCategoryWrite = acl_check($postCalendarCategoryACO[0], $postCalendarCategoryACO[1], '', 'write');
705 } else { // if no aco is set for category
706 $authPostCalendarCategory = true;
707 $authPostCalendarCategoryWrite = true;
710 if ($attendant_type == 'pid' && is_numeric($pid)) {
711 echo '<span class="title">' . text(oeFormatShortDate($encounter_date)) . " " . xlt("Encounter") . '</span>';
713 // Check for no access to the patient's squad.
714 $result = getPatientData($pid, "fname,lname,squad");
715 echo " " . xlt('for') . " " . text($result['fname']) . " " . text($result['lname']);
716 if ($result['squad'] && ! acl_check('squads', $result['squad'])) {
717 $pass_sens_squad = false;
720 // Check for no access to the encounter's sensitivity level.
721 $result = sqlQuery("SELECT sensitivity FROM form_encounter WHERE " .
722 "pid = ? AND encounter = ? LIMIT 1", array($pid, $encounter));
723 if (($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) || !$authPostCalendarCategory) {
724 $pass_sens_squad = false;
726 // for therapy group
727 } else {
728 echo '<span class="title">' . text(oeFormatShortDate($encounter_date)) . " " . xlt("Group Encounter") . '</span>';
729 // Check for no access to the patient's squad.
730 $result = getGroup($groupId);
731 echo " " . xlt('for') . " " . text($result['group_name']);
732 if ($result['squad'] && ! acl_check('squads', $result['squad'])) {
733 $pass_sens_squad = false;
735 // Check for no access to the encounter's sensitivity level.
736 $result = sqlQuery("SELECT sensitivity FROM form_groups_encounter WHERE " .
737 "group_id = ? AND encounter = ? LIMIT 1", array($groupId, $encounter));
738 if (($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) || !$authPostCalendarCategory) {
739 $pass_sens_squad = false;
743 </div>
744 <div style='margin-top:8px;'>
745 <?php
746 // ESign for entire encounter
747 $esign = $esignApi->createEncounterESign($encounter);
748 if ($esign->isButtonViewable()) {
749 echo $esign->buttonHtml();
752 <?php if (acl_check('admin', 'super')) { ?>
753 <a href='#' class='css_button' onclick='return deleteme()'><span><?php echo xlt('Delete') ?></span></a>
754 <?php } ?>
755 &nbsp;&nbsp;&nbsp;<a href="#" onClick='expandcollapse("expand");' style="font-size:80%;"><?php echo xlt('Expand All'); ?></a>
756 &nbsp;&nbsp;&nbsp;<a style="font-size:80%;" href="#" onClick='expandcollapse("collapse");'><?php echo xlt('Collapse All'); ?></a>
757 </div>
758 </div>
760 <div class='encounter-summary-column'>
761 <?php if ($esign->isLogViewable()) {
762 $esign->renderLog();
763 } ?>
764 </div>
766 <div class='encounter-summary-column'>
767 <?php if ($GLOBALS['enable_amc_prompting']) { ?>
768 <div style='float:right;margin-right:25px;border-style:solid;border-width:1px;'>
769 <div style='float:left;margin:5px 5px 5px 5px;'>
770 <table>
771 <tr>
772 <td>
773 <?php // Display the education resource checkbox (AMC prompting)
774 $itemAMC = amcCollect("patient_edu_amc", $pid, 'form_encounter', $encounter);
776 <?php if (!(empty($itemAMC))) { ?>
777 <input type="checkbox" id="prov_edu_res" checked>
778 <?php } else { ?>
779 <input type="checkbox" id="prov_edu_res">
780 <?php } ?>
781 </td>
782 <td>
783 <span class="text"><?php echo xlt('Provided Education Resource(s)?') ?></span>
784 </td>
785 </tr>
786 <tr>
787 <td>
788 <?php // Display the Provided Clinical Summary checkbox (AMC prompting)
789 $itemAMC = amcCollect("provide_sum_pat_amc", $pid, 'form_encounter', $encounter);
791 <?php if (!(empty($itemAMC))) { ?>
792 <input type="checkbox" id="provide_sum_pat_flag" checked>
793 <?php } else { ?>
794 <input type="checkbox" id="provide_sum_pat_flag">
795 <?php } ?>
796 </td>
797 <td>
798 <span class="text"><?php echo xlt('Provided Clinical Summary?') ?></span>
799 </td>
800 </tr>
801 <?php // Display the medication reconciliation checkboxes (AMC prompting)
802 $itemAMC = amcCollect("med_reconc_amc", $pid, 'form_encounter', $encounter);
804 <?php if (!(empty($itemAMC))) { ?>
805 <tr>
806 <td>
807 <input type="checkbox" id="trans_trand_care" checked>
808 </td>
809 <td>
810 <span class="text"><?php echo xlt('Transition/Transfer of Care?') ?></span>
811 </td>
812 </tr>
813 </table>
814 <table style="margin-left:2em;">
815 <tr>
816 <td>
817 <?php if (!(empty($itemAMC['date_completed']))) { ?>
818 <input type="checkbox" id="med_reconc_perf" checked>
819 <?php } else { ?>
820 <input type="checkbox" id="med_reconc_perf">
821 <?php } ?>
822 </td>
823 <td>
824 <span class="text"><?php echo xlt('Medication Reconciliation Performed?') ?></span>
825 </td>
826 </tr>
827 <tr>
828 <td>
829 <?php if (!(empty($itemAMC['soc_provided']))) { ?>
830 <input type="checkbox" id="soc_provided" checked>
831 <?php } else { ?>
832 <input type="checkbox" id="soc_provided">
833 <?php } ?>
834 </td>
835 <td>
836 <span class="text"><?php echo xlt('Summary Of Care Provided?') ?></span>
837 </td>
838 </tr>
839 </table>
840 <?php } else { ?>
841 <tr>
842 <td>
843 <input type="checkbox" id="trans_trand_care">
844 </td>
845 <td>
846 <span class="text"><?php echo xlt('Transition/Transfer of Care?') ?></span>
847 </td>
848 </tr>
849 </table>
850 <table style="margin-left:2em;">
851 <tr>
852 <td>
853 <input type="checkbox" id="med_reconc_perf" DISABLED>
854 </td>
855 <td>
856 <span class="text"><?php echo xlt('Medication Reconciliation Performed?') ?></span>
857 </td>
858 </tr>
859 <tr>
860 <td>
861 <input type="checkbox" id="soc_provided" DISABLED>
862 </td>
863 <td>
864 <span class="text"><?php echo xlt('Summary of Care Provided?') ?></span>
865 </td>
866 </tr>
867 </table>
868 <?php } ?>
869 </div>
870 </div>
871 <?php } ?>
872 </div>
874 </div>
876 <!-- Get the documents tagged to this encounter and display the links and notes as the tooltip -->
877 <?php
878 if ($attendant_type == 'pid') {
879 $docs_list = getDocumentsByEncounter($pid, $_SESSION['encounter']);
880 } else {
881 // already doesn't exist document for therapy groups
882 $docs_list = array();
884 if (!empty($docs_list) && count($docs_list) > 0) {
886 <div class='enc_docs'>
887 <span class="bold"><?php echo xlt("Document(s)"); ?>:</span>
888 <?php
889 $doc = new C_Document();
890 foreach ($docs_list as $doc_iter) {
891 $doc_url = $doc->_tpl_vars[CURRENT_ACTION]. "&view&patient_id=" . attr_url($pid) . "&document_id=" . attr_url($doc_iter[id]) . "&";
892 // Get notes for this document.
893 $queryString = "SELECT GROUP_CONCAT(note ORDER BY date DESC SEPARATOR '|') AS docNotes, GROUP_CONCAT(date ORDER BY date DESC SEPARATOR '|') AS docDates
894 FROM notes WHERE foreign_id = ? GROUP BY foreign_id";
895 $noteData = sqlQuery($queryString, array($doc_iter['id']));
896 $note = '';
897 if ($noteData) {
898 $notes = array();
899 $notes = explode("|", $noteData['docNotes']);
900 $dates = explode("|", $noteData['docDates']);
901 for ($i = 0; $i < count($notes); $i++) {
902 $note .= oeFormatShortDate(date('Y-m-d', strtotime($dates[$i]))) . " : " . $notes[$i] . "\n";
906 <br>
907 <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>
908 <?php if ($note != '') {?>
909 <a href="javascript:void(0);" title="<?php echo attr($note);?>"><img src="../../../images/info.png"/></a>
910 <?php }?>
911 <?php } ?>
912 </div>
913 <?php } ?>
914 <br/>
916 <?php
917 if ($pass_sens_squad &&
918 ($result = getFormByEncounter(
919 $attendant_id,
920 $encounter,
921 "id, date, form_id, form_name, formdir, user, deleted",
923 "FIND_IN_SET(formdir,'newpatient') DESC, form_name, date DESC"
924 ))) {
925 echo "<table width='100%' id='partable'>";
926 $divnos = 1;
927 foreach ($result as $iter) {
928 $formdir = $iter['formdir'];
930 // skip forms whose 'deleted' flag is set to 1
931 if ($iter['deleted'] == 1) {
932 continue;
935 $aco_spec = false;
937 if (substr($formdir, 0, 3) == 'LBF') {
938 // Skip LBF forms that we are not authorized to see.
939 $lrow = sqlQuery(
940 "SELECT grp_aco_spec " .
941 "FROM layout_group_properties WHERE " .
942 "grp_form_id = ? AND grp_group_id = '' AND grp_activity = 1",
943 array($formdir)
945 if (!empty($lrow)) {
946 if (!empty($lrow['grp_aco_spec'])) {
947 $aco_spec = explode('|', $lrow['grp_aco_spec']);
948 if (!acl_check($aco_spec[0], $aco_spec[1])) {
949 continue;
953 } else {
954 // Skip non-LBF forms that we are not authorized to see.
955 $tmp = getRegistryEntryByDirectory($formdir, 'aco_spec');
956 if (!empty($tmp['aco_spec'])) {
957 $aco_spec = explode('|', $tmp['aco_spec']);
958 if (!acl_check($aco_spec[0], $aco_spec[1])) {
959 continue;
964 // $form_info = getFormInfoById($iter['id']);
965 if (strtolower(substr($iter['form_name'], 0, 5)) == 'camos') {
966 //CAMOS generates links from report.php and these links should
967 //be clickable without causing view.php to come up unexpectedly.
968 //I feel that the JQuery code in this file leading to a click
969 //on the report.php content to bring up view.php steps on a
970 //form's autonomy to generate it's own html content in it's report
971 //but until any other form has a problem with this, I will just
972 //make an exception here for CAMOS and allow it to carry out this
973 //functionality for all other forms. --Mark
974 echo '<tr title="' . xla('Edit form') . '" '.
975 'id="' . attr($formdir) . '~' . attr($iter['form_id']) . '">';
976 } else {
977 echo '<tr id="' . attr($formdir) . '~' . attr($iter['form_id']) . '" class="text onerow">';
980 $acl_groups = acl_check("groups", "glog", false, 'write') ? true : false;
981 $user = getNameFromUsername($iter['user']);
983 $form_name = ($formdir == 'newpatient') ? xl('Visit Summary') : xl_form_title($iter['form_name']);
985 // Create the ESign instance for this form
986 $esign = $esignApi->createFormESign($iter['id'], $formdir, $encounter);
988 // echo "<tr>"; // Removed as bug fix.
990 echo "<td style='border-bottom:1px solid'>";
992 // Figure out the correct author (encounter authors are the '$providerNameRes', while other
993 // form authors are the '$user['fname'] . " " . $user['lname']').
994 if ($formdir == 'newpatient') {
995 $form_author = $providerNameRes;
996 } else {
997 $form_author = $user['fname'] . " " . $user['lname'];
999 echo "<div class='form_header'>";
1000 echo "<a href='#' onclick='divtoggle(" . attr_js('spanid_'.$divnos) . "," . attr_js('divid_'.$divnos) . ");' class='small' id='aid_" . attr($divnos) . "'>" .
1001 "<div class='formname'>" . text($form_name) . "</div> " .
1002 xlt('by') . " " . text($form_author) . " " .
1003 "(<span id=spanid_" . attr($divnos) . " class=\"indicator\">" . ($divnos == 1 ? xlt('Collapse') : xlt('Expand')) . "</span>)</a>";
1004 echo "</div>";
1006 // a link to edit the form
1007 echo "<div class='form_header_controls'>";
1009 // If the form is locked, it is no longer editable
1010 if ($esign->isLocked()) {
1011 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>";
1012 } else {
1013 if ((!$aco_spec || acl_check($aco_spec[0], $aco_spec[1], '', 'write') and $is_group == 0 and $authPostCalendarCategoryWrite)
1014 or (((!$aco_spec || acl_check($aco_spec[0], $aco_spec[1], '', 'write')) and $is_group and acl_check("groups", "glog", false, 'write')) and $authPostCalendarCategoryWrite)) {
1015 echo "<a class='css_button_small form-edit-button' " .
1016 "id='form-edit-button-" . attr($formdir) . "-" . attr($iter['id']) . "' " .
1017 "href='#' " .
1018 "title='" . xla('Edit this form') . "' " .
1019 "onclick=\"return openEncounterForm(" . attr_js($formdir) . ", " .
1020 attr_js($form_name) . ", " . attr_js($iter['form_id']) . ")\">";
1021 echo "<span>" . xlt('Edit') . "</span></a>";
1025 if (($esign->isButtonViewable() and $is_group == 0 and $authPostCalendarCategoryWrite) or ($esign->isButtonViewable() and $is_group and acl_check("groups", "glog", false, 'write') and $authPostCalendarCategoryWrite)) {
1026 if (!$aco_spec || acl_check($aco_spec[0], $aco_spec[1], '', 'write')) {
1027 echo $esign->buttonHtml();
1031 if (substr($formdir, 0, 3) == 'LBF') {
1032 // A link for a nice printout of the LBF
1033 echo "<a target='_blank' " .
1034 "href='$rootdir/forms/LBF/printable.php?" .
1035 "formname=" . attr_url($formdir) .
1036 "&formid=" . attr_url($iter['form_id']) .
1037 "&visitid=" . attr_url($encounter) .
1038 "&patientid=" . attr_url($pid) .
1039 "' class='css_button_small' title='" . xla('Print this form') .
1040 "' onclick='top.restoreSession()'><span>" . xlt('Print') . "</span></a>";
1043 if (acl_check('admin', 'super')) {
1044 if ($formdir != 'newpatient' && $formdir != 'newGroupEncounter') {
1045 // a link to delete the form from the encounter
1046 echo "<a href='$rootdir/patient_file/encounter/delete_form.php?" .
1047 "formname=" . attr_url($formdir) .
1048 "&id=" . attr_url($iter['id']) .
1049 "&encounter=". attr_url($encounter) .
1050 "&pid=" . attr_url($pid) .
1051 "' class='css_button_small' title='" . xla('Delete this form') . "' onclick='top.restoreSession()'><span>" . xlt('Delete') . "</span></a>";
1052 } else {
1053 ?><a href='javascript:;' class='css_button_small' style='color:gray'><span><?php echo xlt('Delete'); ?></span></a><?php
1056 echo "</div>\n"; // Added as bug fix.
1058 echo "</td>\n";
1059 echo "</tr>";
1060 echo "<tr>";
1061 echo "<td valign='top' class='formrow'><div class='tab' id='divid_" . attr($divnos) . "' ";
1062 echo "style='display:" . ($divnos == 1 ? 'block' : 'none') . "'>";
1064 // Use the form's report.php for display. Forms with names starting with LBF
1065 // are list-based forms sharing a single collection of code.
1067 if (substr($formdir, 0, 3) == 'LBF') {
1068 include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
1070 call_user_func("lbf_report", $attendant_id, $encounter, 2, $iter['form_id'], $formdir, true);
1071 } else {
1072 include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
1073 call_user_func($formdir . "_report", $attendant_id, $encounter, 2, $iter['form_id']);
1076 if ($esign->isLogViewable()) {
1077 $esign->renderLog();
1080 echo "</div></td></tr>";
1081 $divnos=$divnos+1;
1083 echo "</table>";
1085 if (!$pass_sens_squad) {
1086 echo xlt("Not authorized to view this encounter");
1090 </div> <!-- end large encounter_forms DIV -->
1091 </body>
1092 </html>