minor improvement to tabs style
[openemr.git] / library / classes / InsuranceCompany.class.php
bloba666a62389bad909c3b57bca61fd849cb9516dbe
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{
45 var $id;
46 var $name;
47 var $phone;
48 var $attn;
49 var $cms_id;
50 var $alt_cms_id;
51 //this is now deprecated use new x12 partners instead
52 var $x12_receiver_id;
53 var $x12_default_partner_id;
56 * OpenEMR used this value to determine special formatting for the specified type of payer.
57 * This value is a mutually exclusive choice answering the FB.Payer.isX API calls
58 * It references a set of constant defined in this file INS_TYPE_XXX
59 * Defaults to type INS_TYPE_OTHER_HCFA
60 * @var int Holds constant for type of payer as far as INS is concerned, see FB.Payer.isXXX API calls
62 var $ins_type_code;
65 * Array used to populate select dropdowns or other form elements, it must coincide with the INS_TYPE_XXX constants
66 * @var array Values are display strings that match constants for FB.Payer.isXXX payer types, used for populating select dropdowns, etc
68 var $ins_type_code_array = array('','Other HCFA'
69 ,'Medicare Part B'
70 ,'Medicaid'
71 ,'ChampUSVA'
72 ,'ChampUS'
73 ,'Blue Cross Blue Shield'
74 ,'FECA'
75 ,'Self Pay'
76 ,'Central Certification'
77 ,'Other Non-Federal Programs'
78 ,'Preferred Provider Organization (PPO)'
79 ,'Point of Service (POS)'
80 ,'Exclusive Provider Organization (EPO)'
81 ,'Indemnity Insurance'
82 ,'Health Maintenance Organization (HMO) Medicare Risk'
83 ,'Automobile Medical'
84 ,'Commercial Insurance Co.'
85 ,'Disability'
86 ,'Health Maintenance Organization'
87 ,'Liability'
88 ,'Liability Medical'
89 ,'Other Federal Program'
90 ,'Title V'
91 ,'Veterans Administration Plan'
92 ,'Workers Compensation Health Plan'
93 ,'Mutually Defined'
96 var $ins_claim_type_array = array(''
97 ,'16'
98 ,'MB'
99 ,'MC'
100 ,'CH'
101 ,'CH'
102 ,'BL'
103 ,'16'
104 ,'09'
105 ,'10'
106 ,'11'
107 ,'12'
108 ,'13'
109 ,'14'
110 ,'15'
111 ,'16'
112 ,'AM'
113 ,'CI'
114 ,'DS'
115 ,'HM'
116 ,'LI'
117 ,'LM'
118 ,'OF'
119 ,'TV'
120 ,'VA'
121 ,'WC'
122 ,'ZZ'
126 var $address;
129 * Constructor sets all Insurance Company attributes to their default value
131 function __construct($id = "", $prefix = "") {
132 $this->id = $id;
133 $this->name = "";
134 $this->_table = "insurance_companies";
135 $phone = new PhoneNumber();
136 $phone->set_type(TYPE_WORK);
137 $this->phone = $phone;
138 $this->address = new Address();
139 $this->phone_numbers = array();
140 if ($id != "") {
141 $this->populate();
143 $this->X12Partner = new X12Partner();
146 function set_id($id = "") {
147 $this->id = $id;
149 function get_id() {
150 return $this->id;
153 //special function the the html forms use to prepopulate which allows for partial edits and wizard functionality
154 function set_form_id ($id = "") {
155 if (!empty($id)) {
156 $this->populate($id);
160 function set_address($aobj) {
161 $this->address = $aobj;
163 function get_address() {
164 return $this->address;
166 function set_address_line1($line) {
167 $this->address->set_line1($line);
169 function set_address_line2($line) {
170 $this->address->set_line2($line);
173 function set_city($city) {
174 $this->address->set_city($city);
176 function set_state($state) {
177 $this->address->set_state($state);
179 function set_zip($zip) {
180 $this->address->set_zip($zip);
182 function set_inactive($inactive){
183 $this->inactive = $inactive;
185 function get_inactive(){
186 return $this->inactive;
188 function set_name($name) {
189 $this->name = $name;
191 function get_name() {
192 return $this->name;
194 function set_attn($attn) {
195 $this->attn = $attn;
197 function get_attn() {
198 return $this->attn;
200 function set_cms_id($id) {
201 $this->cms_id = $id;
203 function get_cms_id() {
204 return $this->cms_id;
206 function set_alt_cms_id($id) {
207 $this->alt_cms_id = $id;
209 function get_alt_cms_id() {
210 return $this->alt_cms_id;
212 function set_ins_type_code($type) {
213 $this->ins_type_code = $type;
215 function get_ins_type_code() {
216 return $this->ins_type_code;
218 function get_ins_type_code_display() {
219 return $this->ins_type_code_array[$this->ins_type_code];
221 function get_ins_claim_type() {
222 return $this->ins_claim_type_array[$this->ins_type_code];
224 function get_phone() {
225 foreach($this->phone_numbers as $phone) {
226 if ($phone->type == TYPE_WORK) {
227 return $phone->get_phone_display();
230 return "";
232 function _set_number($num, $type) {
233 $found = false;
234 for ($i=0;$i<count($this->phone_numbers);$i++) {
235 if ($this->phone_numbers[$i]->type == $type) {
236 $found = true;
237 $this->phone_numbers[$i]->set_phone($num);
240 if ($found == false) {
241 $p = new PhoneNumber("",$this->id);
242 $p->set_type($type);
243 $p->set_phone($num);
244 $this->phone_numbers[] = $p;
245 //print_r($this->phone_numbers);
246 //echo "num is now:" . $p->get_phone_display() . "<br />";
250 function set_phone($phone) {
251 $this->_set_number($phone, TYPE_WORK);
254 function set_x12_receiver_id($id) {
255 //trigger_error("The set_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
256 $this->x12_receiver_id = $id;
259 function get_x12_receiver_id() {
260 //trigger_error("The get_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
261 return $this->x12_receiver_id;
264 function set_x12_default_partner_id($id) {
265 $this->x12_receiver_id = $id;
268 function get_x12_default_partner_id() {
269 return $this->x12_receiver_id;
272 function get_x12_default_partner_name() {
273 $xa = $this->_utility_array($this->X12Partner->x12_partner_factory());
274 return $xa[$this->get_x12_default_partner_id()];
277 function populate() {
278 parent::populate();
279 $this->address = Address::factory_address($this->id);
280 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
283 function persist() {
284 parent::persist();
285 $this->address->persist($this->id);
286 foreach ($this->phone_numbers as $phone) {
287 $phone->persist($this->id);
291 function utility_insurance_companies_array() {
292 $pharmacy_array = array();
293 $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";
294 $res = sqlQ($sql);
295 while ($row = sqlFetchArray($res) ) {
296 $d_string = $row['city'];
297 if (!empty($row['city']) && $row['state']) {
298 $d_string .= ", ";
300 $d_string .= $row['state'];
301 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
303 return ($pharmacy_array);
306 function insurance_companies_factory ($city = "", $sort = "ORDER BY name, id") {
307 if (empty($city)) {
308 $city= "";
310 else {
311 $city = " WHERE city = " . add_escape_custom($foreign_id);
313 $p = new InsuranceCompany();
314 $icompanies = array();
315 $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);
317 //echo $sql . "<bR />";
318 $results = sqlQ($sql);
319 //echo "sql: $sql";
320 //print_r($results);
321 while($row = sqlFetchArray($results) ) {
322 $icompanies[] = new InsuranceCompany($row['id']);
324 return $icompanies;
327 function toString($html = false) {
328 $string .= "\n"
329 . "ID: " . $this->id."\n"
330 . "Name: " . $this->name ."\n"
331 . "Attn:" . $this->attn . "\n"
332 . "CMS ID:" . $this->cms_id . "\n"
333 . "ALT CMS ID:" . $this->alt_cms_id . "\n"
334 //. "Phone: " . $this->phone_numbers[0]->toString($html) . "\n"
335 . "Address: " . $this->address->toString($html) . "\n";
337 if ($html) {
338 return nl2br($string);
340 else {
341 return $string;
345 } //End Of InsuranceCompanies