another minor fix to prior commit
[openemr.git] / library / classes / InsuranceCompany.class.php
blobe4218de367bb6ef3880f8ff183352221d55d5ae1
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);
38 require_once("PhoneNumber.class.php");
39 require_once("Address.class.php");
40 require_once("X12Partner.class.php");
41 require_once("ORDataObject.class.php");
43 /**
44 * class Insurance Company
48 class InsuranceCompany extends ORDataObject{
49 var $id;
50 var $name;
51 var $phone;
52 var $attn;
53 var $cms_id;
54 var $alt_cms_id;
55 //this is now deprecated use new x12 partners instead
56 var $x12_receiver_id;
57 var $x12_default_partner_id;
60 * OpenEMR used this value to determine special formatting for the specified type of payer.
61 * This value is a mutually exclusive choice answering the FB.Payer.isX API calls
62 * It references a set of constant defined in this file INS_TYPE_XXX
63 * Defaults to type INS_TYPE_OTHER_HCFA
64 * @var int Holds constant for type of payer as far as INS is concerned, see FB.Payer.isXXX API calls
66 var $ins_type_code;
69 * Array used to populate select dropdowns or other form elements, it must coincide with the INS_TYPE_XXX constants
70 * @var array Values are display strings that match constants for FB.Payer.isXXX payer types, used for populating select dropdowns, etc
72 var $ins_type_code_array = array('','Other HCFA'
73 ,'Medicare Part B'
74 ,'Medicaid'
75 ,'ChampUSVA'
76 ,'ChampUS'
77 ,'Blue Cross Blue Shield'
78 ,'FECA'
79 ,'Self Pay'
80 ,'Central Certification'
81 ,'Other Non-Federal Programs'
82 ,'Preferred Provider Organization (PPO)'
83 ,'Point of Service (POS)'
84 ,'Exclusive Provider Organization (EPO)'
85 ,'Indemnity Insurance'
86 ,'Health Maintenance Organization (HMO) Medicare Risk'
87 ,'Automobile Medical'
88 ,'Commercial Insurance Co.'
89 ,'Disability'
90 ,'Health Maintenance Organization'
91 ,'Liability'
92 ,'Liability Medical'
93 ,'Other Federal Program'
94 ,'Title V'
95 ,'Veterans Administration Plan'
96 ,'Workers Compensation Health Plan'
97 ,'Mutually Defined'
100 var $ins_claim_type_array = array(''
101 ,'16'
102 ,'MB'
103 ,'MC'
104 ,'CH'
105 ,'CH'
106 ,'BL'
107 ,'16'
108 ,'09'
109 ,'10'
110 ,'11'
111 ,'12'
112 ,'13'
113 ,'14'
114 ,'15'
115 ,'16'
116 ,'AM'
117 ,'CI'
118 ,'DS'
119 ,'HM'
120 ,'LI'
121 ,'LM'
122 ,'OF'
123 ,'TV'
124 ,'VA'
125 ,'WC'
126 ,'ZZ'
130 var $address;
133 * Constructor sets all Insurance Company attributes to their default value
135 function __construct($id = "", $prefix = "") {
136 $this->id = $id;
137 $this->name = "";
138 $this->_table = "insurance_companies";
139 $phone = new PhoneNumber();
140 $phone->set_type(TYPE_WORK);
141 $this->phone = $phone;
142 $this->address = new Address();
143 $this->phone_numbers = array();
144 if ($id != "") {
145 $this->populate();
147 $this->X12Partner = new X12Partner();
150 function set_id($id = "") {
151 $this->id = $id;
153 function get_id() {
154 return $this->id;
157 //special function the the html forms use to prepopulate which allows for partial edits and wizard functionality
158 function set_form_id ($id = "") {
159 if (!empty($id)) {
160 $this->populate($id);
164 function set_address($aobj) {
165 $this->address = $aobj;
167 function get_address() {
168 return $this->address;
170 function set_address_line1($line) {
171 $this->address->set_line1($line);
173 function set_address_line2($line) {
174 $this->address->set_line2($line);
177 function set_city($city) {
178 $this->address->set_city($city);
180 function set_state($state) {
181 $this->address->set_state($state);
183 function set_zip($zip) {
184 $this->address->set_zip($zip);
187 function set_name($name) {
188 $this->name = $name;
190 function get_name() {
191 return $this->name;
193 function set_attn($attn) {
194 $this->attn = $attn;
196 function get_attn() {
197 return $this->attn;
199 function set_cms_id($id) {
200 $this->cms_id = $id;
202 function get_cms_id() {
203 return $this->cms_id;
205 function set_alt_cms_id($id) {
206 $this->alt_cms_id = $id;
208 function get_alt_cms_id() {
209 return $this->alt_cms_id;
211 function set_ins_type_code($type) {
212 $this->ins_type_code = $type;
214 function get_ins_type_code() {
215 return $this->ins_type_code;
217 function get_ins_type_code_display() {
218 return $this->ins_type_code_array[$this->ins_type_code];
220 function get_ins_claim_type() {
221 return $this->ins_claim_type_array[$this->ins_type_code];
223 function get_phone() {
224 foreach($this->phone_numbers as $phone) {
225 if ($phone->type == TYPE_WORK) {
226 return $phone->get_phone_display();
229 return "";
231 function _set_number($num, $type) {
232 $found = false;
233 for ($i=0;$i<count($this->phone_numbers);$i++) {
234 if ($this->phone_numbers[$i]->type == $type) {
235 $found = true;
236 $this->phone_numbers[$i]->set_phone($num);
239 if ($found == false) {
240 $p = new PhoneNumber("",$this->id);
241 $p->set_type($type);
242 $p->set_phone($num);
243 $this->phone_numbers[] = $p;
244 //print_r($this->phone_numbers);
245 //echo "num is now:" . $p->get_phone_display() . "<br />";
249 function set_phone($phone) {
250 $this->_set_number($phone, TYPE_WORK);
253 function set_x12_receiver_id($id) {
254 //trigger_error("The set_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
255 $this->x12_receiver_id = $id;
258 function get_x12_receiver_id() {
259 //trigger_error("The get_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
260 return $this->x12_receiver_id;
263 function set_x12_default_partner_id($id) {
264 $this->x12_receiver_id = $id;
267 function get_x12_default_partner_id() {
268 return $this->x12_receiver_id;
271 function get_x12_default_partner_name() {
272 $xa = $this->_utility_array($this->X12Partner->x12_partner_factory());
273 return $xa[$this->get_x12_default_partner_id()];
276 function populate() {
277 parent::populate();
278 $this->address = Address::factory_address($this->id);
279 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
282 function persist() {
283 parent::persist();
284 $this->address->persist($this->id);
285 foreach ($this->phone_numbers as $phone) {
286 $phone->persist($this->id);
290 function utility_insurance_companies_array() {
291 $pharmacy_array = array();
292 $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";
293 $res = sqlQ($sql);
294 while ($row = sqlFetchArray($res) ) {
295 $d_string = $row['city'];
296 if (!empty($row['city']) && $row['state']) {
297 $d_string .= ", ";
299 $d_string .= $row['state'];
300 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
302 return ($pharmacy_array);
305 function insurance_companies_factory ($city = "", $sort = "ORDER BY name, id") {
306 if (empty($city)) {
307 $city= "";
309 else {
310 $city = " WHERE city = " . add_escape_custom($foreign_id);
312 $p = new InsuranceCompany();
313 $icompanies = array();
314 $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);
316 //echo $sql . "<bR />";
317 $results = sqlQ($sql);
318 //echo "sql: $sql";
319 //print_r($results);
320 while($row = sqlFetchArray($results) ) {
321 $icompanies[] = new InsuranceCompany($row['id']);
323 return $icompanies;
326 function toString($html = false) {
327 $string .= "\n"
328 . "ID: " . $this->id."\n"
329 . "Name: " . $this->name ."\n"
330 . "Attn:" . $this->attn . "\n"
331 . "CMS ID:" . $this->cms_id . "\n"
332 . "ALT CMS ID:" . $this->alt_cms_id . "\n"
333 //. "Phone: " . $this->phone_numbers[0]->toString($html) . "\n"
334 . "Address: " . $this->address->toString($html) . "\n";
336 if ($html) {
337 return nl2br($string);
339 else {
340 return $string;
344 } //End Of InsuranceCompanies