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/acl.inc");
11 $mode = $_REQUEST['mode'];
12 $type = $_REQUEST['type'];
13 $code = $_REQUEST['code'];
14 $modifier = $_REQUEST['modifier'];
15 $units = $_REQUEST['units'];
16 $fee = $_REQUEST['fee'];
17 $text = $_REQUEST['text'];
18 $payment_method = $_REQUEST['payment_method'];
19 $insurance_company = $_REQUEST['insurance_company'];
23 // Possible units of measure for NDC drug quantities.
24 $ndc_uom_choices = array(
32 if ($payment_method == "insurance") {
33 $payment_method = "insurance: " . $insurance_company;
37 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
38 die(xlt('Authentication Error'));
42 // Get the provider ID from the new encounter form if possible, otherwise
43 // it's the logged-in user.
44 $tmp = sqlQuery("SELECT users.id FROM forms, users WHERE " .
45 "forms.pid = ? AND forms.encounter = ? AND " .
46 "forms.formdir='newpatient' AND users.username = forms.user AND " .
47 "users.authorized = 1", array($pid, $encounter));
48 $provid = $tmp['id'] ?
$tmp['id'] : $_SESSION["authUserID"];
50 if (strtolower($type) == "copay") {
54 sprintf("%01.2f", $code),
61 sprintf("%01.2f", 0 - $code)
63 } elseif (strtolower($type) == "other") {
74 sprintf("%01.2f", $fee)
78 // If HCPCS, get and save default NDC data.
79 if (strtolower($type) == "hcpcs") {
80 $tmp = sqlQuery("SELECT ndc_info FROM billing WHERE " .
81 "code_type = 'HCPCS' AND code = ? AND ndc_info LIKE 'N4%' " .
82 "ORDER BY date DESC LIMIT 1", array($code));
84 $ndc_info = $tmp['ndc_info'];
102 } elseif ($mode == "justify") {
103 $diags = $_POST['code']['diag'];
104 $procs = $_POST['code']['proc'];
106 if (!empty($procs) && !empty($diags)) {
108 foreach ($procs as $proc) {
109 $justify_string = "";
110 foreach ($diags as $diag) {
111 $justify_string .= $diag . ":";
114 $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) . "'";
119 foreach ($sql as $q) {
124 // Save NDC fields, if present.
125 $ndcarr = $_POST['ndc'];
126 for ($lino = 1; !empty($ndcarr["$lino"]['code']); ++
$lino) {
127 $ndc = $ndcarr["$lino"];
129 if ($ndc['ndcnum']) {
130 $ndc_info = 'N4' . trim($ndc['ndcnum']) . ' ' . $ndc['ndcuom'] .
131 trim($ndc['ndcqty']);
134 sqlStatement("UPDATE billing SET ndc_info = ? WHERE " .
135 "encounter = ? AND " .
137 "code = ?", array($ndc_info, $_POST['encounter_id'], $_POST['patient_id'], $ndc['code']));
145 <?php
html_header_show();?
>
146 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
148 <script language
="JavaScript">
150 function validate(f
) {
151 for (var lino
= 1; f
['ndc['+lino+
'][code]']; ++lino
) {
152 var pfx
= 'ndc['+lino+
']';
153 if (f
[pfx+
'[ndcnum]'] && f
[pfx+
'[ndcnum]'].value
) {
154 // Check NDC number format.
156 var ndc
= f
[pfx+
'[ndcnum]'].value
;
157 var a
= ndc
.split('-');
161 else if (a
[0].length
< 1 || a
[1].length
< 1 || a
[2].length
< 1 ||
162 a
[0].length
> 5 || a
[1].length
> 4 || a
[2].length
> 2) {
166 for (var i
= 0; i
< 3; ++i
) {
167 for (var j
= 0; j
< a
[i
].length
; ++j
) {
168 var c
= a
[i
].charAt(j
);
169 if (c
< '0' || c
> '9') ndcok
= false;
174 alert('<?php echo xls('Format incorrect
for NDC
'); ?> "' + ndc +
175 '", <?php echo xls('should be like nnnnn
-nnnn
-nn
'); ?>');
176 if (f
[pfx+
'[ndcnum]'].focus
) f
[pfx+
'[ndcnum]'].focus();
179 // Check for valid quantity.
180 var qty
= f
[pfx+
'[ndcqty]'].value
- 0;
181 if (isNaN(qty
) || qty
<= 0) {
182 alert('<?php echo xls('Quantity
for NDC
'); ?> "' + ndc +
183 '" <?php echo xls('is not
valid (decimal fractions are OK
).'); ?>');
184 if (f
[pfx+
'[ndcqty]'].focus
) f
[pfx+
'[ndcqty]'].focus();
189 top
.restoreSession();
197 <body
class="body_bottom">
200 $thisauth = acl_check('encounters', 'coding_a');
202 $erow = sqlQuery("SELECT user FROM forms WHERE " .
203 "encounter = ? AND formdir = 'newpatient' LIMIT 1", array($encounter));
204 if ($erow['user'] == $_SESSION['authUser']) {
205 $thisauth = acl_check('encounters', 'coding');
210 $tmp = getPatientData($pid, "squad");
211 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad'])) {
217 echo "<p>(".xlt('Coding not authorized').")</p>\n";
218 echo "</body>\n</html>\n";
223 <form name
="diagnosis" method
="post" action
="diagnosis.php?mode=justify&csrf_token_form=<?php echo attr(urlencode(collectCsrfToken())); ?>"
224 onsubmit
="return validate(this)">
225 <table border
=0 cellspacing
=0 cellpadding
=0 height
=100%
>
232 <a href
="diagnosis_full.php" target
="<?php echo attr($target); ?>" onclick
="top.restoreSession()">
233 <span
class=title
><?php
echo ($GLOBALS['phone_country_code'] == '1') ?
xlt('Billing') : xlt('Coding'); ?
></span
>
234 <font
class=more
><?php
echo text($tmore); ?
></font
></a
>
237 if (!empty($_GET["back"]) ||
!empty($_POST["back"])) {
238 print " <a href=\"superbill_codes.php\" target=\"" . attr($target) . "\" onclick=\"top.restoreSession()\"><font class=more>" . text($tback) . "</font></a>";
239 print "<input type=\"hidden\" name=\"back\" value=\"1\">";
242 <?php
if (!$GLOBALS['weight_loss_clinic']) { ?
>
243  
; 
; 
; 
; 
; 
; 
; 
; 
; 
;
244 <input type
="submit" name
="justify" value
="<?php echo xla('Justify/Save');?>">
249 <a href
="cash_receipt.php?" class='link_submit' target
='new' onclick
='top.restoreSession()'>
250 [<?php
echo xlt('Receipt'); ?
>]
254 if ($result = getBillingByEncounter($pid, $encounter, "*")) {
255 $billing_html = array();
258 foreach ($result as $iter) {
259 if ($iter["code_type"] == "ICD9") {
261 $html .= "<td valign=\"middle\">" .
262 '<input style="width: 11px;height: 11px;" name="code[diag][' .
263 attr($iter["code"]) . ']" type="checkbox" value="' . attr($iter["code"]) . '">' .
264 "</td><td><div><a target='" . attr($target) . "' class='small' " .
265 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
266 text($iter{"code"}) . "</b> " . text($iter{"code_text"}) .
267 "</a></div></td></tr>\n";
268 $billing_html[$iter["code_type"]] .= $html;
270 } elseif ($iter["code_type"] == "COPAY") {
271 $billing_html[$iter["code_type"]] .=
272 "<tr><td></td><td><a target='" . attr($target) . "' class='small' " .
273 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
274 text(oeFormatMoney($iter['code'])) . "</b> " .
275 text(ucwords(strtolower($iter['code_text']))) .
276 ' ' . xlt('payment entered on') . ' ' .
277 text(oeFormatShortDate(substr($iter['date'], 0, 10))) . text(substr($iter['date'], 10, 6)) . "</a></td></tr>\n";
279 $billing_html[$iter["code_type"]] .=
280 "<tr><td>" . '<input style="width: 11px;height: 11px;" name="code[proc][' .
281 attr($iter["code"]) . ']" type="checkbox" value="' . attr($iter["code"]) . '">' .
282 "</td><td><a target='$target' class='small' " .
283 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
284 text($iter{"code"}) . ' ' . text($iter['modifier']) . "</b> " .
285 text(ucwords(strtolower($iter{"code_text"}))) . ' ' . text(oeFormatMoney($iter['fee'])) .
286 "</a><span class=\"small\">";
287 $total +
= $iter['fee'];
288 $js = explode(":", $iter['justify']);
290 foreach ($js as $j) {
293 $billing_html[$iter["code_type"]] .= " (<b>" . text($j) . "</b>)";
295 $billing_html[$iter["code_type"]] .= " (" . text($j) . ")";
302 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
304 // If this is HCPCS, write NDC line.
305 if ($iter['code_type'] == 'HCPCS') {
310 if (preg_match('/^N4(\S+)\s+(\S\S)(.*)/', $iter['ndc_info'], $tmp)) {
316 $billing_html[$iter["code_type"]] .=
317 "<tr><td> </td><td class='small'>NDC: \n" .
318 "<input type='hidden' name='ndc[" . attr($ndclino) . "][code]' value='" . attr($iter["code"]) . "'>" .
319 "<input type='text' name='ndc[" . attr($ndclino) . "][ndcnum]' value='" . attr($ndcnum) . "' " .
320 "size='11' style='background-color:transparent'>" .
321 " Qty: " .
322 "<input type='text' name='ndc[" . attr($ndclino) . "][ndcqty]' value='" . attr($ndcqty) . "' " .
323 "size='3' style='background-color:transparent;text-align:right'> " .
324 "<select name='ndc[" . attr($ndclino) . "][ndcuom]' style='background-color:transparent'>";
325 foreach ($ndc_uom_choices as $key => $value) {
326 $billing_html[$iter["code_type"]] .= "<option value='" . attr($key) . "'";
327 if ($key == $ndcuom) {
328 $billing_html[$iter["code_type"]] .= " selected";
331 $billing_html[$iter["code_type"]] .= ">" . text($value) . "</option>";
334 $billing_html[$iter["code_type"]] .= "</select></td></tr>\n";
339 $billing_html["CPT4"] .= "<tr><td>" . xlt('total') . ":</td><td>" . text(oeFormatMoney($total)) . "</td></tr>\n";
340 foreach ($billing_html as $key => $val) {
341 print "<tr><td>" . text($key) . "</td><td><table>" . $val . "</table><td></tr><tr><td height=\"5\"></td></tr>\n";
348 <input type
="hidden" name
="encounter_id" value
="<?php echo attr($encounter); ?>">
349 <input type
="hidden" name
="patient_id" value
="<?php echo attr($pid); ?>">