acknowledgments update
[openemr.git] / interface / main / messages / lab_results_messages.php
blob21ebd0b4e1b39f7566b81d3b56718cb83a3bfe46
1 <?php
2 // Copyright (C) 2010 OpenEMR Support 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.
8 require_once("$include_root/globals.php");
9 require_once("$srcdir/pnotes.inc");
10 require_once("$srcdir/patient.inc");
11 require_once("$srcdir/auth.inc");
12 include_once("$srcdir/formdata.inc.php");
14 function lab_results_messages($set_pid, $rid, $provider_id="") {
15 global $userauthorized;
16 if ($provider_id != "") {
17 $where = "AND id = '".$provider_id."'";
19 // Get all active users.
20 $rez = sqlStatement("select id, username from users where username != '' AND active = '1' $where");
21 for ($iter = 0; $row = sqlFetchArray($rez); $iter++) {
22 $result[$iter] = $row;
25 if (!empty($result)) {
26 foreach ($result as $user_detail) {
27 unset($thisauth); // Make sure it is empty.
28 // Check user authorization. Only send the panding review message to authorised user.
29 // $thisauth = acl_check('patients', 'sign', $user_detail['username']);
31 // Route message to administrators if there is no provider match.
32 if ($provider_id == "") {
33 $thisauth = acl_check('admin', 'super', $user_detail['username']);
35 else {
36 $thisauth = true;
39 if ($thisauth) {
40 // Send lab result message to the ordering provider when there is a new lab report.
41 $pname = getPatientName($set_pid);
42 $link = "<a href='../../orders/orders_results.php?review=1&set_pid=$set_pid'" .
43 " onclick='return top.restoreSession()'>here</a>";
44 $note = "Patient $pname's lab results have arrived. Please click $link to review them.<br/>";
45 $note_type = "Lab Results";
46 $message_status = "New";
47 // Add pnote.
48 $noteid = addPnote($set_pid, $note, $userauthorized, '1', $note_type, $user_detail['username'], '', $message_status);