The Third Reminders email bug fix - contributed by arnabnaha
[openemr.git] / interface / patient_file / summary / stats.php
blobba0d0d6c61696c804142ea60a7de947a5e6ce5aa
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 $erx_upload_complete = 0;
50 $old_key="";$display_current_medications_below=1;
51 foreach ($ISSUE_TYPES as $key => $arr) {
52 // $result = getListByType($pid, $key, "id,title,begdate,enddate,returndate,extrainfo", "all", "all", 0);
54 $query = "SELECT * FROM lists WHERE pid = ? AND type = ? AND ";
55 $query .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
56 if($GLOBALS['erx_enable'] && $GLOBALS['erx_medication_display'] && $key=='medication')
57 $query .= "and erx_uploaded != '1' ";
58 if($GLOBALS['erx_enable'] && $GLOBALS['erx_allergy_display'] && $key=='allergy')
59 $query .= "and erx_uploaded != '1' ";
60 $query .= "ORDER BY begdate";
61 $pres = sqlStatement($query, array($pid, $key) );
62 if($old_key=="medication" && $GLOBALS['erx_enable'] && $erx_upload_complete == 1)
64 $display_current_medications_below=0;
66 <div>
67 <table id="patient_stats_prescriptions">
68 <?php if($GLOBALS['erx_enable']){ ?>
69 <tr><td>
70 <?php if ($_POST['embeddedScreen']) {
71 $widgetTitle = '';
72 $widgetTitle = xl('Current Medications');
73 $widgetLabel = "current_prescriptions";
74 $widgetButtonLabel = '';
75 $widgetButtonLink = '';
76 $widgetAuth = false;
77 $widgetButtonClass = '';
78 $bodyClass = "summary_item small";
79 $fixedWidth = false;
80 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
84 <?php
85 $res=sqlStatement("select * from prescriptions where patient_id=? and active='1'",array($pid));
87 <table>
88 <?php
89 if(sqlNumRows($res)==0)
92 <tr class=text>
93 <td><?php echo htmlspecialchars(xl('None'), ENT_NOQUOTES);?></td>
94 </tr>
95 <?php
97 while($row_currentMed=sqlFetchArray($res))
99 $runit=generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'),htmlspecialchars($row_currentMed['unit'],ENT_NOQUOTES));
100 $rin=generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'),htmlspecialchars($row_currentMed['form'],ENT_NOQUOTES));
101 $rroute=generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'),htmlspecialchars($row_currentMed['route'],ENT_NOQUOTES));
102 $rint=generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'),htmlspecialchars($row_currentMed['interval'],ENT_NOQUOTES));
104 <tr class=text >
105 <td><?php echo htmlspecialchars($row_currentMed['drug'],ENT_NOQUOTES);?></td>
106 <td><?php
107 $unit='';
108 if($row_currentMed['size']>0)
109 $unit=$row_currentMed['size']." ".$runit." ";
110 echo htmlspecialchars($unit." ".$row_currentMed['dosage']." ".$rin." ".$rroute." ".$rint,ENT_NOQUOTES);
111 ?></td>
112 </tr>
113 <?php
116 </table>
117 </td></tr>
118 <?php }
119 $old_key='';
121 if (sqlNumRows($pres) > 0 || $arr[4] == 1) {
122 $old_key=$key;
123 if ($_POST['embeddedScreen']) {
125 if($GLOBALS['erx_enable'] && $key == "medication"){
126 $query_uploaded = "SELECT * FROM lists WHERE pid = ? AND type = 'medication' AND ";
127 $query_uploaded .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
128 $query_uploaded .= "and erx_uploaded != '1' ";
129 $query_uploaded .= "ORDER BY begdate";
130 $res_uploaded = sqlStatement($query_uploaded, array($pid) );
131 if(sqlNumRows($res_uploaded) == 0){
132 $erx_upload_complete = 1;
133 continue;
137 echo "<tr><td>";
138 // Issues expand collapse widget
139 $widgetTitle = $arr[0];
140 $widgetLabel = $key;
141 if(($key == "allergy" || $key == "medication") && $GLOBALS['erx_enable'])
143 $widgetButtonLabel = xl("Add");
144 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/eRx.php?page=medentry\")";
146 else
148 $widgetButtonLabel = xl("Edit");
149 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/stats_full.php?active=all&category=" . $key . "\")";
151 $widgetButtonClass = "";
152 $linkMethod = "javascript";
153 $bodyClass = "summary_item small";
154 $widgetAuth = true;
155 $fixedWidth = false;
156 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
158 else { ?>
159 <tr class='issuetitle'>
160 <td colspan='$numcols'>
161 <span class="text"><b><?php echo htmlspecialchars($arr[0],ENT_NOQUOTES); ?></b></span>
162 <a href="javascript:;" class="small" onclick="load_location('stats_full.php?active=all&category=" . $key . "')">
163 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES); ?></b>)
164 </a>
165 </td>
166 </tr>
167 <?php }
168 echo "<table>";
169 if (sqlNumRows($pres) == 0) {
170 if ( getListTouch($pid,$key) ) {
171 // Data entry has happened to this type, so can display an explicit None.
172 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td></tr>\n";
174 else {
175 // Data entry has not happened to this type, so show 'Nothing Recorded"
176 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('Nothing Recorded'), ENT_NOQUOTES) . "</td></tr>\n";
180 while ($row = sqlFetchArray($pres)) {
181 // output each issue for the $ISSUE_TYPE
182 if (!$row['enddate'] && !$row['returndate'])
183 $rowclass="noend_noreturn";
184 else if (!$row['enddate'] && $row['returndate'])
185 $rowclass="noend";
186 else if ($row['enddate'] && !$row['returndate'])
187 $rowclass = "noreturn";
189 echo " <tr class='text $rowclass;'>\n";
191 //turn allergies red and bold and show the reaction (if exist)
192 if ($key == "allergy") {
193 $reaction = "";
194 if (!empty($row['reaction'])) {
195 $reaction = " (" . $row['reaction'] . ")";
197 echo " <td colspan='$numcols' style='color:red;font-weight:bold;'>&nbsp;&nbsp;" . htmlspecialchars( $row['title'] . $reaction, ENT_NOQUOTES) . "</td>\n";
199 else {
200 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . htmlspecialchars($row['title'],ENT_NOQUOTES) . "</td>\n";
203 echo " </tr>\n";
205 echo "</table>";
206 if ($_POST['embeddedScreen']) {
207 echo "</div></td></tr>";
213 </table> <!-- end patient_stats_issues -->
215 <table id="patient_stats_spreadsheets">
216 <?php
218 // Show spreadsheet forms if any are present.
220 $need_head = true;
221 foreach (array('treatment_protocols','injury_log') as $formname) {
222 if (sqlNumRows(sqlStatement("SHOW TABLES LIKE ?", array("form_".$formname) )) > 0) {
223 $dres = sqlStatement("SELECT tp.id, tp.value FROM forms, " .
224 "form_" . add_escape_custom($formname) .
225 " AS tp WHERE forms.pid = ? AND " .
226 "forms.formdir = ? AND tp.id = forms.form_id AND " .
227 "tp.rownbr = -1 AND tp.colnbr = -1 AND tp.value LIKE '0%' " .
228 "ORDER BY tp.value DESC", array($pid, $formname) );
229 if (sqlNumRows($dres) > 0 && $need_head) {
230 $need_head = false;
231 echo " <tr>\n";
232 echo " <td colspan='$numcols' valign='top'>\n";
233 echo " <span class='title'>Injury Log</span>\n";
234 echo " </td>\n";
235 echo " </tr>\n";
237 while ($row = sqlFetchArray($dres)) {
238 list($completed, $start_date, $template_name) = explode('|', $row['value'], 3);
239 echo " <tr>\n";
240 echo " <td colspan='$numcols'>&nbsp;&nbsp;";
241 echo "<a class='link' href='javascript:;' ";
242 echo "onclick='load_location(\"../../forms/$formname/new.php?popup=1&id=";
243 echo htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
244 htmlspecialchars($start_date,ENT_NOQUOTES) . " " .
245 htmlspecialchars($template_name,ENT_NOQUOTES) . "</a></td>\n";
246 echo " </tr>\n";
251 </table> <!-- end patient_stats_spreadsheets -->
253 <?php if (!$GLOBALS['disable_immunizations'] && !$GLOBALS['weight_loss_clinic']) { ?>
254 <div>
255 <table id="patient_stats_imm">
256 <tr>
257 <?php if ($_POST['embeddedScreen']) {
258 echo "<td>";
259 // Issues expand collapse widget
260 $widgetTitle = xl('Immunizations');
261 $widgetLabel = "immunizations";
262 $widgetButtonLabel = xl("Edit");
263 $widgetButtonLink = "javascript:load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/immunizations.php\")";
264 $widgetButtonClass = "";
265 $linkMethod = "javascript";
266 $bodyClass = "summary_item small";
267 $widgetAuth = true;
268 $fixedWidth = false;
269 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
271 else { ?>
272 <td colspan='<?php echo $numcols ?>' valign='top'>
273 <span class="text"><b><?php echo htmlspecialchars(xl('Immunizations', 'e'),ENT_NOQUOTES); ?></b></span>
274 <a href="javascript:;" class="small" onclick="javascript:load_location('immunizations.php')">
275 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES) ?></b>)
276 </a>
277 </td></tr>
278 <tr><td>
279 <?php } ?>
281 <?php
282 $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, ".
283 " if (i1.administered_date, concat(i1.administered_date,' - '), substring(i1.note,1,20)) as immunization_data ".
284 " from immunizations i1 ".
285 " left join code_types ct on ct.ct_key = 'CVX' ".
286 " left join codes c on c.code_type = ct.ct_id AND i1.cvx_code = c.code ".
287 " where i1.patient_id = ? ".
288 " order by i1.administered_date desc";
290 $result = sqlStatement($sql, array($pid) );
292 if (sqlNumRows($result) == 0) {
293 echo " <table><tr>\n";
294 echo " <td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td>\n";
295 echo " </tr></table>\n";
298 while ($row=sqlFetchArray($result)){
299 echo "&nbsp;&nbsp;";
300 echo "<a class='link'";
301 echo "' href='javascript:;' onclick='javascript:load_location(\"immunizations.php?mode=edit&id=".htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
302 htmlspecialchars($row{'immunization_data'},ENT_NOQUOTES);
304 // Figure out which name to use (ie. from cvx list or from the custom list)
305 if ($GLOBALS['use_custom_immun_list']) {
306 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
308 else {
309 if (!(empty($row['cvx_text']))) {
310 echo htmlspecialchars( xl($row['cvx_text']), ENT_NOQUOTES );
312 else {
313 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
316 echo "</a><br>\n";
320 <?php if ($_POST['embeddedScreen']) {
321 echo "</td></tr></div>";
322 } ?>
324 </td>
325 </tr>
326 </table> <!-- end patient_stats_imm-->
327 </div>
328 <?php } ?>
330 <?php if (!$GLOBALS['disable_prescriptions']) { ?>
331 <div>
332 <table id="patient_stats_prescriptions">
333 <?php if($GLOBALS['erx_enable'] && $display_current_medications_below==1){ ?>
334 <tr><td>
335 <?php if ($_POST['embeddedScreen']) {
336 $widgetTitle = '';
337 $widgetTitle = xl('Current Medications');
338 $widgetLabel = "current_prescriptions";
339 $widgetButtonLabel = '';
340 $widgetButtonLink = '';
341 $widgetAuth = false;
342 $widgetButtonClass = '';
343 $bodyClass = "summary_item small";
344 $fixedWidth = false;
345 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
349 <?php
350 $res=sqlStatement("select * from prescriptions where patient_id=? and active='1'",array($pid));
352 <table>
353 <?php
354 if(sqlNumRows($res)==0)
357 <tr class=text>
358 <td><?php echo htmlspecialchars(xl('None'), ENT_NOQUOTES);?></td>
359 </tr>
360 <?php
362 while($row_currentMed=sqlFetchArray($res))
364 $runit=generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'),$row_currentMed['unit']);
365 $rin=generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'),$row_currentMed['form']);
366 $rroute=generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'),$row_currentMed['route']);
367 $rint=generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'),$row_currentMed['interval']);
369 <tr class=text >
370 <td><?php echo $row_currentMed['drug'];?></td>
371 <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>
372 </tr>
373 <?php
376 </table>
377 </td></tr>
378 <?php } ?>
379 <tr><td colspan='<?php echo $numcols ?>' class='issuetitle'>
381 <?php if ($_POST['embeddedScreen']) {
382 // Issues expand collapse widget
383 $widgetLabel = "prescriptions";
384 $linkMethod = "html";
385 if($GLOBALS['erx_enable'])
387 $widgetTitle = xl('Prescription History');
388 $widgetButtonLabel = xl("Add/Edit eRx");
389 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/eRx.php?page=compose";
390 $widgetButtonClass = "";
392 else
394 $widgetTitle = xl('Prescription');
395 $widgetButtonLabel = xl("Edit");
396 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/patient_file/summary/rx_frameset.php";
397 $widgetButtonClass = "iframe rx_modal";
399 $bodyClass = "summary_item small";
400 $widgetAuth = true;
401 $fixedWidth = false;
402 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
404 else { ?>
405 <span class='text'><b><?php echo htmlspecialchars(xl('Prescriptions'),ENT_NOQUOTES); ?></b></span>
406 </td></tr>
407 </tr><td>
408 <?php } ?>
410 <?php
411 $cwd= getcwd();
412 chdir("../../../");
413 require_once("library/classes/Controller.class.php");
414 $c = new Controller();
415 echo $c->act(array("prescription" => "", "fragment" => "", "patient_id" => $pid));
418 <?php if ($_POST['embeddedScreen']) {
419 echo "</div>";
420 } ?>
422 </td></tr>
424 <?php }
426 if($erx_upload_complete == 1){
427 echo "<tr><td>";
428 // Old Medication Widget
429 $widgetTitle = "Old Medication";
430 $widgetLabel = "old_medication";
431 $widgetButtonLabel = xl("Edit");
432 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/stats_full.php?active=all&category=medication\")";
433 $widgetButtonClass = "";
434 $linkMethod = "javascript";
435 $bodyClass = "summary_item small";
436 $widgetAuth = true;
437 $fixedWidth = false;
438 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
439 $query_uploaded_old = "SELECT * FROM lists WHERE pid = ? AND type = 'medication' AND ";
440 $query_uploaded_old .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
441 $query_uploaded_old .= "ORDER BY begdate";
442 $res_uploaded_old = sqlStatement($query_uploaded_old, array($pid) );
443 echo "<table>";
444 while ($row = sqlFetchArray($res_uploaded_old)) {
445 // output each issue for the $ISSUE_TYPE
446 if (!$row['enddate'] && !$row['returndate'])
447 $rowclass="noend_noreturn";
448 else if (!$row['enddate'] && $row['returndate'])
449 $rowclass="noend";
450 else if ($row['enddate'] && !$row['returndate'])
451 $rowclass = "noreturn";
452 echo " <tr class='text $rowclass;'>\n";
453 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . htmlspecialchars($row['title'],ENT_NOQUOTES) . "</td>\n";
454 echo " </tr>\n";
456 echo "</table>";
457 echo "</div></td></tr>";
461 </table> <!-- end patient_stats_prescriptions -->
462 </div>
463 </div> <!-- end patient_stats_summary -->