Setup script bootstrapped with new theme selector - Take 2 (#2139)
[openemr.git] / library / classes / InsuranceCompany.class.php
blob3d1370911bf87e27465fb4ab3814e9d406b614c5
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("INS_TYPE_OTHER_HCFA", 1);
12 define("INS_TYPE_MEDICARE", 2);
13 define("INS_TYPE_MEDICAID", 3);
14 define("INS_TYPE_CHAMPUSVA", 4);
15 define("INS_TYPE_CHAMPUS", 5);
16 define("INS_TYPE_BCBS", 6);
17 define("INS_TYPE_FECA", 7);
18 define("INS_TYPE_SELF_PAY", 8);
19 define("INS_TYPE_CENTRAL_CERTIFICATION", 9);
20 define("INS_TYPE_OTHER_NON-FEDERAL_PROGRAMS", 10);
21 define("INS_TYPE_PREFERRED_PROVIDER_ORGANIZATION", 11);
22 define("INS_TYPE_POINT_OF_SERVICE", 12);
23 define("INS_TYPE_EXCLUSIVE_PROVIDER_ORGANIZATION", 13);
24 define("INS_TYPE_INDEMNITY_INSURANCE", 14);
25 define("INS_TYPE_HMO_MEDICARE_RISK", 15);
26 define("INS_TYPE_AUTOMOBILE_MEDICAL", 16);
27 define("INS_TYPE_COMMERCIAL_INSURANCE", 17);
28 define("INS_TYPE_DISABILITY", 18);
29 define("INS_TYPE_HEALTH_MAINTENANCE_ORGANIZATION", 19);
30 define("INS_TYPE_LIABILITY", 20);
31 define("INS_TYPE_LIABILITY_MEDICAL", 21);
32 define("INS_TYPE_OTHER_FEDERAL_PROGRAM", 22);
33 define("INS_TYPE_TITLE_V", 23);
34 define("INS_TYPE_VETERANS_ADMINISTRATION_PLAN", 24);
35 define("INS_TYPE_WORKERS_COMPENSATION_HEALTH_PLAN", 25);
36 define("INS_TYPE_MUTUALLY_DEFINED", 26);
39 /**
40 * class Insurance Company
44 class InsuranceCompany extends ORDataObject
46 var $id;
47 var $name;
48 var $phone;
49 var $attn;
50 var $cms_id;
51 var $alt_cms_id;
52 //this is now deprecated use new x12 partners instead
53 var $x12_receiver_id;
54 var $x12_default_partner_id;
57 * OpenEMR used this value to determine special formatting for the specified type of payer.
58 * This value is a mutually exclusive choice answering the FB.Payer.isX API calls
59 * It references a set of constant defined in this file INS_TYPE_XXX
60 * Defaults to type INS_TYPE_OTHER_HCFA
61 * @var int Holds constant for type of payer as far as INS is concerned, see FB.Payer.isXXX API calls
63 var $ins_type_code;
66 * Array used to populate select dropdowns or other form elements, it must coincide with the INS_TYPE_XXX constants
67 * @var array Values are display strings that match constants for FB.Payer.isXXX payer types, used for populating select dropdowns, etc
69 var $ins_type_code_array = array('','Other HCFA'
70 ,'Medicare Part B'
71 ,'Medicaid'
72 ,'ChampUSVA'
73 ,'ChampUS'
74 ,'Blue Cross Blue Shield'
75 ,'FECA'
76 ,'Self Pay'
77 ,'Central Certification'
78 ,'Other Non-Federal Programs'
79 ,'Preferred Provider Organization (PPO)'
80 ,'Point of Service (POS)'
81 ,'Exclusive Provider Organization (EPO)'
82 ,'Indemnity Insurance'
83 ,'Health Maintenance Organization (HMO) Medicare Risk'
84 ,'Automobile Medical'
85 ,'Commercial Insurance Co.'
86 ,'Disability'
87 ,'Health Maintenance Organization'
88 ,'Liability'
89 ,'Liability Medical'
90 ,'Other Federal Program'
91 ,'Title V'
92 ,'Veterans Administration Plan'
93 ,'Workers Compensation Health Plan'
94 ,'Mutually Defined'
97 var $ins_claim_type_array = array(''
98 ,'16'
99 ,'MB'
100 ,'MC'
101 ,'CH'
102 ,'CH'
103 ,'BL'
104 ,'16'
105 ,'09'
106 ,'10'
107 ,'11'
108 ,'12'
109 ,'13'
110 ,'14'
111 ,'15'
112 ,'16'
113 ,'AM'
114 ,'CI'
115 ,'DS'
116 ,'HM'
117 ,'LI'
118 ,'LM'
119 ,'OF'
120 ,'TV'
121 ,'VA'
122 ,'WC'
123 ,'ZZ'
127 var $address;
130 * Constructor sets all Insurance Company attributes to their default value
132 function __construct($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();
146 $this->X12Partner = new X12Partner();
149 function set_id($id = "")
151 $this->id = $id;
153 function get_id()
155 return $this->id;
158 //special function the the html forms use to prepopulate which allows for partial edits and wizard functionality
159 function set_form_id($id = "")
161 if (!empty($id)) {
162 $this->populate($id);
166 function set_address($aobj)
168 $this->address = $aobj;
170 function get_address()
172 return $this->address;
174 function set_address_line1($line)
176 $this->address->set_line1($line);
178 function set_address_line2($line)
180 $this->address->set_line2($line);
183 function set_city($city)
185 $this->address->set_city($city);
187 function set_state($state)
189 $this->address->set_state($state);
191 function set_zip($zip)
193 $this->address->set_zip($zip);
195 function set_inactive($inactive)
197 $this->inactive = $inactive;
199 function get_inactive()
201 return $this->inactive;
203 function set_name($name)
205 $this->name = $name;
207 function get_name()
209 return $this->name;
211 function set_attn($attn)
213 $this->attn = $attn;
215 function get_attn()
217 return $this->attn;
219 function set_cms_id($id)
221 $this->cms_id = $id;
223 function get_cms_id()
225 return $this->cms_id;
227 function set_alt_cms_id($id)
229 $this->alt_cms_id = $id;
231 function get_alt_cms_id()
233 return $this->alt_cms_id;
235 function set_ins_type_code($type)
237 $this->ins_type_code = $type;
239 function get_ins_type_code()
241 return $this->ins_type_code;
243 function get_ins_type_code_display()
245 return $this->ins_type_code_array[$this->ins_type_code];
247 function get_ins_claim_type()
249 return $this->ins_claim_type_array[$this->ins_type_code];
251 function get_phone()
253 foreach ($this->phone_numbers as $phone) {
254 if ($phone->type == TYPE_WORK) {
255 return $phone->get_phone_display();
259 return "";
261 function _set_number($num, $type)
263 $found = false;
264 for ($i=0; $i<count($this->phone_numbers); $i++) {
265 if ($this->phone_numbers[$i]->type == $type) {
266 $found = true;
267 $this->phone_numbers[$i]->set_phone($num);
271 if ($found == false) {
272 $p = new PhoneNumber("", $this->id);
273 $p->set_type($type);
274 $p->set_phone($num);
275 $this->phone_numbers[] = $p;
276 //print_r($this->phone_numbers);
277 //echo "num is now:" . $p->get_phone_display() . "<br />";
281 function set_phone($phone)
283 $this->_set_number($phone, TYPE_WORK);
286 function set_x12_receiver_id($id)
288 //trigger_error("The set_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
289 $this->x12_receiver_id = $id;
292 function get_x12_receiver_id()
294 //trigger_error("The get_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
295 return $this->x12_receiver_id;
298 function set_x12_default_partner_id($id)
300 $this->x12_receiver_id = $id;
303 function get_x12_default_partner_id()
305 return $this->x12_receiver_id;
308 function get_x12_default_partner_name()
310 $xa = $this->_utility_array($this->X12Partner->x12_partner_factory());
311 return $xa[$this->get_x12_default_partner_id()];
314 function populate()
316 parent::populate();
317 $this->address = Address::factory_address($this->id);
318 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
321 function persist()
323 parent::persist();
324 $this->address->persist($this->id);
325 foreach ($this->phone_numbers as $phone) {
326 $phone->persist($this->id);
330 function utility_insurance_companies_array()
332 $pharmacy_array = array();
333 $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";
334 $res = sqlQ($sql);
335 while ($row = sqlFetchArray($res)) {
336 $d_string = $row['city'];
337 if (!empty($row['city']) && $row['state']) {
338 $d_string .= ", ";
341 $d_string .= $row['state'];
342 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
345 return ($pharmacy_array);
348 function insurance_companies_factory($city = "", $sort = "ORDER BY name, id")
350 if (empty($city)) {
351 $city= "";
352 } else {
353 $city = " WHERE city = " . add_escape_custom($foreign_id);
356 $p = new InsuranceCompany();
357 $icompanies = array();
358 $sql = "SELECT p.id, a.city FROM " . $p->_table . " as p INNER JOIN addresses as a on p.id = a.foreign_id " .$city . " " . add_escape_custom($sort);
360 //echo $sql . "<bR />";
361 $results = sqlQ($sql);
362 //echo "sql: $sql";
363 //print_r($results);
364 while ($row = sqlFetchArray($results)) {
365 $icompanies[] = new InsuranceCompany($row['id']);
368 return $icompanies;
371 function toString($html = false)
373 $string .= "\n"
374 . "ID: " . $this->id."\n"
375 . "Name: " . $this->name ."\n"
376 . "Attn:" . $this->attn . "\n"
377 . "Payer ID:" . $this->cms_id . "\n"
378 . "ALT Payer ID:" . $this->alt_cms_id . "\n"
379 //. "Phone: " . $this->phone_numbers[0]->toString($html) . "\n"
380 . "Address: " . $this->address->toString($html) . "\n";
382 if ($html) {
383 return nl2br($string);
384 } else {
385 return $string;
388 } //End Of InsuranceCompanies