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.
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']) {
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,
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
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'
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");
86 <?php
html_header_show();?
>
88 <?php
echo htmlspecialchars(xl('Clinical Reports','e'), ENT_QUOTES
) ?
>
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);
105 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
106 <style type
="text/css">
107 /* specifically include & exclude from printing */
113 #report_parameters_daterange {
117 #report_results table {
122 /* specifically exclude some from the screen */
124 #report_parameters_daterange {
132 if($type != 'Prescription' ||
$type == '')
141 <script language
="javascript" type
="text/javascript">
142 function checkType(){
143 if($
('#type').val() == 'Prescription'){
144 $
('.optional_area').css("display", "inline");
147 $
('.optional_area').css("display", "none");
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
>
158 <?php
echo htmlspecialchars(xl('Report - Billing Services/Encounter Summary'), ENT_QUOTES
) ?
>
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)) ." to ". 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">
173 <div style
='float:left'>
178 <?php
echo htmlspecialchars(xl('Facility'), ENT_QUOTES
) ?
>:
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";
201 <?php
echo htmlspecialchars(xl('Provider'), ENT_QUOTES
) ?
>:
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";
233 <?php
echo htmlspecialchars(xl('From'), ENT_QUOTES
) ?
>:
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) ?>'>
243 <?php
echo htmlspecialchars(xl('To'), ENT_QUOTES
) ?
>:
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) ?>'>
261 <td align
='left' valign
='middle' height
="100%">
262 <table style
='border-left:1px solid; width:100%; height:100%' >
265 <div style
='margin-left:15px'>
266 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
268 <?php
echo htmlspecialchars(xl('Submit'), ENT_QUOTES
) ?
>
272 <?php
if ($_POST['form_refresh'] ||
$_POST['form_orderby'] ) { ?
>
273 <a href
='#' class='css_button' onclick
='window.print()'>
275 <?php
echo htmlspecialchars(xl('Print'), ENT_QUOTES
) ?
>
280 <?php
if ($_POST['form_refresh']) { ?
>
281 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","export"); $("#theform").submit();'>
283 <?php
echo htmlspecialchars(xl('Export'), ENT_QUOTES
) ?
>
295 </div
> <!-- end report_parameters
-->
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">
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
>
323 while($row = sqlFetchArray($result))
327 <td style
="border: none;"> <?php
echo $row['patient_name'] ?
> 
;</td
>
328 <td style
="border: none;"> <?php
echo $row['sex'] ?
> 
;</td
>
329 <td style
="border: none;"> <?php
echo $row['DOB'] ?
> 
;</td
>
330 <td style
="border: none;"> <?php
echo $row['SS'] ?
> 
;</td
>
331 <td style
="border: none;"> <?php
echo $row['DOS'] ?
> 
;</td
>
332 <td style
="border: none;"> <?php
echo $row['address'] ?
> 
;</td
>
333 <td style
="border: none;"> <?php
echo $row['insurance_company_name'] ?
> 
;</td
>
334 <td style
="border: none;"> <?php
echo $row['insurance_policy'] ?
> 
;</td
>
335 <td style
="border: none;"> <?php
echo $row['CPT4_ICD9'] ?
> 
;</td
>
336 <td style
="border: none;"> 
;</td
>
339 <td colspan
="11" valign
="top">
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
>
351 <!-- end of results
-->
359 ?
><div
class='text'> <?php
echo htmlspecialchars(xl('Please input search criteria above, and click Submit to view results.'), ENT_QUOTES
) ?
> </div
><?php
365 <!-- stuff
for the popup calendar
-->
366 <style type
="text/css">
367 @import
url(../../library
/dynarch_calendar
.css
);
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"});