minor changes to prior commit
[openemr.git] / interface / patient_file / summary / stats_full.php
blob66550176a9cf670fe9c3e2d1c92ea1d7f4b09f44
1 <?php
2 /**
3 * Copyright (C) 2005-2017 Rod Roark <rod@sunsetsystems.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 */
13 require_once('../../globals.php');
14 require_once($GLOBALS['srcdir'].'/lists.inc');
15 require_once($GLOBALS['srcdir'].'/acl.inc');
16 require_once($GLOBALS['fileroot'].'/custom/code_types.inc.php');
17 require_once($GLOBALS['srcdir'].'/options.inc.php');
19 use OpenEMR\Core\Header;
20 use OpenEMR\Menu\PatientMenuRole;
22 // Check if user has permission for any issue type.
23 $auth = false;
24 foreach ($ISSUE_TYPES as $type => $dummy) {
25 if (acl_check_issue($type)) {
26 $auth = true;
27 break;
31 if ($auth) {
32 $tmp = getPatientData($pid, "squad");
33 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad'])) {
34 die(xlt('Not authorized'));
36 } else {
37 die(xlt('Not authorized'));
40 // Collect parameter(s)
41 $category = empty($_REQUEST['category']) ? '' : $_REQUEST['category'];
43 // Get patient's preferred language for the patient education URL.
44 $tmp = getPatientData($pid, 'language');
45 $language = $tmp['language'];
47 <html>
49 <head>
51 <?php Header::setupHeader(); ?>
53 <title><?php echo xlt('Patient Issues'); ?></title>
55 <script language="JavaScript">
57 // callback from add_edit_issue.php:
58 function refreshIssue(issue, title) {
59 top.restoreSession();
60 location.reload();
63 function dopclick(id,category) {
64 top.restoreSession();
65 if (category == 0) category = '';
66 dlgopen('add_edit_issue.php?issue=' + encodeURIComponent(id) + '&thistype=' + encodeURIComponent(category), '_blank', 650, 500, '', '<?php echo xla("Add/Edit Issue"); ?>');
67 //dlgopen('add_edit_issue.php?issue=' + encodeURIComponent(id) + '&thistype=' + encodeURIComponent(category), '_blank', 650, 600);
70 // Process click on number of encounters.
71 function doeclick(id) {
72 top.restoreSession();
73 dlgopen('../problem_encounter.php?issue=' + id, '_blank', 700, 400);
76 // Process click on diagnosis for patient education popup.
77 function educlick(codetype, codevalue) {
78 top.restoreSession();
79 dlgopen('../education.php?type=' + encodeURIComponent(codetype) +
80 '&code=' + encodeURIComponent(codevalue) +
81 '&language=<?php echo urlencode($language); ?>',
82 '_blank', 1024, 750,true); // Force a new window instead of iframe to address cross site scripting potential
85 // Add Encounter button is clicked.
86 function newEncounter() {
87 var f = document.forms[0];
88 top.restoreSession();
89 location.href='../../forms/newpatient/new.php?autoloaded=1&calenc=';
91 </script>
92 <?php
93 //to determine and set the form to open in the desired state - expanded or centered, any selection the user makes will
94 //become the user-specific default for that page. collectAndOrganizeExpandSetting() contains a single array as an
95 //argument, containing one or more elements, the name of the current file is the first element, if there are linked
96 // files they should be listed thereafter, please add _xpd suffix to the file name
97 $arr_files_php = array("stats_full_patient_xpd", "external_data_patient_xpd", "patient_ledger_patient_xpd");
98 $current_state = collectAndOrganizeExpandSetting($arr_files_php);
99 require_once("$srcdir/expand_contract_inc.php");
101 <script>
102 <?php
103 require_once("$include_root/patient_file/erx_patient_portal_js.php"); // jQuery for popups for eRx and patient portal
104 require_once("$include_root/expand_contract_js.php");//jQuery to provide expand/contract icon toggle if form is expandable
106 </script>
107 </head>
109 <body class="body_top">
110 <div class="<?php echo $container;?> expandable">
111 <?php $header_title = xl('Medical Issues for');?>
112 <div class="row">
113 <div class="col-sm-12">
114 <?php
115 $expandable = 1;
116 require_once("$include_root/patient_file/summary/dashboard_header.php")
118 </div>
119 </div>
120 <div class="row" >
121 <div class="col-sm-12">
122 <?php
123 $list_id = "nav-list6"; // to indicate nav item is active, count and give correct id
124 // Collect the patient menu then build it
125 $menuPatient = new PatientMenuRole();
126 $menuPatient->displayHorizNavBarMenu();
128 </div>
129 </div>
131 <div id='patient_stats'>
132 <form method='post' action='stats_full.php' onsubmit='return top.restoreSession()'>
134 <table>
136 <?php
137 $encount = 0;
138 $lasttype = "";
139 $first = 1; // flag for first section
140 foreach ($ISSUE_TYPES as $focustype => $focustitles) {
141 if (!acl_check_issue($focustype)) {
142 continue;
145 if ($category) {
146 // Only show this category
147 if ($focustype != $category) {
148 continue;
152 if ($first) {
153 $first = 0;
154 } else {
155 echo "</table>";
158 // Show header
159 $disptype = $focustitles[0];
160 if (acl_check_issue($focustype, '', array('write', 'addonly'))) {
161 if (($focustype=='allergy' || $focustype=='medication') && $GLOBALS['erx_enable']) {
162 echo "<a href='../../eRx.php?page=medentry' class='css_button_small' onclick='top.restoreSession()' ><span>" .
163 xlt('Add') . "</span></a>\n";
164 } else {
165 echo "<a href='javascript:;' class='css_button_small' onclick='dopclick(0,\"" .
166 attr($focustype) . "\")'><span>" . xlt('Add') . "</span></a>\n";
170 echo " <span class='title'>" . text($disptype) . "</span>\n";
171 // echo " <table style='margin-bottom:1em;text-align:center'>";
172 echo " <table style='margin-bottom:1em;'>";
174 <tr class='head'>
175 <th style='text-align:left'><?php echo xlt('Title'); ?></th>
176 <th style='text-align:left'><?php echo xlt('Begin'); ?></th>
177 <th style='text-align:left'><?php echo xlt('End'); ?></th>
178 <th style='text-align:left'><?php echo xlt('Coding (click for education)'); ?></th>
179 <th style='text-align:left'><?php echo xlt('Status'); ?></th>
180 <th style='text-align:left'><?php echo xlt('Occurrence'); ?></th>
181 <?php if ($focustype == "allergy") { ?>
182 <th style='text-align:left'><?php echo xlt('Reaction'); ?></th>
183 <?php } ?>
184 <th style='text-align:left'><?php echo xlt('Referred By'); ?></th>
185 <th style='text-align:left'><?php echo xlt('Modify Date'); ?></th>
186 <th style='text-align:left'><?php echo xlt('Comments'); ?></th>
187 <th><?php echo xlt('Enc'); ?></th>
188 </tr>
189 <?php
191 // collect issues
192 $condition = '';
193 if ($GLOBALS['erx_enable'] && $GLOBALS['erx_medication_display'] && $focustype=='medication') {
194 $condition .= "and erx_uploaded != '1' ";
197 $pres = sqlStatement("SELECT * FROM lists WHERE pid = ? AND type = ? $condition" .
198 "ORDER BY begdate", array($pid,$focustype));
200 // if no issues (will place a 'None' text vs. toggle algorithm here)
201 if (sqlNumRows($pres) < 1) {
202 if (getListTouch($pid, $focustype)) {
203 // Data entry has happened to this type, so can display an explicit None.
204 echo "<tr><td class='text'><b>" . xlt("None") . "</b></td></tr>";
205 } else {
206 // Data entry has not happened to this type, so can show the none selection option.
207 echo "<tr><td class='text'><input type='checkbox' class='noneCheck' name='" .
208 attr($focustype) . "' value='none'";
209 if (!acl_check_issue($focustype, '', 'write')) {
210 echo " disabled";
213 echo " /><b>" . xlt("None") . "</b></td></tr>";
217 // display issues
218 while ($row = sqlFetchArray($pres)) {
219 $rowid = $row['id'];
221 $disptitle = trim($row['title']) ? $row['title'] : "[Missing Title]";
223 $ierow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
224 "list_id = ?", array($rowid));
226 // encount is used to toggle the color of the table-row output below
227 ++$encount;
228 $bgclass = (($encount & 1) ? "bg1" : "bg2");
230 $colorstyle = empty($row['enddate']) ? "style='color:red'" : "";
232 // look up the diag codes
233 $codetext = "";
234 if ($row['diagnosis'] != "") {
235 $diags = explode(";", $row['diagnosis']);
236 foreach ($diags as $diag) {
237 $codedesc = lookup_code_descriptions($diag);
238 list($codetype, $code) = explode(':', $diag);
239 if ($codetext) {
240 $codetext .= "<br />";
243 $codetext .= "<a href='javascript:educlick(\"$codetype\",\"$code\")' $colorstyle>" .
244 text($diag . " (" . $codedesc . ")") . "</a>";
248 // calculate the status
249 if ($row['outcome'] == "1" && $row['enddate'] != null) {
250 // Resolved
251 $statusCompute = generate_display_field(array('data_type'=>'1','list_id'=>'outcome'), $row['outcome']);
252 } elseif ($row['enddate'] == null) {
253 $statusCompute = xlt("Active");
254 } else {
255 $statusCompute = xlt("Inactive");
258 $click_class='statrow';
259 if ($row['erx_source']==1 && $focustype=='allergy') {
260 $click_class='';
261 } elseif ($row['erx_uploaded']==1 && $focustype=='medication') {
262 $click_class='';
265 echo " <tr class='$bgclass detail' $colorstyle>\n";
266 echo " <td style='text-align:left' class='$click_class' id='$rowid'>" . text($disptitle) . "</td>\n";
267 echo " <td>" . text($row['begdate']) . "&nbsp;</td>\n";
268 echo " <td>" . text($row['enddate']) . "&nbsp;</td>\n";
269 // both codetext and statusCompute have already been escaped above with htmlspecialchars)
270 echo " <td>" . $codetext . "</td>\n";
271 echo " <td>" . $statusCompute . "&nbsp;</td>\n";
272 echo " <td class='nowrap'>";
273 echo generate_display_field(array('data_type'=>'1','list_id'=>'occurrence'), $row['occurrence']);
274 echo "</td>\n";
275 if ($focustype == "allergy") {
276 echo " <td>";
277 echo generate_display_field(array('data_type'=>'1','list_id'=>'reaction'), $row['reaction']);
278 echo "</td>\n";
281 echo " <td>" . text($row['referredby']) . "</td>\n";
282 echo " <td>" . text($row['modifydate']) . "</td>\n";
283 echo " <td>" . text($row['comments']) . "</td>\n";
284 echo " <td id='e_$rowid' class='noclick center' title='" . xla('View related encounters') . "'>";
285 echo " <input type='button' value='" . attr($ierow['count']) . "' class='editenc' id='" . attr($rowid) . "' />";
286 echo " </td>";
287 echo " </tr>\n";
291 echo "</table>";
294 </table>
296 </form>
297 </div> <!-- end patient_stats -->
298 </div><!--end of container div -->
299 <?php
300 //home of the help modal ;)
301 //$GLOBALS['enable_help'] = 0; // Please comment out line if you want help modal to function on this page
302 if ($GLOBALS['enable_help'] == 1) {
303 echo "<script>var helpFile = 'issues_dashboard_help.php'</script>";
304 require "$include_root/help_modal.php";
308 </body>
310 <script language="javascript">
311 // jQuery stuff to make the page a little easier to use
313 $(document).ready(function(){
314 $(".statrow").mouseover(function() { $(this).toggleClass("highlight"); });
315 $(".statrow").mouseout(function() { $(this).toggleClass("highlight"); });
317 $(".statrow").click(function() { dopclick(this.id,0); });
318 $(".editenc").click(function(event) { doeclick(this.id); });
319 $("#newencounter").click(function() { newEncounter(); });
320 $("#history").click(function() { GotoHistory(); });
321 $("#back").click(function() { GoBack(); });
323 $(".noneCheck").click(function() {
324 top.restoreSession();
325 $.post( "../../../library/ajax/lists_touch.php", { type: this.name, patient_id: <?php echo htmlspecialchars($pid, ENT_QUOTES); ?> });
326 $(this).hide();
330 var GotoHistory = function() {
331 top.restoreSession();
332 location.href='../history/history_full.php';
335 var GoBack = function () {
336 top.restoreSession();
337 location.href='demographics.php';
340 var listId = '#' + '<?php echo text($list_id); ?>';
341 $(document).ready(function(){
342 $(listId).addClass("active");
344 </script>
347 </html>