Merge pull request #1302 from bradymiller/update-service-by-category-report_1
[openemr.git] / controllers / C_InsuranceNumbers.class.php
blobf973e6461ff8f783f607b734d7c46369a2ddf99b
1 <?php
4 class C_InsuranceNumbers extends Controller
7 var $template_mod;
8 var $providers;
9 var $insurance_numbers;
11 function __construct($template_mod = "general")
13 parent::__construct();
14 $this->providers = array();
15 $this->insurance_numbers = array();
16 $this->template_mod = $template_mod;
17 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . attr($_SERVER['QUERY_STRING']));
18 $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_numbers&");
19 $this->assign("STYLE", $GLOBALS['style']);
22 function default_action()
24 return $this->list_action();
27 function edit_action($id = "", $provider_id = "", $p_obj = null)
30 //case where a direct id is provided, doesn't matter if a provider id is available get it from the insurance_numbers record
31 if (get_class($this->insurance_numbers[0]) != "insurancenumbers" && is_numeric($id)) {
32 $this->insurance_numbers[0] = new InsuranceNumbers($id);
33 $this->providers[0] = new Provider($this->insurance_numbers[0]->get_provider_id());
34 } elseif (is_numeric($provider_id)) {
35 $this->providers[0] = new Provider($provider_id);
36 if (get_class($this->insurance_numbers[0]) != "insurancenumbers") {
37 if ($id == "default") {
38 $this->insurance_numbers[0] = $this->providers[0]->get_insurance_numbers_default();
39 if (!is_object($this->insurance_numbers[0])) {
40 $this->insurance_numbers[0] = new InsuranceNumbers();
41 $this->insurance_numbers[0]->set_provider_id($provider_id);
43 } else {
44 $this->insurance_numbers[0] = new InsuranceNumbers();
45 $this->insurance_numbers[0]->set_provider_id($provider_id);
48 } elseif (get_class($this->insurance_numbers[0]) == "insurancenumbers") {
49 //this is the case that occurs after an update
50 $this->providers[0] = new Provider($this->insurance_numbers[0]->get_provider_id());
51 } else {
52 $this->insurance_numbers[0] = new InsuranceNumbers();
53 $this->providers[0] = new Provider();
54 $this->assign("ERROR", "A provider must be specified. Check the link you you came from or the URL and try again.");
57 $ic = new InsuranceCompany();
58 $icompanies = $ic->insurance_companies_factory();
60 //It is possible to set a group and provider number to be used in the event that there is not direct hit on the insurance-provider lookup
61 //Those numbers are entered uder default
62 $ic_array = array("Default");
64 foreach ($icompanies as $ic_tmp) {
65 $ic_array[$ic_tmp->get_id()] = $ic_tmp->get_name();
68 $ic_type_options_array = array();
70 foreach ($this->insurance_numbers[0]->provider_number_type_array as $type => $type_title) {
71 $ic_type_options_array[$type] = "$type $type_title";
74 $ic_rendering_type_options_array = array();
76 foreach ($this->insurance_numbers[0]->rendering_provider_number_type_array as $type => $type_title) {
77 $ic_rendering_type_options_array[$type] = "$type $type_title";
80 $this->assign("ic_array", $ic_array);
81 $this->assign("ic_type_options_array", $ic_type_options_array);
82 $this->assign("ic_rendering_type_options_array", $ic_rendering_type_options_array);
84 $this->assign("provider", $this->providers[0]);
85 $this->assign("ins", $this->insurance_numbers[0]);
87 if ($_GET['showform'] == "true") {
88 $this->assign("show_edit_gui", true);
89 } else {
90 $this->assign("show_edit_gui", false);
93 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_edit.html");
96 function list_action()
99 $p = new Provider();
100 $this->assign("providers", $p->providers_factory());
101 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_list.html");
105 function edit_action_process()
107 if ($_POST['process'] != "true") {
108 return;
111 //print_r($_POST);
112 if (is_numeric($_POST['id'])) {
113 $this->insurance_numbers[0] = new InsuranceNumbers($_POST['id']);
114 } else {
115 $this->insurance_numbers[0] = new InsuranceNumbers();
118 parent::populate_object($this->insurance_numbers[0]);
120 $this->insurance_numbers[0]->persist();
121 //insurance numbers need to be repopulated so that insurance_company_name recieves a value
122 $this->insurance_numbers[0]->populate();
124 //echo "action processeed";
125 $_POST['process'] = "";
127 if (!is_numeric($_POST['id'])) {//Z&H
128 header('Location:'.$GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_numbers&action=list");//Z&H
129 }//Z&H