fixed javascript bug
[openemr.git] / controllers / C_InsuranceCompany.class.php
blob6fa8cbaf6d4a96ed96ded6e41e2d19ba22d22869
1 <?php
3 require_once($GLOBALS['fileroot'] . "/library/classes/Controller.class.php");
4 require_once($GLOBALS['fileroot'] . "/library/classes/InsuranceCompany.class.php");
5 require_once($GLOBALS['fileroot'] . "/library/classes/X12Partner.class.php");
6 require_once($GLOBALS['fileroot'] . "/library/classes/WSWrapper.class.php");
8 class C_InsuranceCompany extends Controller {
10 var $template_mod;
11 var $icompanies;
13 function C_InsuranceCompany($template_mod = "general") {
14 parent::Controller();
15 $this->icompanies = array();
16 $this->template_mod = $template_mod;
17 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
18 $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_company&");
19 $this->assign("STYLE", $GLOBALS['style']);
22 function default_action() {
23 return $this->list_action();
26 function edit_action($id = "",$patient_id="",$p_obj = null) {
27 if ($p_obj != null && get_class($p_obj) == "insurancecompany") {
28 $this->icompanies[0] = $p_obj;
30 elseif (get_class($this->icompanies[0]) != "insurancecompany" ) {
31 $this->icompanies[0] = new InsuranceCompany($id);
34 $x = new X12Partner();
35 $this->assign("x12_partners", $x->_utility_array($x->x12_partner_factory()));
37 $this->assign("insurancecompany", $this->icompanies[0]);
38 return $this->fetch($GLOBALS['template_dir'] . "insurance_companies/" . $this->template_mod . "_edit.html");
41 function list_action($sort = "") {
43 if (!empty($sort)) {
44 $this->assign("icompanies", InsuranceCompany::insurance_companies_factory("",$sort));
46 else {
47 $this->assign("icompanies", InsuranceCompany::insurance_companies_factory());
50 return $this->fetch($GLOBALS['template_dir'] . "insurance_companies/" . $this->template_mod . "_list.html");
54 function edit_action_process() {
55 if ($_POST['process'] != "true")
56 return;
57 //print_r($_POST);
58 if (is_numeric($_POST['id'])) {
59 $this->icompanies[0] = new InsuranceCompany($_POST['id']);
61 else {
62 $this->icompanies[0] = new InsuranceCompany();
65 parent::populate_object($this->icompanies[0]);
67 $this->icompanies[0]->persist();
68 $this->icompanies[0]->populate();
70 // Post insurance companies as customers to the accounting system
71 // unless globals.php requests otherwise.
73 if (! $GLOBALS['insurance_companies_are_not_customers'])
74 $this->_sync_ws($this->icompanies[0]);
76 //echo "action processeed";
77 $_POST['process'] = "";
80 function _sync_ws($ic) {
82 $db = $GLOBALS['adodb']['db'];
84 $customer_info = array();
86 $sql = "SELECT foreign_id,foreign_table FROM integration_mapping where local_table = 'insurance_companies' and local_id = '" . $ic->get_id() . "'";
87 $result = $db->Execute($sql);
88 if ($result && !$result->EOF) {
89 $customer_info['foreign_update'] = true;
90 $customer_info['foreign_id'] = $result->fields['foreign_id'];
91 $customer_info['foreign_table'] = $result->fields['foreign_table'];
94 ///xml rpc code to connect to accounting package and add user to it
95 $customer_info['firstname'] = "";
96 $customer_info['lastname'] = $ic->get_name();
97 $a = $ic->get_address();
98 $customer_info['address'] = $a->get_line1() . " " . $a->get_line2();
99 $customer_info['suburb'] = $a->get_city();
100 $customer_info['postcode'] = $a->get_zip();
102 //ezybiz wants state as a code rather than abbreviation
103 $customer_info['geo_zone_id'] = "";
104 $sql = "SELECT zone_id from geo_zone_reference where zone_code = '" . strtoupper($a->get_state()) . "'";
105 $db = $GLOBALS['adodb']['db'];
106 $result = $db->Execute($sql);
107 if ($result && !$result->EOF) {
108 $customer_info['geo_zone_id'] = $result->fields['zone_id'];
111 //ezybiz wants country as a code rather than abbreviation
112 $customer_info['country'] = "";
114 //assume USA for insurance companies
115 $country_code = 223;
116 $sql = "SELECT countries_id from geo_country_reference where countries_iso_code_2 = '" . strtoupper($country_code) . "'";
117 $db = $GLOBALS['adodb']['db'];
118 $result = $db->Execute($sql);
119 if ($result && !$result->EOF) {
120 $customer_info['geo_country_id'] = $result->fields['countries_id'];
123 $customer_info['phone1'] = $ic->get_phone();
124 $customer_info['phone1comment'] = "Phone Number";
125 $customer_info['phone2'] = "";
126 $customer_info['phone2comment'] = "";
127 $customer_info['email'] = "";
128 $customer_info['is_payer'] = true;
129 $function['ezybiz.add_customer'] = array(new xmlrpcval($customer_info,"struct"));
130 $ws = new WSWrapper($function);
132 // if the remote patient was added make an entry in the local mapping table to that updates can be made correctly
133 if (is_numeric($ws->value)) {
134 $sql = "REPLACE INTO integration_mapping set id = '" . $db->GenID("sequences") . "', foreign_id ='" . $ws->value . "', foreign_table ='customer', local_id = '" . $ic->get_id() . "', local_table = 'insurance_companies' ";
135 $db->Execute($sql) or die ("error: " . $db->ErrorMsg());