Bug fix to add appt with multi provider feature (note Find Available appt is not...
[openemr.git] / library / classes / InsuranceCompany.class.php
blob25f66d2394171ae66c58a1df8b1079a5db1e8b2f
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 var $alt_cms_id;
54 //this is now deprecated use new x12 partners instead
55 var $x12_receiver_id;
56 var $x12_default_partner_id;
59 * Freeb used this value to determine special formatting for the specified type of payer.
60 * This value is a mutually exclusive choice answering the FB.Payer.isX API calls
61 * It references a set of constant defined in this file FREEB_TYPE_XXX
62 * Defaults to type FREEB_TYPE_OTHER_HCFA
63 * @var int Holds constant for type of payer as far as FREEB is concerned, see FB.Payer.isXXX API calls
65 var $freeb_type;
68 * Array used to populate select dropdowns or other form elements, it must coincide with the FREEB_TYPE_XXX constants
69 * @var array Values are display strings that match constants for FB.Payer.isXXX payer types, used for populating select dropdowns, etc
71 var $freeb_type_array = array('','Other HCFA'
72 ,'Medicare Part B'
73 ,'Medicaid'
74 ,'ChampUSVA'
75 ,'ChampUS'
76 ,'Blue Cross Blue Shield'
77 ,'FECA'
78 ,'Self Pay'
79 ,'Central Certification'
80 ,'Other Non-Federal Programs'
81 ,'Preferred Provider Organization (PPO)'
82 ,'Point of Service (POS)'
83 ,'Exclusive Provider Organization (EPO)'
84 ,'Indemnity Insurance'
85 ,'Health Maintenance Organization (HMO) Medicare Risk'
86 ,'Automobile Medical'
87 ,'Commercial Insurance Co.'
88 ,'Disability'
89 ,'Health Maintenance Organization'
90 ,'Liability'
91 ,'Liability Medical'
92 ,'Other Federal Program'
93 ,'Title V'
94 ,'Veterans Administration Plan'
95 ,'Workers Compensation Health Plan'
96 ,'Mutually Defined'
99 var $freeb_claim_type_array = array(''
100 ,'16'
101 ,'MB'
102 ,'MC'
103 ,'CH'
104 ,'CH'
105 ,'BL'
106 ,'16'
107 ,'09'
108 ,'10'
109 ,'11'
110 ,'12'
111 ,'13'
112 ,'14'
113 ,'15'
114 ,'16'
115 ,'AM'
116 ,'CI'
117 ,'DS'
118 ,'HM'
119 ,'LI'
120 ,'LM'
121 ,'OF'
122 ,'TV'
123 ,'VA'
124 ,'WC'
125 ,'ZZ'
129 var $address;
132 * Constructor sets all Insurance Company attributes to their default value
134 function InsuranceCompany($id = "", $prefix = "") {
135 $this->id = $id;
136 $this->name = "";
137 $this->_table = "insurance_companies";
138 $phone = new PhoneNumber();
139 $phone->set_type(TYPE_WORK);
140 $this->phone = $phone;
141 $this->address = new Address();
142 $this->phone_numbers = array();
143 if ($id != "") {
144 $this->populate();
148 function set_id($id = "") {
149 $this->id = $id;
151 function get_id() {
152 return $this->id;
155 //special function the the html forms use to prepopulate which allows for partial edits and wizard functionality
156 function set_form_id ($id = "") {
157 if (!empty($id)) {
158 $this->populate($id);
162 function set_address($aobj) {
163 $this->address = $aobj;
165 function get_address() {
166 return $this->address;
168 function set_address_line1($line) {
169 $this->address->set_line1($line);
171 function set_address_line2($line) {
172 $this->address->set_line2($line);
175 function set_city($city) {
176 $this->address->set_city($city);
178 function set_state($state) {
179 $this->address->set_state($state);
181 function set_zip($zip) {
182 $this->address->set_zip($zip);
185 function set_name($name) {
186 $this->name = $name;
188 function get_name() {
189 return $this->name;
191 function set_attn($attn) {
192 $this->attn = $attn;
194 function get_attn() {
195 return $this->attn;
197 function set_cms_id($id) {
198 $this->cms_id = $id;
200 function get_cms_id() {
201 return $this->cms_id;
203 function set_alt_cms_id($id) {
204 $this->alt_cms_id = $id;
206 function get_alt_cms_id() {
207 return $this->alt_cms_id;
209 function set_freeb_type($type) {
210 $this->freeb_type = $type;
212 function get_freeb_type() {
213 return $this->freeb_type;
215 function get_freeb_type_display() {
216 return $this->freeb_type_array[$this->freeb_type];
218 function get_freeb_claim_type() {
219 return $this->freeb_claim_type_array[$this->freeb_type];
221 function get_phone() {
222 foreach($this->phone_numbers as $phone) {
223 if ($phone->type == TYPE_WORK) {
224 return $phone->get_phone_display();
227 return "";
229 function _set_number($num, $type) {
230 $found = false;
231 for ($i=0;$i<count($this->phone_numbers);$i++) {
232 if ($this->phone_numbers[$i]->type == $type) {
233 $found = true;
234 $this->phone_numbers[$i]->set_phone($num);
237 if ($found == false) {
238 $p = new PhoneNumber("",$this->id);
239 $p->set_type($type);
240 $p->set_phone($num);
241 $this->phone_numbers[] = $p;
242 //print_r($this->phone_numbers);
243 //echo "num is now:" . $p->get_phone_display() . "<br />";
247 function set_phone($phone) {
248 $this->_set_number($phone, TYPE_WORK);
251 function set_x12_receiver_id($id) {
252 //trigger_error("The set_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
253 $this->x12_receiver_id = $id;
256 function get_x12_receiver_id() {
257 //trigger_error("The get_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
258 return $this->x12_receiver_id;
261 function set_x12_default_partner_id($id) {
262 $this->x12_receiver_id = $id;
265 function get_x12_default_partner_id() {
266 return $this->x12_receiver_id;
269 function get_x12_default_partner_name() {
270 $xa = $this->_utility_array(X12Partner::x12_partner_factory());
271 return $xa[$this->get_x12_default_partner_id()];
274 function populate() {
275 parent::populate();
276 $this->address = Address::factory_address($this->id);
277 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
280 function persist() {
281 parent::persist();
282 $this->address->persist($this->id);
283 foreach ($this->phone_numbers as $phone) {
284 $phone->persist($this->id);
288 function utility_insurance_companies_array() {
289 $pharmacy_array = array();
290 $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";
291 $res = sqlQ($sql);
292 while ($row = mysql_fetch_array($res) ) {
293 $d_string = $row['city'];
294 if (!empty($row['city']) && $row['state']) {
295 $d_string .= ", ";
297 $d_string .= $row['state'];
298 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
300 return ($pharmacy_array);
303 function insurance_companies_factory ($city = "", $sort = "ORDER BY name, id") {
304 if (empty($city)) {
305 $city= "";
307 else {
308 $city = " WHERE city = " . mysql_real_escape_string($foreign_id);
310 $p = new InsuranceCompany();
311 $icompanies = array();
312 $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);
314 //echo $sql . "<bR />";
315 $results = sqlQ($sql);
316 //echo "sql: $sql";
317 //print_r($results);
318 while($row = mysql_fetch_array($results) ) {
319 $icompanies[] = new InsuranceCompany($row['id']);
321 return $icompanies;
324 function toString($html = false) {
325 $string .= "\n"
326 . "ID: " . $this->id."\n"
327 . "Name: " . $this->name ."\n"
328 . "Attn:" . $this->attn . "\n"
329 . "CMS ID:" . $this->cms_id . "\n"
330 . "ALT CMS ID:" . $this->alt_cms_id . "\n"
331 //. "Phone: " . $this->phone_numbers[0]->toString($html) . "\n"
332 . "Address: " . $this->address->toString($html) . "\n";
334 if ($html) {
335 return nl2br($string);
337 else {
338 return $string;
342 } //End Of InsuranceCompanies