<?php
	class Rekap_chasmix_model extends CI_Model {
		function __construct()
		{
			// Call the Model constructor
			parent::__construct();
			
			$this->dbhost=$this->load->database('hospistar', TRUE);
					
			date_default_timezone_set('Asia/Jakarta');
		}
		
		public function hasilRekapChasmixBPJS($followup,$tglawal,$tglakhir)
		{
			
			$q=$this->dbhost->query("SELECT a.`ID`, a.`TanggalMasuk`, a.`TanggalKeluar`, b.`NoRM`,b.`Nama`,h.`Item`,a.`user`,g.`PintuMasuk`, a.`NoSEP_BPJS`, a.`NoAsuransi` AS No_kartu_BPJS, a.`kelas`,a.`FollowUp`, c.`ICD10`,
IF(c.`ICD10` IS NOT NULL,d.`Nama`,IF((c.`ICD10` IS NULL AND c.`NoICD10` IS NOT NULL),c.`NoICD10`,'')) AS Diagnosa,
GROUP_CONCAT(f.`actName`) AS tindakan, GROUP_CONCAT(e.`actDesc`) AS ket_tindakan 
FROM pendaftaran AS a 
LEFT JOIN datapasien AS b ON a.`PasienID`=b.`ID`
LEFT JOIN `summery_pasien` AS c ON a.`ID`=c.`PendaftaranID`
LEFT JOIN `icd10` AS d ON c.`ICD10`=d.`ID`
LEFT JOIN `tindakan_pasien` AS e ON a.`ID`=e.`PendaftaranID`
LEFT JOIN `tindakan` AS f ON e.`actID`=f.`actID`
LEFT JOIN pintumasuk AS g ON a.`PintuMasuk`=g.`ID`
LEFT JOIN ket_nama AS h ON b.`ketNamaID`=h.`ID`
WHERE (a.`JnsPenjamin`='2' AND a.`PershID`='1') AND $followup a.`Pulang`='S' AND a.`PintuMasuk` NOT IN('15','16') AND a.`TanggalMasuk` BETWEEN '$tglawal' AND '$tglakhir'
GROUP BY a.`ID`;");				
				
			return $q->result();
		}
		
		public function hasilRekapChasmixBPJSLab($followup,$tglawal,$tglakhir)
		{
			
			$q=$this->dbhost->query("SELECT a.`ID`, a.`TanggalMasuk`, a.`TanggalKeluar`, b.`NoRM`,b.`Nama`,h.`Item`,a.`user`,g.`PintuMasuk`, a.`NoSEP_BPJS`, a.`NoAsuransi` AS No_kartu_BPJS, a.`kelas`,a.`FollowUp`, c.`ICD10`,
IF(c.`ICD10` IS NOT NULL,d.`Nama`,IF((c.`ICD10` IS NULL AND c.`NoICD10` IS NOT NULL),c.`NoICD10`,'')) AS Diagnosa,
GROUP_CONCAT(f.`actName`) AS tindakan, GROUP_CONCAT(e.`actDesc`) AS ket_tindakan 
FROM pendaftaran AS a 
LEFT JOIN datapasien AS b ON a.`PasienID`=b.`ID`
LEFT JOIN `summery_pasien` AS c ON a.`ID`=c.`PendaftaranID`
LEFT JOIN `icd10` AS d ON c.`ICD10`=d.`ID`
LEFT JOIN `tindakan_pasien` AS e ON a.`ID`=e.`PendaftaranID`
LEFT JOIN `tindakan` AS f ON e.`actID`=f.`actID`
LEFT JOIN pintumasuk AS g ON a.`PintuMasuk`=g.`ID`
LEFT JOIN ket_nama AS h ON b.`ketNamaID`=h.`ID`
WHERE (a.`JnsPenjamin`='2' AND a.`PershID`='1') AND $followup a.`Pulang`='S' AND a.`PintuMasuk`='15' AND a.`TanggalMasuk` BETWEEN '$tglawal' AND '$tglakhir'
GROUP BY a.`ID`;");				
				
			return $q->result();
		}
		
		public function hasilRekapChasmixBPJSRadio($followup,$tglawal,$tglakhir)
		{
			
			$q=$this->dbhost->query("SELECT a.`ID`, a.`TanggalMasuk`, a.`TanggalKeluar`, b.`NoRM`,b.`Nama`,h.`Item`,a.`user`,g.`PintuMasuk`, a.`NoSEP_BPJS`, a.`NoAsuransi` AS No_kartu_BPJS, a.`kelas`,a.`FollowUp`, c.`ICD10`,
IF(c.`ICD10` IS NOT NULL,d.`Nama`,IF((c.`ICD10` IS NULL AND c.`NoICD10` IS NOT NULL),c.`NoICD10`,'')) AS Diagnosa,
GROUP_CONCAT(f.`actName`) AS tindakan, GROUP_CONCAT(e.`actDesc`) AS ket_tindakan 
FROM pendaftaran AS a 
LEFT JOIN datapasien AS b ON a.`PasienID`=b.`ID`
LEFT JOIN `summery_pasien` AS c ON a.`ID`=c.`PendaftaranID`
LEFT JOIN `icd10` AS d ON c.`ICD10`=d.`ID`
LEFT JOIN `tindakan_pasien` AS e ON a.`ID`=e.`PendaftaranID`
LEFT JOIN `tindakan` AS f ON e.`actID`=f.`actID`
LEFT JOIN pintumasuk AS g ON a.`PintuMasuk`=g.`ID`
LEFT JOIN ket_nama AS h ON b.`ketNamaID`=h.`ID`
WHERE (a.`JnsPenjamin`='2' AND a.`PershID`='1') AND $followup a.`Pulang`='S' AND a.`PintuMasuk`='16' AND a.`TanggalMasuk` BETWEEN '$tglawal' AND '$tglakhir'
GROUP BY a.`ID`;");				
				
			return $q->result();
		}
		
	}
