Cleanup to remove multibox functionality which proved to be confusing in use.
[openemr.git] / library / classes / InsuranceCompany.class.php
blob90728914ffff86661171f7fa66f5a41148e0e794
1 <?php
2 /************************************************************************
3 InsuranceCompany.php - Copyright duhlman
7 This file was generated on %date% at %time%
8 The original location of this file is /home/duhlman/uml-generated-code/prescription.php
9 **************************************************************************/
11 define ("FREEB_TYPE_OTHER_HCFA",1);
12 define ("FREEB_TYPE_MEDICARE",2);
13 define ("FREEB_TYPE_MEDICAID",3);
14 define ("FREEB_TYPE_CHAMPUSVA",4);
15 define ("FREEB_TYPE_CHAMPUS",5);
16 define ("FREEB_TYPE_BCBS",6);
17 define ("FREEB_TYPE_FECA",7);
18 define ("FREEB_TYPE_SELF_PAY",8);
19 define ("FREEB_TYPE_CENTRAL_CERTIFICATION",9);
20 define ("FREEB_TYPE_OTHER_NON-FEDERAL_PROGRAMS",10);
21 define ("FREEB_TYPE_PREFERRED_PROVIDER_ORGANIZATION",11);
22 define ("FREEB_TYPE_POINT_OF_SERVICE",12);
23 define ("FREEB_TYPE_EXCLUSIVE_PROVIDER_ORGANIZATION",13);
24 define ("FREEB_TYPE_INDEMNITY_INSURANCE",14);
25 define ("FREEB_TYPE_HMO_MEDICARE_RISK",15);
26 define ("FREEB_TYPE_AUTOMOBILE_MEDICAL",16);
27 define ("FREEB_TYPE_COMMERCIAL_INSURANCE",17);
28 define ("FREEB_TYPE_DISABILITY",18);
29 define ("FREEB_TYPE_HEALTH_MAINTENANCE_ORGANIZATION",19);
30 define ("FREEB_TYPE_LIABILITY",20);
31 define ("FREEB_TYPE_LIABILITY_MEDICAL",21);
32 define ("FREEB_TYPE_OTHER_FEDERAL_PROGRAM",22);
33 define ("FREEB_TYPE_TITLE_V",23);
34 define ("FREEB_TYPE_VETERANS_ADMINISTRATION_PLAN",24);
35 define ("FREEB_TYPE_WORKERS_COMPENSATION_HEALTH_PLAN",25);
36 define ("FREEB_TYPE_MUTUALLY_DEFINED",26);
38 require_once("PhoneNumber.class.php");
39 require_once("Address.class.php");
42 require_once("ORDataObject.class.php");
43 /**
44 * class Insurance Company
47 class InsuranceCompany extends ORDataObject{
48 var $id;
49 var $name;
50 var $phone;
51 var $attn;
52 var $cms_id;
53 //this is now deprecated use new x12 partners instead
54 var $x12_receiver_id;
55 var $x12_default_partner_id;
58 * Freeb used this value to determine special formatting for the specified type of payer.
59 * This value is a mutually exclusive choice answering the FB.Payer.isX API calls
60 * It references a set of constant defined in this file FREEB_TYPE_XXX
61 * Defaults to type FREEB_TYPE_OTHER_HCFA
62 * @var int Holds constant for type of payer as far as FREEB is concerned, see FB.Payer.isXXX API calls
64 var $freeb_type;
67 * Array used to populate select dropdowns or other form elements, it must coincide with the FREEB_TYPE_XXX constants
68 * @var array Values are display strings that match constants for FB.Payer.isXXX payer types, used for populating select dropdowns, etc
70 var $freeb_type_array = array('','Other HCFA'
71 ,'Medicare Part B'
72 ,'Medicaid'
73 ,'ChampUSVA'
74 ,'ChampUS'
75 ,'Blue Cross Blue Shield'
76 ,'FECA'
77 ,'Self Pay'
78 ,'Central Certification'
79 ,'Other Non-Federal Programs'
80 ,'Preferred Provider Organization (PPO)'
81 ,'Point of Service (POS)'
82 ,'Exclusive Provider Organization (EPO)'
83 ,'Indemnity Insurance'
84 ,'Health Maintenance Organization (HMO) Medicare Risk'
85 ,'Automobile Medical'
86 ,'Commercial Insurance Co.'
87 ,'Disability'
88 ,'Health Maintenance Organization'
89 ,'Liability'
90 ,'Liability Medical'
91 ,'Other Federal Program'
92 ,'Title V'
93 ,'Veterans Administration Plan'
94 ,'Workers Compensation Health Plan'
95 ,'Mutually Defined'
98 var $freeb_claim_type_array = array(''
99 ,'16'
100 ,'MB'
101 ,'MC'
102 ,'CH'
103 ,'CH'
104 ,'BL'
105 ,'16'
106 ,'09'
107 ,'10'
108 ,'11'
109 ,'12'
110 ,'13'
111 ,'14'
112 ,'15'
113 ,'16'
114 ,'AM'
115 ,'CI'
116 ,'DS'
117 ,'HM'
118 ,'LI'
119 ,'LM'
120 ,'OF'
121 ,'TV'
122 ,'VA'
123 ,'WC'
124 ,'ZZ'
128 var $address;
131 * Constructor sets all Insurance Company attributes to their default value
133 function InsuranceCompany($id = "", $prefix = "") {
134 $this->id = $id;
135 $this->name = "";
136 $this->_table = "insurance_companies";
137 $phone = new PhoneNumber();
138 $phone->set_type(TYPE_WORK);
139 $this->phone = $phone;
140 $this->address = new Address();
141 $this->phone_numbers = array();
142 if ($id != "") {
143 $this->populate();
147 function set_id($id = "") {
148 $this->id = $id;
150 function get_id() {
151 return $this->id;
154 //special function the the html forms use to prepopulate which allows for partial edits and wizard functionality
155 function set_form_id ($id = "") {
156 if (!empty($id)) {
157 $this->populate($id);
161 function set_address($aobj) {
162 $this->address = $aobj;
164 function get_address() {
165 return $this->address;
167 function set_address_line1($line) {
168 $this->address->set_line1($line);
170 function set_address_line2($line) {
171 $this->address->set_line2($line);
174 function set_city($city) {
175 $this->address->set_city($city);
177 function set_state($state) {
178 $this->address->set_state($state);
180 function set_zip($zip) {
181 $this->address->set_zip($zip);
184 function set_name($name) {
185 $this->name = $name;
187 function get_name() {
188 return $this->name;
190 function set_attn($attn) {
191 $this->attn = $attn;
193 function get_attn() {
194 return $this->attn;
196 function set_cms_id($id) {
197 $this->cms_id = $id;
199 function get_cms_id() {
200 return $this->cms_id;
202 function set_freeb_type($type) {
203 $this->freeb_type = $type;
205 function get_freeb_type() {
206 return $this->freeb_type;
208 function get_freeb_type_display() {
209 return $this->freeb_type_array[$this->freeb_type];
211 function get_freeb_claim_type() {
212 return $this->freeb_claim_type_array[$this->freeb_type];
214 function get_phone() {
215 foreach($this->phone_numbers as $phone) {
216 if ($phone->type == TYPE_WORK) {
217 return $phone->get_phone_display();
220 return "";
222 function _set_number($num, $type) {
223 $found = false;
224 for ($i=0;$i<count($this->phone_numbers);$i++) {
225 if ($this->phone_numbers[$i]->type == $type) {
226 $found = true;
227 $this->phone_numbers[$i]->set_phone($num);
230 if ($found == false) {
231 $p = new PhoneNumber("",$this->id);
232 $p->set_type($type);
233 $p->set_phone($num);
234 $this->phone_numbers[] = $p;
235 //print_r($this->phone_numbers);
236 //echo "num is now:" . $p->get_phone_display() . "<br />";
240 function set_phone($phone) {
241 $this->_set_number($phone, TYPE_WORK);
244 function set_x12_receiver_id($id) {
245 //trigger_error("The set_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
246 $this->x12_receiver_id = $id;
249 function get_x12_receiver_id() {
250 //trigger_error("The get_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
251 return $this->x12_receiver_id;
254 function set_x12_default_partner_id($id) {
255 $this->x12_receiver_id = $id;
258 function get_x12_default_partner_id() {
259 return $this->x12_receiver_id;
262 function get_x12_default_partner_name() {
263 $xa = $this->_utility_array(X12Partner::x12_partner_factory());
264 return $xa[$this->get_x12_default_partner_id()];
267 function populate() {
268 parent::populate();
269 $this->address = Address::factory_address($this->id);
270 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
273 function persist() {
274 parent::persist();
275 $this->address->persist($this->id);
276 foreach ($this->phone_numbers as $phone) {
277 $phone->persist($this->id);
281 function utility_insurance_companies_array() {
282 $pharmacy_array = array();
283 $sql = "Select p.id, p.name, a.city, a.state from " . $this->_table ." as p INNER JOIN addresses as a on p.id = a.foreign_id";
284 $res = sqlQ($sql);
285 while ($row = mysql_fetch_array($res) ) {
286 $d_string = $row['city'];
287 if (!empty($row['city']) && $row['state']) {
288 $d_string .= ", ";
290 $d_string .= $row['state'];
291 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
293 return ($pharmacy_array);
296 function insurance_companies_factory ($city = "", $sort = "ORDER BY name, id") {
297 if (empty($city)) {
298 $city= "";
300 else {
301 $city = " WHERE city = " . mysql_real_escape_string($foreign_id);
303 $p = new InsuranceCompany();
304 $icompanies = array();
305 $sql = "SELECT p.id, a.city FROM " . $p->_table . " as p INNER JOIN addresses as a on p.id = a.foreign_id " .$city . " " . mysql_real_escape_string($sort);
307 //echo $sql . "<bR />";
308 $results = sqlQ($sql);
309 //echo "sql: $sql";
310 //print_r($results);
311 while($row = mysql_fetch_array($results) ) {
312 $icompanies[] = new InsuranceCompany($row['id']);
314 return $icompanies;
317 function toString($html = false) {
318 $string .= "\n"
319 . "ID: " . $this->id."\n"
320 . "Name: " . $this->name ."\n"
321 . "Attn:" . $this->attn . "\n"
322 . "CMS ID:" . $this->cms_id . "\n"
323 //. "Phone: " . $this->phone_numbers[0]->toString($html) . "\n"
324 . "Address: " . $this->address->toString($html) . "\n";
326 if ($html) {
327 return nl2br($string);
329 else {
330 return $string;
334 } //End Of InsuranceCompanies