migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / main / messages / lab_results_messages.php
blob054d2d680b2e014886b80cb9b02f331acdc31335
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");
13 function lab_results_messages($set_pid, $rid, $provider_id="") {
14 global $userauthorized;
15 if ($provider_id != "") {
16 $where = "AND id = '".$provider_id."'";
18 // Get all active users.
19 $rez = sqlStatement("select id, username from users where username != '' AND active = '1' $where");
20 for ($iter = 0; $row = sqlFetchArray($rez); $iter++) {
21 $result[$iter] = $row;
24 if (!empty($result)) {
25 foreach ($result as $user_detail) {
26 unset($thisauth); // Make sure it is empty.
27 // Check user authorization. Only send the panding review message to authorised user.
28 // $thisauth = acl_check('patients', 'sign', $user_detail['username']);
30 // Route message to administrators if there is no provider match.
31 if ($provider_id == "") {
32 $thisauth = acl_check('admin', 'super', $user_detail['username']);
34 else {
35 $thisauth = true;
38 if ($thisauth) {
39 // Send lab result message to the ordering provider when there is a new lab report.
40 $pname = getPatientName($set_pid);
41 $link = "<a href='../../orders/orders_results.php?review=1&set_pid=$set_pid'" .
42 " onclick='return top.restoreSession()'>here</a>";
43 $note = "Patient $pname's lab results have arrived. Please click $link to review them.<br/>";
44 $note_type = "Lab Results";
45 $message_status = "New";
46 // Add pnote.
47 $noteid = addPnote($set_pid, $note, $userauthorized, '1', $note_type, $user_detail['username'], '', $message_status);