Merge pull request #1150 from sjpadgett/add-visit-history
[openemr.git] / interface / reports / services_by_category.php
blobb91411ae233317b6d3623c0bfe8fe9f138113b80
1 <?php
2 // Copyright (C) 2008-2016 Rod Roark <rod@sunsetsystems.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 use OpenEMR\Core\Header;
11 require_once("../globals.php");
12 require_once("../../custom/code_types.inc.php");
14 // Format dollars for display.
16 function bucks($amount)
18 if (empty($amount)) {
19 return '';
22 return oeFormatMoney($amount);
25 $filter = $_REQUEST['filter'] + 0;
26 $where = "c.active = 1";
27 if ($filter) {
28 $where .= " AND c.code_type = '$filter'";
31 if (empty($_REQUEST['include_uncat'])) {
32 $where .= " AND c.superbill != '' AND c.superbill != '0'";
35 <html>
36 <head>
38 <?php Header::setupHeader(['datetime-picker', 'report-helper']); ?>
40 <style type="text/css">
42 /* specifically include & exclude from printing */
43 @media print {
44 #report_parameters {
45 visibility: hidden;
46 display: none;
48 #report_parameters_daterange {
49 visibility: visible;
50 display: inline;
52 #report_results table {
53 margin-top: 0px;
57 /* specifically exclude some from the screen */
58 @media screen {
59 #report_parameters_daterange {
60 visibility: hidden;
61 display: none;
65 table.mymaintable, table.mymaintable td, table.mymaintable th {
66 border: 1px solid #aaaaaa;
67 border-collapse: collapse;
69 table.mymaintable td, table.mymaintable th {
70 padding: 1pt 4pt 1pt 4pt;
72 </style>
74 <title><?php xl('Services by Category', 'e'); ?></title>
76 <script language="JavaScript">
78 $(document).ready(function() {
79 oeFixedHeaderSetup(document.getElementById('mymaintable'));
80 var win = top.printLogSetup ? top : opener.top;
81 win.printLogSetup(document.getElementById('printbutton'));
82 });
84 </script>
86 </head>
88 <body class="body_top">
90 <span class='title'><?php xl('Report', 'e'); ?> - <?php xl('Services by Category', 'e'); ?></span>
92 <form method='post' action='services_by_category.php' name='theform' id='theform'>
94 <div id="report_parameters">
96 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
98 <table>
99 <tr>
100 <td width='280px'>
101 <div style='float:left'>
103 <table class='text'>
104 <tr>
105 <td>
106 <select name='filter' class='form-control'>
107 <option value='0'><?php xl('All', 'e'); ?></option>
108 <?php
109 foreach ($code_types as $key => $value) {
110 echo "<option value='" . $value['id'] . "'";
111 if ($value['id'] == $filter) {
112 echo " selected";
115 echo ">$key</option>\n";
118 </select>
119 </td>
120 <td>
121 <div class="checkbox">
122 <label><input type='checkbox' name='include_uncat' value='1'<?php if (!empty($_REQUEST['include_uncat'])) {
123 echo " checked";
124 } ?> />
125 <?php xl('Include Uncategorized', 'e'); ?></label>
126 </div>
127 </td>
128 </tr>
129 </table>
131 </div>
133 </td>
134 <td align='left' valign='middle' height="100%">
135 <table style='border-left:1px solid; width:100%; height:100%' >
136 <tr>
137 <td>
138 <div class="text-center">
139 <div class="btn-group" role="group">
140 <a href='#' class='btn btn-default btn-save' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
141 <?php echo xlt('Submit'); ?>
142 </a>
143 <?php if ($_POST['form_refresh']) { ?>
144 <a href='#' class='btn btn-default btn-print' id='printbutton'>
145 <?php echo xlt('Print'); ?>
146 </a>
147 <?php } ?>
148 </div>
149 </div>
150 </td>
151 </tr>
152 </table>
153 </td>
154 </tr>
155 </table>
156 </div> <!-- end of parameters -->
158 <?php
159 if ($_POST['form_refresh']) {
162 <div id="report_results">
165 <table width='98%' id='mymaintable' class='mymaintable'>
166 <thead style='display:table-header-group'>
167 <tr bgcolor="#dddddd">
168 <th class='bold'><?php xl('Category', 'e'); ?></th>
169 <th class='bold'><?php xl('Type', 'e'); ?></th>
170 <th class='bold'><?php xl('Code', 'e'); ?></th>
171 <th class='bold'><?php xl('Mod', 'e'); ?></th>
172 <th class='bold'><?php xl('Units', 'e'); ?></th>
173 <th class='bold'><?php xl('Description', 'e'); ?></th>
174 <?php if (related_codes_are_used()) { ?>
175 <th class='bold'><?php xl('Related', 'e'); ?></th>
176 <?php } ?>
177 <?php
178 $pres = sqlStatement("SELECT title FROM list_options " .
179 "WHERE list_id = 'pricelevel' AND activity = 1 ORDER BY seq");
180 while ($prow = sqlFetchArray($pres)) {
181 // Added 5-09 by BM - Translate label if applicable
182 echo " <th class='bold' align='right' nowrap>" . xl_list_label($prow['title']) . "</th>\n";
185 </tr>
186 </thead>
187 <tbody>
188 <?php
189 $res = sqlStatement("SELECT c.*, lo.title FROM codes AS c " .
190 "LEFT OUTER JOIN list_options AS lo ON lo.list_id = 'superbill' " .
191 "AND lo.option_id = c.superbill AND lo.activity = 1 " .
192 "WHERE $where ORDER BY lo.title, c.code_type, c.code, c.modifier");
194 $last_category = '';
195 $irow = 0;
196 while ($row = sqlFetchArray($res)) {
197 $category = $row['title'] ? $row['title'] : 'Uncategorized';
198 $disp_category = '&nbsp';
199 if ($category !== $last_category) {
200 $last_category = $category;
201 $disp_category = $category;
202 ++$irow;
205 foreach ($code_types as $key => $value) {
206 if ($value['id'] == $row['code_type']) {
207 break;
211 $bgcolor = (($irow & 1) ? "#ffdddd" : "#ddddff");
212 echo " <tr bgcolor='$bgcolor'>\n";
213 // Added 5-09 by BM - Translate label if applicable
214 echo " <td class='text'>" . xl_list_label($disp_category) . "</td>\n";
215 echo " <td class='text'>$key</td>\n";
216 echo " <td class='text'>" . $row['code'] . "</td>\n";
217 echo " <td class='text'>" . $row['modifier'] . "</td>\n";
218 echo " <td class='text'>" . $row['units'] . "</td>\n";
219 echo " <td class='text'>" . $row['code_text'] . "</td>\n";
221 if (related_codes_are_used()) {
222 // Show related codes.
223 echo " <td class='text'>";
224 $arel = explode(';', $row['related_code']);
225 foreach ($arel as $tmp) {
226 list($reltype, $relcode) = explode(':', $tmp);
227 $reltype = $code_types[$reltype]['id'];
228 $relrow = sqlQuery("SELECT code_text FROM codes WHERE " .
229 "code_type = '$reltype' AND code = '$relcode' LIMIT 1");
230 echo $relcode . ' ' . trim($relrow['code_text']) . '<br />';
233 echo "</td>\n";
236 $pres = sqlStatement("SELECT p.pr_price " .
237 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
238 "p.pr_id = '" . $row['id'] . "' AND p.pr_selector = '' " .
239 "AND p.pr_level = lo.option_id " .
240 "WHERE lo.list_id = 'pricelevel' AND lo.activity = 1 ORDER BY lo.seq");
241 while ($prow = sqlFetchArray($pres)) {
242 echo " <td class='text' align='right'>" . bucks($prow['pr_price']) . "</td>\n";
245 echo " </tr>\n";
248 </tbody>
249 </table>
251 <?php } // end of submit logic ?>
252 </div>
254 </body>
255 </html>