5 * @link http://www.open-emr.org
6 * @author Sherwin Gaddis <sherwingaddis@gmail.com>
7 * @copyright Copyright (c )2020. Sherwin Gaddis <sherwingaddis@gmail.com>
8 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once "../interface/globals.php";
15 use OpenEMR\Common\Acl\AclMain
;
16 use OpenEMR\Common\Csrf\CsrfUtils
;
17 use OpenEMR\Common\Logging\EventAuditLogger
;
19 //ensure user has proper access
20 if (!AclMain
::aclCheckCore('patient', 'rx', '', 'write')) {
21 echo xlt('ACL Administration Not Authorized');
25 $id = filter_input(INPUT_POST
, 'drugId', FILTER_VALIDATE_INT
);
28 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
29 CsrfUtils
::csrfNotVerified();
33 * find the drug name in the prescription table
36 $drug_name = "SELECT patient_id, drug FROM prescriptions WHERE id = ?";
37 $dn = sqlQuery($drug_name, [$id]);
38 } catch (Exception
$e) {
39 echo 'Caught exception ', text($e->getMessage()), "\n";
40 if ($e->getMessage()) {
46 * remove drug from the medication list if exist
49 $pid = $dn['patient_id'];
50 $drugname = $dn['drug'];
51 if (!empty($drugname)) {
52 $medicationlist = "DELETE FROM lists WHERE pid = ? AND type = 'medication' AND title = ?";
53 sqlStatement($medicationlist, [$pid, $drugname]);
54 EventAuditLogger
::instance()->newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], 1, $drugname . " prescription/medication removed", $pid);
56 } catch (Exception
$e) {
57 echo 'Caught exception ', text($e->getMessage()), "\n";
58 if ($e->getMessage()) {
64 * remove drug from the prescription
67 $sql = "delete from prescriptions where id = ?";
68 sqlQuery($sql, [$id]);
69 } catch (Exception
$e) {
70 echo 'Caught exception ', text($e->getMessage()), "\n";
71 if ($e->getMessage()) {
76 echo xlt("Finished Deleting");