<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Hospital_model extends CI_Model {
	public function insert(){
		$data=array("hos_name"=>$_POST['hosname'],
					"area_name"=>$_POST['area'],
					"contact"=>$_POST['contactno'],
					"Longitude"=>$_POST['longitude'],
					"Latitude"=>$_POST['latitude'],
					"type"=>$_POST['type'],
					"Inserted_SI"=>$this->session->userdata('id'),
                   "Inserted_BY"=>$this->session->userdata('name'),
                   "Inserted_DT"=>date('Y-m-d H:i:s')
				);
		$this->db->insert('mst_hospital',$data);
	}
	
	
	public function insert_isolation(){
		$data=array("hos_name"=>$_POST['hosname'],
					"area_name"=>$_POST['area'],
					"contact"=>$_POST['contactno'],
					"Longitude"=>$_POST['longitude'],
					"Latitude"=>$_POST['latitude'],
					"type"=>$_POST['type'],
					"covi_care_type"=>$_POST['ctype'],
					"district_name"=>$_POST['disname'],
					"Inserted_SI"=>$this->session->userdata('id'),
                   "Inserted_BY"=>$this->session->userdata('name'),
                   "Inserted_DT"=>date('Y-m-d H:i:s')
				);
		$this->db->insert('mst_hospital',$data);
	}
	
	
	public function insert_govtquorantine(){
		$data=array("hos_name"=>$_POST['hosname'],
					"area_name"=>$_POST['area'],
					"contact"=>$_POST['contactno'],
					"Longitude"=>$_POST['longitude'],
					"Latitude"=>$_POST['latitude'],
					"type"=>$_POST['type'],
					"Inserted_SI"=>$this->session->userdata('id'),
                   "Inserted_BY"=>$this->session->userdata('name'),
                   "Inserted_DT"=>date('Y-m-d H:i:s')
				);
		$this->db->insert('mst_hospital',$data);
	}
	

	public function fetch_data()
	{
	 $this->db->select('*'); 
  	 $this->db->from('mst_hospital');
  	 $this->db->where('type',1);
  	 $this->db->where('deleted_DT',NULL);
  	 $this->db->order_by('hos_id','DESC');
 	 $query = $this->db->get();
     return $query->result();
	}
	
	
	public function isolation_data()
	{
	 $this->db->select('*'); 
  	 $this->db->from('mst_hospital');
  	 $this->db->where('type',2);
  	 $this->db->where('deleted_DT',NULL);
  	 $this->db->order_by('hos_id','DESC');
 	 $query = $this->db->get();
     return $query->result();
	}
	
	public function government_data()
	{
	 $this->db->select('*'); 
  	 $this->db->from('mst_hospital');
  	 $this->db->where('type',3);
  	 $this->db->where('deleted_DT',NULL);
  	 $this->db->order_by('hos_id','DESC');
 	 $query = $this->db->get();
     return $query->result();
	}
	
	

	public function display_hospital_recordsById($id)
	{
		$query=$this->db->query("select * from mst_hospital where hos_id='".$id."'");
		return $query->row();
	}

	public function update($id)
	{


/*	$n=$this->input->post('name');
		$a=$this->input->post('address');
		$e=$this->input->post('emailid');
		$c=$this->input->post('contact');
		$city=$this->input->post('city');
		$lo=$this->input->post('Longitude');
		$lt=$this->input->post('Latitude');	

	$query=$this->db->query("update mst_office SET name='$n',address='$a',email='$e',contact='$c',
		city='$city',Longitude='lo',Latitude='lt' where id='".$id."'");*/
			
			$data=array("hos_name"=>$_POST['hosname'],
					"area_name"=>$_POST['area'],
					"contact"=>$_POST['contactno'],
					"Longitude"=>$_POST['longitude'],
					"Latitude"=>$_POST['latitude'],
					"type"=>$_POST['type'],
					"covi_care_type"=>$_POST['ctype'],
					
					"district_name"=>$_POST['disname'],
					   "Modify_SI"=>$this->session->userdata('id'),
                   	 "Modify_BY"=>$this->session->userdata('username'),
                    "Modify_DT"=>date('Y-m-d H:i:s'));
       				 $c=$this->db->where('hos_id',$id)->update('mst_hospital',$data); 
       				 
       				 

	}
    
    public function get_users()
    {
         $this->db->select('*'); 
  	     $this->db->from('mst_guard');
  	     $this->db->where('deleted_DT',NULL);
  	    // $this->db->where('patient_status!=',NULL);
  	     $this->db->order_by('id','DESC');
 	     $query = $this->db->get();
         return $query->result();
    }
    
    
    public function register_case_grid()
    {
         $this->db->select('*'); 
  	     $this->db->from('tbl_positive_case_register');
  	     $this->db->where('deleted_DT',NULL);
  	    // $this->db->where('patient_status!=',NULL);
  	     $this->db->order_by('case_id','DESC');
 	     $query = $this->db->get();
         return $query->result();
    }
    
    
     public function getgovernmet()
    {
         $this->db->select('*'); 
  	     $this->db->from('mst_hospital');
  	     $this->db->where('Deleted_DT',NULL);
  	     $this->db->where('type',3);
  	    // $this->db->where('patient_status!=',NULL);
  	     $this->db->order_by('hos_id','DESC');
 	     $query = $this->db->get();
         return $query->result();
    }

    
//     public function save_case_register()
//     {
    
// 		$data=array("sso_no"=>$_POST['covidportal'],
// 					"dist_case_no"=>$_POST['distcase'],
// 					"name"=>$_POST['patient_name'],
// 					"address"=>$_POST['address'],
// 					"contact"=>$_POST['contactno'],
// 					"age"=>$_POST['age'],
					
// 					"gender"=>$_POST['gender'],
// 					"health_center"=>$_POST['healthcenter'],
// 					"prabhag_name"=>$_POST['prabhagid'],
// 					"ha_hosname1"=>$_POST['hospitalname'],
// 					"ha_district"=>$_POST['distname'],
// 					"ha_admitdate1"=>$_POST['firstadmit'],
					
// 					"ha_admit_symptom"=>$_POST['symptoms'],
// 					"ha_onset_date"=>$_POST['onsetsym'],
// 					"ha_present_symp"=>$_POST['presentsym'],
// 					"ha_morbility"=>$_POST['comorbility'],
// 					"ha_clinic_condition"=>$_POST['clinic'],
// 					"ha_term_protocol"=>$_POST['protocol'],
					
					
// 					"ha_hospital_2"=>$_POST['secondhos'],
// 					"ha_admitdate2"=>$_POST['seconddate'],
// 					"ha_today_condition"=>$_POST['todaycondition'],
// 					"eh_traveloutside"=>$_POST['outsideindia'],
// 					"eh_countryname"=>$_POST['visitcon'],
// 					"eh_travelinside"=>$_POST['inindia'],
					
					
// 					"eh_cityname"=>$_POST['cityname'],
// 					"con_familymember"=>$_POST['positive'],
// 					"con_persons"=>$_POST['hocovid'],
// 					"con_mass_gather"=>$_POST['gathering'],
// 					"con_totalrisk"=>$_POST['totalcontat'],
// 					"con_admitted"=>$_POST['contactadmin'],
                    
//                     "con_home"=>$_POST['contacthome'],
// 					"con_sample_sent"=>$_POST['contactsent'],
// 					"con_positive_found"=>$_POST['positivefound'],
// 					"lab_sam_date"=>$_POST['samplecollect'],
// 					"lab_center_name"=>$_POST['samplecentre'],
// 					"lab_test_date"=>$_POST['sampletest'],

				    
// 				    "lab_sam_result"=>$_POST['firstsample'],
// 					"lab_fourteen_result"=>$_POST['result'],
// 					"lab_fifteen_date"=>$_POST['fitestdate'],
// 					"lab_fifteen_result"=>$_POST['lastresult'],
// 					"lab_outcome"=>$_POST['outcome'],
// 					"remark"=>$_POST['remark'],
                    
//                     "status"=>1,
// 					"patient_type"=>$_POST['checkname'],
				
					
// 					"inserted_SI"=>$this->session->userdata('id'),
//                   "inserted_by"=>$this->session->userdata('name'),
//                   "inserted_DT"=>date('Y-m-d H:i:s')
// 				);
// 		$this->db->insert('tbl_positive_case_register',$data);
	
//     }
    
    
    
    public function save_case_register()
    {
    
    	if($_POST['patient_name']!='')
    	{
    		$pname = $_POST['patient_name'];

    		$info = array("name"=>$pname,"contact"=>$_POST['contactno'],"age"=>$_POST['age'],"gender"=>$_POST['gender'],"address"=>$_POST['address'],"prabhag_id"=>$_POST['prabhagid'],"Health_center"=>$_POST['healthcenter'],"patient_status"=>1,"status"=>"Active","positive_case_type"=>2,"inserted_SI"=>$this->session->userdata('id'),"inserted_by"=>$this->session->userdata('username'),"inserted_DT"=>date('Y-m-d H:i:s'));
             $this->db->insert('mst_guard',$info);
             $patient_id = $gid;
    	}
    	else if($_POST['guard_name']!='')
    	{
    		$gid = $_POST['guard_name'];

    		$info = $this->db->select('*')->where('id',$gid)->where('Deleted_DT',NULL)->get('mst_guard')->row();
    		$pname = $info->name;
    		$getdata = array("positive_case_type"=>1,"modify_SI"=>$this->session->userdata('id'),"modify_BY"=>$this->session->userdata('username'),"modify_DT"=>date('Y-m-d H:i:s'));
    		$updateinfo = $this->db->where('id',$gid)->update('mst_guard',$getdata);
    		$patient_id = $gid;
    	}
    	else if($_POST['highrisk']!='')
    	{
    		$highid = $_POST['highrisk'];
    		$info = $this->db->select('*')->where('add_id',$highid)->where('Deleted_DT',NULL)->get('tbl_risk_addmore')->row();
    		$pname = $info->memeber_name;	
    		$info = array("name"=>$pname,"contact"=>$_POST['contactno'],"age"=>$_POST['age'],"gender"=>$_POST['gender'],"address"=>$_POST['address'],"prabhag_id"=>$_POST['prabhagid'],"Health_center"=>$_POST['healthcenter'],"patient_status"=>1,"status"=>"Active","positive_case_type"=>3,"inserted_SI"=>$this->session->userdata('id'),"inserted_by"=>$this->session->userdata('username'),"inserted_DT"=>date('Y-m-d H:i:s'));
             $this->db->insert('mst_guard',$info);
             $patient_id = $highid;
             
    	}
    	else if($_POST['lowrisk']!='')
    	{
    		$lowid = $_POST['lowrisk'];
    		$info = $this->db->select('*')->where('add_id',$lowid)->where('Deleted_DT',NULL)->get('tbl_risk_addmore')->row();
    		$pname = $info->memeber_name;	
    		$info = array("name"=>$pname,"contact"=>$_POST['contactno'],"age"=>$_POST['age'],"gender"=>$_POST['gender'],"address"=>$_POST['address'],"prabhag_id"=>$_POST['prabhagid'],"Health_center"=>$_POST['healthcenter'],"patient_status"=>1,"status"=>"Active","positive_case_type"=>4,"inserted_SI"=>$this->session->userdata('id'),"inserted_by"=>$this->session->userdata('username'),"inserted_DT"=>date('Y-m-d H:i:s'));
             $this->db->insert('mst_guard',$info);
             $patient_id = $lowid;
             
    	}
    	else
    	{
    		$pname='';
    		$patient_id = '';
    	}


		$data=array("sso_no"=>$_POST['covidportal'],
					"dist_case_no"=>$_POST['distcase'],
					"name"=>$pname,
					"address"=>$_POST['address'],
					"contact"=>$_POST['contactno'],
					"age"=>$_POST['age'],
					"patient_id"=>$patient_id,
					"gender"=>$_POST['gender'],
					"health_center"=>$_POST['healthcenter'],
					"prabhag_name"=>$_POST['prabhagid'],
					"ha_hosname1"=>$_POST['hospitalname'],
					"ha_district"=>$_POST['distname'],
					"ha_admitdate1"=>$_POST['firstadmit'],
					
					"ha_admit_symptom"=>$_POST['symptoms'],
					"ha_onset_date"=>$_POST['onsetsym'],
					"ha_present_symp"=>$_POST['presentsym'],
					"ha_morbility"=>$_POST['comorbility'],
					"ha_clinic_condition"=>$_POST['clinic'],
					"ha_term_protocol"=>$_POST['protocol'],
					
					
					"ha_hospital_2"=>$_POST['secondhos'],
					"ha_admitdate2"=>$_POST['seconddate'],
					"ha_today_condition"=>$_POST['todaycondition'],
					"eh_traveloutside"=>$_POST['outsideindia'],
					"eh_countryname"=>$_POST['visitcon'],
					"eh_travelinside"=>$_POST['inindia'],
					
					
					"eh_cityname"=>$_POST['cityname'],
					"con_familymember"=>$_POST['positive'],
					"con_persons"=>$_POST['hocovid'],
					"con_mass_gather"=>$_POST['gathering'],
					"con_totalrisk"=>$_POST['totalcontat'],
					"con_admitted"=>$_POST['contactadmin'],
                    
                    "con_home"=>$_POST['contacthome'],
					"con_sample_sent"=>$_POST['contactsent'],
					"con_positive_found"=>$_POST['positivefound'],
					"lab_sam_date"=>$_POST['samplecollect'],
					"lab_center_name"=>$_POST['samplecentre'],
					"lab_test_date"=>$_POST['sampletest'],

				    
				    "lab_sam_result"=>$_POST['firstsample'],
					"lab_fourteen_result"=>$_POST['result'],
					"lab_fifteen_date"=>$_POST['fitestdate'],
					"lab_fifteen_result"=>$_POST['lastresult'],
					"lab_outcome"=>$_POST['outcome'],
					"remark"=>$_POST['remark'],
                    
                    "status"=>1,
					"patient_type"=>$_POST['checkname'],
				
					
				   "inserted_SI"=>$this->session->userdata('id'),
                   "inserted_by"=>$this->session->userdata('name'),
                   "inserted_DT"=>date('Y-m-d H:i:s')
				);
		$this->db->insert('tbl_positive_case_register',$data);
	
    }
    
    
    public function update_case_register($id)
    {
    
		$data=array("sso_no"=>$_POST['covidportal'],
					"dist_case_no"=>$_POST['distcase'],
					"name"=>$_POST['patient_name'],
					"address"=>$_POST['address'],
					"contact"=>$_POST['contactno'],
					"age"=>$_POST['age'],
					
					"gender"=>$_POST['gender'],
					"health_center"=>$_POST['healthcenter'],
					"prabhag_name"=>$_POST['prabhagid'],
					"ha_hosname1"=>$_POST['hospitalname'],
					"ha_district"=>$_POST['distname'],
					"ha_admitdate1"=>$_POST['firstadmit'],
					
					"ha_admit_symptom"=>$_POST['symptoms'],
					"ha_onset_date"=>$_POST['onsetsym'],
					"ha_present_symp"=>$_POST['presentsym'],
					"ha_morbility"=>$_POST['comorbility'],
					"ha_clinic_condition"=>$_POST['clinic'],
					"ha_term_protocol"=>$_POST['protocol'],
					
					
					"ha_hospital_2"=>$_POST['secondhos'],
					"ha_admitdate2"=>$_POST['seconddate'],
					"ha_today_condition"=>$_POST['todaycondition'],
					"eh_traveloutside"=>$_POST['outsideindia'],
					"eh_countryname"=>$_POST['visitcon'],
					"eh_travelinside"=>$_POST['inindia'],
					
					
					"eh_cityname"=>$_POST['cityname'],
					"con_familymember"=>$_POST['positive'],
					"con_persons"=>$_POST['hocovid'],
					"con_mass_gather"=>$_POST['gathering'],
					"con_totalrisk"=>$_POST['totalcontat'],
					"con_admitted"=>$_POST['contactadmin'],
                    
                    "con_home"=>$_POST['contacthome'],
					"con_sample_sent"=>$_POST['contactsent'],
					"con_positive_found"=>$_POST['positivefound'],
					"lab_sam_date"=>$_POST['samplecollect'],
					"lab_center_name"=>$_POST['samplecentre'],
					"lab_test_date"=>$_POST['sampletest'],

				    
				    "lab_sam_result"=>$_POST['firstsample'],
					"lab_fourteen_result"=>$_POST['result'],
					"lab_fifteen_date"=>$_POST['fitestdate'],
					"lab_fifteen_result"=>$_POST['lastresult'],
					"lab_outcome"=>$_POST['outcome'],
					"remark"=>$_POST['remark'],
                    
					"modify_SI"=>$this->session->userdata('id'),
                   "modify_BY"=>$this->session->userdata('name'),
                   "modify_DT"=>date('Y-m-d H:i:s')
				);
		$this->db->where('case_id',$id)->update('tbl_positive_case_register',$data);
	
    }
	
}
