From f9b6555a12b6f05769bd93777f2252dde874be69 Mon Sep 17 00:00:00 2001 From: sunsetsystems Date: Tue, 25 Apr 2006 19:59:07 +0000 Subject: [PATCH] refinements for in-house drugs --- includes/config.php | 9 ++ interface/drugs/dispense_drug.php | 60 +++++++- interface/drugs/drugs.inc.php | 25 +++ interface/reports/prescriptions_report.php | 238 +++++++++++++++++++++++++++++ templates/report/general_default.html | 2 + 5 files changed, 327 insertions(+), 7 deletions(-) create mode 100644 interface/reports/prescriptions_report.php diff --git a/includes/config.php b/includes/config.php index 738852fe0..47730a328 100644 --- a/includes/config.php +++ b/includes/config.php @@ -52,6 +52,15 @@ $GLOBALS['oer_config']['prescriptions']['right'] = 30; $GLOBALS['oer_config']['prescriptions']['top'] = 72; $GLOBALS['oer_config']['prescriptions']['bottom'] = 30; +// Similarly for bottle labels if you are dispensing drugs. Note that paper +// size here or for prescriptions may be an array (0, 0, width, height). +// All of these measurements are in points. +$GLOBALS['oer_config']['druglabels']['paper_size'] = array(0, 0, 216, 144); +$GLOBALS['oer_config']['druglabels']['left'] = 18; +$GLOBALS['oer_config']['druglabels']['right'] = 18; +$GLOBALS['oer_config']['druglabels']['top'] = 18; +$GLOBALS['oer_config']['druglabels']['bottom'] = 18; + //accounting system web services integration //whether to use the system $GLOBALS['oer_config']['ws_accounting']['enabled'] = false; diff --git a/interface/drugs/dispense_drug.php b/interface/drugs/dispense_drug.php index 6e7ddb8a2..d78511e05 100644 --- a/interface/drugs/dispense_drug.php +++ b/interface/drugs/dispense_drug.php @@ -10,6 +10,7 @@ require_once("$srcdir/acl.inc"); require_once("drugs.inc.php"); require_once($GLOBALS['fileroot'] . "/library/classes/class.phpmailer.php"); + require_once($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php"); function send_email($subject, $body) { $recipient = $GLOBALS['practice_return_email_path']; @@ -29,7 +30,7 @@ } } - $sales_id = $_REQUEST['sales_id']; + $sale_id = $_REQUEST['sale_id']; $drug_id = $_REQUEST['drug_id']; $prescription_id = $_REQUEST['prescription']; $quantity = $_REQUEST['quantity']; @@ -47,7 +48,9 @@ $bad_lot_list = ''; $today = date('Y-m-d'); - if (! $sales_id) { + // If there is no sale_id then this is a new dispensation. + // + if (! $sale_id) { // Find and update inventory, deal with errors. // if ($drug_id) { @@ -94,16 +97,59 @@ } - $sales_id = sqlInsert("INSERT INTO drug_sales ( " . + $sale_id = sqlInsert("INSERT INTO drug_sales ( " . "drug_id, inventory_id, prescription_id, pid, user, sale_date, quantity, fee " . ") VALUES ( " . "'$drug_id', '$inventory_id', '$prescription_id', '$pid', '$user', '$today', '$quantity', '$fee' " . ")"); - - echo "Inventory has been updated. Here we will send a PDF for the bottle label.\n"; } - // TBD: Generate the bottle label PDF for the sale identified by $sales_id. + // Generate the bottle label PDF for the sale identified by $sale_id. + + $row = sqlQuery("SELECT " . + "s.pid, s.quantity, s.prescription_id, " . + "i.manufacturer, i.lot_number, i.expiration, " . + "d.name, d.ndc_number, d.form, d.size, d.unit, " . + "r.date_modified, r.dosage, r.route, r.interval, r.substitute, r.refills, " . + "p.fname, p.lname, p.mname " . + "FROM drug_sales AS s, drug_inventory AS i, drugs AS d, " . + "prescriptions AS r, patient_data AS p WHERE " . + "s.sale_id = '$sale_id' AND " . + "i.inventory_id = s.inventory_id AND " . + "d.drug_id = i.drug_id AND " . + "r.id = s.prescription_id AND " . + "p.pid = s.pid"); + + $label_text = 'RX# ' . $row['prescription_id'] . ' ' . + $row['fname'] . ' ' . $row['lname'] . ' ' . $row['date_modified'] . "\n" . + $row['name'] . ' ' . $row['size'] . ' ' . + $unit_array[$row['unit']] . ' QTY ' . + $row['quantity'] . "\n" . + 'NDC ' . $row['ndc_number'] . ' Lot ' . $row['lot_number'] . ' ' . + $row['manufacturer'] . "\n" . + 'Take ' . $row['dosage'] . ' ' . $form_array[$row['form']] . + ($row['dosage'] > 1 ? 's ' : ' ') . + $interval_array_verbose[$row['interval']] . ' ' . + $route_array_verbose[$row['route']] . ".\n"; + + if ($row['refills']) { + // Find out how many times this prescription has been filled/refilled. + // Is this right? Perhaps we should instead sum the dispensed quantities + // and reconcile with the prescription quantities. + $refills_row = sqlQuery("SELECT count(*) AS count FROM drug_sales " . + "WHERE prescription_id = '" . $row['prescription_id'] . + "' AND quantity > 0"); + $label_text .= ($refills_row['count'] - 1) . ' of ' . $row['refills'] . ' refills'; + } -?> + $dconfig = $GLOBALS['oer_config']['druglabels']; + $pdf =& new Cezpdf($dconfig['paper_size']); + $pdf->ezSetMargins($dconfig['top'],$dconfig['bottom'],$dconfig['left'],$dconfig['right']); + $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm"); + if(!empty($dconfig['logo'])) { + $pdf->ezImage($dconfig['logo']); + } + $pdf->ezText($label_text, 10); + $pdf->ezStream(); +?> \ No newline at end of file diff --git a/interface/drugs/drugs.inc.php b/interface/drugs/drugs.inc.php index 718c195f7..d9be4d980 100644 --- a/interface/drugs/drugs.inc.php +++ b/interface/drugs/drugs.inc.php @@ -21,5 +21,30 @@ $interval_array = array('', 'b.i.d.', 't.i.d.', 'q.i.d.', 'q.3h', 'q.4h', 'q.5h', 'q.6h', 'q.8h', 'q.d.'); + $interval_array_verbose = array('', + 'twice daily', + '3 times daily', + '4 times daily', + 'every 3 hours', + 'every 4 hours', + 'every 5 hours', + 'every 6 hours', + 'every 8 hours', + 'daily'); + + $route_array_verbose = array('', + 'by mouth', + 'rectally', + 'to skin', + 'to affected area', + 'under tongue', + 'in left eye', + 'in right eye', + 'in each eye', + 'subcutaneously', + 'intramuscularly', + 'intravenously', + 'in nostril'); + $substitute_array = array('', 'Allowed', 'Not Allowed'); ?> diff --git a/interface/reports/prescriptions_report.php b/interface/reports/prescriptions_report.php new file mode 100644 index 000000000..e3f871d97 --- /dev/null +++ b/interface/reports/prescriptions_report.php @@ -0,0 +1,238 @@ + + // + // This program is free software; you can redistribute it and/or + // modify it under the terms of the GNU General Public License + // as published by the Free Software Foundation; either version 2 + // of the License, or (at your option) any later version. + + // This report lists prescriptions and their dispensations according + // to various input selection criteria. + + require_once("../globals.php"); + require_once("$srcdir/patient.inc"); + require_once("../drugs/drugs.inc.php"); + + $form_from_date = fixDate($_POST['form_from_date'], date('Y-01-01')); + $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d')); + $form_patient_id = trim($_POST['form_patient_id']); + $form_drug_name = trim($_POST['form_drug_name']); + $form_lot_number = trim($_POST['form_lot_number']); +?> + + +<? xl('Prescriptions and Dispensations','e'); ?> + + + + + + + + + + + + + +
+ +

