update message codes
[openemr.git] / patients / get_lab_results.php
blobc47352ceb55546e01d3fd7b3407dbbad5959149a
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 require_once("verify_session.php");
12 require_once('../library/options.inc.php');
14 $selects =
15 "po.procedure_order_id, po.date_ordered, pc.procedure_order_seq, " .
16 "pt1.procedure_type_id AS order_type_id, pc.procedure_name, " .
17 "pr.procedure_report_id, pr.date_report, pr.date_collected, pr.specimen_num, " .
18 "pr.report_status, pr.review_status";
20 $joins =
21 "JOIN procedure_order_code AS pc ON pc.procedure_order_id = po.procedure_order_id " .
22 "LEFT JOIN procedure_type AS pt1 ON pt1.lab_id = po.lab_id AND pt1.procedure_code = pc.procedure_code " .
23 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id AND " .
24 "pr.procedure_order_seq = pc.procedure_order_seq";
26 $orderby =
27 "po.date_ordered, po.procedure_order_id, " .
28 "pc.procedure_order_seq, pr.procedure_report_id";
30 $where = "1 = 1";
32 $res = sqlStatement("SELECT $selects " .
33 "FROM procedure_order AS po $joins " .
34 "WHERE po.patient_id = ? AND $where " .
35 "ORDER BY $orderby", array($pid));
37 if(sqlNumRows($res)>0)
40 <table class="class1">
41 <tr class="header">
42 <th><?php echo htmlspecialchars( xl('Order Date'),ENT_NOQUOTES); ?></th>
43 <th><?php echo htmlspecialchars( xl('Order Name'),ENT_NOQUOTES); ?></th>
44 <th><?php echo htmlspecialchars( xl('Result Name'),ENT_NOQUOTES); ?></th>
45 <th><?php echo htmlspecialchars( xl('Abnormal'),ENT_NOQUOTES); ?></th>
46 <th><?php echo htmlspecialchars( xl('Value'),ENT_NOQUOTES); ?></th>
47 <th><?php echo htmlspecialchars( xl('Range'),ENT_NOQUOTES); ?></th>
48 <th><?php echo htmlspecialchars( xl('Units'),ENT_NOQUOTES); ?></th>
49 <th><?php echo htmlspecialchars( xl('Result Status'),ENT_NOQUOTES); ?></th>
50 <th><?php echo htmlspecialchars( xl('Report Status'),ENT_NOQUOTES); ?></th>
51 </tr>
52 <?php
53 $even=false;
55 while ($row = sqlFetchArray($res)) {
56 $order_type_id = empty($row['order_type_id' ]) ? 0 : ($row['order_type_id' ] + 0);
57 $report_id = empty($row['procedure_report_id']) ? 0 : ($row['procedure_report_id'] + 0);
59 $selects = "pt2.procedure_type, pt2.procedure_code, pt2.units AS pt2_units, " .
60 "pt2.range AS pt2_range, pt2.procedure_type_id AS procedure_type_id, " .
61 "pt2.name AS name, pt2.description, pt2.seq AS seq, " .
62 "ps.procedure_result_id, ps.result_code AS result_code, ps.result_text, ps.abnormal, ps.result, " .
63 "ps.range, ps.result_status, ps.facility, ps.comments, ps.units, ps.comments";
65 // procedure_type_id for order:
66 $pt2cond = "pt2.parent = $order_type_id AND " .
67 "(pt2.procedure_type LIKE 'res%' OR pt2.procedure_type LIKE 'rec%')";
69 // pr.procedure_report_id or 0 if none:
70 $pscond = "ps.procedure_report_id = $report_id";
72 $joincond = "ps.result_code = pt2.procedure_code";
74 // This union emulates a full outer join. The idea is to pick up all
75 // result types defined for this order type, as well as any actual
76 // results that do not have a matching result type.
77 $query = "(SELECT $selects FROM procedure_type AS pt2 " .
78 "LEFT JOIN procedure_result AS ps ON $pscond AND $joincond " .
79 "WHERE $pt2cond" .
80 ") UNION (" .
81 "SELECT $selects FROM procedure_result AS ps " .
82 "LEFT JOIN procedure_type AS pt2 ON $pt2cond AND $joincond " .
83 "WHERE $pscond) " .
84 "ORDER BY seq, name, procedure_type_id, result_code";
86 $rres = sqlStatement($query);
87 while ($rrow = sqlFetchArray($rres)) {
89 if ($even) {
90 $class="class1_even";
91 $even=false;
92 } else {
93 $class="class1_odd";
94 $even=true;
96 $date=explode('-',$row['date_ordered']);
97 echo "<tr class='".$class."'>";
98 echo "<td>".htmlspecialchars($date[1]."/".$date[2]."/".$date[0],ENT_NOQUOTES)."</td>";
99 echo "<td>".htmlspecialchars($row['procedure_name'],ENT_NOQUOTES)."</td>";
100 echo "<td>".htmlspecialchars($rrow['name'],ENT_NOQUOTES)."</td>";
101 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_res_abnormal'),$rrow['abnormal'])."</td>";
102 echo "<td>".htmlspecialchars($row['result'],ENT_NOQUOTES)."</td>";
103 echo "<td>".htmlspecialchars($rrow['pt2_range'],ENT_NOQUOTES)."</td>";
104 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_unit'),$rrow['pt2_units'])."</td>";
105 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_res_status'),$rrow['result_status'])."</td>";
106 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_rep_status'),$row['report_status'])."</td>";
107 echo "</tr>";
113 echo "</table>";
115 else
117 echo htmlspecialchars( xl("No Results"),ENT_NOQUOTES);