<?php
	class Rajal_model extends CI_Model {
		function __construct()
		{
			parent::__construct();
			
			// DETERMINE DB
			$this->dbhost=$this->load->database('khanza', TRUE);
			//$this->nm_db = array('1' => 'jobs', 'db_hro', '');
			//$this->user_admin = 'user_admin';
		}	
		public function getPintuMasuk()
		{
			/* $stat = array('1','2','3','4','5');
			//$this->db->where_in('NurseStation', $stat);
			
			
			$q=$this->db
				->select('b.`NurseStation` AS nama_ns, a.*')
				->from('`kamar` AS a')
				->join('nursestation AS b','a.`NurseStation`=b.`ID`','left')
				->where_in('a.NurseStation', $stat)
				//->order_by('a.`id_poli`')
				->get(); */
			$q=$this->dbhost->get('pintumasuk');	
			return $q->result();
		}
		
		function getDataRegistrasi($tglawal,$tglakhir,$poli)
		{
			
			$q=$this->dbhost->query("SELECT  b.`NoRM`, b.`NIK`,b.`Nama`,b.`NoHP`,f.`Item`, b.`TglLhr`,c.`DQueue`,l.`JadwalID`,l.`JamStart`,l.`JamFinish`,d.`Dokter` AS nm_dokter, b.`Alamat`,e.`nmkecamatan`,g.`NamaPerujuk`,
IF(a.`JnsPenjamin`='2',h.`NamaLengkap`,IF(a.`JnsPenjamin`='3',i.`NamaLengkap`,'Umum')) AS penjamin,
IF(j.`ICD10` IS NOT NULL,k.`Nama`,IF((j.`ICD10` IS NULL AND j.`NoICD10` IS NOT NULL),j.`NoICD10`,'')) AS Diagnosa,
a.*
FROM pendaftaran AS a
LEFT JOIN datapasien AS b ON a.`PasienID`=b.`ID`
LEFT JOIN pendaftaran_poli AS c ON a.`ID`=c.`RegID`
LEFT JOIN dokter AS d ON a.`Dokter`=d.`ID`
LEFT JOIN kecamatan AS e ON b.`Kecamatan`=e.`ID`
LEFT JOIN ket_nama AS f ON b.`ketNamaID`=f.`ID`
LEFT JOIN perujuk AS g ON a.`Perujuk`=g.`ID`
LEFT JOIN datapasien_asuransi AS h ON a.`JnsPenjamin`='2' AND a.`PershID`=h.`ID`
LEFT JOIN datapasien_persh AS i ON a.`JnsPenjamin`='3' AND a.`PershID`=i.`ID`
LEFT JOIN `summery_pasien` AS j ON a.`ID`=j.`PendaftaranID`
LEFT JOIN `icd10` AS k ON j.`ICD10`=k.`ID`
LEFT JOIN jadwal_praktek_dokter AS l ON c.`JadwalID`=l.`JadwalID`
WHERE a.`PintuMasuk`='$poli' AND a.`TanggalMasuk` BETWEEN '$tglawal' AND '$tglakhir' GROUP BY a.`ID` ORDER BY a.`JamMasuk` DESC;");
			return $q->result();
		}
		
		
		//Json
		function getKamar($idkamar)
		{
			//$this->db->select('ID,NamaKamar,Kapasitas,terisi');
			$q=$this->db->get_where('kamar', array('ID' => $idkamar));
			
			if($q->num_rows() > 0)
			{
				return $q->result();
			}
		}			
		
	}
