<?php
class Drm_ranap extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('user_model');
        $this->load->model('dashboard_model');
        $this->load->model('live_model');
        $this->load->helper('content');

        if ($this->user_model->is_logged_in() == FALSE)
            redirect(base_url(), 'refresh');
    }

    function bulan() {
        $view['content'] = 'chart/kelengkapan_drm_ranap_bln';
        $view['data'] = $this->live_model->drm_ranap_bln()->result();
        $this->load->view('admin/index', $view);
    }

    function tahun() {        
        $view['content'] = 'chart/kelengkapan_drm_ranap_thn';
        $view['data'] = $this->live_model->drm_ranap_thn()->result();
        $this->load->view('admin/index', $view);
    }

    function input_bulan() {
        $this->db->where('bulan', date('m'));
        $this->db->where('tahun', date('Y'));
        $this->db->delete('drm_ranap_bln');

        $data = $this->dashboard_model->insert_drm_ranap_bln();
        foreach ($data as $row) {
            $this->db->set('tanggal', $row->tanggal);
            $this->db->set('bulan', date('m'));
            $this->db->set('tahun', date('Y'));
            $this->db->set('jumlahPasien', $row->jumlahPasien); 
            $this->db->set('hariPertama', $row->hariPertama);
            $this->db->set('harikedua', $row->harikedua);
            $this->db->set('hariketiga', $row->hariketiga);
            $this->db->set('lebih3hari', $row->lebih3hari);
            $this->db->set('belumlengkap', $row->belumLengkap);
            $this->db->insert('drm_ranap_bln');
        }

    }

    function input_tahun() {
        $this->db->where('tahun', date('Y'));
        $this->db->delete('drm_ranap_thn');

        $data = $this->dashboard_model->insert_drm_ranap_thn();
        foreach ($data as $row) {
            $this->db->set('bulan', $row->bulan);
            $this->db->set('tahun', date('Y'));
            $this->db->set('jumlahPasien', $row->jumlahPasien); 
            $this->db->set('hariPertama', $row->hariPertama);
            $this->db->set('harikedua', $row->harikedua);
            $this->db->set('hariketiga', $row->hariketiga);
            $this->db->set('lebih3hari', $row->lebih3hari);
            $this->db->set('belumlengkap', $row->belumLengkap);
            $this->db->insert('drm_ranap_thn');
        }
    }


}