utf8 bug fix - removed some casing functions calls that break utf8 encoding
[openemr.git] / interface / patient_file / encounter / diagnosis.php
blob0aeefe04196a08c53f0b69e80ce091b1b85244bc
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/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(
28 'ML' => 'ML',
29 'GR' => 'Grams',
30 'ME' => 'Milligrams',
31 'F2' => 'I.U.',
32 'UN' => 'Units'
35 if ($payment_method == "insurance") {
36 $payment_method = "insurance: " . $insurance_company;
38 if (isset($mode)) {
39 if ($mode == "add") {
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));
58 else {
59 $ndc_info = '';
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'];
74 $sql = array();
75 if (!empty($procs) && !empty($diags)) {
76 $sql = array();
77 foreach ($procs as $proc) {
78 $justify_string = "";
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) . "'";
86 if (!empty($sql)) {
87 foreach ($sql as $q) {
88 $results = sqlQ($q);
92 // Save NDC fields, if present.
93 $ndcarr = $_POST['ndc'];
94 for ($lino = 1; !empty($ndcarr["$lino"]['code']); ++$lino) {
95 $ndc = $ndcarr["$lino"];
96 $ndc_info = '';
97 if ($ndc['ndcnum']) {
98 $ndc_info = 'N4' . trim($ndc['ndcnum']) . ' ' . $ndc['ndcuom'] .
99 trim($ndc['ndcqty']);
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']) . "'");
111 <html>
112 <head>
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.
123 var ndcok = true;
124 var ndc = f[pfx+'[ndcnum]'].value;
125 var a = ndc.split('-');
126 if (a.length != 3) {
127 ndcok = false;
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) {
131 ndcok = false;
133 else {
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;
141 if (!ndcok) {
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();
145 return false;
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();
153 return false;
157 top.restoreSession();
158 return true;
161 </script>
163 </head>
165 <body class="body_bottom">
167 <?php
168 $thisauth = acl_check('encounters', 'coding_a');
169 if (!$thisauth) {
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');
175 if ($thisauth) {
176 $tmp = getPatientData($pid, "squad");
177 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
178 $thisauth = 0;
180 if (!$thisauth) {
181 echo "<p>(".xl('Coding not authorized').")</p>\n";
182 echo "</body>\n</html>\n";
183 exit();
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%>
191 <tr>
193 <td valign=top>
195 <dl>
196 <dt>
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>
201 <?php
202 if( !empty( $_GET["back"] ) || !empty( $_POST["back"] ) ){
203 print "&nbsp;<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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
209 <input type="submit" name="justify" value="<?php xl('Justify/Save','e');?>">
210 <?php } ?>
211 </dt>
212 </dl>
214 <a href="cash_receipt.php?" class='link_submit' target='new' onclick='top.restoreSession()'>
215 [<?php xl('Receipt','e'); ?>]
216 </a>
217 <table border="0">
218 <?php
219 if ($result = getBillingByEncounter($pid,$encounter,"*") ) {
220 $billing_html = array();
221 $total = 0.0;
222 $ndclino = 0;
223 foreach ($result as $iter) {
224 if ($iter["code_type"] == "ICD9") {
225 $html = "<tr>";
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;
234 $counter++;
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";
245 else {
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']);
256 $counter = 0;
257 foreach ($js as $j) {
258 if(!empty($j)) {
259 if ($counter == 0) {
260 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
262 else {
263 $billing_html[$iter["code_type"]] .= " ($j)";
265 $counter++;
268 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
270 // If this is HCPCS, write NDC line.
271 if ($iter['code_type'] == 'HCPCS') {
272 ++$ndclino;
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>&nbsp;</td><td class='small'>NDC:&nbsp;\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 " &nbsp;Qty:&nbsp;" .
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";
303 </tr></table>
304 </td>
305 </tr>
306 <input type="hidden" name="encounter_id" value="<?php echo $encounter?>">
307 <input type="hidden" name="patient_id" value="<?php echo $pid?>">
308 </form>
309 </table>
311 </body>
312 </html>