Highway to PSR2
[openemr.git] / controllers / C_InsuranceNumbers.class.php
blob4f782b8409541f4bae9544e05c98078966a8895d
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?" . $_SERVER['QUERY_STRING']);
18 $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_numbers&");
19 $this->assign("STYLE", $GLOBALS['style']);
20 $this->assign("WEB_ROOT", $GLOBALS['webroot']);
23 function default_action()
25 return $this->list_action();
28 function edit_action($id = "", $provider_id = "", $p_obj = null)
31 //case where a direct id is provided, doesn't matter if a provider id is available get it from the insurance_numbers record
32 if (get_class($this->insurance_numbers[0]) != "insurancenumbers" && is_numeric($id)) {
33 $this->insurance_numbers[0] = new InsuranceNumbers($id);
34 $this->providers[0] = new Provider($this->insurance_numbers[0]->get_provider_id());
35 } elseif (is_numeric($provider_id)) {
36 $this->providers[0] = new Provider($provider_id);
37 if (get_class($this->insurance_numbers[0]) != "insurancenumbers") {
38 if ($id == "default") {
39 $this->insurance_numbers[0] = $this->providers[0]->get_insurance_numbers_default();
40 if (!is_object($this->insurance_numbers[0])) {
41 $this->insurance_numbers[0] = new InsuranceNumbers();
42 $this->insurance_numbers[0]->set_provider_id($provider_id);
44 } else {
45 $this->insurance_numbers[0] = new InsuranceNumbers();
46 $this->insurance_numbers[0]->set_provider_id($provider_id);
49 } elseif (get_class($this->insurance_numbers[0]) == "insurancenumbers") {
50 //this is the case that occurs after an update
51 $this->providers[0] = new Provider($this->insurance_numbers[0]->get_provider_id());
52 } else {
53 $this->insurance_numbers[0] = new InsuranceNumbers();
54 $this->providers[0] = new Provider();
55 $this->assign("ERROR", "A provider must be specified. Check the link you you came from or the URL and try again.");
58 $ic = new InsuranceCompany();
59 $icompanies = $ic->insurance_companies_factory();
61 //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
62 //Those numbers are entered uder default
63 $ic_array = array("Default");
65 foreach ($icompanies as $ic_tmp) {
66 $ic_array[$ic_tmp->get_id()] = $ic_tmp->get_name();
69 $ic_type_options_array = array();
71 foreach ($this->insurance_numbers[0]->provider_number_type_array as $type => $type_title) {
72 $ic_type_options_array[$type] = "$type $type_title";
75 $ic_rendering_type_options_array = array();
77 foreach ($this->insurance_numbers[0]->rendering_provider_number_type_array as $type => $type_title) {
78 $ic_rendering_type_options_array[$type] = "$type $type_title";
81 $this->assign("ic_array", $ic_array);
82 $this->assign("ic_type_options_array", $ic_type_options_array);
83 $this->assign("ic_rendering_type_options_array", $ic_rendering_type_options_array);
85 $this->assign("provider", $this->providers[0]);
86 $this->assign("ins", $this->insurance_numbers[0]);
87 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_edit.html");
90 function list_action()
93 $p = new Provider();
94 $this->assign("providers", $p->providers_factory());
95 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_list.html");
99 function edit_action_process()
101 if ($_POST['process'] != "true") {
102 return;
105 //print_r($_POST);
106 if (is_numeric($_POST['id'])) {
107 $this->insurance_numbers[0] = new InsuranceNumbers($_POST['id']);
108 } else {
109 $this->insurance_numbers[0] = new InsuranceNumbers();
112 parent::populate_object($this->insurance_numbers[0]);
114 $this->insurance_numbers[0]->persist();
115 //insurance numbers need to be repopulated so that insurance_company_name recieves a value
116 $this->insurance_numbers[0]->populate();
118 //echo "action processeed";
119 $_POST['process'] = "";
121 if (!is_numeric($_POST['id'])) {//Z&H
122 header('Location:'.$GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_numbers&action=list");//Z&H
123 }//Z&H