e6afe49aa65b3c5f8aec0c452e780df647df10b3
[openemr.git] / patients / get_lab_results.php
blobe6afe49aa65b3c5f8aec0c452e780df647df10b3
1 <?php
2 // Copyright (C) 2011 Cassian LUP <cassi.lup@gmail.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;
12 //STOP FAKE REGISTER GLOBALS
13 $fake_register_globals=false;
15 //continue session
16 session_start();
19 //landing page definition -- where to go if something goes wrong
20 $landingpage = "index.php?site=".$_SESSION['site_id'];
23 // kick out if patient not authenticated
24 if ( isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite']) ) {
25 $pid = $_SESSION['pid'];
27 else {
28 session_destroy();
29 header('Location: '.$landingpage.'&w');
30 exit;
34 $ignoreAuth=true;
35 require_once('../interface/globals.php');
36 require_once('../library/options.inc.php');
38 $selects = "po.procedure_order_id, po.date_ordered, " .
39 "po.procedure_type_id AS order_type_id, pt1.name AS procedure_name, " .
40 "ptrc.name AS result_category_name, " .
41 "pt2.procedure_type AS result_type, " .
42 "pt2.procedure_type_id AS result_type_id, pt2.name AS result_name, " .
43 "pt2.units AS result_def_units, pt2.range AS result_def_range, " .
44 "pt2.description AS result_description, lo.title AS units_name, " .
45 "pr.procedure_report_id, pr.date_report, pr.date_collected, pr.specimen_num, pr.report_status, pr.review_status, " .
46 "ps.procedure_result_id, ps.abnormal, ps.result, ps.range, ps.result_status, " .
47 "ps.facility, ps.comments";
49 $joins = "LEFT JOIN procedure_type AS pt1 ON pt1.procedure_type_id = po.procedure_type_id ";
50 $joins .= "LEFT JOIN procedure_type AS ptrc ON ptrc.procedure_type_id = pt1.parent ";
51 $joins .= "AND ptrc.procedure_type LIKE 'grp%' " .
52 "LEFT JOIN procedure_type AS pt2 ON " .
53 "( ( ptrc.procedure_type_id IS NULL AND ( pt2.parent = po.procedure_type_id " .
54 "OR pt2.procedure_type_id = po.procedure_type_id ) ) OR ";
55 $joins .= "( pt2.procedure_type_id IS NOT NULL AND pt2.parent = pt1.procedure_type_id ) " .
56 ") AND ( pt2.procedure_type LIKE 'res%' OR pt2.procedure_type LIKE 'rec%' ) " .
57 "LEFT JOIN list_options AS lo ON list_id = 'proc_unit' AND option_id = pt2.units " .
58 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id " .
59 "LEFT JOIN procedure_result AS ps ON ps.procedure_report_id = pr.procedure_report_id " .
60 "AND ps.procedure_type_id = pt2.procedure_type_id";
62 $orderby ="po.date_ordered, po.procedure_order_id, pr.procedure_report_id, " .
63 "ptrc.seq, ptrc.name, ptrc.procedure_type_id, " .
64 "pt2.seq, pt2.name, pt2.procedure_type_id";
66 $where = "1 = 1";
68 $res = sqlStatement("SELECT $selects " .
69 "FROM procedure_order AS po $joins " .
70 "WHERE po.patient_id = ? AND $where " .
71 "ORDER BY $orderby", array($pid));
73 if(sqlNumRows($res)>0)
76 <table class="class1">
77 <tr class="header">
78 <th><?php echo htmlspecialchars( xl('Order Date'),ENT_NOQUOTES); ?></th>
79 <th><?php echo htmlspecialchars( xl('Order Name'),ENT_NOQUOTES); ?></th>
80 <th><?php echo htmlspecialchars( xl('Result Name'),ENT_NOQUOTES); ?></th>
81 <th><?php echo htmlspecialchars( xl('Abnormal'),ENT_NOQUOTES); ?></th>
82 <th><?php echo htmlspecialchars( xl('Value'),ENT_NOQUOTES); ?></th>
83 <th><?php echo htmlspecialchars( xl('Range'),ENT_NOQUOTES); ?></th>
84 <th><?php echo htmlspecialchars( xl('Units'),ENT_NOQUOTES); ?></th>
85 <th><?php echo htmlspecialchars( xl('Result Status'),ENT_NOQUOTES); ?></th>
86 <th><?php echo htmlspecialchars( xl('Report Status'),ENT_NOQUOTES); ?></th>
87 </tr>
88 <?php
89 $even=false;
90 while ($row = sqlFetchArray($res)) {
91 if ($even) {
92 $class="class1_even";
93 $even=false;
94 } else {
95 $class="class1_odd";
96 $even=true;
98 $date=explode('-',$row['date_ordered']);
99 echo "<tr class='".$class."'>";
100 echo "<td>".htmlspecialchars($date[1]."/".$date[2]."/".$date[0],ENT_NOQUOTES)."</td>";
101 echo "<td>".htmlspecialchars($row['procedure_name'],ENT_NOQUOTES)."</td>";
102 echo "<td>".htmlspecialchars($row['result_name'],ENT_NOQUOTES)."</td>";
103 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_res_abnormal'),$row['abnormal'])."</td>";
104 echo "<td>".htmlspecialchars($row['result'],ENT_NOQUOTES)."</td>";
105 echo "<td>".htmlspecialchars($row['result_def_range'],ENT_NOQUOTES)."</td>";
106 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_unit'),$row['result_def_units'])."</td>";
107 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_res_status'),$row['result_status'])."</td>";
108 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_rep_status'),$row['report_status'])."</td>";
109 echo "</tr>";
111 echo "</table>";
113 else
115 echo htmlspecialchars( xl("No Results"),ENT_NOQUOTES);