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);
40 * class Insurance Company
44 class InsuranceCompany
extends ORDataObject
{
51 //this is now deprecated use new x12 partners instead
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
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'
73 ,'Blue Cross Blue Shield'
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'
84 ,'Commercial Insurance Co.'
86 ,'Health Maintenance Organization'
89 ,'Other Federal Program'
91 ,'Veterans Administration Plan'
92 ,'Workers Compensation Health Plan'
96 var $ins_claim_type_array = array(''
129 * Constructor sets all Insurance Company attributes to their default value
131 function __construct($id = "", $prefix = "") {
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();
143 $this->X12Partner
= new X12Partner();
146 function set_id($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 = "") {
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) {
191 function get_name() {
194 function set_attn($attn) {
197 function get_attn() {
200 function set_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();
232 function _set_number($num, $type) {
234 for ($i=0;$i<count($this->phone_numbers
);$i++
) {
235 if ($this->phone_numbers
[$i]->type
== $type) {
237 $this->phone_numbers
[$i]->set_phone($num);
240 if ($found == false) {
241 $p = new PhoneNumber("",$this->id
);
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() {
279 $this->address
= Address
::factory_address($this->id
);
280 $this->phone_numbers
= PhoneNumber
::factory_phone_numbers($this->id
);
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";
295 while ($row = sqlFetchArray($res) ) {
296 $d_string = $row['city'];
297 if (!empty($row['city']) && $row['state']) {
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") {
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);
321 while($row = sqlFetchArray($results) ) {
322 $icompanies[] = new InsuranceCompany($row['id']);
327 function toString($html = false) {
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";
338 return nl2br($string);
345 } //End Of InsuranceCompanies