2 // Copyright (C) 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 $report_by = htmlspecialchars($_POST['report_by'], ENT_QUOTES
);
20 $facility_id = htmlspecialchars($_POST['form_facility'], ENT_QUOTES
);
21 $provider_id = htmlspecialchars($_POST['form_provider'], ENT_QUOTES
);
22 $txtSearch = htmlspecialchars($_POST['txtSearch'], ENT_QUOTES
);
24 //billing.date = date of services
25 $sqlBindArray = array();
27 if ($_POST['form_refresh'])
30 concat(patient_data.fname, ' ', patient_data.lname) AS patient_name,
31 patient_data.pid AS pid,
35 patient_data.city as county";
37 if($report_by == 'ICD9' ||
$report_by == 'CPT4')
40 form_encounter.encounter AS encounter_id,
41 form_encounter.date AS date_of_visit ";
42 $sql .= ", codes.code AS code, codes.code_text AS code_text,
43 concat(users.lname, ', ', users.fname) AS provider,
44 concat(users.fname, ' ', users.lname) AS provider2 FROM form_encounter
45 INNER JOIN patient_data ON patient_data.pid = form_encounter.pid
46 INNER JOIN billing ON billing.encounter = form_encounter.encounter
47 LEFT OUTER JOIN codes ON codes.code = billing.code
48 LEFT OUTER JOIN users ON users.id = billing.provider_id
49 LEFT OUTER JOIN facility ON facility.id = users.facility_id ";
53 if($report_by == 'ICD9')
55 $where_str = " WHERE billing.code_type = 'ICD9'";
57 else if($report_by == 'CPT4')
59 $where_str = " WHERE billing.code_type = 'CPT4'";
62 if(strlen($txtSearch) > 0)
64 $where_str .= " AND codes.code LIKE ?";
65 array_push($sqlBindArray, "%".$txtSearch."%");
68 if(strlen($facility_id) > 0)
70 $where_str .= " AND facility.id = ?";
71 array_push($sqlBindArray, $facility_id);
74 if(strlen($provider_id) > 0)
76 $where_str .= " AND users.id = ?";
77 array_push($sqlBindArray, $provider_id);
82 else if($report_by == 'Drugs')
84 $sql .= ", prescriptions.date_added AS date_of_visit,
85 prescriptions.drug AS drug,
86 concat(users.lname, ', ', users.fname) AS provider,
87 concat(users.fname, ' ', users.lname) AS provider2
89 INNER JOIN patient_data ON patient_data.pid = prescriptions.patient_id
90 LEFT OUTER JOIN users ON users.id = prescriptions.provider_id
91 LEFT OUTER JOIN facility ON facility.id = users.facility_id";
95 if(strlen($txtSearch) > 0)
97 $where_str = " WHERE prescriptions.drug LIKE ?";
98 array_push($sqlBindArray, "%".$txtSearch."%");
101 if(strlen($facility_id) > 0)
103 if(strlen($where_str) > 0)
105 $where_str .= " AND facility.id = ?";
106 array_push($sqlBindArray, $facility_id);
110 $where_str = " WHERE facility.id = ?";
111 array_push($sqlBindArray, $facility_id);
115 if(strlen($provider_id) > 0)
117 if(strlen($where_str) > 0)
119 $where_str .= " AND users.id = ?";
120 array_push($sqlBindArray, $provider_id);
124 $where_str = " WHERE users.id = ?";
125 array_push($sqlBindArray, $provider_id);
131 else if($report_by == 'Referral')
134 concat(patient_data.fname, ' ', patient_data.lname) AS patient_name,
135 patient_data.pid AS pid,
139 patient_data.city as county,
140 transactions.refer_related_code AS code,
141 concat(users.lname, ', ', users.fname) AS provider,
142 concat(users.fname, ' ', users.lname) AS provider2,
143 transactions.date AS date_of_visit
145 INNER JOIN patient_data ON transactions.pid = patient_data.pid
146 INNER JOIN users ON transactions.user = users.username
147 LEFT OUTER JOIN facility ON facility.id = users.facility_id
148 WHERE transactions.title = 'Referral'";
150 if(strlen($facility_id) > 0)
152 $sql .= " AND facility.id = ?";
153 array_push($sqlBindArray, $facility_id);
156 if(strlen($provider_id) > 0)
158 $sql .= " AND users.id = ?";
159 array_push($sqlBindArray, $provider_id);
164 if ($_POST['form_refresh'] == "export")
166 $result = sqlStatement($sql, $sqlBindArray);
168 if($report_by == 'ICD9' ||
$report_by == 'CPT4')
170 $out = "Code, ICD9/CPT4 Description, Patient Name, Date of Birth, Patient ID, Encounter ID, Date of Visit, Provider\n";
172 else if($report_by == 'Drugs')
174 $out = "Drugs, Patient Name, Date of Birth, Patient ID, Date of Visit, Provider\n";
176 else if($report_by == 'Referral')
178 $out = "Code, ICD9/CPT4 Description, Patient Name, Date of Birth, Patient ID, Date of Visit, Provider\n";
181 while($row = sqlFetchArray($result))
183 if($report_by == 'Referral')
185 $current_code = $row['code'];
188 if(strlen($current_code) > 0)
190 $current_code_arr = explode(":", $current_code);
191 $result_search = sqlStatement("SELECT * FROM codes WHERE code = ?", array($current_code_arr[1]));
193 if(sqlNumRows($result_search) > 0)
195 $row_search = sqlFetchArray($result_search);
196 $code_desc = $row_search['code_text'];
201 if($report_by == 'ICD9' ||
$report_by == 'CPT4')
203 $out .= "{$row['code']}, {$row['code_text']}, {$row['patient_name']}, {$row['DOB']}, {$row['pid']}, {$row['encounter_id']}, {$row['date_of_visit']}, {$row['provider2']}\n";
205 else if($report_by == 'Drugs')
207 $out .= "{$row['drug']}, {$row['patient_name']}, {$row['DOB']}, {$row['pid']}, {$row['date_of_visit']}, {$row['provider2']}\n";
209 else if($report_by == 'Referral')
211 $out .= "{$row['code']}, {$code_desc}, {$row['patient_name']}, {$row['DOB']}, {$row['pid']}, {$row['date_of_visit']}, {$row['provider2']}\n";
215 $dt_str = date("Ymd");
217 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
218 header("Content-Length: " . strlen($out));
219 header("Content-type: text/x-csv");
220 header("Content-type: application/csv");
221 header("Content-Disposition: attachment; filename=patient_research_".$dt_str.".csv");
228 <?php
html_header_show();?
>
230 <?php
echo htmlspecialchars(xl('Clinical Reports'), ENT_QUOTES
) ?
>
232 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
233 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
234 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
235 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
236 <script language
="JavaScript">
238 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
240 // The OnClick handler for receipt display.
241 function show_receipt(payid
) {
242 // dlgopen('../patient_file/front_payment.php?receipt=1&payid=' + payid, '_blank', 550, 400);
247 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
248 <style type
="text/css">
249 /* specifically include & exclude from printing */
255 #report_parameters_daterange {
259 #report_results table {
264 /* specifically exclude some from the screen */
266 #report_parameters_daterange {
274 if($report_by == 'Referral')
283 <script language
="javascript" type
="text/javascript">
284 function checkType() {
285 if($
('#report_by').val() == 'Referral') {
286 $
('.optional_area').css("display", "none");
289 $
('.optional_area').css("display", "inline");
295 <body
class="body_top">
297 <!-- Required
for the popup date selectors
-->
298 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
300 <?php
echo htmlspecialchars(xl('Report - Facility/Prov Patient Research Reports'), ENT_QUOTES
) ?
>
302 <!-- Search can be done using age range
, gender
, and ethnicity filters
.
303 Search options
include diagnosis
, procedure
, prescription
, medical history
, and lab results
.
305 <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
>
307 <form method
='post' name
='theform' id
='theform' action
='<?php echo $_SERVER['REQUEST_URI
'] ?>'>
308 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
310 <div id
="report_parameters">
314 <div style
='float:left'>
319 <?php
echo htmlspecialchars(xl('Facility'), ENT_QUOTES
) ?
>:
323 // Build a drop-down list of facilities.
325 $query = "SELECT id, name FROM facility ORDER BY name";
326 $fres = sqlStatement($query);
327 echo " <select name='form_facility'>\n";
328 echo " <option value=''>-- " . htmlspecialchars(xl('All Facilities'), ENT_QUOTES
) . " --\n";
329 while ($frow = sqlFetchArray($fres)) {
330 $facid = $frow['id'];
331 echo " <option value='$facid'";
332 if ($facid == $facility_id) echo " selected";
333 echo ">" . htmlspecialchars($frow['name'], ENT_QUOTES
) . "\n";
335 echo " <option value='0'";
336 if ($form_facility === '0') echo " selected";
337 echo ">-- " . htmlspecialchars(xl('Unspecified'), ENT_QUOTES
) . " --\n";
342 <?php
echo htmlspecialchars(xl('Provider'), ENT_QUOTES
) ?
>:
347 // Build a drop-down list of providers.
350 $query = "SELECT id, lname, fname FROM users WHERE ".
351 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
353 $ures = sqlStatement($query);
355 echo " <select name='form_provider'>\n";
356 echo " <option value=''>-- " . htmlspecialchars(xl('All'), ENT_QUOTES
) . " --\n";
358 while ($urow = sqlFetchArray($ures)) {
359 $provid = htmlspecialchars($urow['id'], ENT_QUOTES
);
360 echo " <option value='$provid'";
361 if ($provid == $_POST['form_provider']) echo " selected";
362 echo ">" . htmlspecialchars($urow['lname'] . ", " . $urow['fname'], ENT_QUOTES
) . "\n";
374 <?php
echo htmlspecialchars(xl('Search'), ENT_QUOTES
) ?
>:
377 <select name
="report_by" id
="report_by" onChange
="checkType();">
378 <option value
="ICD9" <?php
echo ($report_by == 'ICD9') ?
"selected='selected'" : ''; ?
>><?php
echo htmlspecialchars(xl('ICD9'), ENT_QUOTES
) ?
></option
>
379 <option value
="CPT4" <?php
echo ($report_by == 'CPT4') ?
"selected='selected'" : ''; ?
>><?php
echo htmlspecialchars(xl('CPT4'), ENT_QUOTES
) ?
></option
>
380 <option value
="Drugs" <?php
echo ($report_by == 'Drugs') ?
"selected='selected'" : ''; ?
>><?php
echo htmlspecialchars(xl('Drugs'), ENT_QUOTES
) ?
></option
>
381 <option value
="Referral" <?php
echo ($report_by == 'Referral') ?
"selected='selected'" : ''; ?
>><?php
echo htmlspecialchars(xl('Referral'), ENT_QUOTES
) ?
></option
>
383 <label
for="txtSearch"></label
>
384 <input type
="text" name
="txtSearch" id
="txtSearch" value
="<?php echo $txtSearch?>" class="optional_area"> 
;</td
>
400 <td align
='left' valign
='middle' height
="100%">
401 <table style
='border-left:1px solid; width:100%; height:100%' >
404 <div style
='margin-left:15px'>
405 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
407 <?php
echo htmlspecialchars(xl('Submit'), ENT_QUOTES
) ?
>
411 <?php
if ($_POST['form_refresh'] ||
$_POST['form_orderby'] ) { ?
>
412 <a href
='#' class='css_button' onclick
='window.print()'>
414 <?php
echo htmlspecialchars(xl('Print'), ENT_QUOTES
) ?
>
419 <?php
if ($_POST['form_refresh']) { ?
>
420 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","export"); $("#theform").submit();'>
422 <?php
echo htmlspecialchars(xl('Export'), ENT_QUOTES
) ?
>
434 </div
> <!-- end report_parameters
-->
438 // SQL scripts for the various searches
440 if ($_POST['form_refresh']) {
441 $result = sqlStatement($sql, $sqlBindArray);
443 if(sqlNumRows($result) > 0){
445 <div id
="report_results">
449 if($report_by == 'ICD9' ||
$report_by == 'CPT4'){
451 <th
><?php
echo htmlspecialchars(xl('Code'), ENT_QUOTES
) ?
></th
>
452 <th
><?php
echo htmlspecialchars(xl('ICD9/CPT4 Description'), ENT_QUOTES
) ?
></th
>
455 else if($report_by == 'Drugs'){
457 <th
><?php
echo htmlspecialchars(xl('Drugs'), ENT_QUOTES
) ?
></th
>
460 else if($report_by == 'Referral'){
462 <th
><?php
echo htmlspecialchars(xl('Code'), ENT_QUOTES
); ?
></th
>
463 <th
><?php
echo htmlspecialchars(xl('ICD9/CPT4 Description'), ENT_QUOTES
) ?
></th
>
467 <th
> <?php
echo htmlspecialchars(xl('Patient Name'), ENT_QUOTES
) ?
></th
>
468 <th
> <?php
echo htmlspecialchars(xl('Date of Birth'), ENT_QUOTES
) ?
></th
>
469 <th
> <?php
echo htmlspecialchars(xl('Patient ID'), ENT_QUOTES
) ?
></th
>
472 if($report_by != 'Referral' && $report_by != 'Drugs' ){
474 <th
> <?php
echo htmlspecialchars(xl('Encounter ID'), ENT_QUOTES
) ?
></th
>
480 <th
> <?php
echo htmlspecialchars(xl('Date of Visit'), ENT_QUOTES
) ?
></th
>
481 <th
> <?php
echo htmlspecialchars(xl('Provider'), ENT_QUOTES
) ?
></th
>
485 while($row = sqlFetchArray($result)){
486 if($report_by == 'Referral'){
487 $current_code = $row['code'];
490 if(strlen($current_code) > 0){
491 $current_code_arr = explode(":", $current_code);
492 $result_search = sqlStatement("SELECT * FROM codes WHERE code = '".$current_code_arr[1]."'");
494 if(sqlNumRows($result_search) > 0){
495 $row_search = sqlFetchArray($result_search);
496 $code_desc = $row_search['code_text'];
503 if($report_by == 'ICD9' ||
$report_by == 'CPT4'){
505 <td
> <?php
echo htmlspecialchars($row['code'], ENT_QUOTES
); ?
> 
;</td
>
506 <td
> <?php
echo htmlspecialchars($row['code_text'], ENT_QUOTES
); ?
> 
;</td
>
509 else if($report_by == 'Drugs'){
511 <td width
="200"> <?php
echo htmlspecialchars($row['drug'], ENT_QUOTES
) ?
> 
;</td
>
514 else if($report_by == 'Referral'){
516 <td
> <?php
echo htmlspecialchars($row['code'], ENT_QUOTES
); ?
> 
;</td
>
517 <td
> <?php
echo htmlspecialchars($code_desc, ENT_QUOTES
); ?
> 
;</td
>
521 <td
> <a target
="RBot" href
="../patient_file/summary/demographics2.php?pid=<?php echo htmlspecialchars($row['pid'], ENT_QUOTES); ?>"><?php
echo htmlspecialchars($row['patient_name'], ENT_QUOTES
); ?
></a
> 
;</td
>
522 <td
> <?php
echo htmlspecialchars($row['DOB'], ENT_QUOTES
); ?
> 
;</td
>
523 <td
> <?php
echo htmlspecialchars($row['pid'], ENT_QUOTES
); ?
> 
;</td
>
526 if($report_by != 'Referral' && $report_by != 'Drugs' ){
528 <td
> <a target
="RBot" href
="../patient_file/encounter/encounter_top.php?set_encounter=<?php echo htmlspecialchars($row['encounter_id'], ENT_QUOTES); ?>&pid=<?php echo htmlspecialchars($row['pid'], ENT_QUOTES); ?>"><?php
echo htmlspecialchars($row['encounter_id'], ENT_QUOTES
); ?
></a
> 
;</td
>
534 <td
> <?php
echo htmlspecialchars($row['date_of_visit'], ENT_QUOTES
); ?
> 
;</td
>
535 <td
> <?php
echo htmlspecialchars($row['provider'], ENT_QUOTES
); ?
> 
;</td
>
543 <!-- end of results
-->
551 ?
><div
class='text'> <?php
echo htmlspecialchars(xl('Please input search criteria above, and click Submit to view results.'), ENT_QUOTES
) ?
> </div
><?php