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");
24 include_once("../../custom/code_types.inc.php");
26 $alertmsg = ''; // not used yet but maybe later
28 function bucks($amount) {
30 printf("%.2f", $amount);
33 if ($_POST['form_search']) {
34 $form_date = fixDate($_POST['form_date'], "");
36 // MySQL doesn't grok full outer joins so we do it the hard way.
43 "p.fname, p.lname, p.pid, " .
44 "u.lname AS docname " .
45 "FROM openemr_postcalendar_events AS e " .
46 "LEFT OUTER JOIN form_encounter AS fe " .
47 "ON LEFT(fe.date, 10) = e.pc_eventDate AND fe.pid = e.pc_pid " .
48 "LEFT OUTER JOIN forms AS f ON f.encounter = fe.encounter AND f.formdir = 'newpatient' " .
49 "LEFT OUTER JOIN patient_data AS p ON p.pid = e.pc_pid " .
50 "LEFT OUTER JOIN users AS u ON u.id = e.pc_aid " .
51 "WHERE e.pc_eventDate = '$form_date' AND " .
52 "( e.pc_catid = 5 OR e.pc_catid = 9 OR e.pc_catid = 10 ) " .
58 "p.fname, p.lname, p.pid, " .
59 "u.lname AS docname " .
60 "FROM form_encounter AS fe " .
61 "LEFT OUTER JOIN openemr_postcalendar_events AS e " .
62 "ON LEFT(fe.date, 10) = e.pc_eventDate AND fe.pid = e.pc_pid AND " .
63 "( e.pc_catid = 5 OR e.pc_catid = 9 OR e.pc_catid = 10 ) " .
64 "LEFT OUTER JOIN forms AS f ON f.encounter = fe.encounter AND f.formdir = 'newpatient' " .
65 "LEFT OUTER JOIN patient_data AS p ON p.pid = fe.pid " .
66 "LEFT OUTER JOIN users AS u ON u.username = f.user " .
67 "WHERE LEFT(fe.date, 10) = '$form_date' " .
69 "ORDER BY docname, pc_startTime";
71 $res = sqlStatement($query);
76 <link rel
=stylesheet href
="<?echo $css_header;?>" type
="text/css">
77 <title
>Appointments
and Encounters
</title
>
80 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
83 <form method
='post' action
='appt_encounter_report.php'>
85 <table border
='0' cellpadding
='5' cellspacing
='0' width
='98%'>
88 <td height
="1" colspan
="2">
92 <tr bgcolor
='#ddddff'>
94 <h2
>Appointments
and Encounters
</h2
>
98 <input type
='text' name
='form_date' size
='10' value
='<? echo $_POST['form_date
']; ?>'
99 title
='Date of appointments mm/dd/yyyy'>
101 <input type
='submit' name
='form_search' value
='Search'>
106 <td height
="1" colspan
="2">
112 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
114 <tr bgcolor
="#dddddd">
124 <td
class="dehead" align
="right">
127 <td
class="dehead" align
="right">
130 <td
class="dehead" align
="right">
133 <td
class="dehead" align
="center">
143 while ($row = sqlFetchArray($res)) {
144 $patient_id = $row['pid'];
145 $encounter = $row['encounter'];
146 $docname = $row['docname'];
152 // Scan the billing items for status and fee total.
154 $query = "SELECT code_type, authorized, billed, fee, justify " .
155 "FROM billing WHERE " .
156 "pid = '$patient_id' AND encounter = '$encounter' AND activity = 1";
157 $bres = sqlStatement($query);
159 while ($brow = sqlFetchArray($bres)) {
160 if (! $brow['billed']) $billed = "";
161 if (! $brow['authorized']) $errmsg = "Needs Auth";
162 if ($code_types[$brow['code_type']]['just']) {
163 if (! $brow['justify']) $errmsg = "Needs Justify";
165 if ($code_types[$brow['code_type']]['fee']) {
166 $charges +
= $brow['fee'];
167 if ($brow['fee'] == 0 ) $errmsg = "Missing Fee";
169 if ($brow['fee'] != 0) $errmsg = "Misplaced Fee";
172 if (! $charges) $billed = "";
174 <tr bgcolor
='<? echo $bgcolor ?>'>
176  
;<?
echo ($docname == $lastdocname) ?
"" : $docname ?
>
179  
;<?
echo substr($row['pc_startTime'], 0, 5) ?
>
182  
;<?
echo $row['fname'] . " " . $row['lname'] ?
>
184 <td
class="detail" align
="right">
185 <?
echo $row['pid'] ?
> 
;
187 <td
class="detail" align
="right">
188 <?
echo $row['encounter'] ?
> 
;
190 <td
class="detail" align
="right">
191 <?
bucks($charges) ?
> 
;
193 <td
class="detail" align
="center">
196 <td
class="detail" align
="left">
197  
;<?
echo $errmsg ?
>
201 $lastdocname = $docname;
213 echo " alert('$alertmsg');\n";