CTL Revision (#1950)
[openemr.git] / controllers / C_InsuranceNumbers.class.php
blobda1ebbf5794811242a2cc95f9db0e144aad15585
1 <?php
2 /**
3 * C_InsuranceNumbers class
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Brady Miller <brady.g.miller@gmail.com>
8 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 class C_InsuranceNumbers extends Controller
16 var $template_mod;
17 var $providers;
18 var $insurance_numbers;
20 function __construct($template_mod = "general")
22 parent::__construct();
23 $this->providers = array();
24 $this->insurance_numbers = array();
25 $this->template_mod = $template_mod;
26 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . attr($_SERVER['QUERY_STRING']));
27 $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_numbers&");
28 $this->assign("STYLE", $GLOBALS['style']);
31 function default_action()
33 return $this->list_action();
36 function edit_action($id = "", $provider_id = "", $p_obj = null)
39 //case where a direct id is provided, doesn't matter if a provider id is available get it from the insurance_numbers record
40 if ((!is_object($this->insurance_numbers[0]) || get_class($this->insurance_numbers[0]) != "insurancenumbers") && is_numeric($id)) {
41 $this->insurance_numbers[0] = new InsuranceNumbers($id);
42 $this->providers[0] = new Provider($this->insurance_numbers[0]->get_provider_id());
43 } elseif (is_numeric($provider_id)) {
44 $this->providers[0] = new Provider($provider_id);
45 if (!is_object($this->insurance_numbers[0]) || get_class($this->insurance_numbers[0]) != "insurancenumbers") {
46 if ($id == "default") {
47 $this->insurance_numbers[0] = $this->providers[0]->get_insurance_numbers_default();
48 if (!is_object($this->insurance_numbers[0])) {
49 $this->insurance_numbers[0] = new InsuranceNumbers();
50 $this->insurance_numbers[0]->set_provider_id($provider_id);
52 } else {
53 $this->insurance_numbers[0] = new InsuranceNumbers();
54 $this->insurance_numbers[0]->set_provider_id($provider_id);
57 } elseif (get_class($this->insurance_numbers[0]) == "insurancenumbers") {
58 //this is the case that occurs after an update
59 $this->providers[0] = new Provider($this->insurance_numbers[0]->get_provider_id());
60 } else {
61 $this->insurance_numbers[0] = new InsuranceNumbers();
62 $this->providers[0] = new Provider();
63 $this->assign("ERROR", "A provider must be specified. Check the link you you came from or the URL and try again.");
66 $ic = new InsuranceCompany();
67 $icompanies = $ic->insurance_companies_factory();
69 //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
70 //Those numbers are entered uder default
71 $ic_array = array("Default");
73 foreach ($icompanies as $ic_tmp) {
74 $ic_array[$ic_tmp->get_id()] = $ic_tmp->get_name();
77 $ic_type_options_array = array();
79 foreach ($this->insurance_numbers[0]->provider_number_type_array as $type => $type_title) {
80 $ic_type_options_array[$type] = "$type $type_title";
83 $ic_rendering_type_options_array = array();
85 foreach ($this->insurance_numbers[0]->rendering_provider_number_type_array as $type => $type_title) {
86 $ic_rendering_type_options_array[$type] = "$type $type_title";
89 $this->assign("ic_array", $ic_array);
90 $this->assign("ic_type_options_array", $ic_type_options_array);
91 $this->assign("ic_rendering_type_options_array", $ic_rendering_type_options_array);
93 $this->assign("provider", $this->providers[0]);
94 $this->assign("ins", $this->insurance_numbers[0]);
96 if ($_GET['showform'] == "true") {
97 $this->assign("show_edit_gui", true);
98 } else {
99 $this->assign("show_edit_gui", false);
102 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_edit.html");
105 function list_action()
108 $p = new Provider();
109 $this->assign("providers", $p->providers_factory());
110 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_list.html");
114 function edit_action_process()
116 if ($_POST['process'] != "true") {
117 return;
120 //print_r($_POST);
121 if (is_numeric($_POST['id'])) {
122 $this->insurance_numbers[0] = new InsuranceNumbers($_POST['id']);
123 } else {
124 $this->insurance_numbers[0] = new InsuranceNumbers();
127 parent::populate_object($this->insurance_numbers[0]);
129 $this->insurance_numbers[0]->persist();
130 //insurance numbers need to be repopulated so that insurance_company_name recieves a value
131 $this->insurance_numbers[0]->populate();
133 //echo "action processeed";
134 $_POST['process'] = "";
136 if (!is_numeric($_POST['id'])) {//Z&H
137 header('Location:'.$GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_numbers&action=list");//Z&H
138 }//Z&H