preparing for 5.0.1 release in several weeks (#1509)
[openemr.git] / interface / forms / fee_sheet / new.php
blobd5c0f3fd835cc9c9fa8ca5e8a1cf9f703bbc48c9
1 <?php
2 /**
3 * Fee Sheet Program used to create charges, copays and add diagnosis codes to the encounter
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Terry Hill <terry@lillysystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2005-2016 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once("../../globals.php");
17 require_once("$srcdir/FeeSheetHtml.class.php");
18 require_once("codes.php");
20 //acl check
21 if (!acl_check_form('fee_sheet')) {
23 <script>alert('<?php echo xls("Not authorized"); ?>')</script>;
24 <?php
25 formJump();
28 // Some table cells will not be displayed unless insurance billing is used.
29 $usbillstyle = $GLOBALS['ippf_specific'] ? " style='display:none'" : "";
30 $justifystyle = justifiers_are_used() ? "" : " style='display:none'";
32 $liprovstyle = (isset($GLOBALS['support_fee_sheet_line_item_provider']) &&
33 $GLOBALS['support_fee_sheet_line_item_provider'] != 1) ? " style='display:none'" : "";
35 // This flag comes from the LBFmsivd form and perhaps later others.
36 $rapid_data_entry = empty($_GET['rde']) ? 0 : 1;
38 // This comes from the Add More Items button, or is preserved from its previous value.
39 $add_more_items = (empty($_GET['addmore']) && empty($_POST['bn_addmore'])) ? 0 : 1;
41 $alertmsg = '';
43 // Determine if more than one price level is in use.
44 $tmp = sqlQuery("SELECT COUNT(*) AS count FROM list_options where list_id = 'pricelevel' AND activity = 1");
45 $price_levels_are_used = $tmp['count'] > 1;
46 // For revenue codes
47 $institutional = $GLOBALS['ub04_support'] == "1" ? true : false;
48 // Format a money amount with decimals but no other decoration.
49 // Second argument is used when extra precision is required.
50 function formatMoneyNumber($value, $extradecimals = 0)
52 return sprintf('%01.' . ($GLOBALS['currency_decimals'] + $extradecimals) . 'f', $value);
55 // Helper function for creating drop-lists.
56 function endFSCategory()
58 global $i, $last_category, $FEE_SHEET_COLUMNS;
59 if (! $last_category) {
60 return;
63 echo " </select>\n";
64 echo " </td>\n";
65 if ($i >= $FEE_SHEET_COLUMNS) {
66 echo " </tr>\n";
67 $i = 0;
71 // Generate JavaScript to build the array of diagnoses.
72 function genDiagJS($code_type, $code)
74 global $code_types;
75 if ($code_types[$code_type]['diag']) {
76 echo "diags.push('" . attr($code_type) . "|" . attr($code) . "');\n";
80 // Write all service lines to the web form.
82 function echoServiceLines()
84 global $code_types, $justinit, $usbillstyle, $liprovstyle, $justifystyle, $fs, $price_levels_are_used, $institutional;
86 foreach ($fs->serviceitems as $lino => $li) {
87 $id = $li['hidden']['id'];
88 $codetype = $li['hidden']['code_type'];
89 $code = $li['hidden']['code'];
90 if ($institutional) {
91 $revenue_code = $li['hidden']['revenue_code'];
93 $modifier = $li['hidden']['mod'];
94 $billed = $li['hidden']['billed'];
95 $ndc_info = isset($li['ndc_info']) ? $li['ndc_info'] : '';
96 $pricelevel = $li['pricelevel'];
97 $justify = $li['justify'];
99 $strike1 = $li['del'] ? "<strike>" : "";
100 $strike2 = $li['del'] ? "</strike>" : "";
102 echo " <tr>\n";
104 echo " <td class='billcell'>$strike1" .
105 ($codetype == 'COPAY' ? xl($codetype) : text($codetype)) . $strike2;
106 // if the line to ouput is copay, show the date here passed as $ndc_info,
107 // since this variable is not applicable in the case of copay.
108 if ($codetype == 'COPAY') {
109 echo "(" . text($ndc_info) . ")";
110 $ndc_info = '';
113 if ($id) {
114 echo "<input type='hidden' name='bill[" . attr($lino) . "][id]' value='" . attr($id) . "' />";
117 echo "<input type='hidden' name='bill[" . attr($lino) . "][code_type]' value='" . attr($codetype) . "' />";
118 echo "<input type='hidden' name='bill[" . attr($lino) . "][code]' value='" . attr($code) . "' />";
119 echo "<input type='hidden' name='bill[" . attr($lino)."][billed]' value='" . attr($billed)."' />";
120 if (isset($li['hidden']['method'])) {
121 echo "<input type='hidden' name='bill[$lino][method]' value='" . attr($li['hidden']['method' ]) . "' />";
122 echo "<input type='hidden' name='bill[$lino][cyp]' value='" . attr($li['hidden']['cyp' ]) . "' />";
123 echo "<input type='hidden' name='bill[$lino][methtype]' value='" . attr($li['hidden']['methtype']) . "' />";
126 echo "</td>\n";
128 if ($codetype != 'COPAY') {
129 echo " <td class='billcell'>$strike1" . text($code) . "$strike2</td>\n";
130 } else {
131 echo " <td class='billcell'>&nbsp;</td>\n";
134 echo " <td class='billcell'>$strike1" . text($li['code_text']) . "$strike2</td>\n";
136 if ($billed) {
137 if ($institutional) {
138 echo " <td class='billcell'>$strike1" . text($revenue_code) . "$strike2" .
139 "<input type='hidden' name='bill[" . attr($lino) . "][revenue_code]' value='" . attr($revenue_code) . "'></td>\n";
142 if (modifiers_are_used(true)) {
143 echo " <td class='billcell'>$strike1" . text($modifier) . "$strike2" .
144 "<input type='hidden' name='bill[" . attr($lino) . "][mod]' value='" . attr($modifier) . "'></td>\n";
147 if (fees_are_used()) {
148 if ($price_levels_are_used) {
149 // Show price level for this line.
150 echo " <td class='billcell' align='center'>";
151 echo $fs->genPriceLevelSelect('', ' ', $li['hidden']['codes_id'], '', $pricelevel, true);
152 echo "</td>\n";
155 echo " <td class='billcell' align='right'>" . text(oeFormatMoney($li['price'])) . "</td>\n";
156 if ($codetype != 'COPAY') {
157 echo " <td class='billcell' align='center'>" . text($li['units']) . "</td>\n";
158 } else {
159 echo " <td class='billcell'>&nbsp;</td>\n";
162 echo " <td class='billcell' align='center'$justifystyle>$justify</td>\n";
165 // Show provider for this line.
166 echo " <td class='billcell' align='center' $liprovstyle>";
167 echo $fs->genProviderSelect('', '-- ' .xl("Default"). ' --', $li['provid'], true);
168 echo "</td>\n";
170 if ($code_types[$codetype]['claim'] && !$code_types[$codetype]['diag']) {
171 echo " <td class='billcell' align='center'$usbillstyle>" .
172 text($li['notecodes']) . "</td>\n";
173 } else {
174 echo " <td class='billcell' align='center'$usbillstyle></td>\n";
177 echo " <td class='billcell' align='center'$usbillstyle><input type='checkbox'" .
178 ($li['auth'] ? " checked" : "") . " disabled /></td>\n";
180 if ($GLOBALS['gbl_auto_create_rx']) {
181 echo " <td class='billcell' align='center'>&nbsp;</td>\n";
184 echo " <td class='billcell' align='center'><input type='checkbox'" .
185 " disabled /></td>\n";
186 } else { // not billed
187 if ($institutional) {
188 if ($codetype != 'COPAY' && $codetype != 'ICD10') {
189 echo " <td class='billcell'><input type='text' class='revcode' name='bill[" . attr($lino) . "][revenue_code]' " .
190 "title='" . xla("Revenue Code for this item. Type for hints/search") . "' " .
191 "value='" . attr($revenue_code) . "' size='4'></td>\n";
192 } else {
193 echo " <td class='billcell'>&nbsp;</td>\n";
196 if (modifiers_are_used(true)) {
197 if ($codetype != 'COPAY' && ($code_types[$codetype]['mod'] || $modifier)) {
198 echo " <td class='billcell'><input type='text' name='bill[" . attr($lino) . "][mod]' " .
199 "title='" . xla("Multiple modifiers can be separated by colons or spaces, maximum of 4 (M1:M2:M3:M4)") . "' " .
200 "value='" . attr($modifier) . "' size='" . attr($code_types[$codetype]['mod']) . "'></td>\n";
201 } else {
202 echo " <td class='billcell'>&nbsp;</td>\n";
206 if (fees_are_used()) {
207 if ($codetype == 'COPAY' || $code_types[$codetype]['fee'] || $fee != 0) {
208 if ($price_levels_are_used) {
209 echo " <td class='billcell' align='center'>";
210 echo $fs->genPriceLevelSelect("bill[$lino][pricelevel]", ' ', $li['hidden']['codes_id'], '', $pricelevel);
211 echo "</td>\n";
214 echo " <td class='billcell' align='right'>" .
215 "<input type='text' name='bill[$lino][price]' " .
216 "value='" . attr($li['price']) . "' size='6' onchange='setSaveAndClose()'";
217 if (acl_check('acct', 'disc')) {
218 echo " style='text-align:right'";
219 } else {
220 echo " style='text-align:right;background-color:transparent' readonly";
223 echo "></td>\n";
225 echo " <td class='billcell' align='center'>";
226 if ($codetype != 'COPAY') {
227 echo "<input type='text' name='bill[" . attr($lino) . "][units]' " .
228 "value='" . attr($li['units']) . "' size='2' style='text-align:right'>";
229 } else {
230 echo "<input type='hidden' name='bill[" . attr($lino) . "][units]' value='" . attr($li['units']) . "'>";
233 echo "</td>\n";
235 if ($code_types[$codetype]['just'] || $li['justify']) {
236 echo " <td class='billcell' align='center'$justifystyle>";
237 echo "<select name='bill[" . attr($lino) . "][justify]' onchange='setJustify(this)'>";
238 echo "<option value='" . attr($li['justify']) . "'>" . text($li['justify']) . "</option></select>";
239 echo "</td>\n";
240 $justinit .= "setJustify(f['bill[" . attr($lino) . "][justify]']);\n";
241 } else {
242 echo " <td class='billcell'$justifystyle>&nbsp;</td>\n";
244 } else {
245 if ($price_levels_are_used) {
246 echo " <td class='billcell'>&nbsp;</td>\n";
249 echo " <td class='billcell'>&nbsp;</td>\n";
250 echo " <td class='billcell'>&nbsp;</td>\n";
251 echo " <td class='billcell'$justifystyle>&nbsp;</td>\n"; // justify
255 // Provider drop-list for this line.
256 echo " <td class='billcell' align='center' $liprovstyle>";
257 echo $fs->genProviderSelect("bill[$lino][provid]", '-- '.xl("Default").' --', $li['provid']);
258 echo "</td>\n";
260 if ($code_types[$codetype]['claim'] && !$code_types[$codetype]['diag']) {
261 echo " <td class='billcell' align='center'$usbillstyle><input type='text' name='bill[" . attr($lino) . "][notecodes]' " .
262 "value='" . text($li['notecodes']) . "' maxlength='10' size='8' /></td>\n";
263 } else {
264 echo " <td class='billcell' align='center'$usbillstyle></td>\n";
267 echo " <td class='billcell' align='center'$usbillstyle><input type='checkbox' name='bill[".attr($lino) . "][auth]' " .
268 "value='1'" . ($li['auth'] ? " checked" : "") . " /></td>\n";
270 if ($GLOBALS['gbl_auto_create_rx']) {
271 echo " <td class='billcell' align='center'>&nbsp;</td>\n"; // KHY: May need to confirm proper location of this cell
274 echo " <td class='billcell' align='center'><input type='checkbox' name='bill[" . attr($lino) . "][del]' " .
275 "value='1'" . ($li['del'] ? " checked" : "") . " /></td>\n";
278 echo " </tr>\n";
280 // If NDC info exists or may be required, add a line for it.
281 if (isset($li['ndcnum'])) {
282 echo " <tr>\n";
283 echo " <td class='billcell' colspan='2'>&nbsp;</td>\n";
284 echo " <td class='billcell' colspan='6'>&nbsp;NDC:&nbsp;";
285 echo "<input type='text' name='bill[" . attr($lino) . "][ndcnum]' value='" . attr($li['ndcnum']) . "' " .
286 "size='11' style='background-color:transparent'>";
287 echo " &nbsp;Qty:&nbsp;";
288 echo "<input type='text' name='bill[" . attr($lino) . "][ndcqty]' value='" . attr($li['ndcqty']) . "' " .
289 "size='3' style='background-color:transparent;text-align:right'>";
290 echo " ";
291 echo "<select name='bill[" . attr($lino) . "][ndcuom]' style='background-color:transparent'>";
292 foreach ($fs->ndc_uom_choices as $key => $value) {
293 echo "<option value='" . attr($key) . "'";
294 if ($key == $li['ndcuom']) {
295 echo " selected";
298 echo ">" . text($value) . "</option>";
301 echo "</select>";
302 echo "</td>\n";
303 echo " </tr>\n";
304 } else if (!empty($li['ndc_info'])) {
305 echo " <tr>\n";
306 echo " <td class='billcell' colspan='2'>&nbsp;</td>\n";
307 echo " <td class='billcell' colspan='6'>&nbsp;" . xlt("NDC Data") . ": " . text($li['ndc_info']) . "</td>\n";
308 echo " </tr>\n";
313 // Write all product lines to the web form.
315 function echoProductLines()
317 global $code_types, $usbillstyle, $liprovstyle, $justifystyle, $fs, $price_levels_are_used;
319 foreach ($fs->productitems as $lino => $li) {
320 $drug_id = $li['hidden']['drug_id'];
321 $selector = $li['hidden']['selector'];
322 $sale_id = $li['hidden']['sale_id'];
323 $billed = $li['hidden']['billed'];
324 $fee = $li['fee'];
325 $price = $li['price'];
326 $pricelevel = $li['pricelevel'];
327 $units = $li['units'];
328 $del = $li['del'];
329 $warehouse_id = $li['warehouse'];
330 $rx = $li['rx'];
332 $strike1 = ($sale_id && $del) ? "<strike>" : "";
333 $strike2 = ($sale_id && $del) ? "</strike>" : "";
335 echo " <tr>\n";
336 echo " <td class='billcell'>{$strike1}" . xlt("Product") . "$strike2";
337 echo "<input type='hidden' name='prod[" . attr($lino) . "][sale_id]' value='" . attr($sale_id) . "'>";
338 echo "<input type='hidden' name='prod[" . attr($lino) . "][drug_id]' value='" . attr($drug_id) . "'>";
339 echo "<input type='hidden' name='prod[" . attr($lino) . "][selector]' value='" . attr($selector) . "'>";
340 echo "<input type='hidden' name='prod[" . attr($lino) . "][billed]' value='" . attr($billed) . "'>";
341 if (isset($li['hidden']['method'])) {
342 echo "<input type='hidden' name='prod[$lino][method]' value='" . attr($li['hidden']['method' ]) . "' />";
343 echo "<input type='hidden' name='prod[$lino][methtype]' value='" . attr($li['hidden']['methtype']) . "' />";
346 echo "</td>\n";
348 echo " <td class='billcell'>$strike1" . text($drug_id) . "$strike2</td>\n";
350 echo " <td class='billcell'>$strike1" . text($li['code_text']) . "$strike2</td>\n";
352 if (modifiers_are_used(true)) {
353 echo " <td class='billcell'>&nbsp;</td>\n";
356 if ($billed) {
357 if (fees_are_used()) {
358 if ($price_levels_are_used) {
359 echo " <td class='billcell' align='center'>";
360 echo $fs->genPriceLevelSelect('', ' ', $drug_id, $selector, $pricelevel, true);
361 echo "</td>\n";
364 echo " <td class='billcell' align='right'>" . text(oeFormatMoney($price)) . "</td>\n";
365 echo " <td class='billcell' align='center'>" . text($units) . "</td>\n";
368 if (justifiers_are_used()) { // KHY Evaluate proper position/usage of if justifiers
369 echo " <td class='billcell' align='center'$justifystyle>&nbsp;</td>\n"; // justify
372 // Show warehouse for this line.
373 echo " <td class='billcell' align='center' $liprovstyle>";
374 echo $fs->genWarehouseSelect('', ' ', $warehouse_id, true, $drug_id, $sale_id > 0);
375 echo "</td>\n";
377 echo " <td class='billcell' align='center'$usbillstyle>&nbsp;</td>\n"; // note codes
378 echo " <td class='billcell' align='center'$usbillstyle>&nbsp;</td>\n"; // auth
379 if ($GLOBALS['gbl_auto_create_rx']) {
380 echo " <td class='billcell' align='center'><input type='checkbox'" . // rx
381 " disabled /></td>\n";
384 echo " <td class='billcell' align='center'><input type='checkbox'" . // del
385 " disabled /></td>\n";
386 } else { // not billed
387 if (fees_are_used()) {
388 if ($price_levels_are_used) {
389 echo " <td class='billcell' align='center'>";
390 echo $fs->genPriceLevelSelect("prod[$lino][pricelevel]", ' ', $drug_id, $selector, $pricelevel);
391 echo "</td>\n";
394 echo " <td class='billcell' align='right'>" .
395 "<input type='text' name='prod[" . attr($lino) . "][price]' " .
396 "value='" . attr($price) . "' size='6' onchange='setSaveAndClose()'";
397 if (acl_check('acct', 'disc')) {
398 echo " style='text-align:right'";
399 } else {
400 echo " style='text-align:right;background-color:transparent' readonly";
403 echo "></td>\n";
404 echo " <td class='billcell' align='center'>";
405 echo "<input type='text' name='prod[" . attr($lino) . "][units]' " .
406 "value='" . attr($units) . "' size='2' style='text-align:right'>";
407 echo "</td>\n";
410 if (justifiers_are_used()) {
411 echo " <td class='billcell'$justifystyle>&nbsp;</td>\n"; // justify
414 // Generate warehouse selector if there is a choice of warehouses.
415 echo " <td class='billcell' align='center' $liprovstyle>";
416 echo $fs->genWarehouseSelect("prod[$lino][warehouse]", ' ', $warehouse_id, false, $drug_id, $sale_id > 0);
417 echo "</td>\n";
419 echo " <td class='billcell' align='center'$usbillstyle>&nbsp;</td>\n"; // note codes
420 echo " <td class='billcell' align='center'$usbillstyle>&nbsp;</td>\n"; // auth
421 if ($GLOBALS['gbl_auto_create_rx']) {
422 echo " <td class='billcell' align='center'>" .
423 "<input type='checkbox' name='prod[$lino][rx]' value='1'" .
424 ($rx ? " checked" : "") . " /></td>\n";
427 echo " <td class='billcell' align='center'><input type='checkbox' name='prod[" . attr($lino) . "][del]' " .
428 "value='1'" . ($del ? " checked" : "") . " /></td>\n";
431 echo " </tr>\n";
435 $fs = new FeeSheetHtml();
437 // $FEE_SHEET_COLUMNS should be defined in codes.php.
438 if (empty($FEE_SHEET_COLUMNS)) {
439 $FEE_SHEET_COLUMNS = 2;
442 // Update price level in patient demographics if it's changed.
443 if (!empty($_POST['pricelevel'])) {
444 $fs->updatePriceLevel($_POST['pricelevel']);
447 $current_checksum = $fs->visitChecksum();
448 // It's important to look for a checksum mismatch even if we're just refreshing
449 // the display, otherwise the error goes undetected on a refresh-then-save.
450 if (isset($_POST['form_checksum'])) {
451 if ($_POST['form_checksum'] != $current_checksum) {
452 $alertmsg = xl('Someone else has just changed this visit. Please cancel this page and try again.');
453 $comment = "CHECKSUM ERROR, expecting '{$_POST['form_checksum']}'";
454 newEvent("checksum", $_SESSION['authUser'], $_SESSION['authProvider'], 1, $comment, $pid);
458 if (!$alertmsg && ($_POST['bn_save'] || $_POST['bn_save_close'])) {
459 $alertmsg = $fs->checkInventory($_POST['prod']);
462 // If Save or Save-and-Close was clicked, save the new and modified billing
463 // lines; then if no error, redirect to $GLOBALS['form_exit_url'].
465 if (!$alertmsg && ($_POST['bn_save'] || $_POST['bn_save_close'] || $_POST['bn_save_stay'])) {
466 $main_provid = 0 + $_POST['ProviderID'];
467 $main_supid = 0 + (int)$_POST['SupervisorID'];
469 $fs->save(
470 $_POST['bill'],
471 $_POST['prod'],
472 $main_provid,
473 $main_supid,
474 $_POST['default_warehouse'],
475 $_POST['bn_save_close']
478 if ($_POST['bn_save_stay']) {
479 $current_checksum = $fs->visitChecksum();
482 // Note: Taxes are computed at checkout time (in pos_checkout.php which
483 // also posts to SL). Currently taxes with insurance claims make no sense,
484 // so for now we'll ignore tax computation in the insurance billing logic.
486 if ($_POST['running_as_ajax']) {
487 // In the case of running as an AJAX handler, we need to return this same
488 // form with an updated checksum to properly support the invoking logic.
489 // See review/js/fee_sheet_core.js for that logic.
490 $current_checksum = $fs->visitChecksum(true);
491 // Also remove form data for the newly entered lines so they are not
492 // duplicated from the database.
493 unset($_POST['bill']);
494 unset($_POST['prod']);
495 } elseif (!isset($_POST['bn_save_stay'])) { // not running as ajax
496 // If appropriate, update the status of the related appointment to
497 // "In exam room".
498 updateAppointmentStatus($fs->pid, $fs->visit_date, '<');
500 // More Family Planning stuff.
501 if (isset($_POST['ippfconmeth'])) {
502 $tmp_form_id = $fs->doContraceptionForm($_POST['ippfconmeth'], $_POST['newmauser'], $main_provid);
503 if ($tmp_form_id) {
504 // Contraceptive method does not match what is in an existing Contraception
505 // form for this visit, or there is no such form. Open the form.
506 formJump("{$GLOBALS['rootdir']}/patient_file/encounter/view_form.php" .
507 "?formname=LBFccicon&id=" . ($tmp_form_id < 0 ? 0 : $tmp_form_id));
508 formFooter();
509 exit;
513 if ($rapid_data_entry || ($_POST['bn_save_close'] && $_POST['form_has_charges'])) {
514 // In rapid data entry mode or if "Save and Checkout" was clicked,
515 // we go directly to the Checkout page.
516 formJump("{$GLOBALS['rootdir']}/patient_file/pos_checkout.php?framed=1" .
517 "&ptid={$fs->pid}&enid={$fs->encounter}&rde=$rapid_data_entry");
518 } else {
519 // Otherwise return to the normal encounter summary frameset.
521 formHeader("Redirecting....");
522 formJump();
525 formFooter();
526 exit;
527 } // end not running as ajax
528 } // end save or save-and-close
530 // Handle reopen request. In that case no other changes will be saved.
531 // If there was a checkout this will undo it.
532 if (!$alertmsg && $_POST['bn_reopen']) {
533 doVoid($fs->pid, $fs->encounter, true);
534 $current_checksum = $fs->visitChecksum();
535 // Remove the line items so they are refreshed from the database on redisplay.
536 unset($_POST['bill']);
537 unset($_POST['prod']);
540 $billresult = getBillingByEncounter($fs->pid, $fs->encounter, "*");
542 <html>
543 <head>
544 <?php html_header_show(); ?>
545 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
546 <style>
547 .billcell { font-family: sans-serif; font-size: 10pt }
548 .ui-autocomplete { max-height: 250px; max-width: 350px; overflow-y: auto; overflow-x: hidden; }
549 </style>
550 <link href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-ui-1-12-1/themes/base/jquery-ui.min.css" rel="stylesheet" type="text/css" />
551 <script type="text/JavaScript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
552 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/knockout-3-4-0/dist/knockout.js"></script>
553 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative'] ?>/jquery-ui-1-12-1/jquery-ui.min.js"></script>
554 <script type="text/javascript" src="../../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
555 <script type="text/javascript" src="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
557 <script>
558 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
559 var diags = new Array();
561 <?php
562 if ($billresult) {
563 foreach ($billresult as $iter) {
564 genDiagJS($iter["code_type"], trim($iter["code"]));
568 if ($_POST['bill']) {
569 foreach ($_POST['bill'] as $iter) {
570 if ($iter["del"]) {
571 continue; // skip if Delete was checked
574 if ($iter["id"]) {
575 continue; // skip if it came from the database
578 genDiagJS($iter["code_type"], $iter["code"]);
582 if ($_POST['newcodes']) {
583 $arrcodes = explode('~', $_POST['newcodes']);
584 foreach ($arrcodes as $codestring) {
585 if ($codestring === '') {
586 continue;
589 $arrcode = explode('|', $codestring);
590 list($code, $modifier) = explode(":", $arrcode[1]);
591 genDiagJS($arrcode[0], $code);
595 function reinitForm(){
596 var cache = {};
597 $( ".revcode" ).autocomplete({
598 minLength: 1,
599 source: function( request, response ) {
600 var term = request.term;
601 request.code_group = "revenue_code";
602 if ( term in cache ) {
603 response( cache[ term ] );
604 return;
606 $.getJSON( "<?php echo $GLOBALS['web_root'] ?>/interface/billing/ub04_helpers.php", request, function( data, status, xhr ) {
607 cache[ term ] = data;
608 response( data );
611 }).dblclick(function(event) {
612 $(this).autocomplete('search'," ");
616 // This is invoked by <select onchange> for the various dropdowns,
617 // including search results.
618 function codeselect(selobj) {
619 var i = selobj ? selobj.selectedIndex : -1;
620 if (i) {
621 top.restoreSession();
622 var f = document.forms[0];
623 if (selobj) f.newcodes.value = selobj.options[i].value;
624 f.submit();
628 function copayselect() {
629 top.restoreSession();
630 var f = document.forms[0];
631 f.newcodes.value = 'COPAY||';
632 f.submit();
635 <?php echo $fs->jsLineItemValidation(); ?>
637 function validate(f) {
638 if (f.bn_reopen) {
639 var reopening = f.bn_reopen.clicked;
640 var voiding = reopening && f.bn_reopen.clicked == 2;
641 f.bn_reopen.clicked = false;
642 if (reopening) {
643 if (voiding) {
644 if (!confirm('<?php echo xls('Re-opening this visit will cause a void. Payment information will need to be re-entered. Do you want to proceed?'); ?>')) {
645 return false;
648 top.restoreSession();
649 return true;
652 var refreshing = false;
653 if (f.bn_refresh) {
654 refreshing = f.bn_refresh.clicked ? true : false;
655 f.bn_refresh.clicked = false;
657 if (f.bn_addmore) {
658 refreshing = refreshing || f.bn_addmore.clicked;
659 f.bn_addmore.clicked = false;
661 var searching = false;
662 if (f.bn_search) {
663 searching = f.bn_search.clicked ? true : false;
664 f.bn_search.clicked = false;
666 if (!refreshing && !searching) {
667 if (!jsLineItemValidation(f)) return false;
669 top.restoreSession();
670 return true;
673 // When a justify selection is made, apply it to the current list for
674 // this procedure and then rebuild its selection list.
676 function setJustify(seljust) {
677 var theopts = seljust.options;
678 var jdisplay = theopts[0].text;
679 // Compute revised justification string. Note this does nothing if
680 // the first entry is still selected, which is handy at startup.
681 if (seljust.selectedIndex > 0) {
682 var newdiag = seljust.value;
683 if (newdiag.length == 0) {
684 jdisplay = '';
686 else {
687 if (jdisplay.length) jdisplay += ',';
688 jdisplay += newdiag;
691 // Rebuild selection list.
692 var jhaystack = ',' + jdisplay + ',';
693 var j = 0;
694 theopts.length = 0;
695 theopts[j++] = new Option(jdisplay,jdisplay,true,true);
696 for (var i = 0; i < diags.length; ++i) {
697 if (jhaystack.indexOf(',' + diags[i] + ',') < 0) {
698 theopts[j++] = new Option(diags[i],diags[i],false,false);
701 theopts[j++] = new Option('Clear','',false,false);
704 // Determine if there are any charges in this visit.
705 function hasCharges() {
706 var f = document.forms[0];
707 for (var i = 0; i < f.elements.length; ++i) {
708 var elem = f.elements[i];
709 if (elem.name.indexOf('[price]') > 0) {
710 var fee = Number(elem.value);
711 if (!isNaN(fee) && fee != 0) return true;
714 return false;
717 // Function to check if there are any charges in the form, and to enable
718 // or disable the Save and Close button accordingly.
720 function setSaveAndClose() {
721 var f = document.forms[0];
722 if (!f.bn_save_close) return;
723 if (hasCharges()) {
724 f.form_has_charges.value = '1';
725 f.bn_save_close.value = '<?php echo xla('Save and Checkout'); ?>';
727 else {
728 f.form_has_charges.value = '0';
729 f.bn_save_close.value = '<?php echo xla('Save and Close'); ?>';
733 // Open the add-event dialog.
734 function newEvt() {
735 var f = document.forms[0];
736 var url = '../../main/calendar/add_edit_event.php?patientid=<?php echo urlencode($fs->pid); ?>';
737 if (f.ProviderID && f.ProviderID.value) {
738 url += '&userid=' + parseInt(f.ProviderID.value);
740 dlgopen(url, '_blank', 600, 300);
741 return false;
744 function warehouse_changed(sel) {
745 if (!confirm('<?php echo xls('Do you really want to change Warehouse?'); ?>')) {
746 // They clicked Cancel so reset selection to its default state.
747 for (var i = 0; i < sel.options.length; ++i) {
748 sel.options[i].selected = sel.options[i].defaultSelected;
753 // Invoked when a line item price level is changed.
754 function pricelevel_changed(sel) {
755 var f = document.forms[0];
756 var prname = sel.name.replace('pricelevel', 'price');
757 if (f[prname]) {
758 var price = parseFloat(sel.options[sel.selectedIndex].id.substring(4));
759 if (isNaN(price)) price = 0;
760 f[prname].value = price;
762 else {
763 alert('<?php echo xls('Form element not found'); ?>: ' + prname);
767 </script>
769 </head>
771 <body class="body_top">
772 <form method="post" action="<?php echo $rootdir; ?>/forms/fee_sheet/new.php?<?php
773 echo "rde=" . urlencode($rapid_data_entry) . "&addmore=" . urlencode($add_more_items); ?>"
774 onsubmit="return validate(this)">
775 <span class="title"><?php echo xlt('Fee Sheet'); ?></span><br>
776 <input type='hidden' name='newcodes' value=''>
778 <center>
780 <?php
781 $isBilled = !$add_more_items && isEncounterBilled($fs->pid, $fs->encounter);
782 if ($isBilled) {
783 echo "<p><font color='green'>" .
784 xlt("This encounter has been billed. To make changes, re-open it or select Add More Items.") .
785 "</font></p>\n";
786 } else { // the encounter is not yet billed
789 <table width='95%'>
790 <?php
791 $i = 0;
792 $last_category = '';
794 // Create drop-lists based on the fee_sheet_options table.
795 $res = sqlStatement("SELECT * FROM fee_sheet_options " .
796 "ORDER BY fs_category, fs_option");
797 while ($row = sqlFetchArray($res)) {
798 $fs_category = $row['fs_category'];
799 $fs_option = $row['fs_option'];
800 $fs_codes = $row['fs_codes'];
801 if ($fs_category !== $last_category) {
802 endFSCategory();
803 $last_category = $fs_category;
804 ++$i;
805 echo ($i <= 1) ? " <tr>\n" : "";
806 echo " <td width='50%' align='center' nowrap>\n";
807 echo " <select style='width:96%' onchange='codeselect(this)'>\n";
808 echo " <option value=''> " . xlt(substr($fs_category, 1)) . "</option>\n";
811 echo " <option value='" . attr($fs_codes) . "'>" . xlt(substr($fs_option, 1)) . "</option>\n";
814 endFSCategory();
816 // Create drop-lists based on categories defined within the codes.
817 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
818 "WHERE list_id = 'superbill' AND activity = 1 ORDER BY seq");
819 while ($prow = sqlFetchArray($pres)) {
820 global $code_types;
821 ++$i;
822 echo ($i <= 1) ? " <tr>\n" : "";
823 echo " <td width='50%' align='center' nowrap>\n";
824 echo " <select style='width:96%' onchange='codeselect(this)'>\n";
825 echo " <option value=''> " . text(xl_list_label($prow['title'])) . "\n";
826 $res = sqlStatement("SELECT code_type, code, code_text,modifier FROM codes " .
827 "WHERE superbill = ? AND active = 1 " .
828 "ORDER BY code_text", array($prow['option_id']));
829 while ($row = sqlFetchArray($res)) {
830 $ctkey = $fs->alphaCodeType($row['code_type']);
831 if ($code_types[$ctkey]['nofs']) {
832 continue;
835 echo " <option value='" . attr($ctkey) . "|" .
836 attr($row['code']) . ':'. attr($row['modifier']) . "|'>" . text($row['code_text']) . "</option>\n";
839 echo " </select>\n";
840 echo " </td>\n";
841 if ($i >= $FEE_SHEET_COLUMNS) {
842 echo " </tr>\n";
843 $i = 0;
847 // Create one more drop-list, for Products.
848 if ($GLOBALS['sell_non_drug_products']) {
849 ++$i;
850 echo ($i <= 1) ? " <tr>\n" : "";
851 echo " <td width='50%' align='center' nowrap>\n";
852 echo " <select name='Products' style='width:96%' onchange='codeselect(this)'>\n";
853 echo " <option value=''> " . xlt('Products') . "\n";
854 $tres = sqlStatement("SELECT dt.drug_id, dt.selector, d.name " .
855 "FROM drug_templates AS dt, drugs AS d WHERE " .
856 "d.drug_id = dt.drug_id AND d.active = 1 AND d.consumable = 0 " .
857 "ORDER BY d.name, dt.selector, dt.drug_id");
858 while ($trow = sqlFetchArray($tres)) {
859 echo " <option value='PROD|" . attr($trow['drug_id']) . '|' . attr($trow['selector']) . "'>";
860 echo text($trow['name']);
861 if ($trow['name'] !== $trow['selector']) {
862 echo ' / ' . text($trow['selector']);
865 echo "</option>\n";
868 echo " </select>\n";
869 echo " </td>\n";
870 if ($i >= $FEE_SHEET_COLUMNS) {
871 echo " </tr>\n";
872 $i = 0;
876 $search_type = $default_search_type;
877 if ($_POST['search_type']) {
878 $search_type = $_POST['search_type'];
881 $ndc_applies = true; // Assume all payers require NDC info.
883 echo $i ? " <td></td>\n </tr>\n" : "";
884 echo " <tr>\n";
885 echo " <td colspan='" . attr($FEE_SHEET_COLUMNS) . "' align='center' nowrap>\n";
887 // If Search was clicked, do it and write the list of results here.
888 // There's no limit on the number of results!
890 $numrows = 0;
891 if ($_POST['bn_search'] && $_POST['search_term']) {
892 $res = main_code_set_search($search_type, $_POST['search_term']);
893 if (!empty($res)) {
894 $numrows = sqlNumRows($res);
898 echo " <select name='Search Results' style='width:98%' " .
899 "onchange='codeselect(this)'";
900 if (! $numrows) {
901 echo ' disabled';
904 echo ">\n";
905 echo " <option value=''> " . xlt("Search Results") . " ($numrows " . xlt("items") . ")\n";
907 if ($numrows) {
908 while ($row = sqlFetchArray($res)) {
909 $code = $row['code'];
910 if ($row['modifier']) {
911 $code .= ":" . $row['modifier'];
914 echo " <option value='" . attr($search_type) . "|" . attr($code) . "|'>" . text($code) . " " .
915 text($row['code_text']) . "</option>\n";
919 echo " </select>\n";
920 echo " </td>\n";
921 echo " </tr>\n";
924 </table>
926 <p style='margin-top:8px;margin-bottom:8px'>
927 <table>
928 <tr>
929 <?php if ($fs->ALLOW_COPAYS) { ?>
930 <td>
931 <input type='button' value='<?php echo xla('Add Copay');?>'
932 onclick="copayselect()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
933 </td>
934 <?php } ?>
935 <td>
936 <?php echo xlt('Search'); ?>&nbsp;
937 </td>
938 <td class='billcell'>
939 <?php
940 $nofs_code_types = array();
941 foreach ($code_types as $key => $value) {
942 if (!empty($value['nofs'])) {
943 continue;
946 $nofs_code_types[$key] = $value;
949 $size_select = (count($nofs_code_types) < 5) ? count($nofs_code_types) : 5;
951 <?php
952 foreach ($nofs_code_types as $key => $value) {
953 echo " <label><input type='radio' name='search_type' value='" . attr($key) . "'";
954 if ($key == $search_type) {
955 echo " checked";
958 echo " />" . xlt($value['label']) . "</label>&nbsp;\n";
961 </td>
962 <td class='billcell'>
963 <?php echo xlt('for'); ?>&nbsp;
964 </td>
965 <td>
966 <input type='text' name='search_term' value=''> &nbsp;
967 </td>
968 <td>
969 <input type='submit' name='bn_search' value='<?php echo xla('Search');?>'
970 onclick='return this.clicked = true;'>
971 </td>
972 </tr>
973 </table>
974 </p>
975 <p style='margin-top:16px;margin-bottom:8px'>
977 <?php } // end encounter not billed ?>
979 <table cellspacing='5'>
980 <?php if ($billresult) { ?>
981 <tr>
982 <td class='billcell'><b><?php echo xlt('Type');?></b></td>
983 <td class='billcell'><b><?php echo xlt('Code');?></b></td>
984 <td class='billcell'><b><?php echo xlt('Description');?></b></td>
985 <?php if ($institutional) { ?>
986 <td class='billcell'><b><?php echo xlt('Revenue');?></b></td>
987 <?php } ?>
988 <?php if (modifiers_are_used(true)) { ?>
989 <td class='billcell'><b><?php echo xlt('Modifiers');?></b></td>
990 <?php } ?>
991 <?php if (fees_are_used()) { ?>
992 <?php if ($price_levels_are_used) { ?>
993 <td class='billcell' align='center'><b><?php echo xlt('Price Level');?></b>&nbsp;</td>
994 <?php } ?>
995 <td class='billcell' align='right'><b><?php echo xlt('Price');?></b>&nbsp;</td>
996 <td class='billcell' align='center'><b><?php echo xlt('Units');?></b></td>
997 <?php } ?>
998 <?php if (justifiers_are_used()) { ?>
999 <td class='billcell' align='center'<?php echo $justifystyle; ?>><b><?php echo xlt('Justify');?></b></td>
1000 <?php } ?>
1001 <td class='billcell' align='center' <?php echo $liprovstyle; ?>><b><?php echo xlt('Provider/Warehouse');?></b></td>
1002 <td class='billcell' align='center'<?php echo $usbillstyle; ?>><b><?php echo xlt('Note Codes');?></b></td>
1003 <td class='billcell' align='center'<?php echo $usbillstyle; ?>><b><?php echo xlt('Auth');?></b></td>
1004 <?php if ($GLOBALS['gbl_auto_create_rx']) { ?>
1005 <td class='billcell' align='center'><b><?php echo xlt('Rx'); ?></b></td>
1006 <?php } ?>
1007 <td class='billcell' align='center'><b><?php echo xlt('Delete');?></b></td>
1008 </tr>
1009 <?php } ?>
1010 <?php
1011 $justinit = "var f = document.forms[0];\n";
1013 // Generate lines for items already in the billing table for this encounter,
1014 // and also set the rendering provider if we come across one.
1016 // $bill_lino = 0;
1017 if ($billresult) {
1018 foreach ($billresult as $iter) {
1019 if (!$ALLOW_COPAYS && $iter["code_type"] == 'COPAY') {
1020 continue;
1023 if ($iter["code_type"] == 'TAX') {
1024 continue;
1027 // ++$bill_lino;
1028 $bill_lino = count($fs->serviceitems);
1029 $bline = $_POST['bill']["$bill_lino"];
1030 $del = $bline['del']; // preserve Delete if checked
1031 if ($institutional) {
1032 $revenue_code = trim($iter["revenue_code"]);
1034 $modifier = trim($iter["modifier"]);
1035 $units = $iter["units"];
1036 $fee = $iter["fee"];
1037 $authorized = $iter["authorized"];
1038 $ndc_info = $iter["ndc_info"];
1039 $justify = trim($iter['justify']);
1040 $notecodes = trim($iter['notecodes']);
1041 if ($justify) {
1042 $justify = substr(str_replace(':', ',', $justify), 0, strlen($justify) - 1);
1045 $provider_id = $iter['provider_id'];
1047 // Also preserve other items from the form, if present.
1048 if ($bline['id'] && !$iter["billed"]) {
1049 if ($institutional) {
1050 //$revenue_code = trim($bline['revenue_code']);
1052 $modifier = trim($bline['mod']);
1053 $units = max(1, intval(trim($bline['units'])));
1054 $fee = formatMoneyNumber((0 + trim($bline['price'])) * $units);
1055 $authorized = $bline['auth'];
1056 $ndc_info = '';
1057 if ($bline['ndcnum']) {
1058 $ndc_info = 'N4' . trim($bline['ndcnum']) . ' ' . $bline['ndcuom'] .
1059 trim($bline['ndcqty']);
1062 $justify = $bline['justify'];
1063 $notecodes = trim($bline['notecodes']);
1064 $provider_id = 0 + (int)$bline['provid'];
1067 if ($iter['code_type'] == 'COPAY') { // moved copay display to below
1068 continue;
1071 $fs->addServiceLineItem(array(
1072 'codetype' => $iter['code_type'],
1073 'code' => trim($iter['code']),
1074 'revenue_code' => $revenue_code,
1075 'modifier' => $modifier,
1076 'ndc_info' => $ndc_info,
1077 'auth' => $authorized,
1078 'del' => $del,
1079 'units' => $units,
1080 'pricelevel' => $iter['pricelevel'],
1081 'fee' => $fee,
1082 'id' => $iter['id'],
1083 'billed' => $iter['billed'],
1084 'code_text' => trim($iter['code_text']),
1085 'justify' => $justify,
1086 'provider_id' => $provider_id,
1087 'notecodes' => $notecodes,
1092 $resMoneyGot = sqlStatement(
1093 "SELECT pay_amount as PatientPay,session_id as id,date(post_time) as date ".
1094 "FROM ar_activity where pid =? and encounter =? and payer_type=0 and account_code='PCP'",
1095 array($fs->pid, $fs->encounter)
1096 ); //new fees screen copay gives account_code='PCP'
1097 while ($rowMoneyGot = sqlFetchArray($resMoneyGot)) {
1098 $PatientPay=$rowMoneyGot['PatientPay']*-1;
1099 $id=$rowMoneyGot['id'];
1100 $fs->addServiceLineItem(array(
1101 'codetype' => 'COPAY',
1102 'code' => '',
1103 'modifier' => '',
1104 'ndc_info' => $rowMoneyGot['date'],
1105 'auth' => 1,
1106 'del' => '',
1107 'units' => '',
1108 'fee' => $PatientPay,
1109 'id' => $id,
1113 // Echo new billing items from this form here, but omit any line
1114 // whose Delete checkbox is checked.
1116 if ($_POST['bill']) {
1117 foreach ($_POST['bill'] as $key => $iter) {
1118 if ($iter["id"]) {
1119 continue; // skip if it came from the database
1122 if ($iter["del"]) {
1123 continue; // skip if Delete was checked
1126 $ndc_info = '';
1127 if ($iter['ndcnum']) {
1128 $ndc_info = 'N4' . trim($iter['ndcnum']) . ' ' . $iter['ndcuom'] .
1129 trim($iter['ndcqty']);
1132 $units = max(1, intval(trim($iter['units'])));
1133 $fee = formatMoneyNumber((0 + trim($iter['price'])) * $units);
1134 //the date is passed as $ndc_info, since this variable is not applicable in the case of copay.
1135 $ndc_info = '';
1136 if ($iter['code_type'] == 'COPAY') {
1137 $ndc_info = date("Y-m-d");
1138 if ($fee > 0) {
1139 $fee = 0 - $fee;
1143 $fs->addServiceLineItem(array(
1144 'codetype' => $iter['code_type'],
1145 'code' => trim($iter['code']),
1146 'revenue_code' => trim($iter['revenue_code']),
1147 'modifier' => trim($iter["mod"]),
1148 'ndc_info' => $ndc_info,
1149 'auth' => $iter['auth'],
1150 'del' => $iter['del'],
1151 'units' => $units,
1152 'fee' => $fee,
1153 'justify' => $iter['justify'],
1154 'provider_id' => $iter['provid'],
1155 'notecodes' => $iter['notecodes'],
1156 'pricelevel' => $iter['pricelevel'],
1161 // Generate lines for items already in the drug_sales table for this encounter.
1163 $query = "SELECT ds.*, di.warehouse_id FROM drug_sales AS ds, drug_inventory AS di WHERE " .
1164 "ds.pid = ? AND ds.encounter = ? AND di.inventory_id = ds.inventory_id " .
1165 "ORDER BY sale_id";
1166 $sres = sqlStatement($query, array($fs->pid, $fs->encounter));
1167 // $prod_lino = 0;
1168 while ($srow = sqlFetchArray($sres)) {
1169 // ++$prod_lino;
1170 $prod_lino = count($fs->productitems);
1171 $pline = $_POST['prod']["$prod_lino"];
1172 $rx = !empty($srow['prescription_id']);
1173 $del = $pline['del']; // preserve Delete if checked
1174 $sale_id = $srow['sale_id'];
1175 $drug_id = $srow['drug_id'];
1176 $selector = $srow['selector'];
1177 $pricelevel = $srow['pricelevel'];
1178 $units = $srow['quantity'];
1179 $fee = $srow['fee'];
1180 $billed = $srow['billed'];
1181 $warehouse_id = $srow['warehouse_id'];
1182 // Also preserve other items from the form, if present and unbilled.
1183 if ($pline['sale_id'] && !$srow['billed']) {
1184 $units = max(1, intval(trim($pline['units'])));
1185 $fee = formatMoneyNumber((0 + trim($pline['price'])) * $units);
1186 $rx = !empty($pline['rx']);
1189 $fs->addProductLineItem(array(
1190 'drug_id' => $drug_id,
1191 'selector' => $selector,
1192 'pricelevel' => $pricelevel,
1193 'rx' => $rx,
1194 'del' => $del,
1195 'units' => $units,
1196 'fee' => $fee,
1197 'sale_id' => $sale_id,
1198 'billed' => $billed,
1199 'warehouse_id' => $warehouse_id,
1203 // Echo new product items from this form here, but omit any line
1204 // whose Delete checkbox is checked.
1206 if ($_POST['prod']) {
1207 foreach ($_POST['prod'] as $key => $iter) {
1208 if ($iter["sale_id"]) {
1209 continue; // skip if it came from the database
1212 if ($iter["del"]) {
1213 continue; // skip if Delete was checked
1216 $units = max(1, intval(trim($iter['units'])));
1217 $fee = formatMoneyNumber((0 + trim($iter['price'])) * $units);
1218 $rx = !empty($iter['rx']); // preserve Rx if checked
1219 $warehouse_id = empty($iter['warehouse_id']) ? '' : $iter['warehouse_id'];
1220 $fs->addProductLineItem(array(
1221 'drug_id' => $iter['drug_id'],
1222 'selector' => $iter['selector'],
1223 'pricelevel' => $iter['pricelevel'],
1224 'rx' => $rx,
1225 'units' => $units,
1226 'fee' => $fee,
1227 'warehouse_id' => $warehouse_id,
1232 // If new billing code(s) were <select>ed, add their line(s) here.
1234 if ($_POST['newcodes'] && !$alertmsg) {
1235 $arrcodes = explode('~', $_POST['newcodes']);
1237 // A first pass here checks for any sex restriction errors.
1238 foreach ($arrcodes as $codestring) {
1239 if ($codestring === '') {
1240 continue;
1243 list($newtype, $newcode) = explode('|', $codestring);
1244 if ($newtype == 'MA') {
1245 list($code, $modifier) = explode(":", $newcode);
1246 $tmp = sqlQuery(
1247 "SELECT sex FROM codes WHERE code_type = ? AND code = ? LIMIT 1",
1248 array($code_types[$newtype]['id'], $code)
1250 if ($tmp['sex'] == '1' && $fs->patient_male || $tmp['sex'] == '2' && !$fs->patient_male) {
1251 $alertmsg = xl('Service is not compatible with the sex of this client.');
1256 if (!$alertmsg) {
1257 foreach ($arrcodes as $codestring) {
1258 if ($codestring === '') {
1259 continue;
1262 $arrcode = explode('|', $codestring);
1263 $newtype = $arrcode[0];
1264 $newcode = $arrcode[1];
1265 $newsel = $arrcode[2];
1266 if ($newtype == 'COPAY') {
1267 $tmp = sqlQuery("SELECT copay FROM insurance_data WHERE pid = ? " .
1268 "AND type = 'primary' ORDER BY date DESC LIMIT 1", array($fs->pid));
1269 $code = formatMoneyNumber(0 + $tmp['copay']);
1270 $fs->addServiceLineItem(array(
1271 'codetype' => $newtype,
1272 'code' => $code,
1273 'ndc_info' => date('Y-m-d'),
1274 'auth' => '1',
1275 'units' => '1',
1276 'fee' => formatMoneyNumber(0 - $code),
1278 } else if ($newtype == 'PROD') {
1279 $result = sqlQuery("SELECT dt.quantity, d.route " .
1280 "FROM drug_templates AS dt, drugs AS d WHERE " .
1281 "dt.drug_id = ? AND dt.selector = ? AND " .
1282 "d.drug_id = dt.drug_id", array($newcode,$newsel));
1283 $units = max(1, intval($result['quantity']));
1284 // By default create a prescription if drug route is set.
1285 $rx = !empty($result['route']);
1286 $fs->addProductLineItem(array(
1287 'drug_id' => $newcode,
1288 'selector' => $newsel,
1289 'rx' => $rx,
1290 'units' => $units,
1292 } else {
1293 list($code, $modifier) = explode(":", $newcode);
1294 $ndc_info = '';
1295 // If HCPCS, find last NDC string used for this code.
1296 if ($newtype == 'HCPCS' && $ndc_applies) {
1297 $tmp = sqlQuery("SELECT ndc_info FROM billing WHERE " .
1298 "code_type = ? AND code = ? AND ndc_info LIKE 'N4%' " .
1299 "ORDER BY date DESC LIMIT 1", array($newtype,$code));
1300 if (!empty($tmp)) {
1301 $ndc_info = $tmp['ndc_info'];
1305 $fs->addServiceLineItem(array(
1306 'codetype' => $newtype,
1307 'code' => $code,
1308 'modifier' => trim($modifier),
1309 'ndc_info' => $ndc_info,
1316 // Write the form's line items.
1317 echoServiceLines();
1318 echoProductLines();
1319 // Ensure DOM is updated.
1320 echo "<script>reinitForm();</script>";
1322 </table>
1323 </p>
1325 <br />
1326 &nbsp;
1328 <?php
1329 // Choose rendering and supervising providers.
1330 echo "<span class='billcell'><b>\n";
1331 echo xlt('Providers') . ": &nbsp;";
1333 echo "&nbsp;&nbsp;" . xlt('Rendering') . "\n";
1334 if ($GLOBALS['default_rendering_provider'] == '0') {
1335 $default_rid = '';
1336 } elseif ($GLOBALS['default_rendering_provider'] == '1') {
1337 $default_rid = $fs->provider_id;
1338 } else {
1339 $default_rid = isset($_SESSION['authUserID']) ? $_SESSION['authUserID'] : $fs->provider_id;
1341 echo $fs->genProviderSelect('ProviderID', '-- ' . xl("Please Select") . ' --', $default_rid, $isBilled);
1343 if (!$GLOBALS['ippf_specific']) {
1344 echo "&nbsp;&nbsp;" . xlt('Supervising') . "\n";
1345 echo $fs->genProviderSelect('SupervisorID', '-- '.xl("N/A").' --', $fs->supervisor_id, $isBilled);
1348 echo "<input type='button' value='" . xla('New Appointment') . "' onclick='newEvt()' />\n";
1350 echo "</b></span>\n";
1354 &nbsp;
1356 <?php
1357 if ($fs->contraception_code && !$isBilled) {
1358 // This will give the form save logic the associated contraceptive method.
1359 echo "<input type='hidden' name='ippfconmeth' value='" . attr($fs->contraception_code) . "'>\n";
1360 // If needed, this generates a dropdown to ask about prior contraception.
1361 echo $fs->generateContraceptionSelector();
1364 // Allow the patient price level to be fixed here.
1365 $plres = sqlStatement("SELECT option_id, title FROM list_options " .
1366 "WHERE list_id = 'pricelevel' AND activity = 1 ORDER BY seq, title");
1367 if (true) {
1368 $pricelevel = $fs->getPriceLevel();
1369 echo " <span class='billcell'><b>" . xlt('Default Price Level') . ":</b></span>\n";
1370 echo " <select name='pricelevel'";
1371 if ($isBilled) {
1372 echo " disabled";
1375 echo ">\n";
1376 while ($plrow = sqlFetchArray($plres)) {
1377 $key = $plrow['option_id'];
1378 $val = $plrow['title'];
1379 echo " <option value='" . attr($key) . "'";
1380 if ($key == $pricelevel) {
1381 echo ' selected';
1384 echo ">" . text(xl_list_label($val)) . "</option>\n";
1387 echo " </select>\n";
1391 &nbsp; &nbsp; &nbsp;
1393 <?php if (!$isBilled) { // visit is not yet billed ?>
1394 <input type='submit' name='bn_save' value='<?php echo xla('Save'); ?>' />
1395 <input type='submit' name='bn_save_stay' value='<?php echo xla('Save Current'); ?>' />
1396 <?php if ($rapid_data_entry) {
1397 echo " style='background-color:#cc0000';color:#ffffff'";
1398 } ?>
1399 <?php if ($GLOBALS['ippf_specific']) { // start ippf-only stuff ?>
1400 <?php if ($fs->hasCharges) { // unbilled with charges ?>
1401 <input type='submit' name='bn_save_close' value='<?php echo xla('Save and Checkout'); ?>' />
1402 <?php } else { // unbilled with no charges ?>
1403 <input type='submit' name='bn_save_close' value='<?php echo xla('Save and Close'); ?>' />
1404 <?php } // end no charges ?>
1405 &nbsp;
1406 <?php } // end ippf-only ?>
1407 <input type='submit' name='bn_refresh' onclick='return this.clicked = true;'
1408 value='<?php echo xla('Refresh');?>' />
1409 &nbsp;
1410 <?php } else { // visit is billed ?>
1411 <?php if ($fs->hasCharges) { // billed with charges ?>
1412 <input type='button' value='<?php echo xla('Show Receipt'); ?>'
1413 onclick="top.restoreSession();location='../../patient_file/pos_checkout.php?framed=1<?php
1414 echo "&ptid=" . urlencode($fs->pid) . "&enc=" . urlencode($fs->encounter); ?>'" />
1415 &nbsp;
1416 <input type='submit' name='bn_reopen' onclick='return this.clicked = 2;'
1417 value='<?php echo xla('Void Checkout and Re-Open'); ?>' />
1418 &nbsp;
1419 <?php } else { ?>
1420 <input type='submit' name='bn_reopen' onclick='return this.clicked = true;'
1421 value='<?php echo xla('Re-Open Visit'); ?>' />
1422 &nbsp;
1423 <?php } // end billed without charges ?>
1424 <input type='submit' name='bn_addmore' onclick='return this.clicked = true;'
1425 value='<?php echo xla('Add More Items'); ?>' />
1426 &nbsp;
1427 <?php } // end billed ?>
1428 <input type='hidden' name='form_has_charges' value='<?php echo $fs->hasCharges ? 1 : 0; ?>' />
1429 <input type='hidden' name='form_checksum' value='<?php echo $current_checksum; ?>' />
1430 <input type='hidden' name='form_alertmsg' value='<?php echo attr($alertmsg); ?>' />
1432 <input type='button' value='<?php echo xla('Cancel');?>'
1433 onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
1435 </center>
1437 </form>
1439 <script type="text/javascript">
1440 setSaveAndClose();
1442 <?php
1443 echo $justinit;
1444 if ($alertmsg) {
1445 echo "alert('" . addslashes($alertmsg) . "');\n";
1448 </script>
1450 </body>
1451 </html>
1452 <?php if (!empty($_POST['running_as_ajax'])) {
1453 exit();
1454 } ?>
1455 <?php require_once("review/initialize_review.php"); ?>
1456 <?php require_once("code_choice/initialize_code_choice.php"); ?>
1457 <?php if ($GLOBALS['ippf_specific']) {
1458 require_once("contraception_products/initialize_contraception_products.php");
1459 } ?>
1460 <script>
1461 var translated_price_header="<?php echo xlt("Price");?>";
1463 $( "[name='search_term']" ).keydown(function(event){
1464 if(event.keyCode==13){
1465 $("[name=bn_search]").trigger('click');
1466 return false;
1470 $("[name=search_term]").focus();
1471 </script>