2 // Copyright (C) 2006-2009 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");
12 require_once("$srcdir/options.inc.php");
15 $drug_id = $_REQUEST['drug'];
19 if (!acl_check('admin', 'drugs')) die(xl('Not authorized'));
21 // Format dollars for display.
23 function bucks($amount) {
25 $amount = sprintf("%.2f", $amount);
26 if ($amount != 0.00) return $amount;
31 // Write a line of data for one template to the form.
33 function writeTemplateLine($selector, $dosage, $period, $quantity, $refills, $prices, $taxrates) {
38 echo " <td class='tmplcell drugsonly'>";
39 echo "<input type='text' name='form_tmpl[$tmpl_line_no][selector]' value='$selector' size='8' maxlength='100'>";
41 echo " <td class='tmplcell drugsonly'>";
42 echo "<input type='text' name='form_tmpl[$tmpl_line_no][dosage]' value='$dosage' size='6' maxlength='10'>";
44 echo " <td class='tmplcell drugsonly'>";
45 generate_form_field(array('data_type'=>1,'field_id'=>'tmpl['.$tmpl_line_no.'][period]','list_id'=>'drug_interval','empty_title'=>'SKIP'), $period);
47 echo " <td class='tmplcell drugsonly'>";
48 echo "<input type='text' name='form_tmpl[$tmpl_line_no][quantity]' value='$quantity' size='3' maxlength='7'>";
50 echo " <td class='tmplcell drugsonly'>";
51 echo "<input type='text' name='form_tmpl[$tmpl_line_no][refills]' value='$refills' size='3' maxlength='5'>";
53 foreach ($prices as $pricelevel => $price) {
54 echo " <td class='tmplcell'>";
55 echo "<input type='text' name='form_tmpl[$tmpl_line_no][price][$pricelevel]' value='$price' size='6' maxlength='12'>";
58 $pres = sqlStatement("SELECT option_id FROM list_options " .
59 "WHERE list_id = 'taxrate' ORDER BY seq");
60 while ($prow = sqlFetchArray($pres)) {
61 echo " <td class='tmplcell'>";
62 echo "<input type='checkbox' name='form_tmpl[$tmpl_line_no][taxrate][" . $prow['option_id'] . "]' value='1'";
63 if (strpos(":$taxrates", $prow['option_id']) !== false) echo " checked";
69 // Translation for form fields.
70 function escapedff($name) {
71 $field = trim($_POST[$name]);
72 if (!get_magic_quotes_gpc()) return addslashes($field);
75 function numericff($name) {
76 $field = trim($_POST[$name]) +
0;
82 <?php
html_header_show(); ?
>
83 <title
><?php
echo $drug_id ?
xl("Edit") : xl("Add New"); xl('Drug','e',' '); ?
></title
>
84 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
87 td
{ font
-size
:10pt
; }
89 <?php
if ($GLOBALS['sell_non_drug_products'] == 2) { ?
>
90 .drugsonly
{ display
:none
; }
95 <?php
if (empty($GLOBALS['ippf_specific'])) { ?
>
96 .ippfonly
{ display
:none
; }
103 <script type
="text/javascript" src
="../../library/topdialog.js"></script
>
104 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
106 <script language
="JavaScript">
108 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
110 // This is for callback by the find-code popup.
111 // Appends to or erases the current list of related codes.
112 function set_related(codetype
, code
, selector
, codedesc
) {
113 var f
= document
.forms
[0];
114 var s
= f
.form_related_code
.value
;
116 if (s
.length
> 0) s +
= ';';
117 s +
= codetype +
':' + code
;
121 f
.form_related_code
.value
= s
;
124 // This invokes the find-code popup.
125 function sel_related() {
126 dlgopen('../patient_file/encounter/find_code_popup.php', '_blank', 500, 400);
133 <body
class="body_top">
135 // If we are saving, then save and close the window.
136 // First check for duplicates.
138 if ($_POST['form_save']) {
139 $crow = sqlQuery("SELECT COUNT(*) AS count FROM drugs WHERE " .
140 "name = '" . escapedff('form_name') . "' AND " .
141 "form = '" . escapedff('form_form') . "' AND " .
142 "size = '" . escapedff('form_size') . "' AND " .
143 "unit = '" . escapedff('form_unit') . "' AND " .
144 "route = '" . escapedff('form_route') . "' AND " .
145 "drug_id != '$drug_id'");
146 if ($crow['count']) {
147 $alertmsg = xl('Cannot add this entry because it already exists!');
151 if (($_POST['form_save'] ||
$_POST['form_delete']) && !$alertmsg) {
154 if ($_POST['form_save']) { // updating an existing drug
155 sqlStatement("UPDATE drugs SET " .
156 "name = '" . escapedff('form_name') . "', " .
157 "ndc_number = '" . escapedff('form_ndc_number') . "', " .
158 "on_order = '" . escapedff('form_on_order') . "', " .
159 "reorder_point = '" . escapedff('form_reorder_point') . "', " .
160 "form = '" . escapedff('form_form') . "', " .
161 "size = '" . escapedff('form_size') . "', " .
162 "unit = '" . escapedff('form_unit') . "', " .
163 "route = '" . escapedff('form_route') . "', " .
164 "cyp_factor = '" . numericff('form_cyp_factor') . "', " .
165 "related_code = '" . escapedff('form_related_code') . "', " .
166 "active = " . (empty($_POST['form_active']) ?
0 : 1) . " " .
167 "WHERE drug_id = '$drug_id'");
168 sqlStatement("DELETE FROM drug_templates WHERE drug_id = '$drug_id'");
171 if (acl_check('admin', 'super')) {
172 sqlStatement("DELETE FROM drug_inventory WHERE drug_id = '$drug_id'");
173 sqlStatement("DELETE FROM drug_templates WHERE drug_id = '$drug_id'");
174 sqlStatement("DELETE FROM drugs WHERE drug_id = '$drug_id'");
175 sqlStatement("DELETE FROM prices WHERE pr_id = '$drug_id' AND pr_selector != ''");
179 else if ($_POST['form_save']) { // saving a new drug
181 $drug_id = sqlInsert("INSERT INTO drugs ( " .
182 "name, ndc_number, on_order, reorder_point, form, " .
183 "size, unit, route, cyp_factor, related_code, active " .
185 "'" . escapedff('form_name') . "', " .
186 "'" . escapedff('form_ndc_number') . "', " .
187 "'" . escapedff('form_on_order') . "', " .
188 "'" . escapedff('form_reorder_point') . "', " .
189 "'" . escapedff('form_form') . "', " .
190 "'" . escapedff('form_size') . "', " .
191 "'" . escapedff('form_unit') . "', " .
192 "'" . escapedff('form_route') . "', " .
193 "'" . numericff('form_cyp_factor') . "', " .
194 "'" . escapedff('form_related_code') . "', " .
195 (empty($_POST['form_active']) ?
0 : 1) .
199 if ($_POST['form_save'] && $drug_id) {
200 $tmpl = $_POST['form_tmpl'];
201 // If using the simplified drug form, then force the one and only
202 // selector name to be the same as the product name.
203 if ($GLOBALS['sell_non_drug_products'] == 2) {
204 $tmpl["1"]['selector'] = escapedff('form_name');
206 sqlStatement("DELETE FROM prices WHERE pr_id = '$drug_id' AND pr_selector != ''");
207 for ($lino = 1; isset($tmpl["$lino"]['selector']); ++
$lino) {
208 $iter = $tmpl["$lino"];
209 $selector = trim($iter['selector']);
212 if (!empty($iter['taxrate'])) {
213 foreach ($iter['taxrate'] as $key => $value) {
214 $taxrates .= "$key:";
217 sqlInsert("INSERT INTO drug_templates ( " .
218 "drug_id, selector, dosage, period, quantity, refills, taxrates " .
221 "'" . $selector . "', " .
222 "'" . trim($iter['dosage']) . "', " .
223 "'" . trim($iter['period']) . "', " .
224 "'" . trim($iter['quantity']) . "', " .
225 "'" . trim($iter['refills']) . "', " .
226 "'" . $taxrates . "' " .
229 // Add prices for this drug ID and selector.
230 foreach ($iter['price'] as $key => $value) {
233 sqlStatement("INSERT INTO prices ( " .
234 "pr_id, pr_selector, pr_level, pr_price ) VALUES ( " .
235 "'$drug_id', '$selector', '$key', '$value' )");
237 } // end foreach price
238 } // end if selector is present
239 } // end for each selector
240 } // end if saving a drug
242 // Close this window and redisplay the updated list of drugs.
244 echo "<script language='JavaScript'>\n";
245 if ($info_msg) echo " alert('$info_msg');\n";
246 echo " if (opener.refreshme) opener.refreshme();\n";
248 echo " window.location.href='add_edit_lot.php?drug=$drug_id&lot=0'\n";
250 echo " window.close();\n";
252 echo "</script></body></html>\n";
257 $row = sqlQuery("SELECT * FROM drugs WHERE drug_id = '$drug_id'");
258 $tres = sqlStatement("SELECT * FROM drug_templates WHERE " .
259 "drug_id = '$drug_id' ORDER BY selector");
263 <form method
='post' name
='theform' action
='add_edit_drug.php?drug=<?php echo $drug_id; ?>'>
266 <table border
='0' width
='100%'>
269 <td valign
='top' nowrap
><b
><?php
xl('Name','e'); ?
>:</b
></td
>
271 <input type
='text' size
='40' name
='form_name' maxlength
='80' value
='<?php echo $row['name
'] ?>' style
='width:100%' />
276 <td valign
='top' nowrap
><b
><?php
xl('Active','e'); ?
>:</b
></td
>
278 <input type
='checkbox' name
='form_active' value
='1'<?php
if ($row['active']) echo ' checked'; ?
> />
283 <td valign
='top' nowrap
><b
><?php
xl('NDC Number','e'); ?
>:</b
></td
>
285 <input type
='text' size
='40' name
='form_ndc_number' maxlength
='20' value
='<?php echo $row['ndc_number
'] ?>' style
='width:100%' />
290 <td valign
='top' nowrap
><b
><?php
xl('On Order','e'); ?
>:</b
></td
>
292 <input type
='text' size
='5' name
='form_on_order' maxlength
='7' value
='<?php echo $row['on_order
'] ?>' />
297 <td valign
='top' nowrap
><b
><?php
xl('Reorder At','e'); ?
>:</b
></td
>
299 <input type
='text' size
='5' name
='form_reorder_point' maxlength
='7' value
='<?php echo $row['reorder_point
'] ?>' />
303 <tr
class='drugsonly'>
304 <td valign
='top' nowrap
><b
><?php
xl('Form','e'); ?
>:</b
></td
>
307 generate_form_field(array('data_type'=>1,'field_id'=>'form','list_id'=>'drug_form','empty_title'=>'SKIP'), $row['form']);
312 <tr
class='drugsonly'>
313 <td valign
='top' nowrap
><b
><?php
xl('Pill Size','e'); ?
>:</b
></td
>
315 <input type
='text' size
='5' name
='form_size' maxlength
='7' value
='<?php echo $row['size
'] ?>' />
319 <tr
class='drugsonly'>
320 <td valign
='top' nowrap
><b
><?php
xl('Units','e'); ?
>:</b
></td
>
323 generate_form_field(array('data_type'=>1,'field_id'=>'unit','list_id'=>'drug_units','empty_title'=>'SKIP'), $row['unit']);
328 <tr
class='drugsonly'>
329 <td valign
='top' nowrap
><b
><?php
xl('Route','e'); ?
>:</b
></td
>
332 generate_form_field(array('data_type'=>1,'field_id'=>'route','list_id'=>'drug_route','empty_title'=>'SKIP'), $row['route']);
337 <tr
class='ippfonly'>
338 <td valign
='top' nowrap
><b
><?php
xl('CYP Factor','e'); ?
>:</b
></td
>
340 <input type
='text' size
='10' name
='form_cyp_factor' maxlength
='20' value
='<?php echo $row['cyp_factor
'] ?>' />
345 <td valign
='top' nowrap
><b
><?php
xl('Relate To','e'); ?
>:</b
></td
>
347 <input type
='text' size
='50' name
='form_related_code'
348 value
='<?php echo $row['related_code
'] ?>' onclick
='sel_related()'
349 title
='<?php xl('Click to select related code
','e
'); ?>'
350 style
='width:100%' readonly
/>
355 <td valign
='top' nowrap
>
356 <b
><?php
$GLOBALS['sell_non_drug_products'] == 2 ?
xl('Fees','e') : xl('Templates','e'); ?
>:</b
>
359 <table border
='0' width
='100%'>
361 <td
class='drugsonly'><b
><?php
xl('Name' ,'e'); ?
></b
></td
>
362 <td
class='drugsonly'><b
><?php
xl('Schedule','e'); ?
></b
></td
>
363 <td
class='drugsonly'><b
><?php
xl('Interval','e'); ?
></b
></td
>
364 <td
class='drugsonly'><b
><?php
xl('Qty' ,'e'); ?
></b
></td
>
365 <td
class='drugsonly'><b
><?php
xl('Refills' ,'e'); ?
></b
></td
>
367 // Show a heading for each price level. Also create an array of prices
368 // for new template lines.
369 $emptyPrices = array();
370 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
371 "WHERE list_id = 'pricelevel' ORDER BY seq");
372 while ($prow = sqlFetchArray($pres)) {
373 $emptyPrices[$prow['option_id']] = '';
375 generate_display_field(array('data_type'=>'1','list_id'=>'pricelevel'), $prow['option_id']) .
378 // Show a heading for each tax rate.
379 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
380 "WHERE list_id = 'taxrate' ORDER BY seq");
381 while ($prow = sqlFetchArray($pres)) {
383 generate_display_field(array('data_type'=>'1','list_id'=>'taxrate'), $prow['option_id']) .
389 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ?
1 : 3;
391 while ($trow = sqlFetchArray($tres)) {
392 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ?
0 : 1;
393 $selector = $trow['selector'];
394 // Get array of prices.
396 $pres = sqlStatement("SELECT lo.option_id, p.pr_price " .
397 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
398 "p.pr_id = '$drug_id' AND p.pr_selector = '$selector' AND " .
399 "p.pr_level = lo.option_id " .
400 "WHERE list_id = 'pricelevel' ORDER BY lo.seq");
401 while ($prow = sqlFetchArray($pres)) {
402 $prices[$prow['option_id']] = $prow['pr_price'];
404 writeTemplateLine($selector, $trow['dosage'], $trow['period'],
405 $trow['quantity'], $trow['refills'], $prices, $trow['taxrates']);
408 for ($i = 0; $i < $blank_lines; ++
$i) {
409 $selector = $GLOBALS['sell_non_drug_products'] == 2 ?
$row['name'] : '';
410 writeTemplateLine($selector, '', '', '', '', $emptyPrices, '');
420 <input type
='submit' name
='form_save' value
='<?php xl('Save
','e
'); ?>' />
422 <?php
if (acl_check('admin', 'super')) { ?
>
424 <input type
='submit' name
='form_delete' value
='<?php xl('Delete
','e
'); ?>' style
='color:red' />
428 <input type
='button' value
='<?php xl('Cancel
','e
'); ?>' onclick
='window.close()' />
435 <script language
="JavaScript">
438 echo "alert('" . htmlentities($alertmsg) . "');\n";