2 // Copyright (C) 2005 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 cross-references appointments with encounters.
10 // For a given date, show a line for each appointment with the
11 // matching encounter, and also for each encounter that has no
12 // matching appointment. This helps to catch these errors:
14 // * Appointments with no encounter
15 // * Encounters with no appointment
16 // * Codes not justified
17 // * Codes not authorized
18 // * Procedure codes without a fee
19 // * Fees assigned to diagnoses (instead of procedures)
20 // * Encounters not billed
22 include_once("../globals.php");
23 include_once("../../library/patient.inc");
27 function bucks($amount) {
29 printf("%.2f", $amount);
32 $today = date("Y-m-d");
34 if ($_POST['form_search']) {
35 $form_date = fixDate($_POST['form_date'], "");
39 "LEFT(e.pc_eventDate, 10), e.pc_startTime, " .
42 "p.fname, p.lname, p.pid, " .
43 "u.lname AS docname " .
44 "FROM openemr_postcalendar_events AS e " .
45 "LEFT OUTER JOIN form_encounter AS fe " .
46 "ON LEFT(fe.date, 10) = e.pc_eventDate AND fe.pid = e.pc_pid " .
47 "LEFT OUTER JOIN forms AS f ON f.encounter = fe.encounter AND f.formdir = 'newpatient' " .
48 "LEFT OUTER JOIN patient_data AS p ON p.pid = e.pc_pid " .
49 "LEFT OUTER JOIN users AS u ON u.id = e.pc_aid " .
50 "WHERE e.pc_eventDate = '$form_date' AND " .
51 "( e.pc_catid = 5 OR e.pc_catid = 9 OR e.pc_catid = 10 ) " .
54 "LEFT(fe.date, 10), e.pc_startTime, " .
57 "p.fname, p.lname, p.pid, " .
58 "u.lname AS docname " .
59 "FROM form_encounter AS fe " .
60 "LEFT OUTER JOIN openemr_postcalendar_events AS e " .
61 "ON LEFT(fe.date, 10) = e.pc_eventDate AND fe.pid = e.pc_pid AND " .
62 "( e.pc_catid = 5 OR e.pc_catid = 9 OR e.pc_catid = 10 ) " .
63 "LEFT OUTER JOIN forms AS f ON f.encounter = fe.encounter AND f.formdir = 'newpatient' " .
64 "LEFT OUTER JOIN patient_data AS p ON p.pid = fe.pid " .
65 "LEFT OUTER JOIN users AS u ON u.username = f.user " .
66 "WHERE LEFT(fe.date, 10) = '$form_date' " .
68 "ORDER BY docname, pc_startTime";
70 $res = sqlStatement($query);
75 <link rel
=stylesheet href
="<?echo $css_header;?>" type
="text/css">
76 <title
>Appointments
and Encounters
</title
>
79 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
82 <form method
='post' action
='appt_encounter_report.php'>
84 <table border
='0' cellpadding
='5' cellspacing
='0' width
='98%'>
87 <td height
="1" colspan
="2">
91 <tr bgcolor
='#ddddff'>
93 <h2
>Appointments
and Encounters
</h2
>
97 <input type
='text' name
='form_date' size
='10' value
='<? echo $_POST['form_date
']; ?>'
98 title
='Date of appointments mm/dd/yyyy'>
100 <input type
='submit' name
='form_search' value
='Search'>
105 <td height
="1" colspan
="2">
111 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
113 <tr bgcolor
="#dddddd">
123 <td
class="dehead" align
="right">
126 <td
class="dehead" align
="right">
129 <td
class="dehead" align
="right">
132 <td
class="dehead" align
="center">
141 while ($row = sqlFetchArray($res)) {
142 $patient_id = $row['pid'];
143 $encounter = $row['encounter'];
149 // Scan the billing items for status and fee total.
151 $query = "SELECT code_type, authorized, billed, fee, justify " .
152 "FROM billing WHERE " .
153 "pid = '$patient_id' AND encounter = '$encounter' AND activity = 1";
154 $bres = sqlStatement($query);
156 while ($brow = sqlFetchArray($bres)) {
157 if (! $brow['billed']) $billed = "";
158 if (! $brow['authorized']) $errmsg = "Needs Auth";
159 if ($brow['code_type'] == 'CPT4' ||
$brow['code_type'] == 'HCPCS') {
160 $charges +
= $brow['fee'];
161 if ($brow['fee'] == 0 ) $errmsg = "Missing Fee";
162 if (! $brow['justify']) $errmsg = "Needs Justify";
164 if ($brow['fee'] != 0) $errmsg = "Misplaced Fee";
167 if (! $charges) $billed = "";
169 <tr bgcolor
='<? echo $bgcolor ?>'>
171  
;<?
echo $row['docname'] ?
>
174  
;<?
echo $row['pc_startTime'] ?
>
177  
;<?
echo $row['fname'] . " " . $row['lname'] ?
>
179 <td
class="detail" align
="right">
180 <?
echo $row['pid'] ?
> 
;
182 <td
class="detail" align
="right">
183 <?
echo $row['encounter'] ?
> 
;
185 <td
class="detail" align
="right">
186 <?
bucks($charges) ?
> 
;
188 <td
class="detail" align
="center">
191 <td
class="detail" align
="left">
192  
;<?
echo $errmsg ?
>
207 echo " alert('$alertmsg');\n";