Interim autoloaded library/classes via composer classmap, take 4. (#422)
[openemr.git] / controllers / C_InsuranceNumbers.class.php
blob84ee948974cabef913a0b97cdab446e96559db54
1 <?php
4 class C_InsuranceNumbers extends Controller {
6 var $template_mod;
7 var $providers;
8 var $insurance_numbers;
10 function __construct($template_mod = "general") {
11 parent::__construct();
12 $this->providers = array();
13 $this->insurance_numbers = array();
14 $this->template_mod = $template_mod;
15 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
16 $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_numbers&");
17 $this->assign("STYLE", $GLOBALS['style']);
18 $this->assign("WEB_ROOT", $GLOBALS['webroot'] );
21 function default_action() {
22 return $this->list_action();
25 function edit_action($id = "",$provider_id="",$p_obj = null) {
27 //case where a direct id is provided, doesn't matter if a provider id is available get it from the insurance_numbers record
28 if (get_class($this->insurance_numbers[0]) != "insurancenumbers" && is_numeric($id) ) {
29 $this->insurance_numbers[0] = new InsuranceNumbers($id);
30 $this->providers[0] = new Provider($this->insurance_numbers[0]->get_provider_id());
32 elseif (is_numeric($provider_id)) {
33 $this->providers[0] = new Provider($provider_id);
34 if (get_class($this->insurance_numbers[0]) != "insurancenumbers") {
35 if ($id == "default") {
36 $this->insurance_numbers[0] = $this->providers[0]->get_insurance_numbers_default();
37 if (!is_object($this->insurance_numbers[0])) {
38 $this->insurance_numbers[0] = new InsuranceNumbers();
39 $this->insurance_numbers[0]->set_provider_id($provider_id);
42 else {
43 $this->insurance_numbers[0] = new InsuranceNumbers();
44 $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());
53 else {
54 $this->insurance_numbers[0] = new InsuranceNumbers();
55 $this->providers[0] = new Provider();
56 $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() {
92 $p = new Provider();
93 $this->assign("providers", $p->providers_factory());
94 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_list.html");
98 function edit_action_process() {
99 if ($_POST['process'] != "true")
100 return;
101 //print_r($_POST);
102 if (is_numeric($_POST['id'])) {
103 $this->insurance_numbers[0] = new InsuranceNumbers($_POST['id']);
105 else {
106 $this->insurance_numbers[0] = new InsuranceNumbers();
109 parent::populate_object($this->insurance_numbers[0]);
111 $this->insurance_numbers[0]->persist();
112 //insurance numbers need to be repopulated so that insurance_company_name recieves a value
113 $this->insurance_numbers[0]->populate();
115 //echo "action processeed";
116 $_POST['process'] = "";
118 if (!is_numeric($_POST['id'])) {//Z&H
119 header('Location:'.$GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_numbers&action=list");//Z&H
120 }//Z&H