removed redundant docs (it is on the wiki)
[openemr.git] / library / gen_hcfa_1500_02_12.inc.php
blob18c4c201b86d6188003afa94f56853bfb392da6b
1 <?php
2 /**
3 * Utilities to support HCFA 1500 02/12 Version
4 * For details on format refer to:
5 * <http://www.nucc.org/index.php?option=com_content&view=article&id=186&Itemid=138>
6 *
7 * Copyright (C) 2013 Kevin Yeh <kevin.y@integralemr.com> and OEMR <www.oemr.org>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @package OpenEMR
21 * @author Kevin Yeh <kevin.y@integralemr.com>
22 * @link http://www.open-emr.org
25 /**
27 * @return type Is the system configured to use the 02/12 version of the form
29 function hcfa_1500_version_02_12()
31 return $GLOBALS['cms_1500']=='1';
35 /**
36 * Helper class to manage which rows and columns information belong in.
37 * This allows "out of order" creation of the content.
39 class hcfa_info
41 protected $row;
42 protected $column;
43 protected $width;
44 protected $info;
46 /**
48 * @param type $row Which row to put this data on
49 * @param type $column Which column to put this data in
50 * @param type $width How many characters max to print on
51 * @param type $info The text to print on the form at the specified location
53 public function __construct($row,$column,$width,$info)
55 $this->row=$row;
56 $this->column=$column;
57 $this->width=$width;
58 $this->info=$info;
61 /**
62 * Determine relative position of an element
64 * @return type integer
66 public function get_position()
68 return $this->row*100+$this->column;
71 /**
72 * Add the info to the form
74 public function put()
76 // Override the default value for "strip" with put_hcfa to keep periods
77 put_hcfa($this->row,$this->column,$this->width,$this->info,'/#/');
81 /**
82 * comparator function for hfca_info class to allow proper sorting
84 * @param type $first
85 * @param type $second
86 * @return int
88 function cmp_hcfa_info($first,$second)
90 $first_value=$first->get_position();
91 $second_value=$second->get_position();
92 if($first_value==$second_value)
94 return 0;
96 return $first_value<$second_value ? -1 : 1;
99 /**
100 * calculate where on the form a given diagnosis belongs and add it to the entries
102 * @param array $hcfa_entries
103 * @param type $number
104 * @param type $diag
106 function add_diagnosis(&$hcfa_entries,$number,$diag)
109 * The diagnoses go across the page.
110 * Positioned
111 * A B C D
112 * E F G H
113 * I J K L
115 $column_num = ($number%4);
116 $row_num = (int)($number / 4);
118 // First column is at location 3, each column is 13 wide
119 $col_pos=3+13*$column_num;
121 // First diagnosis row is 38
122 $strip='/[.#]/';
123 $diag = preg_replace($strip, '', strtoupper($diag));
124 $row_pos=38+$row_num;
125 $hcfa_entries[]=new hcfa_info($row_pos,$col_pos,8,$diag);
131 * Process the diagnoses for a given claim. log any errors
133 * @param type $claim
134 * @param string $log
136 function process_diagnoses_02_12(&$claim,&$log)
139 $hcfa_entries=array();
140 $diags = $claim->diagArray(false);
141 if($claim->diagtype=='ICD10')
143 $icd_indicator='0';
145 else
147 $icd_indicator='9';
150 $hcfa_entries[]=new hcfa_info(37,42,1,$icd_indicator);
152 // Box 22. Medicaid Resubmission Code and Original Ref. No.
153 $hcfa_entries[]=new hcfa_info(38,50,10,$claim->medicaidResubmissionCode());
154 $hcfa_entries[]=new hcfa_info(38,62,10,$claim->medicaidOriginalReference());
156 // Box 23. Prior Authorization Number
157 $hcfa_entries[]=new hcfa_info(40,50,28,$claim->priorAuth());
159 $diag_count=0;
160 foreach($diags as $diag)
162 if($diag_count<12)
164 add_diagnosis($hcfa_entries,$diag_count,$diag);
166 else
168 $log.= "***Too many diagnoses ".($diag_count+1).":".$diag;
170 $diag_count++;
173 // Sort the entries to put them in the page base sequence.
174 usort($hcfa_entries,"cmp_hcfa_info");
176 foreach($hcfa_entries as $hcfa_entry)
178 $hcfa_entry->put();