Merge pull request #1024 for XSS remediation in prescription module
[openemr.git] / controllers / C_InsuranceNumbers.class.php
blobd01227fe76b0c8fce1a8e4ae78a4ceadda46225e
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]);
88 if ($_GET['showform'] == "true") {
89 $this->assign("show_edit_gui", true);
90 } else {
91 $this->assign("show_edit_gui", false);
94 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_edit.html");
97 function list_action()
100 $p = new Provider();
101 $this->assign("providers", $p->providers_factory());
102 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_list.html");
106 function edit_action_process()
108 if ($_POST['process'] != "true") {
109 return;
112 //print_r($_POST);
113 if (is_numeric($_POST['id'])) {
114 $this->insurance_numbers[0] = new InsuranceNumbers($_POST['id']);
115 } else {
116 $this->insurance_numbers[0] = new InsuranceNumbers();
119 parent::populate_object($this->insurance_numbers[0]);
121 $this->insurance_numbers[0]->persist();
122 //insurance numbers need to be repopulated so that insurance_company_name recieves a value
123 $this->insurance_numbers[0]->populate();
125 //echo "action processeed";
126 $_POST['process'] = "";
128 if (!is_numeric($_POST['id'])) {//Z&H
129 header('Location:'.$GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_numbers&action=list");//Z&H
130 }//Z&H