2 // Copyright (C) 2006, 2008 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("drugs.inc.php");
14 $drug_id = $_REQUEST['drug'];
18 if (!acl_check('admin', 'drugs')) die("Not authorized!");
20 // Format dollars for display.
22 function bucks($amount) {
24 $amount = sprintf("%.2f", $amount);
25 if ($amount != 0.00) return $amount;
30 // Write a line of data for one template to the form.
32 function writeTemplateLine($selector, $dosage, $period, $quantity, $refills, $prices, $taxrates) {
33 global $tmpl_line_no, $interval_array;
37 echo " <td class='tmplcell drugsonly'>";
38 echo "<input type='text' name='tmpl[$tmpl_line_no][selector]' value='$selector' size='8' maxlength='100'>";
40 echo " <td class='tmplcell drugsonly'>";
41 echo "<input type='text' name='tmpl[$tmpl_line_no][dosage]' value='$dosage' size='6' maxlength='10'>";
43 echo " <td class='tmplcell drugsonly'>";
44 echo "<select name='tmpl[$tmpl_line_no][period]'>";
45 foreach ($interval_array as $key => $value) {
46 echo "<option value='$key'";
47 if ($key == $period) echo " selected";
48 echo ">$value</option>";
51 echo " <td class='tmplcell drugsonly'>";
52 echo "<input type='text' name='tmpl[$tmpl_line_no][quantity]' value='$quantity' size='3' maxlength='7'>";
54 echo " <td class='tmplcell drugsonly'>";
55 echo "<input type='text' name='tmpl[$tmpl_line_no][refills]' value='$refills' size='3' maxlength='5'>";
57 foreach ($prices as $pricelevel => $price) {
58 echo " <td class='tmplcell'>";
59 echo "<input type='text' name='tmpl[$tmpl_line_no][price][$pricelevel]' value='$price' size='6' maxlength='12'>";
62 $pres = sqlStatement("SELECT option_id FROM list_options " .
63 "WHERE list_id = 'taxrate' ORDER BY seq");
64 while ($prow = sqlFetchArray($pres)) {
65 echo " <td class='tmplcell'>";
66 echo "<input type='checkbox' name='tmpl[$tmpl_line_no][taxrate][" . $prow['option_id'] . "]' value='1'";
67 if (strpos(":$taxrates", $prow['option_id']) !== false) echo " checked";
73 // Translation for form fields.
74 function escapedff($name) {
75 $field = trim($_POST[$name]);
76 if (!get_magic_quotes_gpc()) return addslashes($field);
79 function numericff($name) {
80 $field = trim($_POST[$name]) +
0;
86 <?php
html_header_show();?
>
87 <title
><?php
echo $drug_id ?
xl("Edit") : xl("Add New"); xl (' Drug','e'); ?
></title
>
88 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
91 td
{ font
-size
:10pt
; }
93 <?php
if ($GLOBALS['sell_non_drug_products'] == 2) { ?
>
94 .drugsonly
{ display
:none
; }
99 <?php
if (empty($GLOBALS['ippf_specific'])) { ?
>
100 .ippfonly
{ display
:none
; }
107 <script type
="text/javascript" src
="../../library/topdialog.js"></script
>
108 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
110 <script language
="JavaScript">
112 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
114 // This is for callback by the find-code popup.
115 // Appends to or erases the current list of related codes.
116 function set_related(codetype
, code
, selector
, codedesc
) {
117 var f
= document
.forms
[0];
118 var s
= f
.form_related_code
.value
;
120 if (s
.length
> 0) s +
= ';';
121 s +
= codetype +
':' + code
;
125 f
.form_related_code
.value
= s
;
128 // This invokes the find-code popup.
129 function sel_related() {
130 dlgopen('../patient_file/encounter/find_code_popup.php', '_blank', 500, 400);
137 <body
class="body_top">
139 // If we are saving, then save and close the window.
140 // First check for duplicates.
142 if ($_POST['form_save']) {
143 $crow = sqlQuery("SELECT COUNT(*) AS count FROM drugs WHERE " .
144 "name = '" . escapedff('form_name') . "' AND " .
145 "form = '" . escapedff('form_form') . "' AND " .
146 "size = '" . escapedff('form_size') . "' AND " .
147 "unit = '" . escapedff('form_unit') . "' AND " .
148 "route = '" . escapedff('form_route') . "' AND " .
149 "drug_id != '$drug_id'");
150 if ($crow['count']) {
151 $alertmsg = "Cannot add this entry because it already exists!";
155 if (($_POST['form_save'] ||
$_POST['form_delete']) && !$alertmsg) {
158 if ($_POST['form_save']) { // updating an existing drug
159 sqlStatement("UPDATE drugs SET " .
160 "name = '" . escapedff('form_name') . "', " .
161 "ndc_number = '" . escapedff('form_ndc_number') . "', " .
162 "on_order = '" . escapedff('form_on_order') . "', " .
163 "reorder_point = '" . escapedff('form_reorder_point') . "', " .
164 "form = '" . escapedff('form_form') . "', " .
165 "size = '" . escapedff('form_size') . "', " .
166 "unit = '" . escapedff('form_unit') . "', " .
167 "route = '" . escapedff('form_route') . "', " .
168 "cyp_factor = '" . numericff('form_cyp_factor') . "', " .
169 "related_code = '" . escapedff('form_related_code') . "' " .
170 "WHERE drug_id = '$drug_id'");
171 sqlStatement("DELETE FROM drug_templates WHERE drug_id = '$drug_id'");
174 if (acl_check('admin', 'super')) {
175 sqlStatement("DELETE FROM drug_inventory WHERE drug_id = '$drug_id'");
176 sqlStatement("DELETE FROM drug_templates WHERE drug_id = '$drug_id'");
177 sqlStatement("DELETE FROM drugs WHERE drug_id = '$drug_id'");
178 sqlStatement("DELETE FROM prices WHERE pr_id = '$drug_id' AND pr_selector != ''");
182 else if ($_POST['form_save']) { // saving a new drug
184 $drug_id = sqlInsert("INSERT INTO drugs ( " .
185 "name, ndc_number, on_order, reorder_point, form, " .
186 "size, unit, route, cyp_factor, related_code " .
188 "'" . escapedff('form_name') . "', " .
189 "'" . escapedff('form_ndc_number') . "', " .
190 "'" . escapedff('form_on_order') . "', " .
191 "'" . escapedff('form_reorder_point') . "', " .
192 "'" . escapedff('form_form') . "', " .
193 "'" . escapedff('form_size') . "', " .
194 "'" . escapedff('form_unit') . "', " .
195 "'" . escapedff('form_route') . "', " .
196 "'" . numericff('form_cyp_factor') . "', " .
197 "'" . escapedff('form_related_code') . "' " .
201 if ($_POST['form_save'] && $drug_id) {
202 $tmpl = $_POST['tmpl'];
203 // If using the simplified drug form, then force the one and only
204 // selector name to be the same as the product name.
205 if ($GLOBALS['sell_non_drug_products'] == 2) {
206 $tmpl["1"]['selector'] = escapedff('form_name');
208 sqlStatement("DELETE FROM prices WHERE pr_id = '$drug_id' AND pr_selector != ''");
209 for ($lino = 1; isset($tmpl["$lino"]['selector']); ++
$lino) {
210 $iter = $tmpl["$lino"];
211 $selector = trim($iter['selector']);
214 if (!empty($iter['taxrate'])) {
215 foreach ($iter['taxrate'] as $key => $value) {
216 $taxrates .= "$key:";
219 sqlInsert("INSERT INTO drug_templates ( " .
220 "drug_id, selector, dosage, period, quantity, refills, taxrates " .
223 "'" . $selector . "', " .
224 "'" . trim($iter['dosage']) . "', " .
225 "'" . trim($iter['period']) . "', " .
226 "'" . trim($iter['quantity']) . "', " .
227 "'" . trim($iter['refills']) . "', " .
228 "'" . $taxrates . "' " .
231 // Add prices for this drug ID and selector.
232 foreach ($iter['price'] as $key => $value) {
235 sqlStatement("INSERT INTO prices ( " .
236 "pr_id, pr_selector, pr_level, pr_price ) VALUES ( " .
237 "'$drug_id', '$selector', '$key', '$value' )");
239 } // end foreach price
240 } // end if selector is present
241 } // end for each selector
242 } // end if saving a drug
244 // Close this window and redisplay the updated list of drugs.
246 echo "<script language='JavaScript'>\n";
247 if ($info_msg) echo " alert('$info_msg');\n";
248 echo " if (opener.refreshme) opener.refreshme();\n";
250 echo " window.location.href='add_edit_lot.php?drug=$drug_id&lot=0'\n";
252 echo " window.close();\n";
254 echo "</script></body></html>\n";
259 $row = sqlQuery("SELECT * FROM drugs WHERE drug_id = '$drug_id'");
260 $tres = sqlStatement("SELECT * FROM drug_templates WHERE " .
261 "drug_id = '$drug_id' ORDER BY selector");
265 <form method
='post' name
='theform' action
='add_edit_drug.php?drug=<?php echo $drug_id; ?>'>
268 <table border
='0' width
='100%'>
271 <td valign
='top' nowrap
><b
><?php
xl('Name','e'); ?
>:</b
></td
>
273 <input type
='text' size
='40' name
='form_name' maxlength
='80' value
='<?php echo $row['name
'] ?>' style
='width:100%' />
278 <td valign
='top' nowrap
><b
><?php
xl('NDC Number','e'); ?
>:</b
></td
>
280 <input type
='text' size
='40' name
='form_ndc_number' maxlength
='20' value
='<?php echo $row['ndc_number
'] ?>' style
='width:100%' />
285 <td valign
='top' nowrap
><b
><?php
xl('On Order','e'); ?
>:</b
></td
>
287 <input type
='text' size
='5' name
='form_on_order' maxlength
='7' value
='<?php echo $row['on_order
'] ?>' />
292 <td valign
='top' nowrap
><b
><?php
xl('Reorder At','e'); ?
>:</b
></td
>
294 <input type
='text' size
='5' name
='form_reorder_point' maxlength
='7' value
='<?php echo $row['reorder_point
'] ?>' />
298 <tr
class='drugsonly'>
299 <td valign
='top' nowrap
><b
><?php
xl('Form','e'); ?
>:</b
></td
>
301 <select name
='form_form'>
303 foreach ($form_array as $key => $value) {
304 echo " <option value='$key'";
305 if ($key == $row['form']) echo " selected";
313 <tr
class='drugsonly'>
314 <td valign
='top' nowrap
><b
><?php
xl('Pill Size','e'); ?
>:</b
></td
>
316 <input type
='text' size
='5' name
='form_size' maxlength
='7' value
='<?php echo $row['size
'] ?>' />
320 <tr
class='drugsonly'>
321 <td valign
='top' nowrap
><b
><?php
xl('Units','e'); ?
>:</b
></td
>
323 <select name
='form_unit'>
325 foreach ($unit_array as $key => $value) {
326 echo " <option value='$key'";
327 if ($key == $row['unit']) echo " selected";
335 <tr
class='drugsonly'>
336 <td valign
='top' nowrap
><b
><?php
xl('Route','e'); ?
>:</b
></td
>
338 <select name
='form_route'>
340 foreach ($route_array as $key => $value) {
341 echo " <option value='$key'";
342 if ($key == $row['route']) echo " selected";
350 <tr
class='ippfonly'>
351 <td valign
='top' nowrap
><b
><?php
xl('CYP Factor','e'); ?
>:</b
></td
>
353 <input type
='text' size
='10' name
='form_cyp_factor' maxlength
='20' value
='<?php echo $row['cyp_factor
'] ?>' />
358 <td valign
='top' nowrap
><b
><?php
xl('Relate To','e'); ?
>:</b
></td
>
360 <input type
='text' size
='50' name
='form_related_code'
361 value
='<?php echo $row['related_code
'] ?>' onclick
='sel_related()'
362 title
='<?php xl('Click to select related code
','e
'); ?>'
363 style
='width:100%' readonly
/>
368 <td valign
='top' nowrap
>
369 <b
><?php
xl($GLOBALS['sell_non_drug_products'] == 2 ?
'Fees' : 'Templates','e'); ?
>:</b
>
372 <table border
='0' width
='100%'>
374 <td
class='drugsonly'><b
><?php
xl('Name' ,'e'); ?
></b
></td
>
375 <td
class='drugsonly'><b
><?php
xl('Schedule','e'); ?
></b
></td
>
376 <td
class='drugsonly'><b
><?php
xl('Interval','e'); ?
></b
></td
>
377 <td
class='drugsonly'><b
><?php
xl('Qty' ,'e'); ?
></b
></td
>
378 <td
class='drugsonly'><b
><?php
xl('Refills' ,'e'); ?
></b
></td
>
380 // Show a heading for each price level. Also create an array of prices
381 // for new template lines.
382 $emptyPrices = array();
383 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
384 "WHERE list_id = 'pricelevel' ORDER BY seq");
385 while ($prow = sqlFetchArray($pres)) {
386 $emptyPrices[$prow['option_id']] = '';
387 echo " <td><b>" . $prow['title'] . "</b></td>\n";
389 // Show a heading for each tax rate.
390 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
391 "WHERE list_id = 'taxrate' ORDER BY seq");
392 while ($prow = sqlFetchArray($pres)) {
393 echo " <td><b>" . $prow['title'] . "</b></td>\n";
398 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ?
1 : 3;
400 while ($trow = sqlFetchArray($tres)) {
401 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ?
0 : 1;
402 $selector = $trow['selector'];
403 // Get array of prices.
405 $pres = sqlStatement("SELECT lo.option_id, p.pr_price " .
406 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
407 "p.pr_id = '$drug_id' AND p.pr_selector = '$selector' AND " .
408 "p.pr_level = lo.option_id " .
409 "WHERE list_id = 'pricelevel' ORDER BY lo.seq");
410 while ($prow = sqlFetchArray($pres)) {
411 $prices[$prow['option_id']] = $prow['pr_price'];
413 writeTemplateLine($selector, $trow['dosage'], $trow['period'],
414 $trow['quantity'], $trow['refills'], $prices, $trow['taxrates']);
417 for ($i = 0; $i < $blank_lines; ++
$i) {
418 $selector = $GLOBALS['sell_non_drug_products'] == 2 ?
$row['name'] : '';
419 writeTemplateLine($selector, '', '', '', '', $emptyPrices, '');
429 <input type
='submit' name
='form_save' value
='<?php xl('Save
','e
'); ?>' />
431 <?php
if (acl_check('admin', 'super')) { ?
>
433 <input type
='submit' name
='form_delete' value
='<?php xl('Delete
','e
'); ?>' style
='color:red' />
437 <input type
='button' value
='<?php xl('Cancel
','e
'); ?>' onclick
='window.close()' />
444 <script language
="JavaScript">
447 echo "alert('" . htmlentities($alertmsg) . "');\n";