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

class Dashboard2 extends CI_Controller {
	public function __construct()
    {
        parent::__construct();
        $this->load->model('M_data', 'model_data');
        //$this->load->model('M_action', 'model_action');
        /*if (!empty($this->session->userdata('is_login') == FALSE)) {
            // alert peringatan bahwa harus login
            $this->session->set_flashdata('failed', 'Anda Belum login, silahkan login terlebih dahulu !');
            redirect(base_url('login'));
        }*/
    }

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/userguide3/general/urls.html
	 */
	
	public function index()
	{
		$kamar_terisi = $this->model_data->kamar_terisi()->result_array();

		$total_kamar_terisi = $this->model_data->total_kamar_terisi()->row();
		$total_kmr_terisi = $total_kamar_terisi->ISI;

		$total_kamar_tersedia = $this->model_data->total_kamar_tersedia()->row();
		$total_kmr_tersedia = $total_kamar_tersedia->KOSONG;

		$jumlah_pasien_igd = $this->model_data->jumlah_pasien_igd()->row();
		$jml_pasien_igd = $jumlah_pasien_igd->JML_PASIEN;

		$pasien_masuk_igd = $this->model_data->pasien_masuk_igd()->row();
		$jml_masuk_igd = $pasien_masuk_igd->JML_PASIEN;

		$pasien_terlayani_igd = $this->model_data->pasien_terlayani_igd()->row();
		$jml_terlayani_igd = $pasien_terlayani_igd->JML_PASIEN;

		$pasien_APS_igd = $this->model_data->pasien_APS_igd()->row();
		$jml_APS_igd = $pasien_APS_igd->JML_PASIEN;

		$pasien_pulang_igd = $this->model_data->pasien_pulang_igd()->row();
		$jml_pulang_igd = $pasien_pulang_igd->JML_PASIEN;

		$pasien_rawat_igd = $this->model_data->pasien_rawat_igd()->row();
		$jml_rawat_igd = $pasien_rawat_igd->JML_PASIEN;

		$pasien_meninggal_igd = $this->model_data->pasien_meninggal_igd()->row();
		$jml_menginggal_igd = $pasien_meninggal_igd->JML_PASIEN;

		$pasien_rujuk_igd = $this->model_data->pasien_rujuk_igd()->row();
		$jml_rujuk_igd = $pasien_rujuk_igd->JML_PASIEN;

		$total_pasien_rj = $this->model_data->total_pasien_rj()->row();
		$jml_pasien_rj = $total_pasien_rj->JML_PASIEN;
		$kunjungan_pasien_rj = $this->model_data->kunjungan_pasien_rj()->result_array();

		$pendapatan_jkn = $this->model_data->pendapatan_farmasi_jkn()->row();
		$tot_farmasi_jkn = $pendapatan_jkn->HARGA_PENDAPATAN;

		$jadwal_dokter = $this->model_data->jadwal_operasi()->row();
		$hari_ini = $jadwal_dokter->jumlah_operasi_H1;
		
		$hari_Hplus1 = $jadwal_dokter->jumlah_operasi_Hplus1;
		$hari_Hplus2 = $jadwal_dokter->jumlah_operasi_Hplus2;
		$hari_Hplus3 = $jadwal_dokter->jumlah_operasi_Hplus3;
		
		$today = date('Y-m');
		$lastMonth = date('Y-m', strtotime($today . ' -1 month'));
		$month = date('M Y', strtotime($lastMonth));
    
		$jml_hari = $this->model_data->juml_hari($lastMonth)->row();
		$jml_hari_perawatan = $jml_hari->JML_HARI_PERAWATAN;

		$bor = $this->model_data->bor($lastMonth)->row();
		$jml_bed = $bor->JML_BED;
        $jml_hari = $bor->LD;

		$toi = $this->model_data->toi($lastMonth)->row();
		$jml_lama_dirawat = $toi->LAMA_DIRAWAT;
		$jml_pasien_keluar = $toi->JML_KELUAR;
		$jml_bor = ($jml_hari_perawatan/($jml_bed*$jml_hari))*100;

		$jml_avlos = 0;
		$jml_toi = 0;
		if($jml_pasien_keluar > 0) {
			$jml_avlos = $jml_lama_dirawat/$jml_pasien_keluar;
			$jml_toi = (($jml_bed*$jml_hari)-$jml_hari_perawatan)/$jml_pasien_keluar;
		}	
		$jml_bto = $jml_pasien_keluar/$jml_bed;
		

		$data{'kamar_terisi'} = $kamar_terisi;
		$data{'total_kmr_terisi'} = $total_kmr_terisi;
		$data{'total_kmr_tersedia'} = $total_kmr_tersedia;
		$data{'jml_pasien_igd'} = $jml_pasien_igd;
		$data{'jml_masuk_igd'} = $jml_masuk_igd;
		$data{'jml_terlayani_igd'} = $jml_terlayani_igd;
		$data{'jml_APS_igd'} = $jml_APS_igd;
		$data{'jml_pulang_igd'} = $jml_pulang_igd;
		$data{'jml_rawat_igd'} = $jml_rawat_igd;
		$data{'jml_menginggal_igd'} = $jml_menginggal_igd;
		$data{'jml_rujuk_igd'} = $jml_rujuk_igd;
		$data{'jml_pasien_rj'} = $jml_pasien_rj;
		$data{'kunjungan_pasien_rj'} = $kunjungan_pasien_rj;
		$data{'tot_farmasi_jkn'}= $tot_farmasi_jkn;
		$data{'hari_ini'}= $hari_ini;
		$data{'hari_Hplus1'}= $hari_Hplus1;
		$data{'hari_Hplus2'}= $hari_Hplus2;
		$data{'hari_Hplus3'}= $hari_Hplus3;
		$data{'jml_bor'}= $jml_bor;
		$data{'jml_avlos'}= $jml_avlos;
		$data{'jml_toi'}= $jml_toi;
		$data{'jml_bto'}= $jml_bto;
		$data{'month'} = $month;
        $data{'header'}='Dashboard';  
        $data{'header'}= $this->load->view('templates/header', $data, true);
        $data{'dashboard'}= $this->load->view('dashboard', $data, true);
        $data{'footer'}= $this->load->view('templates/footer', $data, true);
		$this->load->view('dashboard2', $data);
	}
                  
}
?>
