4 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
5 * Copyright (C) 2011 Cassian LUP <cassi.lup@gmail.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @author Cassian LUP <cassi.lup@gmail.com>
20 * @author Jerry Padgett <sjpadgett@gmail.com>
21 * @link http://www.open-emr.org
24 require_once("verify_session.php");
25 require_once('../library/options.inc.php');
28 "po.procedure_order_id, po.date_ordered, pc.procedure_order_seq, " .
29 "pt1.procedure_type_id AS order_type_id, pc.procedure_name, " .
30 "pr.procedure_report_id, pr.date_report, pr.date_collected, pr.specimen_num, " .
31 "pr.report_status, pr.review_status";
34 "JOIN procedure_order_code AS pc ON pc.procedure_order_id = po.procedure_order_id " .
35 "LEFT JOIN procedure_type AS pt1 ON pt1.lab_id = po.lab_id AND pt1.procedure_code = pc.procedure_code " .
36 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id AND " .
37 "pr.procedure_order_seq = pc.procedure_order_seq";
40 "po.date_ordered, po.procedure_order_id, " .
41 "pc.procedure_order_seq, pr.procedure_report_id";
45 $res = sqlStatement("SELECT $selects " .
46 "FROM procedure_order AS po $joins " .
47 "WHERE po.patient_id = ? AND $where " .
48 "ORDER BY $orderby", array($pid));
50 if (sqlNumRows($res)>0) {
52 <table
class="table table-striped table-condensed table-bordered">
54 <th
><?php
echo xlt('Order Date'); ?
></th
>
55 <th
><?php
echo xlt('Order Name'); ?
></th
>
56 <th
><?php
echo xlt('Result Name'); ?
></th
>
57 <th
><?php
echo xlt('Abnormal'); ?
></th
>
58 <th
><?php
echo xlt('Value'); ?
></th
>
59 <th
><?php
echo xlt('Range'); ?
></th
>
60 <th
><?php
echo xlt('Units'); ?
></th
>
61 <th
><?php
echo xlt('Result Status'); ?
></th
>
62 <th
><?php
echo xlt('Report Status'); ?
></th
>
67 while ($row = sqlFetchArray($res)) {
68 $order_type_id = empty($row['order_type_id' ]) ?
0 : ($row['order_type_id' ] +
0);
69 $report_id = empty($row['procedure_report_id']) ?
0 : ($row['procedure_report_id'] +
0);
71 $selects = "pt2.procedure_type, pt2.procedure_code, pt2.units AS pt2_units, " .
72 "pt2.range AS pt2_range, pt2.procedure_type_id AS procedure_type_id, " .
73 "pt2.name AS name, pt2.description, pt2.seq AS seq, " .
74 "ps.procedure_result_id, ps.result_code AS result_code, ps.result_text, ps.abnormal, ps.result, " .
75 "ps.range, ps.result_status, ps.facility, ps.comments, ps.units, ps.comments";
77 // procedure_type_id for order:
78 $pt2cond = "pt2.parent = $order_type_id AND " .
79 "(pt2.procedure_type LIKE 'res%' OR pt2.procedure_type LIKE 'rec%')";
81 // pr.procedure_report_id or 0 if none:
82 $pscond = "ps.procedure_report_id = $report_id";
84 $joincond = "ps.result_code = pt2.procedure_code";
86 // This union emulates a full outer join. The idea is to pick up all
87 // result types defined for this order type, as well as any actual
88 // results that do not have a matching result type.
89 $query = "(SELECT $selects FROM procedure_type AS pt2 " .
90 "LEFT JOIN procedure_result AS ps ON $pscond AND $joincond " .
93 "SELECT $selects FROM procedure_result AS ps " .
94 "LEFT JOIN procedure_type AS pt2 ON $pt2cond AND $joincond " .
96 "ORDER BY seq, name, procedure_type_id, result_code";
98 $rres = sqlStatement($query);
99 while ($rrow = sqlFetchArray($rres)) {
101 $class="class1_even";
108 $date=explode('-', $row['date_ordered']);
109 echo "<tr class='".$class."'>";
110 echo "<td>".text($date[1]."/".$date[2]."/".$date[0])."</td>";
111 echo "<td>".text($row['procedure_name'])."</td>";
112 echo "<td>".text($rrow['name'])."</td>";
113 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_res_abnormal'), $rrow['abnormal'])."</td>";
114 echo "<td>".text($row['result'])."</td>";
115 echo "<td>".text($rrow['pt2_range'])."</td>";
116 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_unit'), $rrow['pt2_units'])."</td>";
117 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_res_status'), $rrow['result_status'])."</td>";
118 echo "<td>".generate_display_field(array('data_type'=>'1','list_id'=>'proc_rep_status'), $row['report_status'])."</td>";
125 echo xlt("No Results");