erx fix 4
[openemr.git] / interface / patient_file / summary / stats.php
blob549995e1b68e12ba3cfd71155af958de87ef6164
1 <?php
3 //SANITIZE ALL ESCAPES
4 $sanitize_all_escapes=true;
5 //
7 //STOP FAKE REGISTER GLOBALS
8 $fake_register_globals=false;
9 //
11 include_once("../../globals.php");
12 include_once("$srcdir/lists.inc");
13 include_once("$srcdir/acl.inc");
14 include_once("$srcdir/options.inc.php");
15 include_once("$srcdir/formdata.inc.php");
18 <div id="patient_stats_summary">
20 <?php
21 $thisauth = acl_check('patients', 'med');
22 if ($thisauth) {
23 $tmp = getPatientData($pid, "squad");
24 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
25 $thisauth = 0;
27 if (!$thisauth) {
28 echo "<p>(".htmlspecialchars(xl('Issues not authorized'),ENT_NOQUOTES).")</p>\n";
29 echo "</body>\n</html>\n";
30 exit();
34 <script type='text/javascript'>
35 function load_location( location ) {
36 top.restoreSession();
37 if ( !top.frames["RTop"] ) {
38 document.location=location;
39 } else {
40 top.frames["RTop"].location=location;
43 </script>
45 <table id="patient_stats_issues">
47 <?php
48 $numcols = '1';
49 $ix = 0;
50 foreach ($ISSUE_TYPES as $key => $arr) {
51 // $result = getListByType($pid, $key, "id,title,begdate,enddate,returndate,extrainfo", "all", "all", 0);
53 $query = "SELECT * FROM lists WHERE pid = ? AND type = ? AND ";
54 $query .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
55 if($GLOBALS['erx_enable'] && $GLOBALS['erx_medication_display'] && $key=='medication')
56 $query .= "and erx_uploaded != '1' ";
57 if($GLOBALS['erx_enable'] && $GLOBALS['erx_allergy_display'] && $key=='allergy')
58 $query .= "and erx_uploaded != '1' ";
59 $query .= "ORDER BY begdate";
60 $pres = sqlStatement($query, array($pid, $key) );
62 if (sqlNumRows($pres) > 0 || $ix == 0 || $key == "allergy" || $key == "medication") {
64 if ($_POST['embeddedScreen']) {
65 echo "<tr><td>";
66 // Issues expand collapse widget
67 $widgetTitle = $arr[0];
68 $widgetLabel = $key;
69 if(($key == "allergy" || $key == "medication") && $GLOBALS['erx_enable'])
71 $widgetButtonLabel = xl("Add");
72 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/eRx.php?page=medentry\")";
74 else
76 $widgetButtonLabel = xl("Edit");
77 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/stats_full.php?active=all&category=" . $key . "\")";
79 $widgetButtonClass = "";
80 $linkMethod = "javascript";
81 $bodyClass = "summary_item small";
82 $widgetAuth = true;
83 $fixedWidth = false;
84 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
86 else { ?>
87 <tr class='issuetitle'>
88 <td colspan='$numcols'>
89 <span class="text"><b><?php echo htmlspecialchars($arr[0],ENT_NOQUOTES); ?></b></span>
90 <a href="javascript:;" class="small" onclick="load_location('stats_full.php?active=all&category=" . $key . "')">
91 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES); ?></b>)
92 </a>
93 </td>
94 </tr>
95 <?php }
96 echo "<table>";
97 if (sqlNumRows($pres) == 0) {
98 if ( getListTouch($pid,$key) ) {
99 // Data entry has happened to this type, so can display an explicit None.
100 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td></tr>\n";
102 else {
103 // Data entry has not happened to this type, so show 'Nothing Recorded"
104 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('Nothing Recorded'), ENT_NOQUOTES) . "</td></tr>\n";
108 while ($row = sqlFetchArray($pres)) {
109 // output each issue for the $ISSUE_TYPE
110 if (!$row['enddate'] && !$row['returndate'])
111 $rowclass="noend_noreturn";
112 else if (!$row['enddate'] && $row['returndate'])
113 $rowclass="noend";
114 else if ($row['enddate'] && !$row['returndate'])
115 $rowclass = "noreturn";
117 echo " <tr class='text $rowclass;'>\n";
119 //turn allergies red and bold and show the reaction (if exist)
120 if ($key == "allergy") {
121 $reaction = "";
122 if (!empty($row['reaction'])) {
123 $reaction = " (" . $row['reaction'] . ")";
125 echo " <td colspan='$numcols' style='color:red;font-weight:bold;'>&nbsp;&nbsp;" . htmlspecialchars( $row['title'] . $reaction, ENT_NOQUOTES) . "</td>\n";
127 else {
128 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . htmlspecialchars($row['title'],ENT_NOQUOTES) . "</td>\n";
131 echo " </tr>\n";
133 echo "</table>";
134 if ($_POST['embeddedScreen']) {
135 echo "</div></td></tr>";
140 ++$ix;
143 </table> <!-- end patient_stats_issues -->
145 <table id="patient_stats_spreadsheets">
146 <?php
148 // Show spreadsheet forms if any are present.
150 $need_head = true;
151 foreach (array('treatment_protocols','injury_log') as $formname) {
152 if (sqlNumRows(sqlStatement("SHOW TABLES LIKE ?", array("form_".$formname) )) > 0) {
153 $dres = sqlStatement("SELECT tp.id, tp.value FROM forms, " .
154 "form_" . add_escape_custom($formname) .
155 " AS tp WHERE forms.pid = ? AND " .
156 "forms.formdir = ? AND tp.id = forms.form_id AND " .
157 "tp.rownbr = -1 AND tp.colnbr = -1 AND tp.value LIKE '0%' " .
158 "ORDER BY tp.value DESC", array($pid, $formname) );
159 if (sqlNumRows($dres) > 0 && $need_head) {
160 $need_head = false;
161 echo " <tr>\n";
162 echo " <td colspan='$numcols' valign='top'>\n";
163 echo " <span class='title'>Injury Log</span>\n";
164 echo " </td>\n";
165 echo " </tr>\n";
167 while ($row = sqlFetchArray($dres)) {
168 list($completed, $start_date, $template_name) = explode('|', $row['value'], 3);
169 echo " <tr>\n";
170 echo " <td colspan='$numcols'>&nbsp;&nbsp;";
171 echo "<a class='link' href='javascript:;' ";
172 echo "onclick='load_location(\"../../forms/$formname/new.php?popup=1&id=";
173 echo htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
174 htmlspecialchars($start_date,ENT_NOQUOTES) . " " .
175 htmlspecialchars($template_name,ENT_NOQUOTES) . "</a></td>\n";
176 echo " </tr>\n";
181 </table> <!-- end patient_stats_spreadsheets -->
183 <?php if (!$GLOBALS['disable_immunizations'] && !$GLOBALS['weight_loss_clinic']) { ?>
184 <div>
185 <table id="patient_stats_imm">
186 <tr>
187 <?php if ($_POST['embeddedScreen']) {
188 echo "<td>";
189 // Issues expand collapse widget
190 $widgetTitle = xl('Immunizations');
191 $widgetLabel = "immunizations";
192 $widgetButtonLabel = xl("Edit");
193 $widgetButtonLink = "javascript:load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/immunizations.php\")";
194 $widgetButtonClass = "";
195 $linkMethod = "javascript";
196 $bodyClass = "summary_item small";
197 $widgetAuth = true;
198 $fixedWidth = false;
199 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
201 else { ?>
202 <td colspan='<?php echo $numcols ?>' valign='top'>
203 <span class="text"><b><?php echo htmlspecialchars(xl('Immunizations', 'e'),ENT_NOQUOTES); ?></b></span>
204 <a href="javascript:;" class="small" onclick="javascript:load_location('immunizations.php')">
205 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES) ?></b>)
206 </a>
207 </td></tr>
208 <tr><td>
209 <?php } ?>
211 <?php
212 $sql = "select i1.id as id, i1.immunization_id as immunization_id, i1.cvx_code as cvx_code, c.code_text_short as cvx_text, ".
213 " if (i1.administered_date, concat(i1.administered_date,' - '), substring(i1.note,1,20)) as immunization_data ".
214 " from immunizations i1 ".
215 " left join codes c on CAST(IFNULL(i1.cvx_code,0) AS CHAR) = c.code ".
216 " left join code_types ct on c.code_type = ct.ct_id ".
217 " where i1.patient_id = ? ".
218 " AND (( i1.cvx_code = '0' OR i1.cvx_code IS NULL ) OR ".
219 " ( ( i1.cvx_code != '0' AND i1.cvx_code IS NOT NULL ) AND ct.ct_key = 'CVX') ) ".
220 " order by i1.administered_date desc";
222 $result = sqlStatement($sql, array($pid) );
224 if (sqlNumRows($result) == 0) {
225 echo " <table><tr>\n";
226 echo " <td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td>\n";
227 echo " </tr></table>\n";
230 while ($row=sqlFetchArray($result)){
231 echo "&nbsp;&nbsp;";
232 echo "<a class='link'";
233 echo "' href='javascript:;' onclick='javascript:load_location(\"immunizations.php?mode=edit&id=".htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
234 htmlspecialchars($row{'immunization_data'},ENT_NOQUOTES);
236 // Figure out which name to use (ie. from cvx list or from the custom list)
237 if ($GLOBALS['use_custom_immun_list']) {
238 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
240 else {
241 if (!(empty($row['cvx_text']))) {
242 echo htmlspecialchars( xl($row['cvx_text']), ENT_NOQUOTES );
244 else {
245 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
248 echo "</a><br>\n";
252 <?php if ($_POST['embeddedScreen']) {
253 echo "</td></tr></div>";
254 } ?>
256 </td>
257 </tr>
258 </table> <!-- end patient_stats_imm-->
259 </div>
260 <?php } ?>
262 <?php if (!$GLOBALS['disable_prescriptions']) { ?>
263 <div>
264 <table id="patient_stats_prescriptions">
265 <?php if($GLOBALS['erx_enable']){ ?>
266 <tr><td>
267 <?php if ($_POST['embeddedScreen']) {
268 $widgetTitle = '';
269 $widgetTitle = xl('Current Medications');
270 $widgetLabel = "current_prescriptions";
271 $widgetButtonLabel = '';
272 $widgetButtonLink = '';
273 $widgetButtonClass = '';
274 $linkMethod = "";
275 $bodyClass = "summary_item small";
276 $widgetAuth = false;
277 $fixedWidth = false;
278 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
282 <?php
283 $res=sqlStatement("select * from prescriptions where patient_id=? and active='1'",array($pid));
285 <table>
286 <?php
287 if(sqlNumRows($res)==0)
290 <tr class=text>
291 <td><?php echo htmlspecialchars(xl('None'), ENT_NOQUOTES);?></td>
292 </tr>
293 <?php
295 while($row_currentMed=sqlFetchArray($res))
297 $runit=generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'),$row_currentMed['unit']);
298 $rin=generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'),$row_currentMed['form']);
299 $rroute=generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'),$row_currentMed['route']);
300 $rint=generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'),$row_currentMed['interval']);
302 <tr class=text style='font-weight:bold;color:blue;'>
303 <td><?php echo $row_currentMed['drug'];?></td>
304 <td><?php $unit=''; if($row_currentMed['size']>0) $unit=$row_currentMed['size']." ".$runit." "; echo htmlspecialchars($unit." ".$row_currentMed['dosage']." ".$rin." ".$rroute." ".$rint,ENT_NOQUOTES);?></td>
305 </tr>
306 <?php
309 </table>
310 </td></tr>
311 <?php } ?>
312 <tr><td colspan='<?php echo $numcols ?>' class='issuetitle'>
314 <?php if ($_POST['embeddedScreen']) {
315 // Issues expand collapse widget
316 $widgetLabel = "prescriptions";
317 $linkMethod = "html";
318 if($GLOBALS['erx_enable'])
320 $widgetTitle = xl('Prescription History');
321 $widgetButtonLabel = xl("Add/Edit eRx");
322 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/eRx.php?page=compose";
323 $widgetButtonClass = "";
325 else
327 $widgetTitle = xl('Prescription');
328 $widgetButtonLabel = xl("Edit");
329 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/patient_file/summary/rx_frameset.php";
330 $widgetButtonClass = "iframe rx_modal";
332 $bodyClass = "summary_item small";
333 $widgetAuth = true;
334 $fixedWidth = false;
335 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
337 else { ?>
338 <span class='text'><b><?php echo htmlspecialchars(xl('Prescriptions'),ENT_NOQUOTES); ?></b></span>
339 </td></tr>
340 </tr><td>
341 <?php } ?>
343 <?php
344 $cwd= getcwd();
345 chdir("../../../");
346 require_once("library/classes/Controller.class.php");
347 $c = new Controller();
348 echo $c->act(array("prescription" => "", "fragment" => "", "patient_id" => $pid));
351 <?php if ($_POST['embeddedScreen']) {
352 echo "</div>";
353 } ?>
355 </td></tr>
356 </table> <!-- end patient_stats_prescriptions -->
357 </div>
358 <?php } ?>
360 </div> <!-- end patient_stats_summary -->