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 ("FREEB_TYPE_OTHER_HCFA",1);
12 define ("FREEB_TYPE_MEDICARE",2);
13 define ("FREEB_TYPE_MEDICAID",3);
14 define ("FREEB_TYPE_CHAMPUSVA",4);
15 define ("FREEB_TYPE_CHAMPUS",5);
16 define ("FREEB_TYPE_BCBS",6);
17 define ("FREEB_TYPE_FECA",7);
20 require_once("PhoneNumber.class.php");
21 require_once("Address.class.php");
24 require_once("ORDataObject.class.php");
26 * class Insurance Company
29 class InsuranceCompany
extends ORDataObject
{
35 //this is now deprecated use new x12 partners instead
37 var $x12_default_partner_id;
40 * Freeb used this value to determine special formatting for the specified type of payer.
41 * This value is a mutually exclusive choice answering the FB.Payer.isX API calls
42 * It references a set of constant defined in this file FREEB_TYPE_XXX
43 * Defaults to type FREEB_TYPE_OTHER_HCFA
44 * @var int Holds constant for type of payer as far as FREEB is concerned, see FB.Payer.isXXX API calls
49 * Array used to populate select dropdowns or other form elements, it must coincide with the FREEB_TYPE_XXX constants
50 * @var array Values are display strings that match constants for FB.Payer.isXXX payer types, used for populating select dropdowns, etc
52 var $freeb_type_array = array("","Other HCFA", "Medicare", "Medicaid", "ChampUSVA", "ChampUS", "Blue Cross Blue Shield", "FECA");
56 * Constructor sets all Insurance Company attributes to their default value
58 function InsuranceCompany($id = "", $prefix = "") {
61 $this->_table
= "insurance_companies";
62 $phone = new PhoneNumber();
63 $phone->set_type(TYPE_WORK
);
64 $this->phone
= $phone;
65 $this->address
= new Address();
66 $this->phone_numbers
= array();
72 function set_id($id = "") {
79 //special function the the html forms use to prepopulate which allows for partial edits and wizard functionality
80 function set_form_id ($id = "") {
86 function set_address($aobj) {
87 $this->address
= $aobj;
89 function get_address() {
90 return $this->address
;
92 function set_address_line1($line) {
93 $this->address
->set_line1($line);
95 function set_address_line2($line) {
96 $this->address
->set_line2($line);
99 function set_city($city) {
100 $this->address
->set_city($city);
102 function set_state($state) {
103 $this->address
->set_state($state);
105 function set_zip($zip) {
106 $this->address
->set_zip($zip);
109 function set_name($name) {
112 function get_name() {
115 function set_attn($attn) {
118 function get_attn() {
121 function set_cms_id($id) {
124 function get_cms_id() {
125 return $this->cms_id
;
127 function set_freeb_type($type) {
128 $this->freeb_type
= $type;
130 function get_freeb_type() {
131 return $this->freeb_type
;
133 function get_freeb_type_display() {
134 return $this->freeb_type_array
[$this->freeb_type
];
136 function get_phone() {
137 foreach($this->phone_numbers
as $phone) {
138 if ($phone->type
== TYPE_WORK
) {
139 return $phone->get_phone_display();
144 function _set_number($num, $type) {
146 for ($i=0;$i<count($this->phone_numbers
);$i++
) {
147 if ($this->phone_numbers
[$i]->type
== $type) {
149 $this->phone_numbers
[$i]->set_phone($num);
152 if ($found == false) {
153 $p = new PhoneNumber("",$this->id
);
156 $this->phone_numbers
[] = $p;
157 //print_r($this->phone_numbers);
158 //echo "num is now:" . $p->get_phone_display() . "<br />";
162 function set_phone($phone) {
163 $this->_set_number($phone, TYPE_WORK
);
166 function set_x12_receiver_id($id) {
167 //trigger_error("The set_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
168 $this->x12_receiver_id
= $id;
171 function get_x12_receiver_id() {
172 //trigger_error("The get_x12_receiver_id function is now deprecated use the newer x12 partners code instead.",E_USER_NOTICE);
173 return $this->x12_receiver_id
;
176 function set_x12_default_partner_id($id) {
177 $this->x12_receiver_id
= $id;
180 function get_x12_default_partner_id() {
181 return $this->x12_receiver_id
;
184 function get_x12_default_partner_name() {
185 $xa = $this->_utility_array(X12Partner
::x12_partner_factory());
186 return $xa[$this->get_x12_default_partner_id()];
189 function populate() {
191 $this->address
= Address
::factory_address($this->id
);
192 $this->phone_numbers
= PhoneNumber
::factory_phone_numbers($this->id
);
197 $this->address
->persist($this->id
);
198 foreach ($this->phone_numbers
as $phone) {
199 $phone->persist($this->id
);
203 function utility_insurance_companies_array() {
204 $pharmacy_array = array();
205 $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";
207 while ($row = mysql_fetch_array($res) ) {
208 $d_string = $row['city'];
209 if (!empty($row['city']) && $row['state']) {
212 $d_string .= $row['state'];
213 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
215 return ($pharmacy_array);
218 function insurance_companies_factory ($city = "", $sort = "ORDER BY name, id") {
223 $city = " WHERE city = " . mysql_real_escape_string($foreign_id);
225 $p = new InsuranceCompany();
226 $icompanies = array();
227 $sql = "SELECT p.id, a.city FROM " . $p->_table
. " as p INNER JOIN addresses as a on p.id = a.foreign_id " .$city . " " . mysql_real_escape_string($sort);
229 //echo $sql . "<bR />";
230 $results = sqlQ($sql);
233 while($row = mysql_fetch_array($results) ) {
234 $icompanies[] = new InsuranceCompany($row['id']);
239 function toString($html = false) {
241 . "ID: " . $this->id
."\n"
242 . "Name: " . $this->name
."\n"
243 . "Attn:" . $this->attn
. "\n"
244 . "CMS ID:" . $this->cms_id
. "\n"
245 //. "Phone: " . $this->phone_numbers[0]->toString($html) . "\n"
246 . "Address: " . $this->address
->toString($html) . "\n";
249 return nl2br($string);
256 } //End Of InsuranceCompanies