7 * @link http://www.open-emr.org
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @copyright Copyright (c) 2023 Jerry Padgett <sjpadgett@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General public License 3
13 namespace OpenEMR\Services
;
16 use OpenEMR\Common\Acl\AclMain
;
17 use OpenEMR\Events\Messaging\SendNotificationEvent
;
19 class PatientPortalService
21 public static bool $isSmsEnabled;
22 public static bool $isEmailEnabled;
23 public static bool $isFaxEnabled;
25 public function __construct()
27 self
::setIsEnabledServices($GLOBALS['oefax_enable_fax'] ??
false, $GLOBALS['oefax_enable_sms'] ??
false, $GLOBALS['oe_enable_email'] ??
false);
31 * @param bool $isSmsEnabled
33 public static function setIsEnabledServices(bool $fax, $sms, $email): void
35 self
::$isFaxEnabled = $fax;
36 self
::$isSmsEnabled = $sms;
37 self
::$isEmailEnabled = $email;
44 public static function isValidPortalPatient($pid): array
46 $patient['valid'] = false;
50 // ensure both portal and patient data match using portal account id.
52 "Select `pid`, `email`, `email_direct` From `patient_data` Where `pid` = ?",
56 "Select `pid`, `portal_username` From `patient_access_onsite` Where `pid` = ?",
57 array($patient['pid'])
60 $patient['valid'] = !empty($portal['portal_username']) && ((int)$pid === (int)$portal['pid']);
68 * @param string $content
72 public function dispatchPortalOneTimeDocumentRequest($pid, $details, string $content = ''): bool|
string
74 $pid = $pid ?
: $details['pid'] ??
0;
75 $document_id = $details['document_id'] ??
0; // if 0 will allow a portal onetime login
76 $audit_id = $details['audit_id'];
77 $name = $details['document_name'];
78 $period = $details['onetime_period'];
79 $method = $details['notification_method'] ??
'both';
82 throw new Exception(xlt("Error! Missing patient id."));
85 if (!empty($content)) {
86 $message = xl("Comment from provider") . ": " . $content . "\n";
88 $message = $message . xl("Please click the below link (only valid for 48 hours) to edit document") . ': "' . $name . "\".\n";
90 $statusMsg = xl("Notification requests are being sent!");
92 'notification_method' => $method,
93 'text_message' => $message,
94 'html_message' => null,
95 'document_id' => $document_id,
96 'document_name' => $name,
97 'audit_id' => $audit_id,
98 'expiry_interval' => $period
100 $eventDispatcher = $GLOBALS['kernel']->getEventDispatcher();
101 $eventDispatcher->dispatch(new SendNotificationEvent($pid, $event_data), SendNotificationEvent
::SEND_NOTIFICATION_SERVICE_ONETIME
);
102 return text($statusMsg);
109 public function getPatientDetails($id): bool|
array
111 $query = "SELECT fname, lname, phone_cell as phone, email, hipaa_allowsms, hipaa_allowemail FROM patient_data WHERE pid = ?";
112 $result = sqlQuery($query, array($id));
113 return $result ??
false;
117 * @param string $sect
122 public static function verifyAcl(string $sect = 'admin', string $v = 'docs', string $u = ''): bool
124 return AclMain
::aclCheckCore($sect, $v, $u);
131 public static function isPortalUser($u = null)
133 $user = $u ?
: $_SESSION['authUserID'];
134 // test for either id or username
135 return sqlQuery("SELECT `portal_user` FROM `users` WHERE `id` = ? OR username = ? LIMIT 1", array($user, $user))['portal_user'];
139 * TODO Move this to AclMain class and refactor portal ACLs
140 * It's important to rely on portal user and not ACL.
141 * @param string $sect
146 public static function authPortalUser(string $sect = 'admin', string $v = 'docs', $u = null): bool
148 if (empty(self
::isPortalUser())) {
149 // default is admin forms
150 if (!self
::verifyAcl($sect, $v)) {
162 * If param not valid then entire super is returned.
165 public function getSession($param = null, $default = null): mixed
168 return $_SESSION[$param] ??
$default;
179 public function getRequest($param = null, $default = null): mixed
182 return $_REQUEST[$param] ??
$default;
193 public function getPost($param = null, $default = null): mixed
196 return $_POST[$param] ??
$default;
207 public function getGET($param = null, $default = null): mixed
210 return $_GET[$param] ??
$default;
219 public static function isSmsEnabled(): bool
221 return self
::$isSmsEnabled;
227 public static function isEmailEnabled(): bool
229 return self
::$isEmailEnabled;
235 public static function isFaxEnabled(): bool
237 return self
::$isFaxEnabled;
241 * Currently only used in portal theme setting
242 * however the patient_settings table is useful anywhere.
244 * @param $setting_patient
245 * @param $setting_label
246 * @param $setting_value
249 public static function persistPatientSetting($setting_patient, $setting_label, $setting_value): int
251 $sql = "INSERT INTO `patient_settings` (`setting_patient`, `setting_label`, `setting_value`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `setting_patient` = ?, `setting_label` = ?, `setting_value` = ?";
256 $setting_patient ??
0, $setting_label, $setting_value ??
'',
257 $setting_patient ??
0, $setting_label, $setting_value ??
'')