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

class Rekap_kunjungan extends MBELINK_Controller {
	
	public function __construct()
	{
		parent::__construct();
		date_default_timezone_set('Asia/Jakarta');
		$this->load->library(array('session'));
		$this->load->helper(array('rsonline'));
				 
		// User Login Information
		$this->data['user'] = user_info();
		$this->data['instansi'] = orgInfo();
		
		// Cek Sesi
		 if(! $this->session->userdata('userid')):
			redirect(base_url('login-system.html'), 'refresh');
		endif;
		//Ngaeng-ngaeng
		$this->load->model('masuk_model');
		$this->load->model('report/rekap_kunjungan_model');
		//$this->load->model('info_model');
	}
	
	public function index()
	{
		$this->load->view('report/rekap_kunjungan_pasien',$this->data);
	}
	
	function hasilRekapKunjungan()
	{
		//print_r($_POST);exit();
		$this->data['followup']=$this->input->post('followup');
		$this->data['statusx']=$this->input->post('statusx');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		//$this->data['filter']=$this->input->post('filter');
		
		if(! $this->data['followup']==''){
			$followupx="a.`status_lanjut`='".$this->data['followup']."' AND";
		}else{
			$followupx="";
		}
		
		if($this->data['statusx']==''){
			$status_pasien="";
		}else if($this->data['statusx']=='customer'){
			$status_pasien="a.`stts`<>'Batal' AND";
		}else{
			$status_pasien="a.`stts`='".$this->data['statusx']."' AND";
		}
		
		/* if($this->data['filter']=='2'){
			$filter="a.`TanggalKeluar`";
		}else{
			$filter="a.`TanggalMasuk`";
		} */
		
		if($this->data['tglakhir'] < $this->data['tglawal']){
			$this->session->set_flashdata('error', 'Tanggal Akhir yang di masukkan Harus Lebih Besar atau Sama dengan Tanggal Awal');	
			redirect(base_url('rekap-kunjungan-perpoli.html'));
		}else{
			$this->data['result']=$this->rekap_kunjungan_model->hasilRekapKunjunganPasien($followupx,$status_pasien,$this->data['tglawal'],$this->data['tglakhir']);
		
			//print_r($_POST);
			$this->load->view('report/result_rekap_kunjungan', $this->data);
		}
	}
	
	function hasilRekapKunjunganToExcel()
	{
		$this->data['followup']=$this->input->post('followup');
		$this->data['statusx']=$this->input->post('statusx');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		
		if(! $this->data['followup']==''){
			$followupx="a.`FollowUp`='".$this->data['followup']."' AND";
		}else{
			$followupx="";
		}
		
		if(! $this->data['statusx']==''){
			$status_pasien="a.`Pulang`='".$this->data['statusx']."' AND";
		}else{
			$status_pasien="";
		}		
		
		$this->data['result']=$this->rekap_kunjungan_model->hasilRekapKunjunganPasien($followupx,$status_pasien,$this->data['tglawal'],$this->data['tglakhir']);
	
		//print_r($_POST);
		$this->load->view('report/result_rekap_kunjungan_to_excel', $this->data);
		
	}
	
	function getDetailRekapKunjunganPasien()
	{
		$this->data['poli']=$this->input->get('poli');
		$tglx=explode("|",$this->input->get('tgl'));
		$this->data['tglawal']= $tglx[0];
		$this->data['tglakhir']=$tglx[1];
		$keyx=explode("|",$this->input->get('key'));
		$this->data['status']= $keyx[0];
		$this->data['followup']= $keyx[1];
		
		if($this->data['followup']=='-'){
			$followupp="";
		}else{
			$followupp="a.`status_lanjut`='".$this->data['followup']."' AND";
		}
		
		if($this->data['status']=='-'){
			$status_pasien="";
		}else if($this->data['status']=='customer'){
			$status_pasien="a.`stts`<>'Batal' AND";
		}else{
			$status_pasien="a.`stts`='".$this->data['status']."' AND";
		}
		//echo $this->data['tglawal']."--".$this->data['tglakhir']."--".$this->data['followup'];exit();
		
		$this->data['hasil']=$this->rekap_kunjungan_model->getDataDetailRekapRajal($followupp,$status_pasien,$this->data['tglawal'],$this->data['tglakhir'],$this->data['poli']);
		
		$this->load->view('report/result_rekap_kunjungan_detail', $this->data);
	}
	
	
	function setDataPasien()
	{
				
		$this->load->view('report/rekap_data_pasien',$this->data);//, $this->data);
	}
	
