Feat: upgrade e2e testing (#7766)
[openemr.git] / interface / main / messages / lab_results_messages.php
blobf45d5deedda31346ef677cbbd21f27500622af84
1 <?php
3 /**
4 * lab_results_messages.php
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2010 OpenEMR Support LLC
10 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
11 * @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.php");
16 require_once("$srcdir/patient.inc.php");
18 use OpenEMR\Common\Acl\AclMain;
20 function lab_results_messages($set_pid, $rid, $provider_id = "")
22 global $userauthorized;
24 $sqlBindArray = array();
25 if ($provider_id != "") {
26 $where = "AND id = ?";
27 array_push($sqlBindArray, $provider_id);
30 // Get all active users.
31 $rez = sqlStatement("select id, username from users where username != '' AND active = '1' $where", $sqlBindArray);
32 for ($iter = 0; $row = sqlFetchArray($rez); $iter++) {
33 $result[$iter] = $row;
36 if (!empty($result)) {
37 foreach ($result as $user_detail) {
38 unset($thisauth); // Make sure it is empty.
39 // Check user authorization. Only send the pending review message to authorised user.
40 // $thisauth = AclMain::aclCheckCore('patients', 'sign', $user_detail['username']);
42 // Route message to administrators if there is no provider match.
43 if ($provider_id == "") {
44 $thisauth = AclMain::aclCheckCore('admin', 'super', $user_detail['username']);
45 } else {
46 $thisauth = true;
49 if ($thisauth) {
50 // Send lab result message to the ordering provider when there is a new lab report.
51 $pname = getPatientName($set_pid);
52 $link = "<a href='../../orders/orders_results.php?review=1&set_pid=" . attr_url($set_pid) . "'" .
53 " onclick='return top.restoreSession()'>here</a>";
54 $note = "Patient $pname's lab results have arrived. Please click $link to review them.<br/>";
55 $note_type = "Lab Results";
56 $message_status = "New";
57 // Add pnote.
58 $noteid = addPnote($set_pid, $note, $userauthorized, '1', $note_type, $user_detail['username'], '', $message_status);