2 // Copyright (C) 2007-2010 Rod Roark <rod@sunsetsystems.com>
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 // This report shows past encounters with filtering and sorting.
11 require_once("../globals.php");
12 require_once("$srcdir/forms.inc");
13 require_once("$srcdir/billing.inc");
14 require_once("$srcdir/patient.inc");
15 require_once("$srcdir/formatting.inc.php");
16 require_once "$srcdir/options.inc.php";
17 require_once "$srcdir/formdata.inc.php";
19 $alertmsg = ''; // not used yet but maybe later
21 // For each sorting option, specify the ORDER BY argument.
24 'doctor' => 'lower(u.lname), lower(u.fname), fe.date',
25 'patient' => 'lower(p.lname), lower(p.fname), fe.date',
26 'pubpid' => 'lower(p.pubpid), fe.date',
27 'time' => 'fe.date, lower(u.lname), lower(u.fname)',
30 function bucks($amount) {
31 if ($amount) printf("%.2f", $amount);
34 function show_doc_total($lastdocname, $doc_encounters) {
37 echo " <td class='detail'>$lastdocname</td>\n";
38 echo " <td class='detail' align='right'>$doc_encounters</td>\n";
43 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
44 $form_to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
45 $form_provider = $_POST['form_provider'];
46 $form_facility = $_POST['form_facility'];
47 $form_details = $_POST['form_details'] ?
true : false;
48 $form_new_patients = $_POST['form_new_patients'] ?
true : false;
50 $form_orderby = $ORDERHASH[$_REQUEST['form_orderby']] ?
51 $_REQUEST['form_orderby'] : 'doctor';
52 $orderby = $ORDERHASH[$form_orderby];
57 "fe.encounter, fe.date, fe.reason, " .
58 "f.formdir, f.form_name, " .
59 "p.fname, p.mname, p.lname, p.pid, p.pubpid, " .
60 "u.lname AS ulname, u.fname AS ufname, u.mname AS umname " .
61 "FROM ( form_encounter AS fe, forms AS f ) " .
62 "LEFT OUTER JOIN patient_data AS p ON p.pid = fe.pid " .
63 "LEFT JOIN users AS u ON u.id = fe.provider_id " .
64 "WHERE f.encounter = fe.encounter AND f.formdir = 'newpatient' ";
66 $query .= "AND fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_to_date 23:59:59' ";
68 $query .= "AND fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_from_date 23:59:59' ";
71 $query .= "AND fe.provider_id = '$form_provider' ";
74 $query .= "AND fe.facility_id = '$form_facility' ";
76 if ($form_new_patients) {
77 $query .= "AND fe.date = (SELECT MIN(fe2.date) FROM form_encounter AS fe2 WHERE fe2.pid = fe.pid) ";
79 $query .= "ORDER BY $orderby";
81 $res = sqlStatement($query);
85 <?php
html_header_show();?
>
86 <title
><?php
xl('Encounters Report','e'); ?
></title
>
88 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
90 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
91 <style type
="text/css">
93 /* specifically include & exclude from printing */
99 #report_parameters_daterange {
103 #report_results table {
108 /* specifically exclude some from the screen */
110 #report_parameters_daterange {
118 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
119 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
120 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
121 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
122 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
123 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
125 <script LANGUAGE
="JavaScript">
127 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
129 function dosort(orderby
) {
130 var f
= document
.forms
[0];
131 f
.form_orderby
.value
= orderby
;
136 function refreshme() {
137 document
.forms
[0].submit();
143 <body
class="body_top">
144 <!-- Required
for the popup date selectors
-->
145 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
147 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Encounters','e'); ?
></span
>
149 <div id
="report_parameters_daterange">
150 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
153 <form method
='post' name
='theform' id
='theform' action
='encounters_report.php'>
155 <div id
="report_parameters">
159 <div style
='float:left'>
164 <?php
xl('Facility','e'); ?
>:
167 <?php
dropdown_facility(strip_escape_custom($form_facility), 'form_facility', true); ?
>
170 <?php
xl('Provider','e'); ?
>:
175 // Build a drop-down list of providers.
178 $query = "SELECT id, lname, fname FROM users WHERE ".
179 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
181 $ures = sqlStatement($query);
183 echo " <select name='form_provider'>\n";
184 echo " <option value=''>-- " . xl('All') . " --\n";
186 while ($urow = sqlFetchArray($ures)) {
187 $provid = $urow['id'];
188 echo " <option value='$provid'";
189 if ($provid == $_POST['form_provider']) echo " selected";
190 echo ">" . $urow['lname'] . ", " . $urow['fname'] . "\n";
198 <input type
='checkbox' name
='form_new_patients' title
='First-time visits only'<?php
if ($form_new_patients) echo ' checked'; ?
>>
199 <?php
xl('New','e'); ?
>
204 <?php
xl('From','e'); ?
>:
207 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
208 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
209 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
210 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
211 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
214 <?php
xl('To','e'); ?
>:
217 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
218 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
219 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
220 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
221 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
224 <input type
='checkbox' name
='form_details'<?php
if ($form_details) echo ' checked'; ?
>>
225 <?php
xl('Details','e'); ?
>
233 <td align
='left' valign
='middle' height
="100%">
234 <table style
='border-left:1px solid; width:100%; height:100%' >
237 <div style
='margin-left:15px'>
238 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
240 <?php
xl('Submit','e'); ?
>
244 <?php
if ($_POST['form_refresh'] ||
$_POST['form_orderby'] ) { ?
>
245 <a href
='#' class='css_button' onclick
='window.print()'>
247 <?php
xl('Print','e'); ?
>
259 </div
> <!-- end report_parameters
-->
262 if ($_POST['form_refresh'] ||
$_POST['form_orderby']) {
264 <div id
="report_results">
268 <?php
if ($form_details) { ?
>
270 <a href
="nojs.php" onclick
="return dosort('doctor')"
271 <?php
if ($form_orderby == "doctor") echo " style=\"color:#00cc00\"" ?
>><?php
xl('Provider','e'); ?
> </a
>
274 <a href
="nojs.php" onclick
="return dosort('time')"
275 <?php
if ($form_orderby == "time") echo " style=\"color:#00cc00\"" ?
>><?php
xl('Date','e'); ?
></a
>
278 <a href
="nojs.php" onclick
="return dosort('patient')"
279 <?php
if ($form_orderby == "patient") echo " style=\"color:#00cc00\"" ?
>><?php
xl('Patient','e'); ?
></a
>
282 <a href
="nojs.php" onclick
="return dosort('pubpid')"
283 <?php
if ($form_orderby == "pubpid") echo " style=\"color:#00cc00\"" ?
>><?php
xl('ID','e'); ?
></a
>
286 <?php
xl('Status','e'); ?
>
289 <?php
xl('Encounter','e'); ?
>
292 <?php
xl('Form','e'); ?
>
295 <?php
xl('Coding','e'); ?
>
298 <th
><?php
xl('Provider','e'); ?
></td
>
299 <th
><?php
xl('Encounters','e'); ?
></td
>
307 while ($row = sqlFetchArray($res)) {
308 $patient_id = $row['pid'];
311 if (!empty($row['ulname']) ||
!empty($row['ufname'])) {
312 $docname = $row['ulname'];
313 if (!empty($row['ufname']) ||
!empty($row['umname']))
314 $docname .= ', ' . $row['ufname'] . ' ' . $row['umname'];
319 // Fetch all other forms for this encounter.
321 $encarr = getFormByEncounter($patient_id, $row['encounter'],
322 "formdir, user, form_name, form_id");
324 foreach ($encarr as $enc) {
325 if ($enc['formdir'] == 'newpatient') continue;
326 if ($encnames) $encnames .= '<br />';
327 $encnames .= $enc['form_name'];
331 // Fetch coding and compute billing status.
335 if ($billres = getBillingByEncounter($row['pid'], $row['encounter'],
336 "code_type, code, code_text, billed"))
338 foreach ($billres as $billrow) {
339 // $title = addslashes($billrow['code_text']);
340 if ($billrow['code_type'] != 'COPAY' && $billrow['code_type'] != 'TAX') {
341 $coded .= $billrow['code'] . ', ';
342 if ($billrow['billed']) ++
$billed_count; else ++
$unbilled_count;
345 $coded = substr($coded, 0, strlen($coded) - 2);
348 // Figure product sales into billing status.
349 $sres = sqlStatement("SELECT billed FROM drug_sales " .
350 "WHERE pid = '{$row['pid']}' AND encounter = '{$row['encounter']}'");
351 while ($srow = sqlFetchArray($sres)) {
352 if ($srow['billed']) ++
$billed_count; else ++
$unbilled_count;
355 // Compute billing status.
356 if ($billed_count && $unbilled_count) $status = xl('Mixed' );
357 else if ($billed_count ) $status = xl('Closed');
358 else if ($unbilled_count ) $status = xl('Open' );
359 else $status = xl('Empty' );
361 <tr bgcolor
='<?php echo $bgcolor ?>'>
363 <?php
echo ($docname == $lastdocname) ?
"" : $docname ?
> 
;
366 <?php
echo oeFormatShortDate(substr($row['date'], 0, 10)) ?
> 
;
369 <?php
echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']; ?
> 
;
372 <?php
echo $row['pubpid']; ?
> 
;
375 <?php
echo $status; ?
> 
;
378 <?php
echo $row['reason']; ?
> 
;
381 <?php
echo $encnames; ?
> 
;
384 <?php
echo $coded; ?
>
389 if ($docname != $lastdocname) {
390 show_doc_total($lastdocname, $doc_encounters);
395 $lastdocname = $docname;
398 if (!$form_details) show_doc_total($lastdocname, $doc_encounters);
403 </div
> <!-- end encresults
-->
406 <?php
echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?
>
410 <input type
="hidden" name
="form_orderby" value
="<?php echo $form_orderby ?>" />
411 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
416 <script language
='JavaScript'>
417 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
418 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});
420 <?php
if ($alertmsg) { echo " alert('$alertmsg');\n"; } ?
>