2 // Copyright (C) 2006-2010 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
>
105 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
107 <script language
="JavaScript">
109 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
111 // This is for callback by the find-code popup.
112 // Appends to or erases the current list of related codes.
113 function set_related(codetype
, code
, selector
, codedesc
) {
114 var f
= document
.forms
[0];
115 var s
= f
.form_related_code
.value
;
117 if (s
.length
> 0) s +
= ';';
118 s +
= codetype +
':' + code
;
122 f
.form_related_code
.value
= s
;
125 // This invokes the find-code popup.
126 function sel_related() {
127 dlgopen('../patient_file/encounter/find_code_popup.php', '_blank', 500, 400);
134 <body
class="body_top">
136 // If we are saving, then save and close the window.
137 // First check for duplicates.
139 if ($_POST['form_save']) {
140 $crow = sqlQuery("SELECT COUNT(*) AS count FROM drugs WHERE " .
141 "name = '" . escapedff('form_name') . "' AND " .
142 "form = '" . escapedff('form_form') . "' AND " .
143 "size = '" . escapedff('form_size') . "' AND " .
144 "unit = '" . escapedff('form_unit') . "' AND " .
145 "route = '" . escapedff('form_route') . "' AND " .
146 "drug_id != '$drug_id'");
147 if ($crow['count']) {
148 $alertmsg = xl('Cannot add this entry because it already exists!');
152 if (($_POST['form_save'] ||
$_POST['form_delete']) && !$alertmsg) {
155 if ($_POST['form_save']) { // updating an existing drug
156 sqlStatement("UPDATE drugs SET " .
157 "name = '" . escapedff('form_name') . "', " .
158 "ndc_number = '" . escapedff('form_ndc_number') . "', " .
159 "on_order = '" . escapedff('form_on_order') . "', " .
160 "reorder_point = '" . escapedff('form_reorder_point') . "', " .
161 "form = '" . escapedff('form_form') . "', " .
162 "size = '" . escapedff('form_size') . "', " .
163 "unit = '" . escapedff('form_unit') . "', " .
164 "route = '" . escapedff('form_route') . "', " .
165 "cyp_factor = '" . numericff('form_cyp_factor') . "', " .
166 "related_code = '" . escapedff('form_related_code') . "', " .
167 "allow_multiple = " . (empty($_POST['form_allow_multiple' ]) ?
0 : 1) . ", " .
168 "allow_combining = " . (empty($_POST['form_allow_combining']) ?
0 : 1) . ", " .
169 "active = " . (empty($_POST['form_active']) ?
0 : 1) . " " .
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, " .
187 "allow_multiple, allow_combining, active " .
189 "'" . escapedff('form_name') . "', " .
190 "'" . escapedff('form_ndc_number') . "', " .
191 "'" . escapedff('form_on_order') . "', " .
192 "'" . escapedff('form_reorder_point') . "', " .
193 "'" . escapedff('form_form') . "', " .
194 "'" . escapedff('form_size') . "', " .
195 "'" . escapedff('form_unit') . "', " .
196 "'" . escapedff('form_route') . "', " .
197 "'" . numericff('form_cyp_factor') . "', " .
198 "'" . escapedff('form_related_code') . "', " .
199 (empty($_POST['form_allow_multiple' ]) ?
0 : 1) . ", " .
200 (empty($_POST['form_allow_combining']) ?
0 : 1) . ", " .
201 (empty($_POST['form_active']) ?
0 : 1) .
205 if ($_POST['form_save'] && $drug_id) {
206 $tmpl = $_POST['form_tmpl'];
207 // If using the simplified drug form, then force the one and only
208 // selector name to be the same as the product name.
209 if ($GLOBALS['sell_non_drug_products'] == 2) {
210 $tmpl["1"]['selector'] = escapedff('form_name');
212 sqlStatement("DELETE FROM prices WHERE pr_id = '$drug_id' AND pr_selector != ''");
213 for ($lino = 1; isset($tmpl["$lino"]['selector']); ++
$lino) {
214 $iter = $tmpl["$lino"];
215 $selector = trim($iter['selector']);
218 if (!empty($iter['taxrate'])) {
219 foreach ($iter['taxrate'] as $key => $value) {
220 $taxrates .= "$key:";
223 sqlInsert("INSERT INTO drug_templates ( " .
224 "drug_id, selector, dosage, period, quantity, refills, taxrates " .
227 "'" . $selector . "', " .
228 "'" . trim($iter['dosage']) . "', " .
229 "'" . trim($iter['period']) . "', " .
230 "'" . trim($iter['quantity']) . "', " .
231 "'" . trim($iter['refills']) . "', " .
232 "'" . $taxrates . "' " .
235 // Add prices for this drug ID and selector.
236 foreach ($iter['price'] as $key => $value) {
239 sqlStatement("INSERT INTO prices ( " .
240 "pr_id, pr_selector, pr_level, pr_price ) VALUES ( " .
241 "'$drug_id', '$selector', '$key', '$value' )");
243 } // end foreach price
244 } // end if selector is present
245 } // end for each selector
246 } // end if saving a drug
248 // Close this window and redisplay the updated list of drugs.
250 echo "<script language='JavaScript'>\n";
251 if ($info_msg) echo " alert('$info_msg');\n";
252 echo " if (opener.refreshme) opener.refreshme();\n";
254 echo " window.location.href='add_edit_lot.php?drug=$drug_id&lot=0'\n";
256 echo " window.close();\n";
258 echo "</script></body></html>\n";
263 $row = sqlQuery("SELECT * FROM drugs WHERE drug_id = '$drug_id'");
264 $tres = sqlStatement("SELECT * FROM drug_templates WHERE " .
265 "drug_id = '$drug_id' ORDER BY selector");
271 'allow_multiple' => '1',
272 'allow_combining' => '',
275 'reorder_point' => '0',
281 'related_code' => '',
286 <form method
='post' name
='theform' action
='add_edit_drug.php?drug=<?php echo $drug_id; ?>'>
289 <table border
='0' width
='100%'>
292 <td valign
='top' nowrap
><b
><?php
xl('Name','e'); ?
>:</b
></td
>
294 <input type
='text' size
='40' name
='form_name' maxlength
='80' value
='<?php echo $row['name
'] ?>' style
='width:100%' />
299 <td valign
='top' nowrap
><b
><?php
xl('Active','e'); ?
>:</b
></td
>
301 <input type
='checkbox' name
='form_active' value
='1'<?php
if ($row['active']) echo ' checked'; ?
> />
306 <td valign
='top' nowrap
><b
><?php
xl('Allow','e'); ?
>:</b
></td
>
308 <input type
='checkbox' name
='form_allow_multiple' value
='1'<?php
if ($row['allow_multiple']) echo ' checked'; ?
> />
309 <?php
xl('Multiple Lots','e'); ?
>  
;
310 <input type
='checkbox' name
='form_allow_combining' value
='1'<?php
if ($row['allow_combining']) echo ' checked'; ?
> />
311 <?php
xl('Combining Lots','e'); ?
>
316 <td valign
='top' nowrap
><b
><?php
xl('NDC Number','e'); ?
>:</b
></td
>
318 <input type
='text' size
='40' name
='form_ndc_number' maxlength
='20'
319 value
='<?php echo $row['ndc_number
'] ?>' style
='width:100%'
320 onkeyup
='maskkeyup(this,"<?php echo addslashes($GLOBALS['gbl_mask_product_id
']); ?>")'
321 onblur
='maskblur(this,"<?php echo addslashes($GLOBALS['gbl_mask_product_id
']); ?>")'
327 <td valign
='top' nowrap
><b
><?php
xl('On Order','e'); ?
>:</b
></td
>
329 <input type
='text' size
='5' name
='form_on_order' maxlength
='7' value
='<?php echo $row['on_order
'] ?>' />
334 <td valign
='top' nowrap
><b
><?php
xl('Reorder At','e'); ?
>:</b
></td
>
336 <input type
='text' size
='5' name
='form_reorder_point' maxlength
='7' value
='<?php echo $row['reorder_point
'] ?>' />
340 <tr
class='drugsonly'>
341 <td valign
='top' nowrap
><b
><?php
xl('Form','e'); ?
>:</b
></td
>
344 generate_form_field(array('data_type'=>1,'field_id'=>'form','list_id'=>'drug_form','empty_title'=>'SKIP'), $row['form']);
349 <tr
class='drugsonly'>
350 <td valign
='top' nowrap
><b
><?php
xl('Pill Size','e'); ?
>:</b
></td
>
352 <input type
='text' size
='5' name
='form_size' maxlength
='7' value
='<?php echo $row['size
'] ?>' />
356 <tr
class='drugsonly'>
357 <td valign
='top' nowrap
><b
><?php
xl('Units','e'); ?
>:</b
></td
>
360 generate_form_field(array('data_type'=>1,'field_id'=>'unit','list_id'=>'drug_units','empty_title'=>'SKIP'), $row['unit']);
365 <tr
class='drugsonly'>
366 <td valign
='top' nowrap
><b
><?php
xl('Route','e'); ?
>:</b
></td
>
369 generate_form_field(array('data_type'=>1,'field_id'=>'route','list_id'=>'drug_route','empty_title'=>'SKIP'), $row['route']);
374 <tr
class='ippfonly'>
375 <td valign
='top' nowrap
><b
><?php
xl('CYP Factor','e'); ?
>:</b
></td
>
377 <input type
='text' size
='10' name
='form_cyp_factor' maxlength
='20' value
='<?php echo $row['cyp_factor
'] ?>' />
382 <td valign
='top' nowrap
><b
><?php
xl('Relate To','e'); ?
>:</b
></td
>
384 <input type
='text' size
='50' name
='form_related_code'
385 value
='<?php echo $row['related_code
'] ?>' onclick
='sel_related()'
386 title
='<?php xl('Click to select related code
','e
'); ?>'
387 style
='width:100%' readonly
/>
392 <td valign
='top' nowrap
>
393 <b
><?php
$GLOBALS['sell_non_drug_products'] == 2 ?
xl('Fees','e') : xl('Templates','e'); ?
>:</b
>
396 <table border
='0' width
='100%'>
398 <td
class='drugsonly'><b
><?php
xl('Name' ,'e'); ?
></b
></td
>
399 <td
class='drugsonly'><b
><?php
xl('Schedule','e'); ?
></b
></td
>
400 <td
class='drugsonly'><b
><?php
xl('Interval','e'); ?
></b
></td
>
401 <td
class='drugsonly'><b
><?php
xl('Qty' ,'e'); ?
></b
></td
>
402 <td
class='drugsonly'><b
><?php
xl('Refills' ,'e'); ?
></b
></td
>
404 // Show a heading for each price level. Also create an array of prices
405 // for new template lines.
406 $emptyPrices = array();
407 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
408 "WHERE list_id = 'pricelevel' ORDER BY seq");
409 while ($prow = sqlFetchArray($pres)) {
410 $emptyPrices[$prow['option_id']] = '';
412 generate_display_field(array('data_type'=>'1','list_id'=>'pricelevel'), $prow['option_id']) .
415 // Show a heading for each tax rate.
416 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
417 "WHERE list_id = 'taxrate' ORDER BY seq");
418 while ($prow = sqlFetchArray($pres)) {
420 generate_display_field(array('data_type'=>'1','list_id'=>'taxrate'), $prow['option_id']) .
426 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ?
1 : 3;
428 while ($trow = sqlFetchArray($tres)) {
429 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ?
0 : 1;
430 $selector = $trow['selector'];
431 // Get array of prices.
433 $pres = sqlStatement("SELECT lo.option_id, p.pr_price " .
434 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
435 "p.pr_id = '$drug_id' AND p.pr_selector = '$selector' AND " .
436 "p.pr_level = lo.option_id " .
437 "WHERE list_id = 'pricelevel' ORDER BY lo.seq");
438 while ($prow = sqlFetchArray($pres)) {
439 $prices[$prow['option_id']] = $prow['pr_price'];
441 writeTemplateLine($selector, $trow['dosage'], $trow['period'],
442 $trow['quantity'], $trow['refills'], $prices, $trow['taxrates']);
445 for ($i = 0; $i < $blank_lines; ++
$i) {
446 $selector = $GLOBALS['sell_non_drug_products'] == 2 ?
$row['name'] : '';
447 writeTemplateLine($selector, '', '', '', '', $emptyPrices, '');
457 <input type
='submit' name
='form_save' value
='<?php xl('Save
','e
'); ?>' />
459 <?php
if (acl_check('admin', 'super')) { ?
>
461 <input type
='submit' name
='form_delete' value
='<?php xl('Delete
','e
'); ?>' style
='color:red' />
465 <input type
='button' value
='<?php xl('Cancel
','e
'); ?>' onclick
='window.close()' />
472 <script language
="JavaScript">
475 echo "alert('" . htmlentities($alertmsg) . "');\n";