The Third Reminders email bug fix - contributed by arnabnaha
[openemr.git] / interface / patient_file / summary / stats_full.php
blob9d7ad03cfbeaf8388319c4d884be9df0cf09cb22
1 <?php
2 // Copyright (C) 2005-2009 Rod Roark <rod@sunsetsystems.com>
3 //
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 //SANITIZE ALL ESCAPES
10 $sanitize_all_escapes=true;
13 //STOP FAKE REGISTER GLOBALS
14 $fake_register_globals=false;
17 require_once("../../globals.php");
18 require_once("$srcdir/lists.inc");
19 require_once("$srcdir/acl.inc");
20 require_once("../../../custom/code_types.inc.php");
21 require_once("$srcdir/options.inc.php");
23 // Check authorization.
24 if (acl_check('patients','med')) {
25 $tmp = getPatientData($pid, "squad");
26 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
27 die(htmlspecialchars( xl('Not authorized'), ENT_NOQUOTES) );
29 else {
30 die(htmlspecialchars( xl('Not authorized'), ENT_NOQUOTES) );
33 // Collect parameter(s)
34 $category = empty($_REQUEST['category']) ? '' : $_REQUEST['category'];
37 <html>
39 <head>
40 <?php html_header_show();?>
42 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
44 <title><?php echo htmlspecialchars( xl('Patient Issues'), ENT_NOQUOTES) ; ?></title>
46 <script type="text/javascript" src="../../../library/dialog.js"></script>
47 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
49 <script language="JavaScript">
51 // callback from add_edit_issue.php:
52 function refreshIssue(issue, title) {
53 top.restoreSession();
54 location.reload();
57 function dopclick(id,category) {
58 <?php if (acl_check('patients','med','','write')): ?>
59 if (category == 0) category = '';
60 dlgopen('add_edit_issue.php?issue=' + encodeURIComponent(id) + '&thistype=' + encodeURIComponent(category), '_blank', 550, 400);
61 <?php else: ?>
62 alert("<?php echo addslashes( xl('You are not authorized to add/edit issues') ); ?>");
63 <?php endif; ?>
66 // Process click on number of encounters.
67 function doeclick(id) {
68 dlgopen('../problem_encounter.php?issue=' + id, '_blank', 550, 400);
71 // Add Encounter button is clicked.
72 function newEncounter() {
73 var f = document.forms[0];
74 top.restoreSession();
75 <?php if ($GLOBALS['concurrent_layout']) { ?>
76 parent.left_nav.setRadio(window.name, 'nen');
77 location.href='../../forms/newpatient/new.php?autoloaded=1&calenc=';
78 <?php } else { ?>
79 top.Title.location.href='../encounter/encounter_title.php';
80 top.Main.location.href='../encounter/patient_encounter.php?mode=new';
81 <?php } ?>
84 </script>
86 </head>
88 <body class="body_top">
90 <br>
91 <div style="text-align:center" class="buttons">
92 <a href='javascript:;' class='css_button' id='back'><span><?php echo htmlspecialchars( xl('Back'), ENT_NOQUOTES); ?></span></a>
93 </div>
94 <br>
95 <br>
97 <div id='patient_stats'>
99 <form method='post' action='stats_full.php' onsubmit='return top.restoreSession()'>
101 <table>
103 <?php
104 $encount = 0;
105 $lasttype = "";
106 $first = 1; // flag for first section
107 foreach ($ISSUE_TYPES as $focustype => $focustitles) {
109 if ($category) {
110 // Only show this category
111 if ($focustype != $category) continue;
114 if ($first) {
115 $first = 0;
117 else {
118 echo "</table>";
121 // Show header
122 $disptype = $focustitles[0];
123 if(($focustype=='allergy' || $focustype=='medication') && $GLOBALS['erx_enable'])
124 echo "<a href='../../eRx.php?page=medentry' class='css_button_small' onclick='top.restoreSession()' ><span>" . htmlspecialchars( xl('Add'), ENT_NOQUOTES) . "</span></a>\n";
125 else
126 echo "<a href='javascript:;' class='css_button_small' onclick='dopclick(0,\"" . htmlspecialchars($focustype,ENT_QUOTES) . "\")'><span>" . htmlspecialchars( xl('Add'), ENT_NOQUOTES) . "</span></a>\n";
127 echo " <span class='title'>" . htmlspecialchars($disptype,ENT_NOQUOTES) . "</span>\n";
128 echo " <table style='margin-bottom:1em;text-align:center'>";
130 <tr class='head'>
131 <th><?php echo htmlspecialchars( xl('Title'), ENT_NOQUOTES); ?></th>
132 <th><?php echo htmlspecialchars( xl('Begin'), ENT_NOQUOTES); ?></th>
133 <th><?php echo htmlspecialchars( xl('End'), ENT_NOQUOTES); ?></th>
134 <th><?php echo htmlspecialchars( xl('Diag'), ENT_NOQUOTES); ?></th>
135 <th><?php echo htmlspecialchars(xl('Status'),ENT_NOQUOTES); ?></th>
136 <th><?php echo htmlspecialchars( xl('Occurrence'), ENT_NOQUOTES); ?></th>
137 <?php if ($focustype == "allergy") { ?>
138 <th><?php echo htmlspecialchars( xl('Reaction'), ENT_NOQUOTES); ?></th>
139 <?php } ?>
140 <?php if ($GLOBALS['athletic_team']) { ?>
141 <th><?php echo htmlspecialchars( xl('Missed'), ENT_NOQUOTES); ?></th>
142 <?php } else { ?>
143 <th><?php echo htmlspecialchars( xl('Referred By'), ENT_NOQUOTES); ?></th>
144 <?php } ?>
145 <th><?php echo htmlspecialchars( xl('Comments'), ENT_NOQUOTES); ?></th>
146 <th><?php echo htmlspecialchars( xl('Enc'), ENT_NOQUOTES); ?></th>
147 </tr>
148 <?php
150 // collect issues
151 $condition = '';
152 if($GLOBALS['erx_enable'] && $GLOBALS['erx_medication_display'] && $focustype=='medication')
153 $condition .= "and erx_uploaded != '1' ";
154 $pres = sqlStatement("SELECT * FROM lists WHERE pid = ? AND type = ? $condition" .
155 "ORDER BY begdate", array($pid,$focustype) );
157 // if no issues (will place a 'None' text vs. toggle algorithm here)
158 if (sqlNumRows($pres) < 1) {
159 if ( getListTouch($pid,$focustype) ) {
160 // Data entry has happened to this type, so can display an explicit None.
161 echo "<tr><td class='text'><b>" . htmlspecialchars( xl("None"), ENT_NOQUOTES) . "</b></td></tr>";
163 else {
164 // Data entry has not happened to this type, so can show the none selection option.
165 echo "<tr><td class='text'><input type='checkbox' class='noneCheck' name='" . htmlspecialchars($focustype,ENT_QUOTES) . "' value='none' /><b>" . htmlspecialchars( xl("None"), ENT_NOQUOTES) . "</b></td></tr>";
169 // display issues
170 while ($row = sqlFetchArray($pres)) {
172 $rowid = $row['id'];
174 $disptitle = trim($row['title']) ? $row['title'] : "[Missing Title]";
176 $ierow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
177 "list_id = ?", array($rowid) );
179 // encount is used to toggle the color of the table-row output below
180 ++$encount;
181 $bgclass = (($encount & 1) ? "bg1" : "bg2");
183 // look up the diag codes
184 $codetext = "";
185 if ($row['diagnosis'] != "") {
186 $diags = explode(";", $row['diagnosis']);
187 foreach ($diags as $diag) {
188 $codedesc = lookup_code_descriptions($diag);
189 $codetext .= htmlspecialchars($diag,ENT_NOQUOTES) . " (" . htmlspecialchars($codedesc,ENT_NOQUOTES) . ")<br>";
193 // calculate the status
194 if ($row['outcome'] == "1" && $row['enddate'] != NULL) {
195 // Resolved
196 $statusCompute = generate_display_field(array('data_type'=>'1','list_id'=>'outcome'), $row['outcome']);
198 else if($row['enddate'] == NULL) {
199 $statusCompute = htmlspecialchars( xl("Active") ,ENT_NOQUOTES);
201 else {
202 $statusCompute = htmlspecialchars( xl("Inactive") ,ENT_NOQUOTES);
204 $click_class='statrow';
205 if($row['erx_source']==1 && $focustype=='allergy')
206 $click_class='';
207 elseif($row['erx_uploaded']==1 && $focustype=='medication')
208 $click_class='';
209 // output the TD row of info
210 if ($row['enddate'] == NULL) {
211 echo " <tr class='$bgclass detail $click_class' style='color:red;font-weight:bold' id='$rowid'>\n";
213 else {
214 echo " <tr class='$bgclass detail $click_class' id='$rowid'>\n";
216 echo " <td style='text-align:left'>" . htmlspecialchars($disptitle,ENT_NOQUOTES) . "</td>\n";
217 echo " <td>" . htmlspecialchars($row['begdate'],ENT_NOQUOTES) . "&nbsp;</td>\n";
218 echo " <td>" . htmlspecialchars($row['enddate'],ENT_NOQUOTES) . "&nbsp;</td>\n";
219 // both codetext and statusCompute have already been escaped above with htmlspecialchars)
220 echo " <td>" . $codetext . "</td>\n";
221 echo " <td>" . $statusCompute . "&nbsp;</td>\n";
222 echo " <td class='nowrap'>";
223 echo generate_display_field(array('data_type'=>'1','list_id'=>'occurrence'), $row['occurrence']);
224 echo "</td>\n";
225 if ($focustype == "allergy") {
226 echo " <td>" . htmlspecialchars($row['reaction'],ENT_NOQUOTES) . "&nbsp;</td>\n";
228 if ($GLOBALS['athletic_team']) {
229 echo " <td class='center'>" . $row['extrainfo'] . "</td>\n"; // games missed
231 else {
232 echo " <td>" . htmlspecialchars($row['referredby'],ENT_NOQUOTES) . "</td>\n";
234 echo " <td>" . htmlspecialchars($row['comments'],ENT_NOQUOTES) . "</td>\n";
235 echo " <td id='e_$rowid' class='noclick center' title='" . htmlspecialchars( xl('View related encounters'), ENT_QUOTES) . "'>";
236 echo " <input type='button' value='" . htmlspecialchars($ierow['count'],ENT_QUOTES) . "' class='editenc' id='" . htmlspecialchars($rowid,ENT_QUOTES) . "' />";
237 echo " </td>";
238 echo " </tr>\n";
241 echo "</table>";
244 </table>
246 </form>
247 </div> <!-- end patient_stats -->
249 </body>
251 <script language="javascript">
252 // jQuery stuff to make the page a little easier to use
254 $(document).ready(function(){
255 $(".statrow").mouseover(function() { $(this).toggleClass("highlight"); });
256 $(".statrow").mouseout(function() { $(this).toggleClass("highlight"); });
258 $(".statrow").click(function() { dopclick(this.id,0); });
259 $(".editenc").click(function(event) { doeclick(this.id); event.stopPropagation(); });
260 $("#newencounter").click(function() { newEncounter(); });
261 $("#history").click(function() { GotoHistory(); });
262 $("#back").click(function() { GoBack(); });
264 $(".noneCheck").click(function() {
265 top.restoreSession();
266 $.post( "../../../library/ajax/lists_touch.php", { type: this.name, patient_id: <?php echo htmlspecialchars($pid,ENT_QUOTES); ?> });
267 $(this).hide();
271 var GotoHistory = function() {
272 top.restoreSession();
273 <?php if ($GLOBALS['concurrent_layout']): ?>
274 parent.left_nav.setRadio(window.name,'his');
275 location.href='../history/history_full.php';
276 <?php else: ?>
277 location.href='../history/history_full.php';
278 <?php endif; ?>
281 var GoBack = function () {
282 top.restoreSession();
283 <?php if ($GLOBALS['concurrent_layout']): ?>
284 parent.left_nav.setRadio(window.name,'dem');
285 location.href='demographics.php';
286 <?php else: ?>
287 location.href="patient_summary.php";
288 <?php endif; ?>
291 </script>
293 </html>