added appointments-encounters report
[openemr.git] / controllers / C_InsuranceNumbers.class.php
blobc146fe7acb801450736e52cb88e30a340db55aa8
1 <?php
3 require_once ($GLOBALS['fileroot'] . "/library/classes/Controller.class.php");
4 require_once($GLOBALS['fileroot'] ."/library/classes/Provider.class.php");
5 require_once($GLOBALS['fileroot'] ."/library/classes/InsuranceNumbers.class.php");
7 class C_InsuranceNumbers extends Controller {
9 var $template_mod;
10 var $providers;
11 var $insurance_numbers;
13 function C_InsuranceNumbers($template_mod = "general") {
14 parent::Controller();
15 $this->providers = array();
16 $this->insurance_numbers = array();
17 $this->template_mod = $template_mod;
18 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
19 $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&insurance_numbers&");
20 $this->assign("STYLE", $GLOBALS['style']);
23 function default_action() {
24 return $this->list_action();
27 function edit_action($id = "",$provider_id="",$p_obj = null) {
29 //case where a direct id is provided, doesn't matter if a provider id is available get it from the insurance_numbers record
30 if (get_class($this->insurance_numbers[0]) != "insurancenumbers" && is_numeric($id) ) {
31 $this->insurance_numbers[0] = new InsuranceNumbers($id);
32 $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);
44 else {
45 $this->insurance_numbers[0] = new InsuranceNumbers();
46 $this->insurance_numbers[0]->set_provider_id($provider_id);
51 elseif (get_class($this->insurance_numbers[0]) == "insurancenumbers") {
52 //this is the case that occurs after an update
53 $this->providers[0] = new Provider($this->insurance_numbers[0]->get_provider_id());
55 else {
56 $this->insurance_numbers[0] = new InsuranceNumbers();
57 $this->providers[0] = new Provider();
58 $this->assign("ERROR","A provider must be specified. Check the link you you came from or the URL and try again.");
60 $ic = new InsuranceCompany();
61 $icompanies = $ic->insurance_companies_factory();
63 //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
64 //Those numbers are entered uder default
65 $ic_array = array("Default");
67 foreach ($icompanies as $ic_tmp) {
68 $ic_array[$ic_tmp->get_id()] = $ic_tmp->get_name();
71 $ic_type_options_array = array();
73 foreach ($this->insurance_numbers[0]->x12_id_type_array as $type => $type_title) {
74 $ic_type_options_array[$type] = "$type $type_title";
77 $this->assign("ic_array", $ic_array);
78 $this->assign("ic_type_options_array", $ic_type_options_array);
80 $this->assign("provider", $this->providers[0]);
81 $this->assign("ins", $this->insurance_numbers[0]);
82 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_edit.html");
85 function list_action() {
87 $p = new Provider();
88 $this->assign("providers", $p->providers_factory());
89 return $this->fetch($GLOBALS['template_dir'] . "insurance_numbers/" . $this->template_mod . "_list.html");
93 function edit_action_process() {
94 if ($_POST['process'] != "true")
95 return;
96 //print_r($_POST);
97 if (is_numeric($_POST['id'])) {
98 $this->insurance_numbers[0] = new InsuranceNumbers($_POST['id']);
100 else {
101 $this->insurance_numbers[0] = new InsuranceNumbers();
104 parent::populate_object($this->insurance_numbers[0]);
106 $this->insurance_numbers[0]->persist();
107 //insurance numbers need to be repopulated so that insurance_company_name recieves a value
108 $this->insurance_numbers[0]->populate();
110 //echo "action processeed";
111 $_POST['process'] = "";