Multiple improvements from IPPF related to layouts. (#1081)
[openemr.git] / interface / patient_file / encounter / diagnosis.php
blob9760f57f42a5fa60fe203714812ba9ce68d79c9e
1 <?php
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'];
21 $target = '_parent';
23 // Possible units of measure for NDC drug quantities.
24 $ndc_uom_choices = array(
25 'ML' => 'ML',
26 'GR' => 'Grams',
27 'ME' => 'Milligrams',
28 'F2' => 'I.U.',
29 'UN' => 'Units'
32 if ($payment_method == "insurance") {
33 $payment_method = "insurance: " . $insurance_company;
36 if (isset($mode)) {
37 if ($mode == "add") {
38 // Get the provider ID from the new encounter form if possible, otherwise
39 // it's the logged-in user.
40 $tmp = sqlQuery("SELECT users.id FROM forms, users WHERE " .
41 "forms.pid = '$pid' AND forms.encounter = '$encounter' AND " .
42 "forms.formdir='newpatient' AND users.username = forms.user AND " .
43 "users.authorized = 1");
44 $provid = $tmp['id'] ? $tmp['id'] : $_SESSION["authUserID"];
46 if (strtolower($type) == "copay") {
47 addBilling(
48 $encounter,
49 $type,
50 sprintf("%01.2f", $code),
51 strip_escape_custom($payment_method),
52 $pid,
53 $userauthorized,
54 $provid,
55 $modifier,
56 $units,
57 sprintf("%01.2f", 0 - $code)
59 } elseif (strtolower($type) == "other") {
60 addBilling(
61 $encounter,
62 $type,
63 $code,
64 strip_escape_custom($text),
65 $pid,
66 $userauthorized,
67 $provid,
68 $modifier,
69 $units,
70 sprintf("%01.2f", $fee)
72 } else {
73 $ndc_info = '';
74 // If HCPCS, get and save default NDC data.
75 if (strtolower($type) == "hcpcs") {
76 $tmp = sqlQuery("SELECT ndc_info FROM billing WHERE " .
77 "code_type = 'HCPCS' AND code = '$code' AND ndc_info LIKE 'N4%' " .
78 "ORDER BY date DESC LIMIT 1");
79 if (!empty($tmp)) {
80 $ndc_info = $tmp['ndc_info'];
84 addBilling(
85 $encounter,
86 $type,
87 $code,
88 strip_escape_custom($text),
89 $pid,
90 $userauthorized,
91 $provid,
92 $modifier,
93 $units,
94 $fee,
95 $ndc_info
98 } elseif ($mode == "justify") {
99 $diags = $_POST['code']['diag'];
100 $procs = $_POST['code']['proc'];
101 $sql = array();
102 if (!empty($procs) && !empty($diags)) {
103 $sql = array();
104 foreach ($procs as $proc) {
105 $justify_string = "";
106 foreach ($diags as $diag) {
107 $justify_string .= $diag . ":";
110 $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) . "'";
114 if (!empty($sql)) {
115 foreach ($sql as $q) {
116 $results = sqlQ($q);
120 // Save NDC fields, if present.
121 $ndcarr = $_POST['ndc'];
122 for ($lino = 1; !empty($ndcarr["$lino"]['code']); ++$lino) {
123 $ndc = $ndcarr["$lino"];
124 $ndc_info = '';
125 if ($ndc['ndcnum']) {
126 $ndc_info = 'N4' . trim($ndc['ndcnum']) . ' ' . $ndc['ndcuom'] .
127 trim($ndc['ndcqty']);
130 sqlStatement("UPDATE billing SET ndc_info = '$ndc_info' WHERE " .
131 "encounter = '" . add_escape_custom($_POST['encounter_id']) . "' AND " .
132 "pid = '" . add_escape_custom($_POST['patient_id']) . "' AND " .
133 "code = '" . add_escape_custom($ndc['code']) . "'");
139 <html>
140 <head>
141 <?php html_header_show();?>
142 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
144 <script language="JavaScript">
146 function validate(f) {
147 for (var lino = 1; f['ndc['+lino+'][code]']; ++lino) {
148 var pfx = 'ndc['+lino+']';
149 if (f[pfx+'[ndcnum]'] && f[pfx+'[ndcnum]'].value) {
150 // Check NDC number format.
151 var ndcok = true;
152 var ndc = f[pfx+'[ndcnum]'].value;
153 var a = ndc.split('-');
154 if (a.length != 3) {
155 ndcok = false;
157 else if (a[0].length < 1 || a[1].length < 1 || a[2].length < 1 ||
158 a[0].length > 5 || a[1].length > 4 || a[2].length > 2) {
159 ndcok = false;
161 else {
162 for (var i = 0; i < 3; ++i) {
163 for (var j = 0; j < a[i].length; ++j) {
164 var c = a[i].charAt(j);
165 if (c < '0' || c > '9') ndcok = false;
169 if (!ndcok) {
170 alert('<?php xl('Format incorrect for NDC', 'e') ?> "' + ndc +
171 '", <?php xl('should be like nnnnn-nnnn-nn', 'e') ?>');
172 if (f[pfx+'[ndcnum]'].focus) f[pfx+'[ndcnum]'].focus();
173 return false;
175 // Check for valid quantity.
176 var qty = f[pfx+'[ndcqty]'].value - 0;
177 if (isNaN(qty) || qty <= 0) {
178 alert('<?php xl('Quantity for NDC', 'e') ?> "' + ndc +
179 '" <?php xl('is not valid (decimal fractions are OK).', 'e') ?>');
180 if (f[pfx+'[ndcqty]'].focus) f[pfx+'[ndcqty]'].focus();
181 return false;
185 top.restoreSession();
186 return true;
189 </script>
191 </head>
193 <body class="body_bottom">
195 <?php
196 $thisauth = acl_check('encounters', 'coding_a');
197 if (!$thisauth) {
198 $erow = sqlQuery("SELECT user FROM forms WHERE " .
199 "encounter = '$encounter' AND formdir = 'newpatient' LIMIT 1");
200 if ($erow['user'] == $_SESSION['authUser']) {
201 $thisauth = acl_check('encounters', 'coding');
205 if ($thisauth) {
206 $tmp = getPatientData($pid, "squad");
207 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad'])) {
208 $thisauth = 0;
212 if (!$thisauth) {
213 echo "<p>(".xl('Coding not authorized').")</p>\n";
214 echo "</body>\n</html>\n";
215 exit();
219 <form name="diagnosis" method="post" action="diagnosis.php?mode=justify"
220 onsubmit="return validate(this)">
222 <table border=0 cellspacing=0 cellpadding=0 height=100%>
223 <tr>
225 <td valign=top>
227 <dl>
228 <dt>
229 <a href="diagnosis_full.php" target="<?php echo $target; ?>" onclick="top.restoreSession()">
230 <span class=title><?php echo ($GLOBALS['phone_country_code'] == '1') ? xl('Billing') : xl('Coding'); ?></span>
231 <font class=more><?php echo $tmore;?></font></a>
233 <?php
234 if (!empty($_GET["back"]) || !empty($_POST["back"])) {
235 print "&nbsp;<a href=\"superbill_codes.php\" target=\"$target\" onclick=\"top.restoreSession()\"><font class=more>$tback</font></a>";
236 print "<input type=\"hidden\" name=\"back\" value=\"1\">";
239 <?php if (!$GLOBALS['weight_loss_clinic']) { ?>
240 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
241 <input type="submit" name="justify" value="<?php xl('Justify/Save', 'e');?>">
242 <?php } ?>
243 </dt>
244 </dl>
246 <a href="cash_receipt.php?" class='link_submit' target='new' onclick='top.restoreSession()'>
247 [<?php xl('Receipt', 'e'); ?>]
248 </a>
249 <table border="0">
250 <?php
251 if ($result = getBillingByEncounter($pid, $encounter, "*")) {
252 $billing_html = array();
253 $total = 0.0;
254 $ndclino = 0;
255 foreach ($result as $iter) {
256 if ($iter["code_type"] == "ICD9") {
257 $html = "<tr>";
258 $html .= "<td valign=\"middle\">" .
259 '<input style="width: 11px;height: 11px;" name="code[diag][' .
260 $iter["code"] . ']" type="checkbox" value="' . $iter[code] . '">' .
261 "</td><td><div><a target='$target' class='small' " .
262 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
263 $iter{"code"} . "</b> " . $iter{"code_text"} .
264 "</a></div></td></tr>\n";
265 $billing_html[$iter["code_type"]] .= $html;
266 $counter++;
267 } elseif ($iter["code_type"] == "COPAY") {
268 $billing_html[$iter["code_type"]] .=
269 "<tr><td></td><td><a target='$target' class='small' " .
270 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
271 oeFormatMoney($iter['code']) . "</b> " .
272 ucwords(strtolower($iter['code_text'])) .
273 ' ' . xl('payment entered on') . ' ' .
274 oeFormatShortDate(substr($iter['date'], 0, 10)) . substr($iter['date'], 10, 6) . "</a></td></tr>\n";
275 } else {
276 $billing_html[$iter["code_type"]] .=
277 "<tr><td>" . '<input style="width: 11px;height: 11px;" name="code[proc][' .
278 $iter["code"] . ']" type="checkbox" value="' . $iter[code] . '">' .
279 "</td><td><a target='$target' class='small' " .
280 "href='diagnosis_full.php' onclick='top.restoreSession()'><b>" .
281 $iter{"code"} . ' ' . $iter['modifier'] . "</b> " .
282 ucwords(strtolower($iter{"code_text"})) . ' ' . oeFormatMoney($iter['fee']) .
283 "</a><span class=\"small\">";
284 $total += $iter['fee'];
285 $js = explode(":", $iter['justify']);
286 $counter = 0;
287 foreach ($js as $j) {
288 if (!empty($j)) {
289 if ($counter == 0) {
290 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
291 } else {
292 $billing_html[$iter["code_type"]] .= " ($j)";
295 $counter++;
299 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
301 // If this is HCPCS, write NDC line.
302 if ($iter['code_type'] == 'HCPCS') {
303 ++$ndclino;
304 $ndcnum = '';
305 $ndcuom = '';
306 $ndcqty = '';
307 if (preg_match('/^N4(\S+)\s+(\S\S)(.*)/', $iter['ndc_info'], $tmp)) {
308 $ndcnum = $tmp[1];
309 $ndcuom = $tmp[2];
310 $ndcqty = $tmp[3];
313 $billing_html[$iter["code_type"]] .=
314 "<tr><td>&nbsp;</td><td class='small'>NDC:&nbsp;\n" .
315 "<input type='hidden' name='ndc[$ndclino][code]' value='" . $iter[code] . "'>" .
316 "<input type='text' name='ndc[$ndclino][ndcnum]' value='$ndcnum' " .
317 "size='11' style='background-color:transparent'>" .
318 " &nbsp;Qty:&nbsp;" .
319 "<input type='text' name='ndc[$ndclino][ndcqty]' value='$ndcqty' " .
320 "size='3' style='background-color:transparent;text-align:right'> " .
321 "<select name='ndc[$ndclino][ndcuom]' style='background-color:transparent'>";
322 foreach ($ndc_uom_choices as $key => $value) {
323 $billing_html[$iter["code_type"]] .= "<option value='$key'";
324 if ($key == $ndcuom) {
325 $billing_html[$iter["code_type"]] .= " selected";
328 $billing_html[$iter["code_type"]] .= ">$value</option>";
331 $billing_html[$iter["code_type"]] .= "</select></td></tr>\n";
336 $billing_html["CPT4"] .= "<tr><td>" . xl('total') . ":</td><td>" . oeFormatMoney($total) . "</td></tr>\n";
337 foreach ($billing_html as $key => $val) {
338 print "<tr><td>$key</td><td><table>$val</table><td></tr><tr><td height=\"5\"></td></tr>\n";
342 </tr></table>
343 </td>
344 </tr>
345 <input type="hidden" name="encounter_id" value="<?php echo $encounter?>">
346 <input type="hidden" name="patient_id" value="<?php echo $pid?>">
347 </form>
348 </table>
350 </body>
351 </html>