Height/length, weight, and blood pressure must be recorded in numerical
[openemr.git] / library / gen_hcfa_1500.inc.php
blobffab7a041234b38e4519fc74fa1b61a6df3e5c47
1 <?php
2 // Copyright (C) 2008-2011 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("Claim.class.php");
10 require_once("gen_hfca_1500_02_12.inc.php");
12 $hcfa_curr_line = 1;
13 $hcfa_curr_col = 1;
14 $hcfa_data = '';
15 $hcfa_proc_index = 0;
18 /**
19 * take the data element and place it at the correct coordinates on the page
21 * @global int $hcfa_curr_line
22 * @global type $hcfa_curr_col
23 * @global type $hcfa_data
24 * @param type $line
25 * @param type $col
26 * @param type $maxlen
27 * @param type $data
28 * @param type $strip regular expression for what to strip from the data. period and has are the defaults
29 * 02/12 version needs to include periods in the diagnoses hence the need to override
31 function put_hcfa($line, $col, $maxlen, $data,$strip='/[.#]/') {
32 global $hcfa_curr_line, $hcfa_curr_col, $hcfa_data;
33 if ($line < $hcfa_curr_line)
34 die("Data item at ($line, $col) precedes current line.");
35 while ($hcfa_curr_line < $line) {
36 $hcfa_data .= "\n";
37 ++$hcfa_curr_line;
38 $hcfa_curr_col = 1;
40 if ($col < $hcfa_curr_col)
41 die("Data item at ($line, $col) precedes current column.");
42 while ($hcfa_curr_col < $col) {
43 $hcfa_data .= " ";
44 ++$hcfa_curr_col;
46 $data = preg_replace($strip, '', strtoupper($data));
47 $len = min(strlen($data), $maxlen);
48 $hcfa_data .= substr($data, 0, $len);
49 $hcfa_curr_col += $len;
52 function gen_hcfa_1500($pid, $encounter, &$log) {
53 global $hcfa_data, $hcfa_proc_index;
55 $hcfa_data = '';
56 $hcfa_proc_index = 0;
58 $today = time();
59 $claim = new Claim($pid, $encounter);
61 $log .= "Generating HCFA claim $pid-$encounter for " .
62 $claim->patientFirstName() . ' ' .
63 $claim->patientMiddleName() . ' ' .
64 $claim->patientLastName() . ' on ' .
65 date('Y-m-d H:i', $today) . ".\n";
67 while ($hcfa_proc_index < $claim->procCount()) {
68 if ($hcfa_proc_index) $hcfa_data .= "\014"; // append form feed for new page
69 gen_hcfa_1500_page($pid, $encounter, $log, $claim);
72 $log .= "\n";
73 return $hcfa_data;
76 function gen_hcfa_1500_page($pid, $encounter, &$log, &$claim) {
77 global $hcfa_curr_line, $hcfa_curr_col, $hcfa_data, $hcfa_proc_index;
79 $hcfa_curr_line = 1;
80 $hcfa_curr_col = 1;
82 // According to:
83 // http://www.ngsmedicare.com/NGSMedicare/PartB/EducationandSupport/ToolsandMaterials/CMS_ClaimFormInst.aspx
84 // Medicare interprets sections 9 and 11 of the claim form in its own
85 // special way. This flag tells us to do that. However I'm not 100%
86 // sure that it applies nationwide, and if you find that it is not right
87 // for you then set it to false. -- Rod 2009-03-26
88 $new_medicare_logic = $claim->claimType() == 'MB';
90 // Payer name, attn, street.
91 put_hcfa(2, 41, 31, $claim->payerName());
92 put_hcfa(3, 41, 31, $claim->payerAttn());
93 put_hcfa(4, 41, 31, $claim->payerStreet());
95 // Payer city, state, zip.
96 $tmp = $claim->payerCity() ? ($claim->payerCity() . ', ') : '';
97 put_hcfa(5, 41, 31, $tmp . $claim->payerState() . ' ' . $claim->payerZip());
99 // Box 1. Insurance Type
100 $ct = $claim->claimType();
101 $tmpcol = 45; // Other
102 if ($ct === 'MB') $tmpcol = 1; // Medicare
103 else if ($ct === 'MC') $tmpcol = 8; // Medicaid
104 else if ($ct === 'CH') $tmpcol = 15; // Champus
105 else if ($ct === 'CH') $tmpcol = 24; // Champus VA (why same code?)
106 else if ($ct === 'BL') $tmpcol = 31; // Group Health Plan (only BCBS?)
107 else if ($ct === '16') $tmpcol = 39; // FECA
108 put_hcfa(8, $tmpcol, 1, 'X');
110 // Box 1a. Insured's ID Number
111 put_hcfa(8, 50, 17, $claim->policyNumber());
113 // Box 2. Patient's Name
114 $tmp = $claim->patientLastName() . ', ' . $claim->patientFirstName();
115 if ($claim->patientMiddleName())
116 $tmp .= ', ' . substr($claim->patientMiddleName(),0,1);
117 put_hcfa(10, 1, 28, $tmp);
119 // Box 3. Patient's Birth Date and Sex
120 $tmp = $claim->patientDOB();
121 put_hcfa(10, 31, 2, substr($tmp,4,2));
122 put_hcfa(10, 34, 2, substr($tmp,6,2));
123 put_hcfa(10, 37, 4, substr($tmp,0,4));
124 put_hcfa(10, $claim->patientSex() == 'M' ? 42 : 47, 1, 'X');
126 // Box 4. Insured's Name
127 $tmp = $claim->insuredLastName() . ', ' . $claim->insuredFirstName();
128 if ($claim->insuredMiddleName())
129 $tmp .= ', ' . substr($claim->insuredMiddleName(),0,1);
130 put_hcfa(10, 50, 28, $tmp);
132 // Box 5. Patient's Address
133 put_hcfa(12, 1, 28, $claim->patientStreet());
135 // Box 6. Patient Relationship to Insured
136 $tmp = $claim->insuredRelationship();
137 $tmpcol = 47; // Other
138 if ($tmp === '18') $tmpcol = 33; // self
139 else if ($tmp === '01') $tmpcol = 38; // spouse
140 else if ($tmp === '19') $tmpcol = 42; // child
141 put_hcfa(12, $tmpcol, 1, 'X');
143 // Box 7. Insured's Address
144 put_hcfa(12, 50, 28, $claim->insuredStreet());
146 // Box 5 continued. Patient's City and State
147 put_hcfa(14, 1, 20, $claim->patientCity());
148 put_hcfa(14, 26, 2, $claim->patientState());
150 // Box 8. Patient (Marital) Status
151 if(!hcfa_1500_version_02_12()) // Box 8 Reserved for NUCC Use in 02/12
153 $tmp = $claim->patientStatus();
154 $tmpcol = 47; // Other
155 if ($tmp === 'S') $tmpcol = 35; // Single
156 else if ($tmp === 'M') $tmpcol = 41; // Married
157 put_hcfa(14, $tmpcol, 1, 'X');
160 // Box 7 continued. Insured's City and State
161 put_hcfa(14, 50, 20, $claim->insuredCity());
162 put_hcfa(14, 74, 2, $claim->insuredState());
164 // Box 5 continued. Patient's Zip Code and Telephone
165 put_hcfa(16, 1, 10, $claim->patientZip());
166 $tmp = $claim->patientPhone();
167 put_hcfa(16, 15, 3, substr($tmp,0,3));
168 put_hcfa(16, 19, 7, substr($tmp,3));
170 // Box 8 continued. Patient (Employment) Status
171 if(!hcfa_1500_version_02_12()) // Box 8 Reserved for NUCC Use in 02/12
173 $tmp = $claim->patientOccupation();
174 if ($tmp === 'STUDENT' ) put_hcfa(16, 41, 1, 'X');
175 else if ($tmp === 'PT STUDENT') put_hcfa(16, 47, 1, 'X');
176 else if ($tmp !== 'UNEMPLOYED') put_hcfa(16, 35, 1, 'X');
179 // Box 7 continued. Insured's Zip Code and Telephone
180 put_hcfa(16, 50, 10, $claim->insuredZip());
181 $tmp = $claim->insuredPhone();
182 put_hcfa(16, 65, 3, substr($tmp,0,3));
183 put_hcfa(16, 69, 7, substr($tmp,3));
185 // Box 9. Other Insured's Name
186 if ($new_medicare_logic) {
187 // TBD: Medigap stuff? How do we know if this is a Medigap transfer?
189 else {
190 if ($claim->payerCount() > 1) {
191 $tmp = $claim->insuredLastName(1) . ', ' . $claim->insuredFirstName(1);
192 if ($claim->insuredMiddleName(1))
193 $tmp .= ', ' . substr($claim->insuredMiddleName(1),0,1);
194 put_hcfa(18, 1, 28, $tmp);
198 // Box 11. Insured's Group Number
199 if ($new_medicare_logic) {
200 // If this is Medicare secondary then we need the primary's policy number
201 // here, otherwise the word "NONE".
202 $tmp = $claim->payerSequence() == 'P' ? 'NONE' : $claim->policyNumber(1);
204 else {
205 $tmp = $claim->groupNumber();
207 put_hcfa(18, 50, 30, $tmp);
209 // Box 9a. Other Insured's Policy or Group Number
210 if ($new_medicare_logic) {
211 // TBD: Medigap stuff?
213 else {
214 if ($claim->payerCount() > 1) {
215 put_hcfa(20, 1, 28, $claim->policyNumber(1));
219 // Box 10a. Employment Related
220 put_hcfa(20, $claim->isRelatedEmployment() ? 35 : 41, 1, 'X');
222 // Box 11a. Insured's Birth Date and Sex
223 if ($new_medicare_logic) {
224 $tmpdob = $tmpsex = '';
225 if ($claim->payerSequence() != 'P') {
226 $tmpdob = $claim->insuredDOB(1);
227 $tmpsex = $claim->insuredSex(1);
230 else {
231 $tmpdob = $claim->insuredDOB();
232 $tmpsex = $claim->insuredSex();
234 if ($tmpdob) {
235 put_hcfa(20, 53, 2, substr($tmpdob,4,2));
236 put_hcfa(20, 56, 2, substr($tmpdob,6,2));
237 put_hcfa(20, 59, 4, substr($tmpdob,0,4));
239 if ($tmpsex) {
240 put_hcfa(20, $tmpsex == 'M' ? 68 : 75, 1, 'X');
243 // Box 9b. Other Insured's Birth Date and Sex
244 if(!hcfa_1500_version_02_12()) // Box 9b Reserved for NUCC Use in 02/12
246 if ($new_medicare_logic) {
247 // TBD: Medigap stuff?
249 else {
250 if ($claim->payerCount() > 1) {
251 $tmp = $claim->insuredDOB(1);
252 put_hcfa(22, 2, 2, substr($tmp,4,2));
253 put_hcfa(22, 5, 2, substr($tmp,6,2));
254 put_hcfa(22, 8, 4, substr($tmp,0,4));
255 put_hcfa(22, $claim->insuredSex(1) == 'M' ? 18 : 24, 1, 'X');
260 // Box 10b. Auto Accident
261 put_hcfa(22, $claim->isRelatedAuto() ? 35 : 41, 1, 'X');
262 if ($claim->isRelatedAuto())
263 put_hcfa(22, 45, 2, $claim->autoAccidentState());
265 // Box 11b. Insured's Employer/School Name
266 if ($new_medicare_logic) {
267 $tmp = $claim->payerSequence() == 'P' ? '' : $claim->groupName(1);
269 else {
270 $tmp = $claim->groupName();
272 put_hcfa(22, 50, 30, $tmp);
274 // Box 9c. Other Insured's Employer/School Name
275 if(!hcfa_1500_version_02_12()) // Box 9c Reserved for NUCC Use in 02/12
277 if ($new_medicare_logic) {
278 // TBD: Medigap stuff?
280 else {
281 if ($claim->payerCount() > 1) {
282 put_hcfa(24, 1, 28, $claim->groupName(1));
287 // Box 10c. Other Accident
288 put_hcfa(24, $claim->isRelatedOther() ? 35 : 41, 1, 'X');
290 // Box 11c. Insurance Plan Name or Program Name
291 if ($new_medicare_logic) {
292 $tmp = '';
293 if ($claim->payerSequence() != 'P') {
294 $tmp = $claim->planName(1);
295 if (!$tmp) $tmp = $claim->payerName(1);
298 else {
299 $tmp = $claim->planName();
301 put_hcfa(24, 50, 30, $tmp);
303 // Box 9d. Other Insurance Plan Name or Program Name
304 if ($new_medicare_logic) {
305 // TBD: Medigap stuff?
307 else {
308 if ($claim->payerCount() > 1) {
309 put_hcfa(26, 1, 28, $claim->planName(1));
313 // Box 11d. Is There Another Health Benefit Plan
314 if (!$new_medicare_logic) {
315 put_hcfa(26, $claim->payerCount() > 1 ? 52 : 57, 1, 'X');
318 // Box 12. Patient's or Authorized Person's Signature
319 put_hcfa(29, 7, 17, 'Signature on File');
320 // Note: Date does not apply unless the person physically signs the form.
322 // Box 13. Insured's or Authorized Person's Signature
323 put_hcfa(29, 55, 17, 'Signature on File');
325 // Box 14. Date of Current Illness/Injury/Pregnancy
326 $tmp = $claim->onsetDate();
327 put_hcfa(32, 2, 2, substr($tmp,4,2));
328 put_hcfa(32, 5, 2, substr($tmp,6,2));
329 put_hcfa(32, 8, 4, substr($tmp,0,4));
331 if(hcfa_1500_version_02_12())
333 put_hcfa(32, 16, 3, $claim->box14qualifier());
336 // Box 15. First Date of Same or Similar Illness, if applicable
337 $tmp = $claim->dateInitialTreatment();
338 if(hcfa_1500_version_02_12() && !empty($tmp))
340 put_hcfa(32, 31, 3, $claim->box15qualifier());
344 put_hcfa(32,37, 2, substr($tmp,4,2));
345 put_hcfa(32,40, 2, substr($tmp,6,2));
346 put_hcfa(32,43, 4, substr($tmp,0,4));
349 // Box 16. Dates Patient Unable to Work in Current Occupation
350 if ($claim->isUnableToWork()) {
351 $tmp = $claim->offWorkFrom();
352 put_hcfa(32, 54, 2, substr($tmp,4,2));
353 put_hcfa(32, 57, 2, substr($tmp,6,2));
354 put_hcfa(32, 60, 4, substr($tmp,0,4));
355 $tmp = $claim->offWorkTo();
356 put_hcfa(32, 68, 2, substr($tmp,4,2));
357 put_hcfa(32, 71, 2, substr($tmp,6,2));
358 put_hcfa(32, 74, 4, substr($tmp,0,4));
361 // Referring provider stuff. Reports are that for primary care doctors,
362 // Medicare forbids an entry here and other payers require one.
363 // There is still confusion over this.
365 if ($claim->referrerLastName() &&
366 (empty($GLOBALS['MedicareReferrerIsRenderer']) || $claim->claimType() != 'MB'))
368 // Box 17a. Referring Provider Alternate Identifier
369 if ($claim->referrerUPIN() && $claim->claimType() != 'MB') {
370 put_hcfa(33, 30, 2, '1G');
371 put_hcfa(33, 33, 15, $claim->referrerUPIN());
374 // Box 17. Name of Referring Provider or Other Source
375 $tmp = $claim->referrerLastName() . ', ' . $claim->referrerFirstName();
376 if ($claim->referrerMiddleName())
377 $tmp .= ', ' . substr($claim->referrerMiddleName(),0,1);
378 put_hcfa(34, 1, 25, $tmp);
380 // Box 17b. Referring Provider NPI
381 if ($claim->referrerNPI()) {
382 put_hcfa(34, 33, 15, $claim->referrerNPI());
386 // Box 18. Hospitalization Dates Related to Current Services
387 if ($claim->isHospitalized()) {
388 $tmp = $claim->hospitalizedFrom();
389 put_hcfa(34, 54, 2, substr($tmp,4,2));
390 put_hcfa(34, 57, 2, substr($tmp,6,2));
391 put_hcfa(34, 60, 4, substr($tmp,0,4));
392 $tmp = $claim->hospitalizedTo();
393 put_hcfa(34, 68, 2, substr($tmp,4,2));
394 put_hcfa(34, 71, 2, substr($tmp,6,2));
395 put_hcfa(34, 74, 4, substr($tmp,0,4));
398 // Box 19. Reserved for Local Use
399 put_hcfa(36, 1, 48, $claim->additionalNotes());
401 // Box 20. Outside Lab
402 put_hcfa(36, $claim->isOutsideLab() ? 52 : 57, 1, 'X');
403 if ($claim->isOutsideLab()) {
404 // Note here that put_hcfa strips the decimal point, as required.
405 // We right-justify this amount (ending in col. 69).
406 put_hcfa(36, 63, 8, sprintf('%8s', $claim->outsideLabAmount()));
409 if(hcfa_1500_version_02_12())
411 process_diagnoses_02_12($claim,$log);
413 else
415 // Box 21. Diagnoses
416 $tmp = $claim->diagArray();
417 $diags = array();
418 foreach ($tmp as $diag) $diags[] = $diag;
419 if (!empty($diags[0])) {
420 put_hcfa(38, 3, 3, substr($diags[0], 0, 3));
421 put_hcfa(38, 7, 2, substr($diags[0], 3));
423 if (!empty($diags[2])) {
424 put_hcfa(38, 30, 3, substr($diags[2], 0, 3));
425 put_hcfa(38, 34, 2, substr($diags[2], 3));
428 // Box 22. Medicaid Resubmission Code and Original Ref. No.
429 put_hcfa(38, 50, 10, $claim->medicaidResubmissionCode());
430 put_hcfa(38, 62, 10, $claim->medicaidOriginalReference());
432 // Box 21 continued. Diagnoses
433 if (!empty($diags[1])) {
434 put_hcfa(40, 3, 3, substr($diags[1], 0, 3));
435 put_hcfa(40, 7, 2, substr($diags[1], 3));
437 if (!empty($diags[3])) {
438 put_hcfa(40, 30, 3, substr($diags[3], 0, 3));
439 put_hcfa(40, 34, 2, substr($diags[3], 3));
442 // Box 23. Prior Authorization Number
443 put_hcfa(40, 50, 28, $claim->priorAuth());
445 $proccount = $claim->procCount(); // number of procedures
447 // Charges, adjustments and payments are accumulated by line item so that
448 // each page of a multi-page claim will stand alone. Payments include the
449 // co-pay for the first page only.
450 $clm_total_charges = 0;
451 $clm_amount_adjusted = 0;
452 $clm_amount_paid = $hcfa_proc_index ? 0 : $claim->patientPaidAmount();
454 // Procedure loop starts here.
456 for ($svccount = 0; $svccount < 6 && $hcfa_proc_index < $proccount; ++$hcfa_proc_index) {
457 $dia = $claim->diagIndexArray($hcfa_proc_index);
459 if (!$claim->cptCharges($hcfa_proc_index)) {
460 $log .= "*** Procedure '" . $claim->cptKey($hcfa_proc_index) .
461 "' has no charges!\n";
464 if (empty($dia)) {
465 $log .= "*** Procedure '" . $claim->cptKey($hcfa_proc_index) .
466 "' is not justified!\n";
469 $clm_total_charges += $claim->cptCharges($hcfa_proc_index);
471 // Compute prior payments and "hard" adjustments.
472 for ($ins = 1; $ins < $claim->payerCount(); ++$ins) {
473 if ($claim->payerSequence($ins) > $claim->payerSequence())
474 continue; // skip future payers
475 $payerpaid = $claim->payerTotals($ins, $claim->cptKey($hcfa_proc_index));
476 $clm_amount_paid += $payerpaid[1];
477 $clm_amount_adjusted += $payerpaid[2];
480 ++$svccount;
481 $lino = $svccount * 2 + 41;
483 // Drug Information. Medicaid insurers want this with HCPCS codes.
485 $ndc = $claim->cptNDCID($hcfa_proc_index);
486 if ($ndc) {
487 if (preg_match('/^(\d\d\d\d\d)-(\d\d\d\d)-(\d\d)$/', $ndc, $tmp)) {
488 $ndc = $tmp[1] . $tmp[2] . $tmp[3];
490 else if(preg_match('/^\d{11}$/', $ndc)){
493 else {
494 $log .= "*** NDC code '$ndc' has invalid format!\n";
496 put_hcfa($lino, 1, 50, "N4$ndc " . $claim->cptNDCUOM($hcfa_proc_index) .
497 $claim->cptNDCQuantity($hcfa_proc_index));
500 //Note Codes.
501 put_hcfa($lino, 25, 7, $claim->cptNotecodes($hcfa_proc_index));
503 // 24i and 24j Top. ID Qualifier and Rendering Provider ID
504 if ($claim->supervisorNumber()) {
505 // If there is a supervising provider and that person has a
506 // payer-specific provider number, then we assume that the SP
507 // must be identified on the claim and this is how we do it
508 // (but the NPI of the actual rendering provider appears below).
509 // BCBS of TN indicated they want it this way. YMMV. -- Rod
510 put_hcfa($lino, 65, 2, $claim->supervisorNumberType());
511 put_hcfa($lino, 68, 10, $claim->supervisorNumber());
513 else if ($claim->providerNumber($hcfa_proc_index)) {
514 put_hcfa($lino, 65, 2, $claim->providerNumberType($hcfa_proc_index));
515 put_hcfa($lino, 68, 10, $claim->providerNumber($hcfa_proc_index));
518 ++$lino;
520 // 24a. Date of Service
521 $tmp = $claim->serviceDate();
522 put_hcfa($lino, 1, 2, substr($tmp,4,2));
523 put_hcfa($lino, 4, 2, substr($tmp,6,2));
524 put_hcfa($lino, 7, 2, substr($tmp,2,2));
525 put_hcfa($lino,10, 2, substr($tmp,4,2));
526 put_hcfa($lino,13, 2, substr($tmp,6,2));
527 put_hcfa($lino,16, 2, substr($tmp,2,2));
529 // 24b. Place of Service
530 put_hcfa($lino, 19, 2, $claim->facilityPOS());
532 // 24c. EMG
533 // Not currently supported.
535 // 24d. Procedures, Services or Supplies
536 put_hcfa($lino, 25, 7, $claim->cptCode($hcfa_proc_index));
537 // replace colon with space for printing
538 put_hcfa($lino, 33, 12, str_replace(':', ' ', $claim->cptModifier($hcfa_proc_index)));
540 // 24e. Diagnosis Pointer
541 $tmp = '';
542 foreach ($claim->diagIndexArray($hcfa_proc_index) as $value)
544 if(hcfa_1500_version_02_12())// For 02/12 Version convert number to letter.
546 // ASCII A is 65, since diagIndexArray is ones based, this will make 1->A, 2->B...
547 $value=chr($value+64);
549 $tmp .= $value;
551 put_hcfa($lino, 45, 4, $tmp);
553 // 24f. Charges
554 put_hcfa($lino, 50, 8, str_replace('.', ' ',
555 sprintf('%8.2f', $claim->cptCharges($hcfa_proc_index))));
557 // 24g. Days or Units
558 put_hcfa($lino, 59, 3, $claim->cptUnits($hcfa_proc_index));
560 // 24h. EPSDT Family Plan
561 // Not currently supported.
563 // 24j. Rendering Provider NPI
564 put_hcfa($lino, 68, 10, $claim->providerNPI($hcfa_proc_index));
567 // 25. Federal Tax ID Number
568 // FrreB hard coded EIN. Changed it to included SSN as well.
569 put_hcfa(56, 1, 15, $claim->billingFacilityETIN());
570 if($claim->federalIdType()=='SY'){
571 put_hcfa(56, 16, 1, 'X'); // The SSN checkbox
573 else{
574 put_hcfa(56, 19, 1, 'X'); // The EIN checkbox
577 // 26. Patient's Account No.
578 // Instructions say hyphens are not allowed, but freeb used them.
579 put_hcfa(56, 23, 15, "$pid-$encounter");
581 // 27. Accept Assignment
582 put_hcfa(56, $claim->billingFacilityAssignment() ? 38 : 43, 1, 'X');
584 // 28. Total Charge
585 put_hcfa(56, 52, 8, str_replace('.',' ',sprintf('%8.2f',$clm_total_charges)));
586 if (!$clm_total_charges) {
587 $log .= "*** This claim has no charges!\n";
590 // 29. Amount Paid
591 put_hcfa(56, 62, 8, str_replace('.',' ',sprintf('%8.2f',$clm_amount_paid)));
593 // 30. Balance Due
594 // For secondary payers this reflects primary "contracted rate" adjustments,
595 // so in general box 30 will not equal box 28 minus box 29.
596 if(!hcfa_1500_version_02_12()) // Box 30 Reserved for NUCC Use in 02/12
598 put_hcfa(56, 71, 8, str_replace('.',' ',sprintf('%8.2f',
599 $clm_total_charges - $clm_amount_paid - $clm_amount_adjusted)));
602 // 33. Billing Provider: Phone Number
603 $tmp = $claim->billingContactPhone();
604 put_hcfa(57, 66, 3, substr($tmp,0,3));
605 put_hcfa(57, 70, 7, substr($tmp,3));
607 // 32. Service Facility Location Information: Name
608 put_hcfa(58, 23, 25, $claim->facilityName());
610 // 33. Billing Provider: Name
611 put_hcfa(58, 50, 25, $claim->billingFacilityName());
613 // 32. Service Facility Location Information: Street
614 put_hcfa(59, 23, 25, $claim->facilityStreet());
616 // 33. Billing Provider: Name
617 put_hcfa(59, 50, 25, $claim->billingFacilityStreet());
619 // 31. Signature of Physician or Supplier
620 // FreeB printed the rendering provider's name and the current date here,
621 // but according to my instructions it must be a real signature and date,
622 // or else "Signature on File" or "SOF".
624 if($GLOBALS['cms_1500_box_31_format']==0)
626 put_hcfa(60, 1, 20, 'Signature on File');
628 else if($GLOBALS['cms_1500_box_31_format']==1)
630 put_hcfa(60, 1, 22, $claim->providerFirstName()." ".$claim->providerLastName());
633 // $tmp = $claim->providerFirstName();
634 // if ($claim->providerMiddleName()) $tmp .= ' ' . substr($claim->providerMiddleName(),0,1);
635 // put_hcfa(60, 1, 20, $tmp . ' ' . $claim->providerLastName());
637 // 32. Service Facility Location Information: City State Zip
638 $tmp = $claim->facilityCity() ? ($claim->facilityCity() . ' ') : '';
639 put_hcfa(60, 23, 27, $tmp . $claim->facilityState() . ' ' .
640 $claim->facilityZip());
642 // 33. Billing Provider: City State Zip
643 $tmp = $claim->billingFacilityCity() ? ($claim->billingFacilityCity() . ' ') : '';
644 put_hcfa(60, 50, 27, $tmp . $claim->billingFacilityState() . ' ' .
645 $claim->billingFacilityZip());
647 // 31. Signature of Physician or Supplier: Date
648 if($GLOBALS['cms_1500_box_31_date']>0)
650 if($GLOBALS['cms_1500_box_31_date']==1)
652 $date_of_service= $claim->serviceDate();
653 $MDY=substr($date_of_service,4,2)." ".substr($date_of_service,6,2)." ".substr($date_of_service,2,2);
655 else if($GLOBALS['cms_1500_box_31_date']==2)
657 $MDY=date("m/d/y");
659 put_hcfa(61,6,10,$MDY);
662 // 32a. Service Facility NPI
663 put_hcfa(61, 24, 10, $claim->facilityNPI());
665 // 32b. Service Facility Other ID
666 // Note that Medicare does NOT want this any more.
667 if ($claim->providerGroupNumber()) {
668 put_hcfa(61, 36, 2, $claim->providerNumberType());
669 put_hcfa(61, 38, 11, $claim->providerGroupNumber());
672 // 33a. Billing Facility NPI
673 put_hcfa(61, 51, 10, $claim->billingFacilityNPI());
675 // 33b. Billing Facility Other ID
676 // Note that Medicare does NOT want this any more.
677 if ($claim->providerGroupNumber() && $claim->claimType() != 'MB') {
678 put_hcfa(61, 63, 2, $claim->providerNumberType());
679 put_hcfa(61, 65, 14, $claim->providerGroupNumber());
682 // Put an extra line here for compatibility with old hcfa text generated form
683 put_hcfa(62, 1, 1, ' ');
685 return;