migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / library / classes / InsuranceCompany.class.php
blobca2e623865c71ba056af03d16d5012c209ed7056
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);
186 function set_inactive($inactive){
187 $this->inactive = $inactive;
189 function get_inactive(){
190 return $this->inactive;
192 function set_name($name) {
193 $this->name = $name;
195 function get_name() {
196 return $this->name;
198 function set_attn($attn) {
199 $this->attn = $attn;
201 function get_attn() {
202 return $this->attn;
204 function set_cms_id($id) {
205 $this->cms_id = $id;
207 function get_cms_id() {
208 return $this->cms_id;
210 function set_alt_cms_id($id) {
211 $this->alt_cms_id = $id;
213 function get_alt_cms_id() {
214 return $this->alt_cms_id;
216 function set_ins_type_code($type) {
217 $this->ins_type_code = $type;
219 function get_ins_type_code() {
220 return $this->ins_type_code;
222 function get_ins_type_code_display() {
223 return $this->ins_type_code_array[$this->ins_type_code];
225 function get_ins_claim_type() {
226 return $this->ins_claim_type_array[$this->ins_type_code];
228 function get_phone() {
229 foreach($this->phone_numbers as $phone) {
230 if ($phone->type == TYPE_WORK) {
231 return $phone->get_phone_display();
234 return "";
236 function _set_number($num, $type) {
237 $found = false;
238 for ($i=0;$i<count($this->phone_numbers);$i++) {
239 if ($this->phone_numbers[$i]->type == $type) {
240 $found = true;
241 $this->phone_numbers[$i]->set_phone($num);
244 if ($found == false) {
245 $p = new PhoneNumber("",$this->id);
246 $p->set_type($type);
247 $p->set_phone($num);
248 $this->phone_numbers[] = $p;
249 //print_r($this->phone_numbers);
250 //echo "num is now:" . $p->get_phone_display() . "<br />";
254 function set_phone($phone) {
255 $this->_set_number($phone, TYPE_WORK);
258 function set_x12_receiver_id($id) {
259 //trigger_error("The set_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
260 $this->x12_receiver_id = $id;
263 function get_x12_receiver_id() {
264 //trigger_error("The get_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
265 return $this->x12_receiver_id;
268 function set_x12_default_partner_id($id) {
269 $this->x12_receiver_id = $id;
272 function get_x12_default_partner_id() {
273 return $this->x12_receiver_id;
276 function get_x12_default_partner_name() {
277 $xa = $this->_utility_array($this->X12Partner->x12_partner_factory());
278 return $xa[$this->get_x12_default_partner_id()];
281 function populate() {
282 parent::populate();
283 $this->address = Address::factory_address($this->id);
284 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
287 function persist() {
288 parent::persist();
289 $this->address->persist($this->id);
290 foreach ($this->phone_numbers as $phone) {
291 $phone->persist($this->id);
295 function utility_insurance_companies_array() {
296 $pharmacy_array = array();
297 $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";
298 $res = sqlQ($sql);
299 while ($row = sqlFetchArray($res) ) {
300 $d_string = $row['city'];
301 if (!empty($row['city']) && $row['state']) {
302 $d_string .= ", ";
304 $d_string .= $row['state'];
305 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
307 return ($pharmacy_array);
310 function insurance_companies_factory ($city = "", $sort = "ORDER BY name, id") {
311 if (empty($city)) {
312 $city= "";
314 else {
315 $city = " WHERE city = " . add_escape_custom($foreign_id);
317 $p = new InsuranceCompany();
318 $icompanies = array();
319 $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);
321 //echo $sql . "<bR />";
322 $results = sqlQ($sql);
323 //echo "sql: $sql";
324 //print_r($results);
325 while($row = sqlFetchArray($results) ) {
326 $icompanies[] = new InsuranceCompany($row['id']);
328 return $icompanies;
331 function toString($html = false) {
332 $string .= "\n"
333 . "ID: " . $this->id."\n"
334 . "Name: " . $this->name ."\n"
335 . "Attn:" . $this->attn . "\n"
336 . "CMS ID:" . $this->cms_id . "\n"
337 . "ALT CMS ID:" . $this->alt_cms_id . "\n"
338 //. "Phone: " . $this->phone_numbers[0]->toString($html) . "\n"
339 . "Address: " . $this->address->toString($html) . "\n";
341 if ($html) {
342 return nl2br($string);
344 else {
345 return $string;
349 } //End Of InsuranceCompanies