<?php
	class Casemix_model extends CI_Model {
		function __construct()
		{
			// Call the Model constructor
			parent::__construct();
			
			$this->dbhost=$this->load->database('khanza', TRUE);
					
			date_default_timezone_set('Asia/Jakarta');
		}
				
		function getDataKamarTersedia()
		{
			$q=$this->dbhost
				->select('k.BPJS_Kelas AS KodeKelas, CONCAT("R",n.ID,k.BPJS_Kelas) AS KodeRuang,n.NurseStation AS NamaRuang, SUM(k.Kapasitas) AS Kapasitas,IF(SUM(k.Kapasitas) - SUM(IFNULL(i.Jml,0)) < 0, 0, SUM(k.Kapasitas) - SUM(IFNULL(i.Jml,0))) AS Tersedia,SUM(k.Kapasitas) - SUM(IFNULL(i.Jml,0)) AS nyatanya')
				->from('kamar AS k')
				->join('nursestation AS n','n.ID = k.NurseStation')
				->join('bpjs_ref_kelas_kamar AS s','s.kodekelas = k.BPJS_Kelas')
				->join('v_kamar_terisihro AS i','i.KamarID = k.ID','left')
				->group_by('n.NurseStation, k.BPJS_Kelas')				
				->get();
				//->get_where('datapasien',array('NoRM'=>$key));
			
			return $q->result();
		}
		
		
	}
