2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 include_once("../../globals.php");
8 include_once("$srcdir/billing.inc");
9 include_once("$srcdir/sql.inc");
10 include_once("$srcdir/acl.inc");
11 require_once("$srcdir/formatting.inc.php");
13 $mode = $_REQUEST['mode'];
14 $type = $_REQUEST['type'];
15 $code = $_REQUEST['code'];
16 $modifier = $_REQUEST['modifier'];
17 $units = $_REQUEST['units'];
18 $fee = $_REQUEST['fee'];
19 $text = $_REQUEST['text'];
20 $payment_method = $_REQUEST['payment_method'];
21 $insurance_company = $_REQUEST['insurance_company'];
23 $target = $GLOBALS['concurrent_layout'] ?
'_parent' : 'Main';
25 // Possible units of measure for NDC drug quantities.
26 $ndc_uom_choices = array(
33 if ($payment_method == "insurance") {
34 $payment_method = "insurance: " . $insurance_company;
39 // Get the provider ID from the new encounter form if possible, otherwise
40 // it's the logged-in user.
41 $tmp = sqlQuery("SELECT users.id FROM forms, users WHERE " .
42 "forms.pid = '$pid' AND forms.encounter = '$encounter' AND " .
43 "forms.formdir='newpatient' AND users.username = forms.user AND " .
44 "users.authorized = 1");
45 $provid = $tmp['id'] ?
$tmp['id'] : $_SESSION["authUserID"];
47 if (strtolower($type) == "copay") {
48 addBilling($encounter, $type, sprintf("%01.2f", $code), $payment_method,
49 $pid, $userauthorized, $provid, $modifier, $units,
50 sprintf("%01.2f", 0 - $code));
52 elseif (strtolower($type) == "other") {
53 addBilling($encounter, $type, $code, $text, $pid, $userauthorized,
54 $provid, $modifier, $units, sprintf("%01.2f", $fee));
58 // If HCPCS, get and save default NDC data.
59 if (strtolower($type) == "hcpcs") {
60 $tmp = sqlQuery("SELECT ndc_info FROM billing WHERE " .
61 "code_type = 'HCPCS' AND code = '$code' AND ndc_info LIKE 'N4%' " .
62 "ORDER BY date DESC LIMIT 1");
63 if (!empty($tmp)) $ndc_info = $tmp['ndc_info'];
65 addBilling($encounter, $type, $code, $text, $pid, $userauthorized,
66 $provid, $modifier, $units, $fee, $ndc_info);
69 elseif ($mode == "justify") {
70 $diags = $_POST['code']['diag'];
71 $procs = $_POST['code']['proc'];
73 if (!empty($procs) && !empty($diags)) {
75 foreach ($procs as $proc) {
77 foreach ($diags as $diag) {
78 $justify_string .= $diag . ":";
80 $sql[] = "UPDATE billing set justify = concat(justify,'" . mysql_real_escape_string($justify_string) ."') where encounter = '" . mysql_real_escape_string($_POST['encounter_id']) . "' and pid = '" . mysql_real_escape_string($_POST['patient_id']) . "' and code = '" . mysql_real_escape_string($proc) . "'";
85 foreach ($sql as $q) {
90 // Save NDC fields, if present.
91 $ndcarr = $_POST['ndc'];
92 for ($lino = 1; !empty($ndcarr["$lino"]['code']); ++
$lino) {
93 $ndc = $ndcarr["$lino"];
96 $ndc_info = 'N4' . trim($ndc['ndcnum']) . ' ' . $ndc['ndcuom'] .
99 sqlStatement("UPDATE billing SET ndc_info = '$ndc_info' WHERE " .
100 "encounter = '" . mysql_real_escape_string($_POST['encounter_id']) . "' AND " .
101 "pid = '" . mysql_real_escape_string($_POST['patient_id']) . "' AND " .
102 "code = '" . mysql_real_escape_string($ndc['code']) . "'");
111 <?php
html_header_show();?
>
112 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
114 <script language
="JavaScript">
116 function validate(f
) {
117 for (var lino
= 1; f
['ndc['+lino+
'][code]']; ++lino
) {
118 var pfx
= 'ndc['+lino+
']';
119 if (f
[pfx+
'[ndcnum]'] && f
[pfx+
'[ndcnum]'].value
) {
120 // Check NDC number format.
122 var ndc
= f
[pfx+
'[ndcnum]'].value
;
123 var a
= ndc
.split('-');
127 else if (a
[0].length
< 1 || a
[1].length
< 1 || a
[2].length
< 1 ||
128 a
[0].length
> 5 || a
[1].length
> 4 || a
[2].length
> 2) {
132 for (var i
= 0; i
< 3; ++i
) {
133 for (var j
= 0; j
< a
[i
].length
; ++j
) {
134 var c
= a
[i
].charAt(j
);
135 if (c
< '0' || c
> '9') ndcok
= false;
140 alert('<?php xl('Format incorrect
for NDC
','e
') ?> "' + ndc +
141 '", <?php xl('should be like nnnnn
-nnnn
-nn
','e
') ?>');
142 if (f
[pfx+
'[ndcnum]'].focus
) f
[pfx+
'[ndcnum]'].focus();
145 // Check for valid quantity.
146 var qty
= f
[pfx+
'[ndcqty]'].value
- 0;
147 if (isNaN(qty
) || qty
<= 0) {
148 alert('<?php xl('Quantity
for NDC
','e
') ?> "' + ndc +
149 '" <?php xl('is not
valid (decimal fractions are OK
).','e
') ?>');
150 if (f
[pfx+
'[ndcqty]'].focus
) f
[pfx+
'[ndcqty]'].focus();
155 top
.restoreSession();
163 <body
class="body_bottom">
166 $thisauth = acl_check('encounters', 'coding_a');
168 $erow = sqlQuery("SELECT user FROM forms WHERE " .
169 "encounter = '$encounter' AND formdir = 'newpatient' LIMIT 1");
170 if ($erow['user'] == $_SESSION['authUser'])
171 $thisauth = acl_check('encounters', 'coding');
174 $tmp = getPatientData($pid, "squad");
175 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
179 echo "<p>(".xl('Coding not authorized').")</p>\n";
180 echo "</body>\n</html>\n";
185 <form name
="diagnosis" method
="post" action
="diagnosis.php?mode=justify"
186 onsubmit
="return validate(this)">
188 <table border
=0 cellspacing
=0 cellpadding
=0 height
=100%
>
195 <a href
="diagnosis_full.php" target
="<?php echo $target; ?>" onclick
="top.restoreSession()">
196 <span
class=title
><?php
echo ($GLOBALS['phone_country_code'] == '1') ?
xl('Billing') : xl('Coding'); ?
></span
>
197 <font
class=more
><?php
echo $tmore;?
></font
></a
>
200 if( !empty( $_GET["back"] ) ||
!empty( $_POST["back"] ) ){
201 print " <a href=\"superbill_codes.php\" target=\"$target\" onclick=\"top.restoreSession()\"><font class=more>$tback</font></a>";
202 print "<input type=\"hidden\" name=\"back\" value=\"1\">";
205 <?php
if (!$GLOBALS['weight_loss_clinic']) { ?
>
206  
; 
; 
; 
; 
; 
; 
; 
; 
; 
;
207 <input type
="submit" name
="justify" value
="<?php xl('Justify/Save','e');?>">
212 <a href
="cash_receipt.php?" class='link_submit' target
='new' onclick
='top.restoreSession()'>
213 [<?php
xl('Receipt','e'); ?
>]
217 if ($result = getBillingByEncounter($pid,$encounter,"*") ) {
218 $billing_html = array();
221 foreach ($result as $iter) {
222 if ($iter["code_type"] == "ICD9") {
224 $html .= "<td valign=\"middle\">" .
225 '<input style="width: 11px;height: 11px;" name="code[diag][' .
226 $iter["code"] . ']" type="checkbox" value="' . $iter[code
] . '">' .
227 "</td><td><div><a target='$target' class='small' " .
228 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
229 $iter{"code"} . "</b> " . ucwords(strtolower($iter{"code_text"})) .
230 "</a></div></td></tr>\n";
231 $billing_html[$iter["code_type"]] .= $html;
234 elseif ($iter["code_type"] == "COPAY") {
235 $billing_html[$iter["code_type"]] .=
236 "<tr><td></td><td><a target='$target' class='small' " .
237 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
238 oeFormatMoney($iter['code']) . "</b> " .
239 ucwords(strtolower($iter['code_text'])) .
240 ' ' . xl('payment entered on') . ' ' .
241 oeFormatShortDate(substr($iter['date'], 0, 10)) . substr($iter['date'], 10, 6) . "</a></td></tr>\n";
244 $billing_html[$iter["code_type"]] .=
245 "<tr><td>" . '<input style="width: 11px;height: 11px;" name="code[proc][' .
246 $iter["code"] . ']" type="checkbox" value="' . $iter[code
] . '">' .
247 "</td><td><a target='$target' class='small' " .
248 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
249 $iter{"code"} . ' ' . $iter['modifier'] . "</b> " .
250 ucwords(strtolower($iter{"code_text"})) . ' ' . oeFormatMoney($iter['fee']) .
251 "</a><span class=\"small\">";
252 $total +
= $iter['fee'];
253 $js = split(":",$iter['justify']);
255 foreach ($js as $j) {
258 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
261 $billing_html[$iter["code_type"]] .= " ($j)";
266 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
268 // If this is HCPCS, write NDC line.
269 if ($iter['code_type'] == 'HCPCS') {
271 $ndcnum = ''; $ndcuom = ''; $ndcqty = '';
272 if (preg_match('/^N4(\S+)\s+(\S\S)(.*)/', $iter['ndc_info'], $tmp)) {
273 $ndcnum = $tmp[1]; $ndcuom = $tmp[2]; $ndcqty = $tmp[3];
275 $billing_html[$iter["code_type"]] .=
276 "<tr><td> </td><td class='small'>NDC: \n" .
277 "<input type='hidden' name='ndc[$ndclino][code]' value='" . $iter[code
] . "'>" .
278 "<input type='text' name='ndc[$ndclino][ndcnum]' value='$ndcnum' " .
279 "size='11' style='background-color:transparent'>" .
280 " Qty: " .
281 "<input type='text' name='ndc[$ndclino][ndcqty]' value='$ndcqty' " .
282 "size='3' style='background-color:transparent;text-align:right'> " .
283 "<select name='ndc[$ndclino][ndcuom]' style='background-color:transparent'>";
284 foreach ($ndc_uom_choices as $key => $value) {
285 $billing_html[$iter["code_type"]] .= "<option value='$key'";
286 if ($key == $ndcuom) $billing_html[$iter["code_type"]] .= " selected";
287 $billing_html[$iter["code_type"]] .= ">$value</option>";
289 $billing_html[$iter["code_type"]] .= "</select></td></tr>\n";
295 $billing_html["CPT4"] .= "<tr><td>" . xl('total') . ":</td><td>" . oeFormatMoney($total) . "</td></tr>\n";
296 foreach ($billing_html as $key => $val) {
297 print "<tr><td>$key</td><td><table>$val</table><td></tr><tr><td height=\"5\"></td></tr>\n";
304 <input type
="hidden" name
="encounter_id" value
="<?php echo $encounter?>">
305 <input type
="hidden" name
="patient_id" value
="<?php echo $pid?>">