consolidate attr_url function (#2143)
[openemr.git] / interface / main / messages / lab_results_messages.php
blob95e771e345d3f0107e5637eb5860f222f5c60c59
1 <?php
2 /**
3 * lab_results_messages.php
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Brady Miller <brady.g.miller@gmail.com>
8 * @copyright Copyright (c) 2010 OpenEMR Support LLC
9 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once("$include_root/globals.php");
15 require_once("$srcdir/pnotes.inc");
16 require_once("$srcdir/patient.inc");
17 require_once("$srcdir/auth.inc");
19 function lab_results_messages($set_pid, $rid, $provider_id = "")
21 global $userauthorized;
23 $sqlBindArray = array();
24 if ($provider_id != "") {
25 $where = "AND id = ?";
26 array_push($sqlBindArray, $provider_id);
29 // Get all active users.
30 $rez = sqlStatement("select id, username from users where username != '' AND active = '1' $where", $sqlBindArray);
31 for ($iter = 0; $row = sqlFetchArray($rez); $iter++) {
32 $result[$iter] = $row;
35 if (!empty($result)) {
36 foreach ($result as $user_detail) {
37 unset($thisauth); // Make sure it is empty.
38 // Check user authorization. Only send the panding review message to authorised user.
39 // $thisauth = acl_check('patients', 'sign', $user_detail['username']);
41 // Route message to administrators if there is no provider match.
42 if ($provider_id == "") {
43 $thisauth = acl_check('admin', 'super', $user_detail['username']);
44 } else {
45 $thisauth = true;
48 if ($thisauth) {
49 // Send lab result message to the ordering provider when there is a new lab report.
50 $pname = getPatientName($set_pid);
51 $link = "<a href='../../orders/orders_results.php?review=1&set_pid=" . attr_url($set_pid) . "'" .
52 " onclick='return top.restoreSession()'>here</a>";
53 $note = "Patient $pname's lab results have arrived. Please click $link to review them.<br/>";
54 $note_type = "Lab Results";
55 $message_status = "New";
56 // Add pnote.
57 $noteid = addPnote($set_pid, $note, $userauthorized, '1', $note_type, $user_detail['username'], '', $message_status);