<?php
	class Jasmed_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 getPasienVisite($dokter,$tglawal, $tglakhir)
		{
			$q=$this->dbhost->query("SELECT b.`no_rawat`, d.`nm_pasien`, b.`kd_dokter`
FROM jns_perawatan_inap AS a
INNER JOIN v_jasmed AS b ON a.`kd_jenis_prw`=b.`kd_jenis_prw`
INNER JOIN reg_periksa AS c ON b.`no_rawat`=c.`no_rawat`
INNER JOIN pasien AS d ON c.`no_rkm_medis`=d.`no_rkm_medis`
INNER JOIN kamar_inap AS e ON c.`no_rawat`=e.`no_rawat`
WHERE a.`kd_kategori`='Vst' AND b.`kd_dokter`='$dokter' AND e.`tgl_keluar` BETWEEN '$tglawal' AND '$tglakhir' GROUP BY d.`no_rkm_medis` ORDER BY b.no_rawat ;");
			
			return $q->result();
		}
		
		function getDataVisiteDokter($tglawal, $tglakhir)
		{
			//$q=$this->dbhost->query("SELECT a.`kd_dokter`, b.`nm_dokter`, COUNT(IF(e.`kd_pj`='BPJ',a.`tgl_perawatan`,NULL)) AS BPJS, COUNT(IF(e.`kd_pj`='-' OR e.`kd_pj`='1',a.`tgl_perawatan`,NULL)) AS Umum, COUNT(IF(e.`kd_pj`<>'BPJ' AND e.`kd_pj`<>'-' AND e.`kd_pj`<>'1',a.`tgl_perawatan`,NULL)) AS Lainnya, COUNT(a.`tgl_perawatan`) AS jml FROM v_jasmed AS aJOIN dokter AS b ON a.`kd_dokter`=b.`kd_dokter` JOIN `jns_perawatan_inap` AS c ON a.`kd_jenis_prw`=c.`kd_jenis_prw` JOIN kamar_inap AS d ON a.`no_rawat`=d.`no_rawat` JOIN reg_periksa AS e ON a.`no_rawat`=e.`no_rawat` WHERE c.`kd_kategori`='Vst' AND d.`tgl_keluar` BETWEEN '$tglawal' AND '$tglakhir' GROUP BY a.`kd_dokter` ;");
			$q=$this->dbhost->query("SELECT b.`kd_dokter`,d.`nm_dokter`,
COUNT(a.`kd_jenis_prw`) AS jml,
COUNT(IF(c.`kd_pj`='BPJ',a.`kd_jenis_prw`,NULL)) AS BPJS,
COUNT(IF(c.`kd_pj`='-' OR c.`kd_pj`='1',a.`kd_jenis_prw`,NULL)) AS Umum,
COUNT(IF(c.`kd_pj`<>'BPJ' AND c.`kd_pj`<>'-' AND c.`kd_pj`<>'1',a.`kd_jenis_prw`,NULL)) AS Lainnya,
SUM(b.`tarif_tindakandr`) AS total
FROM jns_perawatan_inap AS a
INNER JOIN v_jasmed AS b ON a.`kd_jenis_prw`=b.`kd_jenis_prw`
INNER JOIN reg_periksa AS c ON b.`no_rawat`=c.`no_rawat`
INNER JOIN dokter AS d ON b.`kd_dokter`=d.`kd_dokter`
WHERE b.`tgl_perawatan` BETWEEN '$tglawal' AND '$tglakhir' 
AND a.`kd_kategori`='Vst'
AND b.`tarif_tindakandr` >0
GROUP BY b.`kd_dokter`;");
			
			return $q->result();
		}
		
		function getRekapDataVisiteDokterDetail($kode,$tglawal, $tglakhir)
		{
			//$q=$this->dbhost->query("SELECT a.`no_rawat`,f.`nm_pasien`, a.`kd_dokter`, COUNT(DISTINCT(a.`tgl_perawatan`)) AS jml FROM v_jasmed AS a JOIN `jns_perawatan_inap` AS c ON a.`kd_jenis_prw`=c.`kd_jenis_prw` JOIN kamar_inap AS d ON a.`no_rawat`=d.`no_rawat` JOIN reg_periksa AS e ON a.`no_rawat`=e.`no_rawat` JOIN pasien AS f ON e.`no_rkm_medis`=f.`no_rkm_medis` WHERE a.`kd_dokter`='$kode' AND c.`kd_kategori`='vst' AND d.`tgl_keluar` BETWEEN '$tglawal' AND '$tglakhir' GROUP BY a.`no_rawat` ;");
			$q=$this->dbhost->query("SELECT b.`no_rawat`, d.`nm_pasien`, COUNT(a.`kd_jenis_prw`) AS jml
FROM jns_perawatan_inap AS a
INNER JOIN v_jasmed AS b ON a.`kd_jenis_prw`=b.`kd_jenis_prw`
INNER JOIN reg_periksa AS c ON b.`no_rawat`=c.`no_rawat`
INNER JOIN pasien AS d ON c.`no_rkm_medis`=d.`no_rkm_medis`
WHERE a.`kd_kategori`='Vst'
AND b.`kd_dokter`='$kode' AND b.`tgl_perawatan` BETWEEN '$tglawal' AND '$tglakhir'
AND b.`tarif_tindakandr` > 0
GROUP BY b.`no_rawat`;");
			
			return $q->result();
		}
		
		function getRekapDataVisiteDokterPasienDetailTgl($kode,$norawat,$tglawal,$tglakhir)
		{			
			$q=$this->dbhost->query("SELECT b.`no_rawat`, b.`tgl_perawatan`, b.`jam_rawat`, b.`kd_jenis_prw`, a.`nm_perawatan`
FROM jns_perawatan_inap AS a
INNER JOIN v_jasmed AS b ON a.`kd_jenis_prw`=b.`kd_jenis_prw`
WHERE a.`kd_kategori`='Vst' AND b.`kd_dokter`='$kode' AND b.`tgl_perawatan` BETWEEN '$tglawal' AND '$tglakhir'
AND b.`no_rawat`='$norawat' 
AND b.`tarif_tindakandr` > 0 
GROUP BY b.`tgl_perawatan`;");
			
			return $q->result();
		}
	}
