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");
44 * class Insurance Company
48 class InsuranceCompany
extends ORDataObject
{
55 //this is now deprecated use new x12 partners instead
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
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'
77 ,'Blue Cross Blue Shield'
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'
88 ,'Commercial Insurance Co.'
90 ,'Health Maintenance Organization'
93 ,'Other Federal Program'
95 ,'Veterans Administration Plan'
96 ,'Workers Compensation Health Plan'
100 var $ins_claim_type_array = array(''
133 * Constructor sets all Insurance Company attributes to their default value
135 function __construct($id = "", $prefix = "") {
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();
147 $this->X12Partner
= new X12Partner();
150 function set_id($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 = "") {
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) {
195 function get_name() {
198 function set_attn($attn) {
201 function get_attn() {
204 function set_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();
236 function _set_number($num, $type) {
238 for ($i=0;$i<count($this->phone_numbers
);$i++
) {
239 if ($this->phone_numbers
[$i]->type
== $type) {
241 $this->phone_numbers
[$i]->set_phone($num);
244 if ($found == false) {
245 $p = new PhoneNumber("",$this->id
);
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() {
283 $this->address
= Address
::factory_address($this->id
);
284 $this->phone_numbers
= PhoneNumber
::factory_phone_numbers($this->id
);
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";
299 while ($row = sqlFetchArray($res) ) {
300 $d_string = $row['city'];
301 if (!empty($row['city']) && $row['state']) {
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") {
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);
325 while($row = sqlFetchArray($results) ) {
326 $icompanies[] = new InsuranceCompany($row['id']);
331 function toString($html = false) {
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";
342 return nl2br($string);
349 } //End Of InsuranceCompanies