6 * @link http://www.open-emr.org
7 * @author Brady Miller <brady.g.miller@gmail.com>
8 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../../globals.php");
14 require_once("$srcdir/billing.inc");
15 require_once("$srcdir/acl.inc");
17 $mode = $_REQUEST['mode'];
18 $type = $_REQUEST['type'];
19 $code = $_REQUEST['code'];
20 $modifier = $_REQUEST['modifier'];
21 $units = $_REQUEST['units'];
22 $fee = $_REQUEST['fee'];
23 $text = $_REQUEST['text'];
24 $payment_method = $_REQUEST['payment_method'];
25 $insurance_company = $_REQUEST['insurance_company'];
29 // Possible units of measure for NDC drug quantities.
30 $ndc_uom_choices = array(
38 if ($payment_method == "insurance") {
39 $payment_method = "insurance: " . $insurance_company;
43 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
48 // Get the provider ID from the new encounter form if possible, otherwise
49 // it's the logged-in user.
50 $tmp = sqlQuery("SELECT users.id FROM forms, users WHERE " .
51 "forms.pid = ? AND forms.encounter = ? AND " .
52 "forms.formdir='newpatient' AND users.username = forms.user AND " .
53 "users.authorized = 1", array($pid, $encounter));
54 $provid = $tmp['id'] ?
$tmp['id'] : $_SESSION["authUserID"];
56 if (strtolower($type) == "copay") {
60 sprintf("%01.2f", $code),
67 sprintf("%01.2f", 0 - $code)
69 } elseif (strtolower($type) == "other") {
80 sprintf("%01.2f", $fee)
84 // If HCPCS, get and save default NDC data.
85 if (strtolower($type) == "hcpcs") {
86 $tmp = sqlQuery("SELECT ndc_info FROM billing WHERE " .
87 "code_type = 'HCPCS' AND code = ? AND ndc_info LIKE 'N4%' " .
88 "ORDER BY date DESC LIMIT 1", array($code));
90 $ndc_info = $tmp['ndc_info'];
108 } elseif ($mode == "justify") {
109 $diags = $_POST['code']['diag'];
110 $procs = $_POST['code']['proc'];
112 if (!empty($procs) && !empty($diags)) {
114 foreach ($procs as $proc) {
115 $justify_string = "";
116 foreach ($diags as $diag) {
117 $justify_string .= $diag . ":";
120 $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) . "'";
125 foreach ($sql as $q) {
130 // Save NDC fields, if present.
131 $ndcarr = $_POST['ndc'];
132 for ($lino = 1; !empty($ndcarr["$lino"]['code']); ++
$lino) {
133 $ndc = $ndcarr["$lino"];
135 if ($ndc['ndcnum']) {
136 $ndc_info = 'N4' . trim($ndc['ndcnum']) . ' ' . $ndc['ndcuom'] .
137 trim($ndc['ndcqty']);
140 sqlStatement("UPDATE billing SET ndc_info = ? WHERE " .
141 "encounter = ? AND " .
143 "code = ?", array($ndc_info, $_POST['encounter_id'], $_POST['patient_id'], $ndc['code']));
151 <?php
html_header_show();?
>
152 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
154 <script language
="JavaScript">
156 function validate(f
) {
157 for (var lino
= 1; f
['ndc['+lino+
'][code]']; ++lino
) {
158 var pfx
= 'ndc['+lino+
']';
159 if (f
[pfx+
'[ndcnum]'] && f
[pfx+
'[ndcnum]'].value
) {
160 // Check NDC number format.
162 var ndc
= f
[pfx+
'[ndcnum]'].value
;
163 var a
= ndc
.split('-');
167 else if (a
[0].length
< 1 || a
[1].length
< 1 || a
[2].length
< 1 ||
168 a
[0].length
> 5 || a
[1].length
> 4 || a
[2].length
> 2) {
172 for (var i
= 0; i
< 3; ++i
) {
173 for (var j
= 0; j
< a
[i
].length
; ++j
) {
174 var c
= a
[i
].charAt(j
);
175 if (c
< '0' || c
> '9') ndcok
= false;
180 alert(<?php
echo xlj('Format incorrect for NDC'); ?
> +
' ' + ndc +
181 ', ' +
<?php
echo xlj('should be like nnnnn-nnnn-nn'); ?
>);
182 if (f
[pfx+
'[ndcnum]'].focus
) f
[pfx+
'[ndcnum]'].focus();
185 // Check for valid quantity.
186 var qty
= f
[pfx+
'[ndcqty]'].value
- 0;
187 if (isNaN(qty
) || qty
<= 0) {
188 alert(<?php
echo xlj('Quantity for NDC'); ?
> +
' ' + ndc +
189 ' ' +
<?php
echo xlj('is not valid (decimal fractions are OK).'); ?
>);
190 if (f
[pfx+
'[ndcqty]'].focus
) f
[pfx+
'[ndcqty]'].focus();
195 top
.restoreSession();
203 <body
class="body_bottom">
206 $thisauth = acl_check('encounters', 'coding_a');
208 $erow = sqlQuery("SELECT user FROM forms WHERE " .
209 "encounter = ? AND formdir = 'newpatient' LIMIT 1", array($encounter));
210 if ($erow['user'] == $_SESSION['authUser']) {
211 $thisauth = acl_check('encounters', 'coding');
216 $tmp = getPatientData($pid, "squad");
217 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad'])) {
223 echo "<p>(" . xlt('Coding not authorized') . ")</p>\n";
224 echo "</body>\n</html>\n";
229 <form name
="diagnosis" method
="post" action
="diagnosis.php?mode=justify&csrf_token_form=<?php echo attr_url(collectCsrfToken()); ?>"
230 onsubmit
="return validate(this)">
231 <table border
=0 cellspacing
=0 cellpadding
=0 height
=100%
>
238 <a href
="diagnosis_full.php" target
="<?php echo attr($target); ?>" onclick
="top.restoreSession()">
239 <span
class=title
><?php
echo ($GLOBALS['phone_country_code'] == '1') ?
xlt('Billing') : xlt('Coding'); ?
></span
>
240 <font
class=more
><?php
echo text($tmore); ?
></font
></a
>
243 if (!empty($_GET["back"]) ||
!empty($_POST["back"])) {
244 print " <a href=\"superbill_codes.php\" target=\"" . attr($target) . "\" onclick=\"top.restoreSession()\"><font class=more>" . text($tback) . "</font></a>";
245 print "<input type=\"hidden\" name=\"back\" value=\"1\">";
248 <?php
if (!$GLOBALS['weight_loss_clinic']) { ?
>
249  
; 
; 
; 
; 
; 
; 
; 
; 
; 
;
250 <input type
="submit" name
="justify" value
="<?php echo xla('Justify/Save');?>">
255 <a href
="cash_receipt.php?csrf_token_form=<?php echo attr_url(collectCsrfToken()); ?>" class='link_submit' target
='new' onclick
='top.restoreSession()'>
256 [<?php
echo xlt('Receipt'); ?
>]
260 if ($result = getBillingByEncounter($pid, $encounter, "*")) {
261 $billing_html = array();
264 foreach ($result as $iter) {
265 if ($iter["code_type"] == "ICD9") {
267 $html .= "<td valign=\"middle\">" .
268 '<input style="width: 11px;height: 11px;" name="code[diag][' .
269 attr($iter["code"]) . ']" type="checkbox" value="' . attr($iter["code"]) . '">' .
270 "</td><td><div><a target='" . attr($target) . "' class='small' " .
271 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
272 text($iter{"code"}) . "</b> " . text($iter{"code_text"}) .
273 "</a></div></td></tr>\n";
274 $billing_html[$iter["code_type"]] .= $html;
276 } elseif ($iter["code_type"] == "COPAY") {
277 $billing_html[$iter["code_type"]] .=
278 "<tr><td></td><td><a target='" . attr($target) . "' class='small' " .
279 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
280 text(oeFormatMoney($iter['code'])) . "</b> " .
281 text(ucwords(strtolower($iter['code_text']))) .
282 ' ' . xlt('payment entered on') . ' ' .
283 text(oeFormatShortDate(substr($iter['date'], 0, 10))) . text(substr($iter['date'], 10, 6)) . "</a></td></tr>\n";
285 $billing_html[$iter["code_type"]] .=
286 "<tr><td>" . '<input style="width: 11px;height: 11px;" name="code[proc][' .
287 attr($iter["code"]) . ']" type="checkbox" value="' . attr($iter["code"]) . '">' .
288 "</td><td><a target='$target' class='small' " .
289 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
290 text($iter{"code"}) . ' ' . text($iter['modifier']) . "</b> " .
291 text(ucwords(strtolower($iter{"code_text"}))) . ' ' . text(oeFormatMoney($iter['fee'])) .
292 "</a><span class=\"small\">";
293 $total +
= $iter['fee'];
294 $js = explode(":", $iter['justify']);
296 foreach ($js as $j) {
299 $billing_html[$iter["code_type"]] .= " (<b>" . text($j) . "</b>)";
301 $billing_html[$iter["code_type"]] .= " (" . text($j) . ")";
308 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
310 // If this is HCPCS, write NDC line.
311 if ($iter['code_type'] == 'HCPCS') {
316 if (preg_match('/^N4(\S+)\s+(\S\S)(.*)/', $iter['ndc_info'], $tmp)) {
322 $billing_html[$iter["code_type"]] .=
323 "<tr><td> </td><td class='small'>NDC: \n" .
324 "<input type='hidden' name='ndc[" . attr($ndclino) . "][code]' value='" . attr($iter["code"]) . "'>" .
325 "<input type='text' name='ndc[" . attr($ndclino) . "][ndcnum]' value='" . attr($ndcnum) . "' " .
326 "size='11' style='background-color:transparent'>" .
327 " Qty: " .
328 "<input type='text' name='ndc[" . attr($ndclino) . "][ndcqty]' value='" . attr($ndcqty) . "' " .
329 "size='3' style='background-color:transparent;text-align:right'> " .
330 "<select name='ndc[" . attr($ndclino) . "][ndcuom]' style='background-color:transparent'>";
331 foreach ($ndc_uom_choices as $key => $value) {
332 $billing_html[$iter["code_type"]] .= "<option value='" . attr($key) . "'";
333 if ($key == $ndcuom) {
334 $billing_html[$iter["code_type"]] .= " selected";
337 $billing_html[$iter["code_type"]] .= ">" . text($value) . "</option>";
340 $billing_html[$iter["code_type"]] .= "</select></td></tr>\n";
345 $billing_html["CPT4"] .= "<tr><td>" . xlt('total') . ":</td><td>" . text(oeFormatMoney($total)) . "</td></tr>\n";
346 foreach ($billing_html as $key => $val) {
347 print "<tr><td>" . text($key) . "</td><td><table>" . $val . "</table><td></tr><tr><td height=\"5\"></td></tr>\n";
354 <input type
="hidden" name
="encounter_id" value
="<?php echo attr($encounter); ?>">
355 <input type
="hidden" name
="patient_id" value
="<?php echo attr($pid); ?>">