Fixes and enhancements of the newcrop erx module.
[openemr.git] / interface / patient_file / summary / stats_full.php
blob86d6242b09e4acddce5c6c6f649fe64e0f0a8526
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 $thisauth = acl_check('patients', 'med');
25 if ($thisauth) {
26 $tmp = getPatientData($pid, "squad");
27 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
28 $thisauth = 0;
30 if (!$thisauth) die(htmlspecialchars( xl('Not authorized'), ENT_NOQUOTES) );
32 // Collect parameter(s)
33 $category = empty($_REQUEST['category']) ? '' : $_REQUEST['category'];
36 <html>
38 <head>
39 <?php html_header_show();?>
41 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
43 <title><?php echo htmlspecialchars( xl('Patient Issues'), ENT_NOQUOTES) ; ?></title>
45 <script type="text/javascript" src="../../../library/dialog.js"></script>
46 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
48 <script language="JavaScript">
50 // callback from add_edit_issue.php:
51 function refreshIssue(issue, title) {
52 top.restoreSession();
53 location.reload();
56 function dopclick(id,category) {
57 <?php if ($thisauth == 'write'): ?>
58 if (category == 0) category = '';
59 dlgopen('add_edit_issue.php?issue=' + encodeURIComponent(id) + '&thistype=' + encodeURIComponent(category), '_blank', 550, 400);
60 <?php else: ?>
61 alert("<?php echo addslashes( xl('You are not authorized to add/edit issues') ); ?>");
62 <?php endif; ?>
65 // Process click on number of encounters.
66 function doeclick(id) {
67 dlgopen('../problem_encounter.php?issue=' + id, '_blank', 550, 400);
70 // Add Encounter button is clicked.
71 function newEncounter() {
72 var f = document.forms[0];
73 top.restoreSession();
74 <?php if ($GLOBALS['concurrent_layout']) { ?>
75 parent.left_nav.setRadio(window.name, 'nen');
76 location.href='../../forms/newpatient/new.php?autoloaded=1&calenc=';
77 <?php } else { ?>
78 top.Title.location.href='../encounter/encounter_title.php';
79 top.Main.location.href='../encounter/patient_encounter.php?mode=new';
80 <?php } ?>
83 </script>
85 </head>
87 <body class="body_top">
89 <br>
90 <div style="text-align:center" class="buttons">
91 <a href='javascript:;' class='css_button' id='back'><span><?php echo htmlspecialchars( xl('Back'), ENT_NOQUOTES); ?></span></a>
92 </div>
93 <br>
94 <br>
96 <div id='patient_stats'>
98 <form method='post' action='stats_full.php' onsubmit='return top.restoreSession()'>
100 <table>
102 <?php
103 $encount = 0;
104 $lasttype = "";
105 $first = 1; // flag for first section
106 foreach ($ISSUE_TYPES as $focustype => $focustitles) {
108 if ($category) {
109 // Only show this category
110 if ($focustype != $category) continue;
113 if ($first) {
114 $first = 0;
116 else {
117 echo "</table>";
120 // Show header
121 $disptype = $focustitles[0];
122 if(($focustype=='allergy' || $focustype=='medication') && $GLOBALS['erx_enable'])
123 echo "<a href='../../eRx.php?page=medentry' class='css_button_small' onclick='top.restoreSession()' ><span>" . htmlspecialchars( xl('Add'), ENT_NOQUOTES) . "</span></a>\n";
124 else
125 echo "<a href='javascript:;' class='css_button_small' onclick='dopclick(0,\"" . htmlspecialchars($focustype,ENT_QUOTES) . "\")'><span>" . htmlspecialchars( xl('Add'), ENT_NOQUOTES) . "</span></a>\n";
126 echo " <span class='title'>" . htmlspecialchars($disptype,ENT_NOQUOTES) . "</span>\n";
127 echo " <table style='margin-bottom:1em;text-align:center'>";
129 <tr class='head'>
130 <th><?php echo htmlspecialchars( xl('Title'), ENT_NOQUOTES); ?></th>
131 <th><?php echo htmlspecialchars( xl('Begin'), ENT_NOQUOTES); ?></th>
132 <th><?php echo htmlspecialchars( xl('End'), ENT_NOQUOTES); ?></th>
133 <th><?php echo htmlspecialchars( xl('Diag'), ENT_NOQUOTES); ?></th>
134 <th><?php echo htmlspecialchars(xl('Status'),ENT_NOQUOTES); ?></th>
135 <th><?php echo htmlspecialchars( xl('Occurrence'), ENT_NOQUOTES); ?></th>
136 <?php if ($focustype == "allergy") { ?>
137 <th><?php echo htmlspecialchars( xl('Reaction'), ENT_NOQUOTES); ?></th>
138 <?php } ?>
139 <?php if ($GLOBALS['athletic_team']) { ?>
140 <th><?php echo htmlspecialchars( xl('Missed'), ENT_NOQUOTES); ?></th>
141 <?php } else { ?>
142 <th><?php echo htmlspecialchars( xl('Referred By'), ENT_NOQUOTES); ?></th>
143 <?php } ?>
144 <th><?php echo htmlspecialchars( xl('Comments'), ENT_NOQUOTES); ?></th>
145 <th><?php echo htmlspecialchars( xl('Enc'), ENT_NOQUOTES); ?></th>
146 </tr>
147 <?php
149 // collect issues
150 $condition = '';
151 if($GLOBALS['erx_enable'] && $GLOBALS['erx_medication_display'] && $focustype=='medication')
152 $condition .= "and erx_uploaded != '1' ";
153 $pres = sqlStatement("SELECT * FROM lists WHERE pid = ? AND type = ? $condition" .
154 "ORDER BY begdate", array($pid,$focustype) );
156 // if no issues (will place a 'None' text vs. toggle algorithm here)
157 if (sqlNumRows($pres) < 1) {
158 if ( getListTouch($pid,$focustype) ) {
159 // Data entry has happened to this type, so can display an explicit None.
160 echo "<tr><td class='text'><b>" . htmlspecialchars( xl("None"), ENT_NOQUOTES) . "</b></td></tr>";
162 else {
163 // Data entry has not happened to this type, so can show the none selection option.
164 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>";
168 // display issues
169 while ($row = sqlFetchArray($pres)) {
171 $rowid = $row['id'];
173 $disptitle = trim($row['title']) ? $row['title'] : "[Missing Title]";
175 $ierow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
176 "list_id = ?", array($rowid) );
178 // encount is used to toggle the color of the table-row output below
179 ++$encount;
180 $bgclass = (($encount & 1) ? "bg1" : "bg2");
182 // look up the diag codes
183 $codetext = "";
184 if ($row['diagnosis'] != "") {
185 $diags = explode(";", $row['diagnosis']);
186 foreach ($diags as $diag) {
187 $codedesc = lookup_code_descriptions($diag);
188 $codetext .= htmlspecialchars($diag,ENT_NOQUOTES) . " (" . htmlspecialchars($codedesc,ENT_NOQUOTES) . ")<br>";
192 // calculate the status
193 if ($row['outcome'] == "1" && $row['enddate'] != NULL) {
194 // Resolved
195 $statusCompute = generate_display_field(array('data_type'=>'1','list_id'=>'outcome'), $row['outcome']);
197 else if($row['enddate'] == NULL) {
198 $statusCompute = htmlspecialchars( xl("Active") ,ENT_NOQUOTES);
200 else {
201 $statusCompute = htmlspecialchars( xl("Inactive") ,ENT_NOQUOTES);
203 $click_class='statrow';
204 if($row['erx_source']==1 && $focustype=='allergy')
205 $click_class='';
206 elseif($row['erx_uploaded']==1 && $focustype=='medication')
207 $click_class='';
208 // output the TD row of info
209 if ($row['enddate'] == NULL) {
210 echo " <tr class='$bgclass detail $click_class' style='color:red;font-weight:bold' id='$rowid'>\n";
212 else {
213 echo " <tr class='$bgclass detail $click_class' id='$rowid'>\n";
215 echo " <td style='text-align:left'>" . htmlspecialchars($disptitle,ENT_NOQUOTES) . "</td>\n";
216 echo " <td>" . htmlspecialchars($row['begdate'],ENT_NOQUOTES) . "&nbsp;</td>\n";
217 echo " <td>" . htmlspecialchars($row['enddate'],ENT_NOQUOTES) . "&nbsp;</td>\n";
218 // both codetext and statusCompute have already been escaped above with htmlspecialchars)
219 echo " <td>" . $codetext . "</td>\n";
220 echo " <td>" . $statusCompute . "&nbsp;</td>\n";
221 echo " <td class='nowrap'>";
222 echo generate_display_field(array('data_type'=>'1','list_id'=>'occurrence'), $row['occurrence']);
223 echo "</td>\n";
224 if ($focustype == "allergy") {
225 echo " <td>" . htmlspecialchars($row['reaction'],ENT_NOQUOTES) . "&nbsp;</td>\n";
227 if ($GLOBALS['athletic_team']) {
228 echo " <td class='center'>" . $row['extrainfo'] . "</td>\n"; // games missed
230 else {
231 echo " <td>" . htmlspecialchars($row['referredby'],ENT_NOQUOTES) . "</td>\n";
233 echo " <td>" . htmlspecialchars($row['comments'],ENT_NOQUOTES) . "</td>\n";
234 echo " <td id='e_$rowid' class='noclick center' title='" . htmlspecialchars( xl('View related encounters'), ENT_QUOTES) . "'>";
235 echo " <input type='button' value='" . htmlspecialchars($ierow['count'],ENT_QUOTES) . "' class='editenc' id='" . htmlspecialchars($rowid,ENT_QUOTES) . "' />";
236 echo " </td>";
237 echo " </tr>\n";
240 echo "</table>";
243 </table>
245 </form>
246 </div> <!-- end patient_stats -->
248 </body>
250 <script language="javascript">
251 // jQuery stuff to make the page a little easier to use
253 $(document).ready(function(){
254 $(".statrow").mouseover(function() { $(this).toggleClass("highlight"); });
255 $(".statrow").mouseout(function() { $(this).toggleClass("highlight"); });
257 $(".statrow").click(function() { dopclick(this.id,0); });
258 $(".editenc").click(function(event) { doeclick(this.id); event.stopPropagation(); });
259 $("#newencounter").click(function() { newEncounter(); });
260 $("#history").click(function() { GotoHistory(); });
261 $("#back").click(function() { GoBack(); });
263 $(".noneCheck").click(function() {
264 top.restoreSession();
265 $.post( "../../../library/ajax/lists_touch.php", { type: this.name, patient_id: <?php echo htmlspecialchars($pid,ENT_QUOTES); ?> });
266 $(this).hide();
270 var GotoHistory = function() {
271 top.restoreSession();
272 <?php if ($GLOBALS['concurrent_layout']): ?>
273 parent.left_nav.setRadio(window.name,'his');
274 location.href='../history/history_full.php';
275 <?php else: ?>
276 location.href='../history/history_full.php';
277 <?php endif; ?>
280 var GoBack = function () {
281 top.restoreSession();
282 <?php if ($GLOBALS['concurrent_layout']): ?>
283 parent.left_nav.setRadio(window.name,'dem');
284 location.href='demographics.php';
285 <?php else: ?>
286 location.href="patient_summary.php";
287 <?php endif; ?>
290 </script>
292 </html>