+ +
+ + + + + + + + + + + +
+ : + + +  : + + +  : + +  : + +  : + +   + > +
+
+ + + + + + + + + + + + + + + + + + += '$form_from_date' AND " . + "r.date_modified <= '$form_to_date'"; + if ($form_patient_id) $where .= " AND r.id = '$form_patient_id'"; + if ($form_drug_name ) $where .= " AND d.name LIKE '$form_drug_name'"; + if ($form_lot_number) $where .= " AND i.lot_number LIKE '$form_lot_number'"; + + $query = "SELECT r.id, r.patient_id, " . + "r.date_modified, r.dosage, r.route, r.interval, r.refills, " . + "d.name, d.ndc_number, d.form, d.size, d.unit, d.reactions, " . + "s.sale_id, s.sale_date, s.quantity, " . + "i.manufacturer, i.lot_number, i.expiration, " . + "p.fname, p.lname, p.mname " . + "FROM prescriptions AS r " . + "LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id " . + "LEFT OUTER JOIN drug_sales AS s ON s.prescription_id = r.id " . + "LEFT OUTER JOIN drug_inventory AS i ON i.inventory_id = s.inventory_id " . + "LEFT OUTER JOIN patient_data AS p ON p.pid = r.patient_id " . + "WHERE $where " . + "ORDER BY p.lname, p.fname, r.patient_id, r.id, s.sale_id"; + + // echo "\n"; // debugging + $res = sqlStatement($query); + + $last_patient_id = 0; + $last_prescription_id = 0; + while ($row = sqlFetchArray($res)) { + $patient_name = $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']; + $patient_id = $row['patient_id']; + $prescription_id = $row['id']; + $drug_name = $row['name']; + $ndc_number = $row['ndc_number']; + $drug_units = $row['size'] . ' ' . $unit_array[$row['unit']]; + $refills = $row['refills']; + $reactions = $row['reactions']; + $instructed = $row['dosage'] . ' ' . $form_array[$row['form']] . ' ' . + $interval_array[$row['interval']]; + if ($row['patient_id'] == $last_patient_id) { + $patient_name = ' '; + $patient_id = ' '; + if ($row['id'] == $last_prescription_id) { + $prescription_id = ' '; + $drug_name = ' '; + $ndc_number = ' '; + $drug_units = ' '; + $refills = ' '; + $reactions = ' '; + $instructed = ' '; + } + } +?> + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + diff --git a/templates/report/general_default.html b/templates/report/general_default.html index e7b9cc2c6..ded95e2ee 100644 --- a/templates/report/general_default.html +++ b/templates/report/general_default.html @@ -45,6 +45,8 @@ function dopopup(aurl) { Front Office Receipts Report
Unique Seen Patients Report +
+Prescriptions Report {php} if ($GLOBALS['athletic_team']) { echo "
\n"; -- 2.11.4.GIT