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");
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'];
25 // Possible units of measure for NDC drug quantities.
26 $ndc_uom_choices = array(
34 if ($payment_method == "insurance") {
35 $payment_method = "insurance: " . $insurance_company;
40 // Get the provider ID from the new encounter form if possible, otherwise
41 // it's the logged-in user.
42 $tmp = sqlQuery("SELECT users.id FROM forms, users WHERE " .
43 "forms.pid = '$pid' AND forms.encounter = '$encounter' AND " .
44 "forms.formdir='newpatient' AND users.username = forms.user AND " .
45 "users.authorized = 1");
46 $provid = $tmp['id'] ?
$tmp['id'] : $_SESSION["authUserID"];
48 if (strtolower($type) == "copay") {
49 addBilling($encounter, $type, sprintf("%01.2f", $code), strip_escape_custom($payment_method),
50 $pid, $userauthorized, $provid, $modifier, $units,
51 sprintf("%01.2f", 0 - $code));
53 elseif (strtolower($type) == "other") {
54 addBilling($encounter, $type, $code, strip_escape_custom($text), $pid, $userauthorized,
55 $provid, $modifier, $units, sprintf("%01.2f", $fee));
59 // If HCPCS, get and save default NDC data.
60 if (strtolower($type) == "hcpcs") {
61 $tmp = sqlQuery("SELECT ndc_info FROM billing WHERE " .
62 "code_type = 'HCPCS' AND code = '$code' AND ndc_info LIKE 'N4%' " .
63 "ORDER BY date DESC LIMIT 1");
64 if (!empty($tmp)) $ndc_info = $tmp['ndc_info'];
66 addBilling($encounter, $type, $code, strip_escape_custom($text), $pid, $userauthorized,
67 $provid, $modifier, $units, $fee, $ndc_info);
70 elseif ($mode == "justify") {
71 $diags = $_POST['code']['diag'];
72 $procs = $_POST['code']['proc'];
74 if (!empty($procs) && !empty($diags)) {
76 foreach ($procs as $proc) {
78 foreach ($diags as $diag) {
79 $justify_string .= $diag . ":";
81 $sql[] = "UPDATE billing set justify = concat(justify,'" . add_escape_custom($justify_string) ."') where encounter = '" . add_escape_custom($_POST['encounter_id']) . "' and pid = '" . add_escape_custom($_POST['patient_id']) . "' and code = '" . add_escape_custom($proc) . "'";
86 foreach ($sql as $q) {
91 // Save NDC fields, if present.
92 $ndcarr = $_POST['ndc'];
93 for ($lino = 1; !empty($ndcarr["$lino"]['code']); ++
$lino) {
94 $ndc = $ndcarr["$lino"];
97 $ndc_info = 'N4' . trim($ndc['ndcnum']) . ' ' . $ndc['ndcuom'] .
100 sqlStatement("UPDATE billing SET ndc_info = '$ndc_info' WHERE " .
101 "encounter = '" . add_escape_custom($_POST['encounter_id']) . "' AND " .
102 "pid = '" . add_escape_custom($_POST['patient_id']) . "' AND " .
103 "code = '" . add_escape_custom($ndc['code']) . "'");
112 <?php
html_header_show();?
>
113 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
115 <script language
="JavaScript">
117 function validate(f
) {
118 for (var lino
= 1; f
['ndc['+lino+
'][code]']; ++lino
) {
119 var pfx
= 'ndc['+lino+
']';
120 if (f
[pfx+
'[ndcnum]'] && f
[pfx+
'[ndcnum]'].value
) {
121 // Check NDC number format.
123 var ndc
= f
[pfx+
'[ndcnum]'].value
;
124 var a
= ndc
.split('-');
128 else if (a
[0].length
< 1 || a
[1].length
< 1 || a
[2].length
< 1 ||
129 a
[0].length
> 5 || a
[1].length
> 4 || a
[2].length
> 2) {
133 for (var i
= 0; i
< 3; ++i
) {
134 for (var j
= 0; j
< a
[i
].length
; ++j
) {
135 var c
= a
[i
].charAt(j
);
136 if (c
< '0' || c
> '9') ndcok
= false;
141 alert('<?php xl('Format incorrect
for NDC
','e
') ?> "' + ndc +
142 '", <?php xl('should be like nnnnn
-nnnn
-nn
','e
') ?>');
143 if (f
[pfx+
'[ndcnum]'].focus
) f
[pfx+
'[ndcnum]'].focus();
146 // Check for valid quantity.
147 var qty
= f
[pfx+
'[ndcqty]'].value
- 0;
148 if (isNaN(qty
) || qty
<= 0) {
149 alert('<?php xl('Quantity
for NDC
','e
') ?> "' + ndc +
150 '" <?php xl('is not
valid (decimal fractions are OK
).','e
') ?>');
151 if (f
[pfx+
'[ndcqty]'].focus
) f
[pfx+
'[ndcqty]'].focus();
156 top
.restoreSession();
164 <body
class="body_bottom">
167 $thisauth = acl_check('encounters', 'coding_a');
169 $erow = sqlQuery("SELECT user FROM forms WHERE " .
170 "encounter = '$encounter' AND formdir = 'newpatient' LIMIT 1");
171 if ($erow['user'] == $_SESSION['authUser'])
172 $thisauth = acl_check('encounters', 'coding');
175 $tmp = getPatientData($pid, "squad");
176 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
180 echo "<p>(".xl('Coding not authorized').")</p>\n";
181 echo "</body>\n</html>\n";
186 <form name
="diagnosis" method
="post" action
="diagnosis.php?mode=justify"
187 onsubmit
="return validate(this)">
189 <table border
=0 cellspacing
=0 cellpadding
=0 height
=100%
>
196 <a href
="diagnosis_full.php" target
="<?php echo $target; ?>" onclick
="top.restoreSession()">
197 <span
class=title
><?php
echo ($GLOBALS['phone_country_code'] == '1') ?
xl('Billing') : xl('Coding'); ?
></span
>
198 <font
class=more
><?php
echo $tmore;?
></font
></a
>
201 if( !empty( $_GET["back"] ) ||
!empty( $_POST["back"] ) ){
202 print " <a href=\"superbill_codes.php\" target=\"$target\" onclick=\"top.restoreSession()\"><font class=more>$tback</font></a>";
203 print "<input type=\"hidden\" name=\"back\" value=\"1\">";
206 <?php
if (!$GLOBALS['weight_loss_clinic']) { ?
>
207  
; 
; 
; 
; 
; 
; 
; 
; 
; 
;
208 <input type
="submit" name
="justify" value
="<?php xl('Justify/Save','e');?>">
213 <a href
="cash_receipt.php?" class='link_submit' target
='new' onclick
='top.restoreSession()'>
214 [<?php
xl('Receipt','e'); ?
>]
218 if ($result = getBillingByEncounter($pid,$encounter,"*") ) {
219 $billing_html = array();
222 foreach ($result as $iter) {
223 if ($iter["code_type"] == "ICD9") {
225 $html .= "<td valign=\"middle\">" .
226 '<input style="width: 11px;height: 11px;" name="code[diag][' .
227 $iter["code"] . ']" type="checkbox" value="' . $iter[code
] . '">' .
228 "</td><td><div><a target='$target' class='small' " .
229 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
230 $iter{"code"} . "</b> " . $iter{"code_text"} .
231 "</a></div></td></tr>\n";
232 $billing_html[$iter["code_type"]] .= $html;
235 elseif ($iter["code_type"] == "COPAY") {
236 $billing_html[$iter["code_type"]] .=
237 "<tr><td></td><td><a target='$target' class='small' " .
238 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
239 oeFormatMoney($iter['code']) . "</b> " .
240 ucwords(strtolower($iter['code_text'])) .
241 ' ' . xl('payment entered on') . ' ' .
242 oeFormatShortDate(substr($iter['date'], 0, 10)) . substr($iter['date'], 10, 6) . "</a></td></tr>\n";
245 $billing_html[$iter["code_type"]] .=
246 "<tr><td>" . '<input style="width: 11px;height: 11px;" name="code[proc][' .
247 $iter["code"] . ']" type="checkbox" value="' . $iter[code
] . '">' .
248 "</td><td><a target='$target' class='small' " .
249 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
250 $iter{"code"} . ' ' . $iter['modifier'] . "</b> " .
251 ucwords(strtolower($iter{"code_text"})) . ' ' . oeFormatMoney($iter['fee']) .
252 "</a><span class=\"small\">";
253 $total +
= $iter['fee'];
254 $js = explode(":",$iter['justify']);
256 foreach ($js as $j) {
259 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
262 $billing_html[$iter["code_type"]] .= " ($j)";
267 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
269 // If this is HCPCS, write NDC line.
270 if ($iter['code_type'] == 'HCPCS') {
272 $ndcnum = ''; $ndcuom = ''; $ndcqty = '';
273 if (preg_match('/^N4(\S+)\s+(\S\S)(.*)/', $iter['ndc_info'], $tmp)) {
274 $ndcnum = $tmp[1]; $ndcuom = $tmp[2]; $ndcqty = $tmp[3];
276 $billing_html[$iter["code_type"]] .=
277 "<tr><td> </td><td class='small'>NDC: \n" .
278 "<input type='hidden' name='ndc[$ndclino][code]' value='" . $iter[code
] . "'>" .
279 "<input type='text' name='ndc[$ndclino][ndcnum]' value='$ndcnum' " .
280 "size='11' style='background-color:transparent'>" .
281 " Qty: " .
282 "<input type='text' name='ndc[$ndclino][ndcqty]' value='$ndcqty' " .
283 "size='3' style='background-color:transparent;text-align:right'> " .
284 "<select name='ndc[$ndclino][ndcuom]' style='background-color:transparent'>";
285 foreach ($ndc_uom_choices as $key => $value) {
286 $billing_html[$iter["code_type"]] .= "<option value='$key'";
287 if ($key == $ndcuom) $billing_html[$iter["code_type"]] .= " selected";
288 $billing_html[$iter["code_type"]] .= ">$value</option>";
290 $billing_html[$iter["code_type"]] .= "</select></td></tr>\n";
296 $billing_html["CPT4"] .= "<tr><td>" . xl('total') . ":</td><td>" . oeFormatMoney($total) . "</td></tr>\n";
297 foreach ($billing_html as $key => $val) {
298 print "<tr><td>$key</td><td><table>$val</table><td></tr><tr><td height=\"5\"></td></tr>\n";
305 <input type
="hidden" name
="encounter_id" value
="<?php echo $encounter?>">
306 <input type
="hidden" name
="patient_id" value
="<?php echo $pid?>">