switch to explode since split deprecated
[openemr.git] / interface / reports / services_by_category.php
bloba796723439449c1acdc13ec6f0716fb1bb3d8bec
1 <?php
2 // Copyright (C) 2008-2010 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 require_once("../globals.php");
10 require_once("../../custom/code_types.inc.php");
11 require_once("$srcdir/sql.inc");
12 require_once("$srcdir/formatting.inc.php");
14 // Format dollars for display.
16 function bucks($amount) {
17 if (empty($amount)) return '';
18 return oeFormatMoney($amount);
21 $filter = $_REQUEST['filter'] + 0;
22 $where = "c.active = 1";
23 if ($filter) $where .= " AND c.code_type = '$filter'";
24 if (empty($_REQUEST['include_uncat']))
25 $where .= " AND c.superbill != '' AND c.superbill != '0'";
27 <html>
28 <head>
29 <?php html_header_show(); ?>
30 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
31 <style type="text/css">
33 /* specifically include & exclude from printing */
34 @media print {
35 #report_parameters {
36 visibility: hidden;
37 display: none;
39 #report_parameters_daterange {
40 visibility: visible;
41 display: inline;
43 #report_results table {
44 margin-top: 0px;
48 /* specifically exclude some from the screen */
49 @media screen {
50 #report_parameters_daterange {
51 visibility: hidden;
52 display: none;
55 </style>
56 <title><?php xl('Services by Category','e'); ?></title>
58 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
59 <script type="text/javascript" src="../../library/textformat.js"></script>
60 <script type="text/javascript" src="../../library/dialog.js"></script>
61 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
63 </head>
65 <body class="body_top">
67 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Services by Category','e'); ?></span>
69 <form method='post' action='services_by_category.php' name='theform' id='theform'>
71 <div id="report_parameters">
73 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
75 <table>
76 <tr>
77 <td width='280px'>
78 <div style='float:left'>
80 <table class='text'>
81 <tr>
82 <td>
83 <select name='filter'>
84 <option value='0'><?php xl('All','e'); ?></option>
85 <?php
86 foreach ($code_types as $key => $value) {
87 echo "<option value='" . $value['id'] . "'";
88 if ($value['id'] == $filter) echo " selected";
89 echo ">$key</option>\n";
92 </select>
93 </td>
94 <td>
95 <input type='checkbox' name='include_uncat' value='1'<?php if (!empty($_REQUEST['include_uncat'])) echo " checked"; ?> />
96 <?php xl('Include Uncategorized','e'); ?>
97 </td>
98 </tr>
99 </table>
101 </div>
103 </td>
104 <td align='left' valign='middle' height="100%">
105 <table style='border-left:1px solid; width:100%; height:100%' >
106 <tr>
107 <td>
108 <div style='margin-left:15px'>
109 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
110 <span>
111 <?php xl('Submit','e'); ?>
112 </span>
113 </a>
115 <?php if ($_POST['form_refresh']) { ?>
116 <a href='#' class='css_button' onclick='window.print()'>
117 <span>
118 <?php xl('Print','e'); ?>
119 </span>
120 </a>
121 <?php } ?>
122 </div>
123 </td>
124 </tr>
125 </table>
126 </td>
127 </tr>
128 </table>
129 </div> <!-- end of parameters -->
131 <?php
132 if ($_POST['form_refresh']) {
135 <div id="report_results">
138 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
139 <thead style='display:table-header-group'>
140 <tr bgcolor="#dddddd">
141 <th class='bold'><?php xl('Category' ,'e'); ?></th>
142 <th class='bold'><?php xl('Type' ,'e'); ?></th>
143 <th class='bold'><?php xl('Code' ,'e'); ?></th>
144 <th class='bold'><?php xl('Mod' ,'e'); ?></th>
145 <th class='bold'><?php xl('Units' ,'e'); ?></th>
146 <th class='bold'><?php xl('Description','e'); ?></th>
147 <?php if (related_codes_are_used()) { ?>
148 <th class='bold'><?php xl('Related' ,'e'); ?></th>
149 <?php } ?>
150 <?php
151 $pres = sqlStatement("SELECT title FROM list_options " .
152 "WHERE list_id = 'pricelevel' ORDER BY seq");
153 while ($prow = sqlFetchArray($pres)) {
154 // Added 5-09 by BM - Translate label if applicable
155 echo " <th class='bold' align='right' nowrap>" . xl_list_label($prow['title']) . "</th>\n";
158 </tr>
159 </thead>
160 <tbody>
161 <?php
162 $res = sqlStatement("SELECT c.*, lo.title FROM codes AS c " .
163 "LEFT OUTER JOIN list_options AS lo ON lo.list_id = 'superbill' " .
164 "AND lo.option_id = c.superbill " .
165 "WHERE $where ORDER BY lo.title, c.code_type, c.code, c.modifier");
167 $last_category = '';
168 $irow = 0;
169 while ($row = sqlFetchArray($res)) {
170 $category = $row['title'] ? $row['title'] : 'Uncategorized';
171 $disp_category = '&nbsp';
172 if ($category !== $last_category) {
173 $last_category = $category;
174 $disp_category = $category;
175 ++$irow;
177 foreach ($code_types as $key => $value) {
178 if ($value['id'] == $row['code_type']) {
179 break;
182 $bgcolor = (($irow & 1) ? "#ffdddd" : "#ddddff");
183 echo " <tr bgcolor='$bgcolor'>\n";
184 // Added 5-09 by BM - Translate label if applicable
185 echo " <td class='text'>" . xl_list_label($disp_category) . "</td>\n";
186 echo " <td class='text'>$key</td>\n";
187 echo " <td class='text'>" . $row['code'] . "</td>\n";
188 echo " <td class='text'>" . $row['modifier'] . "</td>\n";
189 echo " <td class='text'>" . $row['units'] . "</td>\n";
190 echo " <td class='text'>" . $row['code_text'] . "</td>\n";
192 if (related_codes_are_used()) {
193 // Show related codes.
194 echo " <td class='text'>";
195 $arel = explode(';', $row['related_code']);
196 foreach ($arel as $tmp) {
197 list($reltype, $relcode) = explode(':', $tmp);
198 $reltype = $code_types[$reltype]['id'];
199 $relrow = sqlQuery("SELECT code_text FROM codes WHERE " .
200 "code_type = '$reltype' AND code = '$relcode' LIMIT 1");
201 echo $relcode . ' ' . trim($relrow['code_text']) . '<br />';
203 echo "</td>\n";
206 $pres = sqlStatement("SELECT p.pr_price " .
207 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
208 "p.pr_id = '" . $row['id'] . "' AND p.pr_selector = '' " .
209 "AND p.pr_level = lo.option_id " .
210 "WHERE list_id = 'pricelevel' ORDER BY lo.seq");
211 while ($prow = sqlFetchArray($pres)) {
212 echo " <td class='text' align='right'>" . bucks($prow['pr_price']) . "</td>\n";
214 echo " </tr>\n";
217 </tbody>
218 </table>
220 <?php } // end of submit logic ?>
221 </div>
223 </body>
224 </html>