fixed bug with closed notes appearing in (View All)
[openemr.git] / interface / main / authorizations / authorizations.php
blob671c170f816aefc7aa89e73d02951e8d4a6ec020
1 <?php
2 include_once("../../globals.php");
3 include_once("$srcdir/log.inc");
4 include_once("$srcdir/billing.inc");
5 include_once("$srcdir/forms.inc");
6 include_once("$srcdir/pnotes.inc");
7 include_once("$srcdir/transactions.inc");
8 include_once("$srcdir/lists.inc");
9 include_once("$srcdir/patient.inc");
10 include_once("$srcdir/options.inc.php");
12 //the number of authorizations to display in the quick view:
13 // MAR 20041008 the full authorizations screen sucks... no links to the patient charts
14 // increase to a high number to make the mini frame more useful.
15 $N = 50;
17 $atemp = sqlQuery("SELECT see_auth FROM users WHERE username = '" .
18 $_SESSION['authUser'] . "'");
19 $see_auth = $atemp['see_auth'];
21 $imauthorized = $_SESSION['userauthorized'] || $see_auth > 2;
23 // This authorizes everything for the specified patient.
24 if (isset($_GET["mode"]) && $_GET["mode"] == "authorize" && $imauthorized) {
25 $retVal = getProviderId($_SESSION['authUser']);
26 newEvent("authorize", $_SESSION["authUser"], $_SESSION["authProvider"], $_GET["pid"]);
27 // sqlStatement("update billing set authorized=1, provider_id = '" .
28 // mysql_real_escape_string($retVal[0]['id']) .
29 // "' where pid='" . $_GET["pid"] . "'");
30 sqlStatement("update billing set authorized=1 where pid='" . $_GET["pid"] . "'");
31 sqlStatement("update forms set authorized=1 where pid='" . $_GET["pid"] . "'");
32 sqlStatement("update pnotes set authorized=1 where pid='" . $_GET["pid"] . "'");
33 sqlStatement("update transactions set authorized=1 where pid='" . $_GET["pid"] . "'");
36 <html>
37 <head>
38 <?php html_header_show();?>
39 <link rel='stylesheet' href="<?php echo $css_header;?>" type="text/css">
40 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.2.2.min.js"></script>
41 <style>
42 /* min & max buttons are hidden in the newer concurrent layout */
43 #min {
44 float: right;
45 padding: 3px;
46 margin: 2px;
47 cursor: pointer; cursor: hand;
48 <?php if ($GLOBALS['concurrent_layout']) echo "display: none;"; ?>
50 #max {
51 float: right;
52 padding: 3px;
53 margin: 2px;
54 cursor: pointer; cursor: hand;
55 <?php if ($GLOBALS['concurrent_layout']) echo "display: none;"; ?>
57 </style>
58 </head>
59 <body class="body_bottom">
61 <!-- 'buttons' to min/max the bottom frame -JRM -->
62 <div id="max" title="Restore this information">
63 <img src="<?php echo $GLOBALS['webroot']; ?>/images/max.gif">
64 </div>
65 <div id="min" title="Minimize this information">
66 <img src="<?php echo $GLOBALS['webroot']; ?>/images/min.gif">
67 </div>
69 <?php
70 $_GET['show_all']=='yes' ? $lnkvar="'authorizations.php?show_all=no' name='Just Mine'> (".xl('Just Mine').") " : $lnkvar="'authorizations.php?show_all=yes' name='See All'>(".xl('See All').")";
73 <span class='title'><?php xl('Patient Notes','e')?> </span>
74 <a class='more' href=<?php echo $lnkvar; ?></a>
76 <?php if ($imauthorized) { ?>
77 <span class='title'><?php xl('and ','e')?>
78 <?php if ($GLOBALS['concurrent_layout']) { ?>
79 <a href='authorizations_full.php'>
80 <?php } else { ?>
81 <a href='authorizations_full.php' target='Main'>
82 <?php } ?>
83 <?php xl('Authorizations','e')?> <span class='more'><?php echo $tmore;?></span></a>
84 <?php
87 </span>
89 <?php if (!$GLOBALS['concurrent_layout']) { ?>
90 <span class='more'> &nbsp;
91 <a href="#" id="findpatients" name='Find Patients'>(<?php xl('Find Patient','e')?>)</a>
92 </span>
93 <?php } ?>
95 <div id="pnotes">
96 <?php
97 // Retrieve all active notes addressed to me (or to anybody)
98 $_GET['show_all']=='yes' ? $usrvar='_%' : $usrvar=$_SESSION['authUser'] ;
99 if ($result=getPnotesByDate("", 1, "id,date,body,pid,user,title,assigned_to", '%', "all", 0, $usrvar))
101 echo "<table border='0'>\n";
102 echo " <tr>\n";
103 echo " <td class='bold' nowrap>".xl('Patient')." &nbsp;</td>\n";
104 echo " <td class='bold' nowrap>".xl('Note Type')." &nbsp;</td>\n";
105 echo " <td class='bold' nowrap>".xl('Timestamp and Text')."</td>\n";
106 echo " </tr>\n";
108 foreach ($result as $iter) {
109 $body = $iter['body'];
110 if (preg_match('/^\d\d\d\d-\d\d-\d\d \d\d\:\d\d /', $body)) {
111 $body = nl2br($body);
112 } else {
113 $body = date('Y-m-d H:i', strtotime($iter['date'])) .
114 ' (' . $iter['user'] . ') ' . nl2br($body);
117 echo " <tr class='noterow' id='".$iter['pid']."~".$iter['id']."'>\n";
118 echo " <td valign='top' class='text'>\n";
119 echo getPatientName($iter['pid']) . "\n";
120 echo " </td>\n";
121 echo " <td valign='top'>\n";
123 if ($GLOBALS['concurrent_layout']) {
124 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
125 echo " <a href='../../patient_file/summary/pnotes_full.php" .
126 "?set_pid=" . $iter['pid'] . "&noteid=" . $iter['id'] .
127 "&active=1' class='link_submit'>" .
128 generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $iter['title']) .
129 "</a>\n";
130 } else {
131 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
132 echo " <a href='../../patient_file/patient_file.php" .
133 "?set_pid=" . $iter['pid'] . "&noteid=" . $iter['id'] .
134 "' target='_top' class='link_submit'>" .
135 generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $iter['title']) .
136 "</a>\n";
139 echo " </td>\n";
140 echo " <td valign='top' class='text'>\n";
141 echo " $body\n";
142 echo " </td>\n";
143 echo " </tr>\n";
146 echo "</table>\n";
149 </div> <!-- end of pnotes -->
151 <?php
152 if ($imauthorized && $see_auth > 1) {
154 // provider
155 // billing
156 // forms
157 // pnotes
158 // transactions
160 //fetch billing information:
161 if ($res = sqlStatement("select *, concat(u.fname,' ', u.lname) as user " .
162 "from billing LEFT JOIN users as u on billing.user = u.id where " .
163 "billing.authorized = 0 and billing.activity = 1 and " .
164 "groupname = '$groupname'"))
166 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
167 $result1[$iter] = $row;
168 if ($result1) {
169 foreach ($result1 as $iter) {
170 $authorize{$iter{"pid"}}{"billing"} .= "<span class=text>" .
171 $iter{"code_text"} . " " . date("n/j/Y",strtotime($iter{"date"})) .
172 "</span><br>\n";
174 //$authorize[$iter{"pid"}]{"billing"} = substr($authorize[$iter{"pid"}]{"billing"},0,strlen($authorize[$iter{"pid"}]{"billing"}));
178 //fetch transaction information:
179 if ($res = sqlStatement("select * from transactions where " .
180 "authorized = 0 and groupname = '$groupname'"))
182 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
183 $result2[$iter] = $row;
184 if ($result2) {
185 foreach ($result2 as $iter) {
186 $authorize{$iter{"pid"}}{"transaction"} .= "<span class=text>" .
187 $iter{"title"} . ": " . stripslashes(strterm($iter{"body"},25)) .
188 " " . date("n/j/Y",strtotime($iter{"date"})) . "</span><br>\n";
190 //$authorize[$iter{"pid"}]{"transaction"} = substr($authorize[$iter{"pid"}]{"transaction"},0,strlen($authorize[$iter{"pid"}]{"transaction"}));
194 if (empty($GLOBALS['ignore_pnotes_authorization'])) {
195 //fetch pnotes information:
196 if ($res = sqlStatement("select * from pnotes where authorized = 0 and " .
197 "groupname = '$groupname'"))
199 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
200 $result3[$iter] = $row;
201 if ($result3) {
202 foreach ($result3 as $iter) {
203 $authorize{$iter{"pid"}}{"pnotes"} .= "<span class=text>" .
204 stripslashes(strterm($iter{"body"},25)) . " " .
205 date("n/j/Y",strtotime($iter{"date"})) . "</span><br>\n";
207 //$authorize[$iter{"pid"}]{"pnotes"} = substr($authorize[$iter{"pid"}]{"pnotes"},0,strlen($authorize[$iter{"pid"}]{"pnotes"}));
212 //fetch forms information:
213 if ($res = sqlStatement("select * from forms where authorized = 0 and " .
214 "groupname = '$groupname'"))
216 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
217 $result4[$iter] = $row;
218 if ($result4) {
219 foreach ($result4 as $iter) {
220 $authorize{$iter{"pid"}}{"forms"} .= "<span class=text>" .
221 $iter{"form_name"} . " " . date("n/j/Y",strtotime($iter{"date"})) .
222 "</span><br>\n";
224 //$authorize[$iter{"pid"}]{"forms"} = substr($authorize[$iter{"pid"}]{"forms"},0,strlen($authorize[$iter{"pid"}]{"forms"}));
227 // echo "HERE"; // what the heck was this for?
230 <table border='0' cellpadding='0' cellspacing='2' width='100%'>
231 <tr>
232 <td valign='top'>
234 <?php
235 if ($authorize) {
236 $count = 0;
238 while (list($ppid,$patient) = each($authorize)) {
239 $name = getPatientData($ppid);
241 // If I want to see mine only and this patient is not mine, skip it.
242 if ($see_auth == 2 && $_SESSION['authUserID'] != $name['id'])
243 continue;
245 if ($count >= $N) {
246 print "<tr><td colspan='5' align='center'><a" .
247 ($GLOBALS['concurrent_layout'] ? "" : " target='Main'") .
248 " href='authorizations_full.php?active=1' class='alert'>" .
249 xl('Some authorizations were not displayed. Click here to view all') .
250 "</a></td></tr>\n";
251 break;
254 echo "<tr><td valign='top'>";
255 if ($GLOBALS['concurrent_layout']) {
256 // Clicking the patient name will load both frames for that patient,
257 // as demographics.php takes care of loading the bottom frame.
258 // larry :: dbc change here
259 if( $GLOBALS['dutchpc'] )
261 echo "<a href='$rootdir/patient_file/summary/demographics_dutch.php?set_pid=$ppid' " .
262 "target='RTop'>";
263 } else
265 echo "<a href='$rootdir/patient_file/summary/demographics.php?set_pid=$ppid' " .
266 "target='RTop'>";
268 // larry :: end of dbc change
270 } else {
271 echo "<a href='$rootdir/patient_file/patient_file.php?set_pid=$ppid' " .
272 "target='_top'>";
274 echo "<span class='bold'>" . $name{"fname"} . " " .
275 $name{"lname"} . "</span></a><br>" .
276 "<a class=link_submit href='authorizations.php?mode=authorize" .
277 "&pid=$ppid'>" . xl('Authorize') . "</a></td>\n";
279 /****
280 //Michael A Rowley MD 20041012.
281 // added below 4 lines to add provider to authorizations for ez reference.
282 $providerID = sqlFetchArray(sqlStatement(
283 "select providerID from patient_data where pid=$ppid"));
284 $userID=$providerID{"providerID"};
285 $providerName = sqlFetchArray(sqlStatement(
286 "select lname from users where id=$userID"));
287 ****/
288 // Don't use sqlQuery because there might be no match.
289 $providerName = sqlFetchArray(sqlStatement(
290 "select lname from users where id = '" . $name['providerID'] . "'"));
291 /****/
293 echo "<td valign=top><span class=bold>".xl('Provider').":</span><span class=text><br>" .
294 $providerName{"lname"} . "</td>\n";
295 // ha ha, see if that works....mar.
296 echo "<td valign=top><span class=bold>".xl('Billing').":</span><span class=text><br>" .
297 $patient{"billing"} . "</td>\n";
298 echo "<td valign=top><span class=bold>".xl('Transactions').":</span><span class=text><br>" .
299 $patient{"transaction"} . "</td>\n";
300 echo "<td valign=top><span class=bold>".xl('Patient Notes').":</span><span class=text><br>" .
301 $patient{"pnotes"} . "</td>\n";
302 echo "<td valign=top><span class=bold>".xl('Encounter Forms').":</span><span class=text><br>" .
303 $patient{"forms"} . "</td>\n";
304 echo "</tr>\n";
306 $count++;
311 </td>
313 </tr>
314 </table>
316 <?php } ?>
318 </body>
319 <script language='JavaScript'>
321 /* added to adjust the height of this frame by the min/max buttons */
322 var origRows = null;
323 $(document).ready(function(){
324 $("#findpatients").click(function() { RestoreFrame(this); document.location.href='../calendar/find_patient.php?no_nav=1&mode=reset'; return true; });
326 $(".noterow").mouseover(function() { $(this).toggleClass("highlight"); });
327 $(".noterow").mouseout(function() { $(this).toggleClass("highlight"); });
328 $(".noterow").click(function() { EditNote(this); });
330 <?php if ($GLOBALS['concurrent_layout'] == 0) : ?>
331 $("#min").click(function() { MinimizeFrame(this); });
332 $("#max").click(function() { RestoreFrame(this); });
333 var frmset = parent.document.getElementById('Main');
334 origRows = frmset.rows; // save the original frameset sizes
335 <?php endif; ?>
338 <?php if ($GLOBALS['concurrent_layout'] == 0) : ?>
339 var MinimizeFrame = function(eventObject) {
340 var frmset = parent.document.getElementById('Main');
341 origRows = frmset.rows; // save the original frameset sizes
342 frmset.rows = "*, 10%";
344 var RestoreFrame = function(eventObject) {
345 // restore the original frameset size
346 var frmset = parent.document.getElementById('Main');
347 if (origRows != null) { frmset.rows = origRows; }
349 <?php endif; ?>
351 var EditNote = function(note) {
352 var parts = note.id.split("~");
353 <?php if (true): ?>
354 top.restoreSession();
355 <?php if ($GLOBALS['concurrent_layout']): ?>
356 location.href = "<?php echo $GLOBALS['webroot']; ?>/interface/patient_file/summary/pnotes_full.php?noteid=" + parts[1] + "&set_pid=" + parts[0] + "&active=1";
357 <?php else: ?>
358 top.location.href = "<?php echo $GLOBALS['webroot']; ?>/interface/patient_file/patient_file.php?noteid=" + parts[1] + "&set_pid=" + parts[0];
359 <?php endif; ?>
360 <?php else: ?>
361 // no-op
362 alert("<?php xl('You do not have access to view/edit this note','e'); ?>");
363 <?php endif; ?>
366 </script>
368 </html>