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 require_once("../../globals.php");
8 require_once("$srcdir/billing.inc");
9 require_once("$srcdir/sql.inc");
10 require_once("$srcdir/acl.inc");
11 require_once("$srcdir/formatting.inc.php");
12 require_once("$srcdir/formdata.inc.php");
14 $mode = $_REQUEST['mode'];
15 $type = $_REQUEST['type'];
16 $code = $_REQUEST['code'];
17 $modifier = $_REQUEST['modifier'];
18 $units = $_REQUEST['units'];
19 $fee = $_REQUEST['fee'];
20 $text = $_REQUEST['text'];
21 $payment_method = $_REQUEST['payment_method'];
22 $insurance_company = $_REQUEST['insurance_company'];
24 $target = $GLOBALS['concurrent_layout'] ?
'_parent' : 'Main';
26 // Possible units of measure for NDC drug quantities.
27 $ndc_uom_choices = array(
35 if ($payment_method == "insurance") {
36 $payment_method = "insurance: " . $insurance_company;
41 // Get the provider ID from the new encounter form if possible, otherwise
42 // it's the logged-in user.
43 $tmp = sqlQuery("SELECT users.id FROM forms, users WHERE " .
44 "forms.pid = '$pid' AND forms.encounter = '$encounter' AND " .
45 "forms.formdir='newpatient' AND users.username = forms.user AND " .
46 "users.authorized = 1");
47 $provid = $tmp['id'] ?
$tmp['id'] : $_SESSION["authUserID"];
49 if (strtolower($type) == "copay") {
50 addBilling($encounter, $type, sprintf("%01.2f", $code), strip_escape_custom($payment_method),
51 $pid, $userauthorized, $provid, $modifier, $units,
52 sprintf("%01.2f", 0 - $code));
54 elseif (strtolower($type) == "other") {
55 addBilling($encounter, $type, $code, strip_escape_custom($text), $pid, $userauthorized,
56 $provid, $modifier, $units, sprintf("%01.2f", $fee));
60 // If HCPCS, get and save default NDC data.
61 if (strtolower($type) == "hcpcs") {
62 $tmp = sqlQuery("SELECT ndc_info FROM billing WHERE " .
63 "code_type = 'HCPCS' AND code = '$code' AND ndc_info LIKE 'N4%' " .
64 "ORDER BY date DESC LIMIT 1");
65 if (!empty($tmp)) $ndc_info = $tmp['ndc_info'];
67 addBilling($encounter, $type, $code, strip_escape_custom($text), $pid, $userauthorized,
68 $provid, $modifier, $units, $fee, $ndc_info);
71 elseif ($mode == "justify") {
72 $diags = $_POST['code']['diag'];
73 $procs = $_POST['code']['proc'];
75 if (!empty($procs) && !empty($diags)) {
77 foreach ($procs as $proc) {
79 foreach ($diags as $diag) {
80 $justify_string .= $diag . ":";
82 $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) . "'";
87 foreach ($sql as $q) {
92 // Save NDC fields, if present.
93 $ndcarr = $_POST['ndc'];
94 for ($lino = 1; !empty($ndcarr["$lino"]['code']); ++
$lino) {
95 $ndc = $ndcarr["$lino"];
98 $ndc_info = 'N4' . trim($ndc['ndcnum']) . ' ' . $ndc['ndcuom'] .
101 sqlStatement("UPDATE billing SET ndc_info = '$ndc_info' WHERE " .
102 "encounter = '" . mysql_real_escape_string($_POST['encounter_id']) . "' AND " .
103 "pid = '" . mysql_real_escape_string($_POST['patient_id']) . "' AND " .
104 "code = '" . mysql_real_escape_string($ndc['code']) . "'");
113 <?php
html_header_show();?
>
114 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
116 <script language
="JavaScript">
118 function validate(f
) {
119 for (var lino
= 1; f
['ndc['+lino+
'][code]']; ++lino
) {
120 var pfx
= 'ndc['+lino+
']';
121 if (f
[pfx+
'[ndcnum]'] && f
[pfx+
'[ndcnum]'].value
) {
122 // Check NDC number format.
124 var ndc
= f
[pfx+
'[ndcnum]'].value
;
125 var a
= ndc
.split('-');
129 else if (a
[0].length
< 1 || a
[1].length
< 1 || a
[2].length
< 1 ||
130 a
[0].length
> 5 || a
[1].length
> 4 || a
[2].length
> 2) {
134 for (var i
= 0; i
< 3; ++i
) {
135 for (var j
= 0; j
< a
[i
].length
; ++j
) {
136 var c
= a
[i
].charAt(j
);
137 if (c
< '0' || c
> '9') ndcok
= false;
142 alert('<?php xl('Format incorrect
for NDC
','e
') ?> "' + ndc +
143 '", <?php xl('should be like nnnnn
-nnnn
-nn
','e
') ?>');
144 if (f
[pfx+
'[ndcnum]'].focus
) f
[pfx+
'[ndcnum]'].focus();
147 // Check for valid quantity.
148 var qty
= f
[pfx+
'[ndcqty]'].value
- 0;
149 if (isNaN(qty
) || qty
<= 0) {
150 alert('<?php xl('Quantity
for NDC
','e
') ?> "' + ndc +
151 '" <?php xl('is not
valid (decimal fractions are OK
).','e
') ?>');
152 if (f
[pfx+
'[ndcqty]'].focus
) f
[pfx+
'[ndcqty]'].focus();
157 top
.restoreSession();
165 <body
class="body_bottom">
168 $thisauth = acl_check('encounters', 'coding_a');
170 $erow = sqlQuery("SELECT user FROM forms WHERE " .
171 "encounter = '$encounter' AND formdir = 'newpatient' LIMIT 1");
172 if ($erow['user'] == $_SESSION['authUser'])
173 $thisauth = acl_check('encounters', 'coding');
176 $tmp = getPatientData($pid, "squad");
177 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
181 echo "<p>(".xl('Coding not authorized').")</p>\n";
182 echo "</body>\n</html>\n";
187 <form name
="diagnosis" method
="post" action
="diagnosis.php?mode=justify"
188 onsubmit
="return validate(this)">
190 <table border
=0 cellspacing
=0 cellpadding
=0 height
=100%
>
197 <a href
="diagnosis_full.php" target
="<?php echo $target; ?>" onclick
="top.restoreSession()">
198 <span
class=title
><?php
echo ($GLOBALS['phone_country_code'] == '1') ?
xl('Billing') : xl('Coding'); ?
></span
>
199 <font
class=more
><?php
echo $tmore;?
></font
></a
>
202 if( !empty( $_GET["back"] ) ||
!empty( $_POST["back"] ) ){
203 print " <a href=\"superbill_codes.php\" target=\"$target\" onclick=\"top.restoreSession()\"><font class=more>$tback</font></a>";
204 print "<input type=\"hidden\" name=\"back\" value=\"1\">";
207 <?php
if (!$GLOBALS['weight_loss_clinic']) { ?
>
208  
; 
; 
; 
; 
; 
; 
; 
; 
; 
;
209 <input type
="submit" name
="justify" value
="<?php xl('Justify/Save','e');?>">
214 <a href
="cash_receipt.php?" class='link_submit' target
='new' onclick
='top.restoreSession()'>
215 [<?php
xl('Receipt','e'); ?
>]
219 if ($result = getBillingByEncounter($pid,$encounter,"*") ) {
220 $billing_html = array();
223 foreach ($result as $iter) {
224 if ($iter["code_type"] == "ICD9") {
226 $html .= "<td valign=\"middle\">" .
227 '<input style="width: 11px;height: 11px;" name="code[diag][' .
228 $iter["code"] . ']" type="checkbox" value="' . $iter[code
] . '">' .
229 "</td><td><div><a target='$target' class='small' " .
230 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
231 $iter{"code"} . "</b> " . $iter{"code_text"} .
232 "</a></div></td></tr>\n";
233 $billing_html[$iter["code_type"]] .= $html;
236 elseif ($iter["code_type"] == "COPAY") {
237 $billing_html[$iter["code_type"]] .=
238 "<tr><td></td><td><a target='$target' class='small' " .
239 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
240 oeFormatMoney($iter['code']) . "</b> " .
241 ucwords(strtolower($iter['code_text'])) .
242 ' ' . xl('payment entered on') . ' ' .
243 oeFormatShortDate(substr($iter['date'], 0, 10)) . substr($iter['date'], 10, 6) . "</a></td></tr>\n";
246 $billing_html[$iter["code_type"]] .=
247 "<tr><td>" . '<input style="width: 11px;height: 11px;" name="code[proc][' .
248 $iter["code"] . ']" type="checkbox" value="' . $iter[code
] . '">' .
249 "</td><td><a target='$target' class='small' " .
250 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
251 $iter{"code"} . ' ' . $iter['modifier'] . "</b> " .
252 ucwords(strtolower($iter{"code_text"})) . ' ' . oeFormatMoney($iter['fee']) .
253 "</a><span class=\"small\">";
254 $total +
= $iter['fee'];
255 $js = split(":",$iter['justify']);
257 foreach ($js as $j) {
260 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
263 $billing_html[$iter["code_type"]] .= " ($j)";
268 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
270 // If this is HCPCS, write NDC line.
271 if ($iter['code_type'] == 'HCPCS') {
273 $ndcnum = ''; $ndcuom = ''; $ndcqty = '';
274 if (preg_match('/^N4(\S+)\s+(\S\S)(.*)/', $iter['ndc_info'], $tmp)) {
275 $ndcnum = $tmp[1]; $ndcuom = $tmp[2]; $ndcqty = $tmp[3];
277 $billing_html[$iter["code_type"]] .=
278 "<tr><td> </td><td class='small'>NDC: \n" .
279 "<input type='hidden' name='ndc[$ndclino][code]' value='" . $iter[code
] . "'>" .
280 "<input type='text' name='ndc[$ndclino][ndcnum]' value='$ndcnum' " .
281 "size='11' style='background-color:transparent'>" .
282 " Qty: " .
283 "<input type='text' name='ndc[$ndclino][ndcqty]' value='$ndcqty' " .
284 "size='3' style='background-color:transparent;text-align:right'> " .
285 "<select name='ndc[$ndclino][ndcuom]' style='background-color:transparent'>";
286 foreach ($ndc_uom_choices as $key => $value) {
287 $billing_html[$iter["code_type"]] .= "<option value='$key'";
288 if ($key == $ndcuom) $billing_html[$iter["code_type"]] .= " selected";
289 $billing_html[$iter["code_type"]] .= ">$value</option>";
291 $billing_html[$iter["code_type"]] .= "</select></td></tr>\n";
297 $billing_html["CPT4"] .= "<tr><td>" . xl('total') . ":</td><td>" . oeFormatMoney($total) . "</td></tr>\n";
298 foreach ($billing_html as $key => $val) {
299 print "<tr><td>$key</td><td><table>$val</table><td></tr><tr><td height=\"5\"></td></tr>\n";
306 <input type
="hidden" name
="encounter_id" value
="<?php echo $encounter?>">
307 <input type
="hidden" name
="patient_id" value
="<?php echo $pid?>">