	function resultSetDataPasien()
	{
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		
		$this->data['datapasien']=$this->rekap_kunjungan_model->getDataPasien($this->data['tglawal'],$this->data['tglakhir']);
		
		$this->load->view('report/rekap_data_pasien_result', $this->data);
	}
	
	function rekapDiagnosaKosong()
	{
		$this->load->view('report/rekap_diagnosa_kosong', $this->data);
	}
	
	function resultRekapDiagnosaKosong()
	{
		$this->data['followup']=$this->input->post('followup');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		
		if($this->data['tglakhir'] < $this->data['tglawal']){
			$this->session->set_flashdata('error', 'Tanggal Akhir yang di masukkan Harus Lebih Besar atau Sama dengan Tanggal Awal');	
			redirect(base_url('rekap-diagnosa-kosong.html'));
		}else if($this->input->post('followup')==''){
			$this->session->set_flashdata('error', 'FollowUp Tidak Boleh Kosong');	
			redirect(base_url('rekap-diagnosa-kosong.html'));
		}else{ //if($this->input->post('followup')=='ralan'){
			$this->data['diagnosa']=$this->rekap_kunjungan_model->getDataDiagnosaKsongRJ($this->data['followup'],$this->data['tglawal'],$this->data['tglakhir']);
			
			$this->load->view('report/rekap_diagnosa_kosong_result', $this->data);
		}/* else{
			$this->data['diagnosa']=$this->rekap_kunjungan_model->getDataDiagnosaKsongRI($this->data['tglawal'],$this->data['tglakhir']);
			$this->load->view('report/rekap_diagnosa_kosong_result_ranap', $this->data);
		}	 */
		
	}
	
	function setDataRegistrasiTgl()
	{
		$this->data['tanggal']=$this->input->post('tanggal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		$this->data['result']=$this->rekap_kunjungan_model->getRegistrasiPasien($this->data['tanggal'],$this->data['tglakhir']);
		
		$this->load->view('report/rekap_registrasi_pasien', $this->data);
	}
	
	function setJumlahPasienByDokter()
	{
		$this->data['result']=$this->rekap_kunjungan_model->getJumlahPasienByDokter();
		$this->load->view('report/rekap_pasien_bydokter_now', $this->data);
	}
	
	function setJumlahPasienByDrPeriod()
	{
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		$this->data['result']=$this->rekap_kunjungan_model->getJumlahPasienByDokterPeriode($this->data['tglawal'],$this->data['tglakhir']);
		$this->load->view('report/rekap_pasien_bydokter_periode', $this->data);
	}
	
	function setJumlahPasienPenunjang()
	{
		if($this->input->post('followup')=='0'){
			$this->data['ketfollow']="Semua";
		}else if($this->input->post('followup')=='ralan'){
			$this->data['ketfollow']="Rawat Jalan";
		}else if($this->input->post('followup')=='ranap'){
			$this->data['ketfollow']="Rawat Inap";
		}else{
			$this->data['ketfollow']="-";
		}
		
		$this->data['follow']=$this->input->post('followup');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		
		if($this->input->post('followup')=='0'){
			$this->data['resultrad']=$this->rekap_kunjungan_model->getJumalahPasienRadiologi($this->data['tglawal'],$this->data['tglakhir']);
			$this->data['resultlab']=$this->rekap_kunjungan_model->getJumalahPasienLaborat($this->data['tglawal'],$this->data['tglakhir']);
		}else{
			$this->data['resultrad']=$this->rekap_kunjungan_model->getJumalahPasienRadiologiFU($this->data['follow'],$this->data['tglawal'],$this->data['tglakhir']);
			$this->data['resultlab']=$this->rekap_kunjungan_model->getJumalahPasienLaboratFU($this->data['follow'],$this->data['tglawal'],$this->data['tglakhir']);
		}
		
		
		$this->load->view('report/rekap_data_pasien_penunjang', $this->data);
	}
	
	function reportPasienByRuangan()
	{
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');		
		$this->data['result']=$this->rekap_kunjungan_model->getJmlahPxByRuangan($this->data['tglawal'],$this->data['tglakhir']);
		
		$this->load->view('report/rekap_pasien_byrungan', $this->data);
	}
}
