Update comments
[openemr.git] / interface / reports / billing_enc_summary.php
blob5ed452b9bdae84fb30875ab70c5e2094e02ab299
1 <?php
2 // Copyright (C) 2010 Medical Information Integration, LLC
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 //SANITIZE ALL ESCAPES
9 $sanitize_all_escapes=true;
11 //STOP FAKE REGISTER GLOBALS
12 $fake_register_globals=false;
14 require_once("../globals.php");
15 require_once("$srcdir/patient.inc");
16 require_once("$srcdir/options.inc.php");
17 require_once("../drugs/drugs.inc.php");
19 $form_facility = htmlspecialchars(isset($_POST['form_facility']) ? $_POST['form_facility'] : '', ENT_QUOTES);
20 $form_from_date = htmlspecialchars(fixDate($_POST['form_from_date'], date('Y-01-01')), ENT_QUOTES);
21 $form_to_date = htmlspecialchars(fixDate($_POST['form_to_date'] , date('Y-m-d')), ENT_QUOTES);
22 $form_provider = htmlspecialchars(trim($_POST["form_provider"]), ENT_QUOTES);
24 $sqlBindArray = array();
26 if ($_POST['form_refresh']) {
28 $sql = "SELECT
29 patient_data.id,
30 concat(patient_data.fname, ' ', patient_data.lname) AS patient_name,
31 concat(patient_data.street, ' ', patient_data.city, ' ', patient_data.state, ' ', patient_data.postal_code) AS address,
32 patient_data.sex,
33 patient_data.DOB,
34 patient_data.SS,
35 GROUP_CONCAT(DISTINCT billing.date SEPARATOR '<br>') AS DOS,
36 GROUP_CONCAT(insurance_companies.name SEPARATOR '<br>') AS insurance_company_name,
37 GROUP_CONCAT(insurance_data.policy_number SEPARATOR '<br>') AS insurance_policy,
38 GROUP_CONCAT(DISTINCT billing.code SEPARATOR ', ') AS CPT4_ICD9,
39 GROUP_CONCAT(DISTINCT form_soap.assessment SEPARATOR ', ') AS assessment,
40 GROUP_CONCAT(DISTINCT billing.encounter SEPARATOR '<br>') AS enc
41 FROM billing
42 INNER JOIN patient_data ON patient_data.id = billing.pid
43 LEFT OUTER JOIN insurance_data ON insurance_data.pid = billing.pid AND insurance_data.provider != ''
44 LEFT OUTER JOIN insurance_companies ON insurance_companies.id = insurance_data.provider
45 INNER JOIN form_soap ON form_soap.pid = billing.pid
46 INNER JOIN users ON users.id = billing.provider_id
47 INNER JOIN facility ON users.facility_id = facility.id
48 WHERE billing.code_type != 'COPAY'
49 AND billing.date >= ?
50 AND billing.date <= DATE_ADD(?, INTERVAL 1 DAY)
52 array_push($sqlBindArray, $form_from_date, $form_to_date);
54 if(strlen($form_facility) > 0){
55 $sql .= " AND facility.id = ?";
56 array_push($sqlBindArray, $form_facility);
59 //$sql .= " GROUP BY patient_data.id";
60 $sql .= " GROUP BY billing.encounter";
63 if ($_POST['form_refresh'] == "export"){
64 $result = sqlStatement($sql, $sqlBindArray);
66 $out = "First/Last Name, Sex, DOB, SS, DOS, Street/State/Zip, Insurance Company, Policy#, CPT Codes, ICD9 Codes, MD Assessment\n";
68 while($row = sqlFetchArray($result))
70 $out .= "{$row['patient_name']}, {$row['sex']}, {$row['DOB']}, {$row['SS']}, {$row['DOS']}, {$row['address']}, {$row['patient_insurance_company']}, {$row['policy_number']}, {$row['CPT4']}, {$row['ICD9']}, {$row['assessment']}\n";
73 $dt_str = date("Ymd");
75 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
76 header("Content-Length: " . strlen($out));
77 header("Content-type: text/x-csv");
78 header("Content-type: application/csv");
79 header("Content-Disposition: attachment; filename=billing_enc_summary_".$dt_str.".csv");
80 echo $out;
81 exit;
84 <html>
85 <head>
86 <?php html_header_show();?>
87 <title>
88 <?php echo htmlspecialchars(xl('Clinical Reports','e'), ENT_QUOTES) ?>
89 </title>
90 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
91 <script type="text/javascript" src="../../library/textformat.js"></script>
92 <script type="text/javascript" src="../../library/dialog.js"></script>
93 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
94 <script language="JavaScript">
96 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
98 // The OnClick handler for receipt display.
99 function show_receipt(payid) {
100 // dlgopen('../patient_file/front_payment.php?receipt=1&payid=' + payid, '_blank', 550, 400);
101 return false;
104 </script>
105 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
106 <style type="text/css">
107 /* specifically include & exclude from printing */
108 @media print {
109 #report_parameters {
110 visibility: hidden;
111 display: none;
113 #report_parameters_daterange {
114 visibility: visible;
115 display: inline;
117 #report_results table {
118 margin-top: 0px;
122 /* specifically exclude some from the screen */
123 @media screen {
124 #report_parameters_daterange {
125 visibility: hidden;
126 display: none;
130 .optional_area {
131 <?php
132 if($type != 'Prescription' || $type == '')
135 display: none;
136 <?php
140 </style>
141 <script language="javascript" type="text/javascript">
142 function checkType(){
143 if($('#type').val() == 'Prescription'){
144 $('.optional_area').css("display", "inline");
146 else{
147 $('.optional_area').css("display", "none");
150 </script>
151 </head>
153 <body class="body_top">
155 <!-- Required for the popup date selectors -->
156 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
157 <span class='title'>
158 <?php echo htmlspecialchars(xl('Report - Billing Services/Encounter Summary'), ENT_QUOTES) ?>
159 </span>
160 <!-- Search can be done using age range, gender, and ethnicity filters.
161 Search options include diagnosis, procedure, prescription, medical history, and lab results.
163 <div id="report_parameters_daterange"> <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?> </div>
165 <form method='post' name='theform' id='theform' action='<?php echo $_SERVER['REQUEST_URI'] ?>'>
167 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
169 <div id="report_parameters">
170 <table>
171 <tr>
172 <td width='550px'>
173 <div style='float:left'>
175 <table class='text'>
176 <tr>
177 <td class='label'>
178 <?php echo htmlspecialchars(xl('Facility'), ENT_QUOTES) ?>:
179 </td>
180 <td>
181 <?php
182 // Build a drop-down list of facilities.
184 $query = "SELECT id, name FROM facility ORDER BY name";
185 $fres = sqlStatement($query);
186 echo " <select name='form_facility'>\n";
187 echo " <option value=''>-- " . htmlspecialchars(xl('All Facilities'), ENT_QUOTES) . " --\n";
188 while ($frow = sqlFetchArray($fres)) {
189 $facid = $frow['id'];
190 echo " <option value='$facid'";
191 if ($facid == $form_facility) echo " selected";
192 echo ">" . htmlspecialchars($frow['name'], ENT_QUOTES) . "\n";
194 echo " <option value='0'";
195 if ($form_facility === '0') echo " selected";
196 echo ">-- " . htmlspecialchars(xl('Unspecified'), ENT_QUOTES) . " --\n";
197 echo " </select>\n";
199 </td>
200 <td class='label'>
201 <?php echo htmlspecialchars(xl('Provider'), ENT_QUOTES) ?>:
202 </td>
203 <td>
204 <?php
206 // Build a drop-down list of providers.
209 $query = "SELECT id, lname, fname FROM users WHERE ".
210 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
212 $ures = sqlStatement($query);
214 echo " <select name='form_provider'>\n";
215 echo " <option value=''>-- " . htmlspecialchars(xl('All'), ENT_QUOTES) . " --\n";
217 while ($urow = sqlFetchArray($ures)) {
218 $provid = htmlspecialchars($urow['id'], ENT_QUOTES);
219 echo " <option value='$provid'";
220 if ($provid == $_POST['form_provider']) echo " selected";
221 echo ">" . htmlspecialchars($urow['lname'] . ", " . $urow['fname'], ENT_QUOTES) . "\n";
224 echo " </select>\n";
227 </td>
228 <td>&nbsp;
229 </td>
230 </tr>
231 <tr>
232 <td class='label'>
233 <?php echo htmlspecialchars(xl('From'), ENT_QUOTES) ?>:
234 </td>
235 <td>
236 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
237 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
238 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
239 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
240 title='<?php echo htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES) ?>'>
241 </td>
242 <td class='label'>
243 <?php echo htmlspecialchars(xl('To'), ENT_QUOTES) ?>:
244 </td>
245 <td>
246 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
247 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
248 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
249 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
250 title='<?php echo htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES) ?>'>
251 </td>
252 <td>
254 </td>
255 </tr>
256 </table>
258 </div>
260 </td>
261 <td align='left' valign='middle' height="100%">
262 <table style='border-left:1px solid; width:100%; height:100%' >
263 <tr>
264 <td>
265 <div style='margin-left:15px'>
266 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
267 <span>
268 <?php echo htmlspecialchars(xl('Submit'), ENT_QUOTES) ?>
269 </span>
270 </a>
272 <?php if ($_POST['form_refresh'] || $_POST['form_orderby'] ) { ?>
273 <a href='#' class='css_button' onclick='window.print()'>
274 <span>
275 <?php echo htmlspecialchars(xl('Print'), ENT_QUOTES) ?>
276 </span>
277 </a>
278 <?php } ?>
280 <?php if ($_POST['form_refresh']) { ?>
281 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","export"); $("#theform").submit();'>
282 <span>
283 <?php echo htmlspecialchars(xl('Export'), ENT_QUOTES) ?>
284 </span>
285 </a>
286 <?php } ?>
287 </div>
288 </td>
289 </tr>
290 </table>
291 </td>
292 </tr>
293 </table>
295 </div> <!-- end report_parameters -->
297 <?php
299 // SQL scripts for the various searches
300 if ($_POST['form_refresh'])
302 $result = sqlStatement($sql, $sqlBindArray);
304 if(sqlNumRows($result) > 0)
307 <div id="report_results">
308 <table>
309 <thead>
310 <th><?php echo htmlspecialchars(xl('First/Last Name'), ENT_QUOTES) ?></th>
311 <th> <?php echo htmlspecialchars(xl('Sex'), ENT_QUOTES) ?></th>
312 <th> <?php echo htmlspecialchars(xl('DOB'), ENT_QUOTES) ?></th>
313 <th> <?php echo htmlspecialchars(xl('SS'), ENT_QUOTES) ?></th>
314 <th> <?php echo htmlspecialchars(xl('DOS'), ENT_QUOTES) ?></th>
315 <th> <?php echo htmlspecialchars(xl('Street/State/Zip'), ENT_QUOTES) ?></th>
316 <th> <?php echo htmlspecialchars(xl('Insurance Company'), ENT_QUOTES) ?></th>
317 <th> <?php echo htmlspecialchars(xl('Policy#'), ENT_QUOTES) ?></th>
318 <th> <?php echo htmlspecialchars(xl('CPT4/ICD9 Codes'), ENT_QUOTES) ?></th>
319 <th>&nbsp;</th>
320 </thead>
321 <tbody>
322 <?php
323 while($row = sqlFetchArray($result))
326 <tr>
327 <td style="border: none;"> <?php echo $row['patient_name'] ?>&nbsp;</td>
328 <td style="border: none;"> <?php echo $row['sex'] ?>&nbsp;</td>
329 <td style="border: none;"> <?php echo $row['DOB'] ?>&nbsp;</td>
330 <td style="border: none;"> <?php echo $row['SS'] ?>&nbsp;</td>
331 <td style="border: none;"> <?php echo $row['DOS'] ?>&nbsp;</td>
332 <td style="border: none;"> <?php echo $row['address'] ?>&nbsp;</td>
333 <td style="border: none;"> <?php echo $row['insurance_company_name'] ?>&nbsp;</td>
334 <td style="border: none;"> <?php echo $row['insurance_policy'] ?>&nbsp;</td>
335 <td style="border: none;"> <?php echo $row['CPT4_ICD9'] ?>&nbsp;</td>
336 <td style="border: none;">&nbsp;</td>
337 </tr>
338 <tr>
339 <td colspan="11" valign="top">
340 <form>
341 <strong><?php echo htmlspecialchars(xl('MD Assessment'), ENT_QUOTES) ?>:</strong><br> <textarea name="" cols="100" rows="3" readonly="readonly"><?php echo $row['assessment']?></textarea>
342 </form>
343 </td>
344 </tr>
345 <?php
348 </tbody>
349 </table>
350 </div>
351 <!-- end of results -->
352 <?php
355 <?php
357 else
359 ?><div class='text'> <?php echo htmlspecialchars(xl('Please input search criteria above, and click Submit to view results.'), ENT_QUOTES) ?> </div><?php
362 </form>
363 </body>
365 <!-- stuff for the popup calendar -->
366 <style type="text/css">
367 @import url(../../library/dynarch_calendar.css);
368 </style>
369 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
370 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
371 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
372 <script language="Javascript">
373 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
374 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
375 </script>
376 </html>