Update comments
[openemr.git] / controllers / C_InsuranceCompany.class.php
blob957ec7c3c2e4bc465a6a2d04dc67487584ddeeb9
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']);
20 $this->assign("WEB_ROOT", $GLOBALS['webroot'] );
23 function default_action() {
24 return $this->list_action();
27 function edit_action($id = "",$patient_id="",$p_obj = null) {
28 if ($p_obj != null && get_class($p_obj) == "insurancecompany") {
29 $this->icompanies[0] = $p_obj;
31 elseif (get_class($this->icompanies[0]) != "insurancecompany" ) {
32 $this->icompanies[0] = new InsuranceCompany($id);
35 $x = new X12Partner();
36 $this->assign("x12_partners", $x->_utility_array($x->x12_partner_factory()));
38 $this->assign("insurancecompany", $this->icompanies[0]);
39 return $this->fetch($GLOBALS['template_dir'] . "insurance_companies/" . $this->template_mod . "_edit.html");
42 function list_action($sort = "") {
44 if (!empty($sort)) {
45 $this->assign("icompanies", InsuranceCompany::insurance_companies_factory("",$sort));
47 else {
48 $this->assign("icompanies", InsuranceCompany::insurance_companies_factory());
51 return $this->fetch($GLOBALS['template_dir'] . "insurance_companies/" . $this->template_mod . "_list.html");
55 function edit_action_process() {
56 if ($_POST['process'] != "true")
57 return;
58 //print_r($_POST);
59 if (is_numeric($_POST['id'])) {
60 $this->icompanies[0] = new InsuranceCompany($_POST['id']);
62 else {
63 $this->icompanies[0] = new InsuranceCompany();
66 parent::populate_object($this->icompanies[0]);
68 $this->icompanies[0]->persist();
69 $this->icompanies[0]->populate();
71 // Post insurance companies as customers to the accounting system
72 // unless globals.php requests otherwise.
74 if (! $GLOBALS['insurance_companies_are_not_customers'])
75 $this->_sync_ws($this->icompanies[0]);
77 //echo "action processeed";
78 $_POST['process'] = "";
81 function _sync_ws($ic) {
83 $db = $GLOBALS['adodb']['db'];
85 $customer_info = array();
87 $sql = "SELECT foreign_id,foreign_table FROM integration_mapping where local_table = 'insurance_companies' and local_id = '" . $ic->get_id() . "'";
88 $result = $db->Execute($sql);
89 if ($result && !$result->EOF) {
90 $customer_info['foreign_update'] = true;
91 $customer_info['foreign_id'] = $result->fields['foreign_id'];
92 $customer_info['foreign_table'] = $result->fields['foreign_table'];
95 ///xml rpc code to connect to accounting package and add user to it
96 $customer_info['firstname'] = "";
97 $customer_info['lastname'] = $ic->get_name();
98 $a = $ic->get_address();
99 $customer_info['address'] = $a->get_line1() . " " . $a->get_line2();
100 $customer_info['suburb'] = $a->get_city();
101 $customer_info['postcode'] = $a->get_zip();
103 //ezybiz wants state as a code rather than abbreviation
104 $customer_info['geo_zone_id'] = "";
105 $sql = "SELECT zone_id from geo_zone_reference where zone_code = '" . strtoupper($a->get_state()) . "'";
106 $db = $GLOBALS['adodb']['db'];
107 $result = $db->Execute($sql);
108 if ($result && !$result->EOF) {
109 $customer_info['geo_zone_id'] = $result->fields['zone_id'];
112 //ezybiz wants country as a code rather than abbreviation
113 $customer_info['country'] = "";
115 //assume USA for insurance companies
116 $country_code = 223;
117 $sql = "SELECT countries_id from geo_country_reference where countries_iso_code_2 = '" . strtoupper($country_code) . "'";
118 $db = $GLOBALS['adodb']['db'];
119 $result = $db->Execute($sql);
120 if ($result && !$result->EOF) {
121 $customer_info['geo_country_id'] = $result->fields['countries_id'];
124 $customer_info['phone1'] = $ic->get_phone();
125 $customer_info['phone1comment'] = "Phone Number";
126 $customer_info['phone2'] = "";
127 $customer_info['phone2comment'] = "";
128 $customer_info['email'] = "";
129 $customer_info['is_payer'] = true;
130 $function['ezybiz.add_customer'] = array(new xmlrpcval($customer_info,"struct"));
131 $ws = new WSWrapper($function);
133 // if the remote patient was added make an entry in the local mapping table to that updates can be made correctly
134 if (is_numeric($ws->value)) {
135 $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' ";
136 $db->Execute($sql) or die ("error: " . $db->ErrorMsg());