<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Laborat_panel extends MBELINK_Controller {
	
	public function __construct()
	{
		parent::__construct();
		
		$this->load->library(array('session'));
		$this->load->helper(array('rsonline'));
				 
		// User Login Information
		$this->data['user'] = user_info();
		$this->data['instansi'] = orgInfo();
		
		// Cek Sesi
		 if(! $this->session->userdata('userid')):
			redirect(base_url('login-system.html'), 'refresh');
		endif;
		//Ngaeng-ngaeng
		$this->load->model('laborat/laborat_panel_model');
		$this->load->model('admision/admision_panel_model');
		$this->load->model('inform_model');
		
		$this->data['tanggal']=date("Y-m-d", time());
		$this->data['tglaw']=$this->data['tanggal'];
		$this->data['tglak']=$this->data['tanggal'];
		
		$bulan=date("m", time());
		$tahun=date("Y", time());
		
		$this->data['tglawalx']=$tahun."-".$bulan."-01";
		$this->data['tglakhirx']=date("Y-m-d", time());
	}
	
	public function index()
	{
		$this->data['nama']=$this->input->post('nama');
		$this->data['norm']=$this->input->post('norm');
		
		if(isset($_POST['bCari'])){
			if($this->input->post('nama') <>''){
				$key="c.`Nama` LIKE '%".$this->data['nama']."%'";
			}else if($this->input->post('norm') <>''){
				$key="c.`NoRM`='".$this->data['norm']."'";
			}else if($this->input->post('nama') <>'' AND $this->input->post('norm') <>'')
			{
				$key="c.`Nama` LIKE '%".$this->data['nama']."%' OR c.`NoRM`='".$this->data['norm']."'";
			}else{
				$key="a.`LabTanggal`=LEFT(NOW(),10)";
			}
			$this->data['pasien']=$this->laborat_panel_model->getCariDataPasienLaborat($key);
		}else{
			$this->data['pasien']=$this->laborat_panel_model->getDataPasienLaborat();
		}
		
		$this->load->view('laborat/laborat_pasien',$this->data);
		
	}
	
	function cetakHasilLaborat()
	{
		$dataps=$this->laborat_panel_model->getPasienLaboratByIDReg($this->input->get('key'),$this->input->get('lab'));
		foreach($dataps as $dtps):
			$this->data['norm']=$dtps->NoRM;
			$this->data['nama']=$dtps->Nama;
			$this->data['ketnm']=$dtps->Item;
			$this->data['alamat']=$dtps->Alamat;
			$this->data['tgllahir']=$dtps->TglLhr;
			$this->data['hasil']=$dtps->LabHasil;
			$this->data['periksa']=$dtps->LabDesc;
			$this->data['tglpriksa']=$dtps->LabTanggal;
			$this->data['jkel']=$dtps->Kelamin;
		endforeach;
		
		$this->load->view('laborat/cetak_hasil_laborat',$this->data);
	}
	
	function saveHasilLabRapid()
	{
		//print_r($_POST);//exit();
		$noreg=$this->input->post('noreg');
		$labno=$this->input->post('labno');
		$labid=$this->input->post('labid');
		$labseq=$this->input->post('labseq');
		
		$baru=array(
			'PendaftaranID' => $this->input->post('noreg'),
			'LabSEQ' => $this->input->post('labseq'),
			'LabNo' => $this->input->post('labno'),
			'LabID' => $this->input->post('labid'),
			'LabHasil' => $this->input->post('result'),			
			'H_D' => 'D',
			'Lvl' => '1',
		);
		$upd=array(
			'LabHasil'=>$this->input->post('pj'),
			'TglSelesai'=>date("Y-m-d H:i:s", time()),
		);
		$log=array(
			'PendaftaranID' => $this->input->post('noreg'),
			'LabSEQ' => $this->input->post('labseq'),
			'LabNo' => $this->input->post('labno'),
			'LabID' => $this->input->post('labid'),
			'LabHasil' => $this->input->post('result'),			
			'H_D' => 'D',
			'Lvl' => '1',
			'userID'=> $this->session->userdata('userid'),
			'tglInput' => date("Y-m-d H:i:s", time()),
		);
		
		$cek=$this->laborat_panel_model->cekDetailPxLab($noreg,$labno,$labid,$labseq);
		
		//print_r($cek);echo sizeof($cek);exit();
		if($cek){
			$this->session->set_flashdata('pesan', 'Hasil Lab Pasien Tersebut Sudah Pernah di Input....!!!!');
		}else{
			$insert=$this->laborat_panel_model->insertLabPxDetailRapid($baru);
			
			if($insert){
				
				$this->laborat_panel_model->updLabPxDetailRapit($upd,$noreg,$labno,$labid,$labseq);
				$this->laborat_panel_model->insertLogLabPxDetailRapit($log);
				
			}else{
				$this->session->set_flashdata('error', 'Gagal Input Hasil Lab');
			}
		}
		redirect(base_url('pasien-laborat.html'));
		//print_r($baru);print_r($upd);print_r($log);exit();
	}
	
	function getPxAntigen()
	{
		$this->data['nama']=$this->input->post('nama');
		$this->data['norm']=$this->input->post('norm');
		
		if(isset($_POST['bCari'])){
			if($this->input->post('nama') <>''){
				$key="c.`Nama` LIKE '%".$this->data['nama']."%'";
			}else if($this->input->post('norm') <>''){
				$key="c.`NoRM`='".$this->data['norm']."'";
			}else if($this->input->post('nama') <>'' AND $this->input->post('norm') <>'')
			{
				$key="c.`Nama` LIKE '%".$this->data['nama']."%' OR c.`NoRM`='".$this->data['norm']."'";
			}else{
				$key="a.`LabTanggal`=LEFT(NOW(),10)";
			}
			$this->data['pasien']=$this->laborat_panel_model->getCariPxlaboratAntigen($key);
		}else{
			$this->data['pasien']=$this->laborat_panel_model->getPxlaboratAntigen();
		}
		
		$this->load->view('laborat/laborat_pasien_antigen',$this->data);
	}
	
	function saveHasilLabAntigen()
	{
		//print_r($_POST);
		$noreg=$this->input->post('noreg');
		$labno=$this->input->post('labno');
		$labid=$this->input->post('labid');
		$labseq=$this->input->post('labseq');
		
		$baru=array(
			'PendaftaranID' => $this->input->post('noreg'),
			'LabSEQ' => $this->input->post('labseq'),
			'LabNo' => $this->input->post('labno'),
			'LabID' => $this->input->post('labid'),
			'LabHasil' => $this->input->post('result'),			
			'H_D' => 'D',
			'Lvl' => '1',
		);
		$upd=array(
			'LabHasil'=>$this->input->post('pj'),
			'TglSelesai'=>date("Y-m-d H:i:s", time()),
		);
		$log=array(
			'PendaftaranID' => $this->input->post('noreg'),
			'LabSEQ' => $this->input->post('labseq'),
			'LabNo' => $this->input->post('labno'),
			'LabID' => $this->input->post('labid'),
			'LabHasil' => $this->input->post('result'),			
			'H_D' => 'D',
			'Lvl' => '1',
			'userID'=> $this->session->userdata('userid'),
			'tglInput' => date("Y-m-d H:i:s", time()),
		);
		
		$cek=$this->laborat_panel_model->cekDetailPxLab($noreg,$labno,$labid,$labseq);
		
		//print_r($cek);echo sizeof($cek);exit();
		if($cek){
			$this->session->set_flashdata('pesan', 'Hasil Lab Pasien Tersebut Sudah Pernah di Input....!!!!');
		}else{
			$insert=$this->laborat_panel_model->insertLabPxDetailRapid($baru);
			
			if($insert){
				
				$this->laborat_panel_model->updLabPxDetailRapit($upd,$noreg,$labno,$labid,$labseq);
				$this->laborat_panel_model->insertLogLabPxDetailRapit($log);
				
			}else{
				$this->session->set_flashdata('error', 'Gagal Input Hasil Lab');
			}
		}
		redirect(base_url('pasien-laborat-antigen.html'));
		//print_r($baru);print_r($upd);print_r($log);exit();
	}
	
	function cetakHasilLaboratAntigen()
	{
		$dataps=$this->laborat_panel_model->getPasienLaboratAntigenByIDReg($this->input->get('key'),$this->input->get('lab'),$this->input->get('tgl'));
		foreach($dataps as $dtps):
			$this->data['norm']=$dtps->NoRM;
			$this->data['nama']=$dtps->Nama;
			$this->data['ketnm']=$dtps->Item;
			$this->data['alamat']=$dtps->Alamat;
			$this->data['tgllahir']=$dtps->TglLhr;
			$this->data['hasil']=$dtps->LabHasil;
			$this->data['periksa']=$dtps->LabDesc;
			$this->data['tglpriksa']=$dtps->LabTanggal;
			$this->data['jamperiksa']=$dtps->LabJam;
			$this->data['jkel']=$dtps->Kelamin;
			$this->data['pelaksana']=$dtps->atlm;
		endforeach;
		
		$this->load->view('laborat/cetak_hasil_laborat_antigen',$this->data);
	}
	
	function getPxPCR()
	{
		$this->data['nama']=$this->input->post('nama');
		$this->data['norm']=$this->input->post('norm');
		
		if(isset($_POST['bCari'])){
			if($this->input->post('nama') <>''){
				$key="c.`Nama` LIKE '%".$this->data['nama']."%'";
			}else if($this->input->post('norm') <>''){
				$key="c.`NoRM`='".$this->data['norm']."'";
			}else if($this->input->post('nama') <>'' AND $this->input->post('norm') <>'')
			{
				$key="c.`Nama` LIKE '%".$this->data['nama']."%' OR c.`NoRM`='".$this->data['norm']."'";
			}else{
				$key="a.`LabTanggal`=LEFT(NOW(),10)";
			}
			
			if($this->input->post('nama') <>''){
				$keylokal="a.`nama` LIKE '%".$this->data['nama']."%'";
			}else if($this->input->post('norm') <>''){
				$keylokal="a.`norm`='".$this->data['norm']."'";
			}else if($this->input->post('nama') <>'' AND $this->input->post('norm') <>'')
			{
				$keylokal="a.`nama` LIKE '%".$this->data['nama']."%' OR a.`norm`='".$this->data['norm']."'";
			}else{
				$keylokal="a.`tgl_periksa`=LEFT(NOW(),10)";
			}				
			
			$this->data['pasienlok']=$this->laborat_panel_model->getPXPCRLokalCari($keylokal);
			$this->data['pasien']=$this->laborat_panel_model->getCariPxlaboratPCR($key);
		}else{
			$this->data['pasienlok']=$this->laborat_panel_model->getPXPCRLokal();
			$this->data['pasien']=$this->laborat_panel_model->getPxlaboratPCR();
		}
		
		
		
		$this->load->view('laborat/laborat_pasien_pcr',$this->data);
	}
	
	function saveHasilLabPCR()
	{
		//print_r($_POST);exit();
		$noreg=$this->input->post('noreg');
		$labno=$this->input->post('labno');
		$labid=$this->input->post('labid');
		$labseq=$this->input->post('labseq');
		
		$baru=array(
			'lab_id' => $this->input->post('labid'),
			'labseq' => $this->input->post('labseq'),
			'labno' => $this->input->post('labno'),
			'noreg' => $this->input->post('noreg'),
			'norm' => $this->input->post('norm'),
			'nama' => $this->input->post('nama'),
			'ket_nama' => $this->input->post('ketnama'),
			'tgl_lahir' => $this->input->post('tgllahir'),
			'usia' => $this->input->post('usia'),
			'jkel' => $this->input->post('jkel'),
			'no_telp' => $this->input->post('notelp'),
			'nik' => $this->input->post('nik'),
			'alamat' => $this->input->post('alamat'),
			'kecamatan' => $this->input->post('kecamatan'),
			'kota' => $this->input->post('kota'),
			'tgl_periksa' => $this->input->post('tgl_periksa'),
			'jam_periksa' => $this->input->post('jamperiksa'),
			'kd_spesimen' => $this->input->post('kd_spesimen'),
			'spesimen' => 'Usapan Nasofaring dan Orofaring',
			'tgl_hasil' => $this->input->post('tgl_hasil'),
			'kode_petugas' => $this->input->post('kd_petugas_lab'),
			'petugas_lab' => $this->input->post('petugas_lab'),
			'pj_lab' => 'dr. Gama Diswita Yudhi Hartawan, Sp.PK',
			'sip_pj' => 'SIP.446.3/3094/01-DPMPTSP/OL/2019',
			'petugas_entry' => $this->session->userdata('userid'),
			'tgl_entry' => date("Y-m-d H:i:s", time()),
		);
		
		//print_r($baru);exit();
		/* $upd=array(
			'LabHasil'=>$this->input->post('pj'),
			'TglSelesai'=>date("Y-m-d H:i:s", time()),
		);
		$log=array(
			'PendaftaranID' => $this->input->post('noreg'),
			'LabSEQ' => $this->input->post('labseq'),
			'LabNo' => $this->input->post('labno'),
			'LabID' => $this->input->post('labid'),
			'LabHasil' => $this->input->post('result'),			
			'H_D' => 'D',
			'Lvl' => '1',
			'userID'=> $this->session->userdata('userid'),
			'tglInput' => date("Y-m-d H:i:s", time()),
		); */
		
		$cek=$this->laborat_panel_model->cekDetailPxLabPCR($noreg,$labno,$labid,$labseq);
		
		//print_r($cek);echo sizeof($cek);exit();
		if($cek){
			$this->session->set_flashdata('pesan', 'Hasil Lab Pasien Tersebut Sudah Pernah di Input....!!!!');
		}else{
			$insert=$this->laborat_panel_model->insertLabPxPCR($baru);
			
			if($insert){
				
				/* $this->laborat_panel_model->updLabPxDetailRapit($upd,$noreg,$labno,$labid,$labseq);
				$this->laborat_panel_model->insertLogLabPxDetailRapit($log); */
				$this->session->set_flashdata('pesanok', 'Penympanan Hasil Lab Berhasil');
			}else{
				$this->session->set_flashdata('error', 'Gagal Input Hasil Lab');
			}
		}
		redirect(base_url('pasien-laborat-pcr.html'));
		//print_r($baru);print_r($upd);print_r($log);exit();
	}
	
	function cetakHasilLaboratPCR()
	{
		$dataps=$this->laborat_panel_model->getPXPCRLokalByID($this->input->get('key'),$this->input->get('lab'));
		foreach($dataps as $dtps):
			$this->data['norm']=$dtps->norm;
			$this->data['nama']=$dtps->nama;
			//$this->data['ketnm']=$dtps->Item;
			$this->data['alamat']=$dtps->alamat;
			$this->data['tgllahir']=$dtps->tgl_lahir;
			$this->data['usia']=$dtps->usia;
			$this->data['jkel']=$dtps->jkel;
			$this->data['tglpriksa']=$dtps->tgl_periksa;
			$this->data['jamperiksa']=$dtps->jam_periksa;			
			$this->data['nik']=$dtps->nik;
			$this->data['tgl_hasil']=$dtps->tgl_hasil;
			$this->data['petugas']=$dtps->petugas_lab;
			$this->data['kode_petugas']=$dtps->kode_petugas;
			$this->data['kd_spesimen']=$dtps->kd_spesimen;
			$this->data['spesimen']=$dtps->spesimen;
		endforeach;
		
		$this->load->view('laborat/cetak_hasil_laborat_pcr',$this->data);
	}
	
	function getPasienLaboratReport()
	{
		if(isset($_POST['bProses'])){			
			$this->data['tglaw']=$this->input->post('tglawal');
			$this->data['tglak']=$this->input->post('tglakhir');
			
			$this->data['dtregist']=$this->laborat_panel_model->getDataLaboratReportPeriode($this->data['tglaw'],$this->data['tglak']);
		}else{
			
			$this->data['dtregist']=$this->laborat_panel_model->getDataLaboratReportAllNow();
		} 
		$this->load->view('laborat/laborat_pasien_report',$this->data);
	}
	
	function excelReprotPxLaborat()
	{	
		$this->data['tglaw']=$this->input->post('tglawal');
		$this->data['tglak']=$this->input->post('tglakhir');
		
		$this->data['dtregist']=$this->laborat_panel_model->getDataLaboratReportPeriode($this->data['tglaw'],$this->data['tglak']);
				 
		$this->load->view('laborat/laborat_pasien_report_excel', $this->data);
	}
	
	function getPasienRekapLaborat()
	{
		//echo $this->data['tglawal'];
		//echo $this->data['tglakhir'];
		if(isset($_POST['bProses'])){
			$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		}else{
			$this->data['tglawal']=$this->data['tglawalx'];
			$this->data['tglakhir']=$this->data['tglakhirx'];
		}
		
		$this->data['result']=$this->laborat_panel_model->getDataLaboratRekapPeriode($this->data['tglawal'],$this->data['tglakhir']);
		
		$this->load->view('laborat/laborat_pasien_rekap', $this->data);
	}
	
	
	//dummy
	function listPendaftaran()
	{
		if(isset($_POST['bCari'])){
			$this->data['tanggal']=$this->input->post('tanggal');
		}else{
			$this->data['tanggal']=date("Y-m-d", time());
		}
		
		$this->data['registrasi']=$this->admision_panel_model->getDataPendaftaranBPJS($this->data['tanggal']);
		$this->load->view('admision/data_pendaftaran',$this->data);
	}
	
	function saveUpdateNoSEP()
	{
		print_r($_POST);
		
		$dtupdate=array(
			'NoSEP_BPJS' =>$this->input->post('nosep'),
		);
		$updt=$this->admision_panel_model->simpanUbdapeSEP($dtupdate,$this->input->post('idreg'),$this->input->post('tglmasuk'));
		
		if($updt){		
			$insert=array(
				'idreg'=>$this->input->post('idreg'),
				'nama'=>$this->input->post('nama'),
				'no_sep'=>$this->input->post('nosep'),
				'tgl_masuk'=>$this->input->post('tglmasuk'),
				'tgl_entry'=>date("Y-m-d H:i:s", time()),
			);
			$save=$this->admision_panel_model->insertLogSEP($insert);
			
			$this->session->set_flashdata('pesan', 'Update SEP Berhasil');
			
		}else{
			$this->session->set_flashdata('error', 'Gagal Melakukan Update SEP');
		}
		redirect(base_url('list-pendaftaran.html'));
	}
	
	function daftarPasienPenjamin()
	{
		$this->data['followup']=$this->input->post('followup');
		$this->data['statuspx']=$this->input->post('statuspx');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		
		if(! $this->data['followup']==''){
			$followupx="a.`FollowUp`='".$this->data['followup']."' AND";
		}else{
			$followupx="";
		}
		
		if(! $this->data['statuspx']==''){
			$status_pasien="a.`Pulang`='".$this->data['statuspx']."' AND";
		}else{
			$status_pasien="";
		}
		
		if($this->data['tglakhir'] < $this->data['tglawal']){
			$this->session->set_flashdata('error', 'Tanggal Akhir yang di masukkan Harus Lebih Besar atau Sama dengan Tanggal Awal');	
			redirect(base_url('admision-pasien-penjamin.html'));
		}else{
			$this->data['result']=$this->admision_panel_model->getPasienJaminan($followupx,$status_pasien,$this->data['tglawal'],$this->data['tglakhir']);
		
			$this->load->view('admision/pasien_penjamin',$this->data);
		}
	}
	
	function daftarJenisPasien()
	{
		$this->data['followup']=$this->input->post('followup');
		$this->data['statuspx']=$this->input->post('statuspx');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		//$this->data['lamabaru']=$this->input->post('lamabaru');
		
		if(! $this->data['followup']==''){
			$followupx="a.`FollowUp`='".$this->data['followup']."' AND";
		}else{
			$followupx="";
		}
		
		if(! $this->data['statuspx']==''){
			$status_pasien="a.`Pulang`='".$this->data['statuspx']."' AND";
		}else{
			$status_pasien="";
		}
		
		/* if(! $this->data['lamabaru']==''){
			$status_lama="a.`KategoriLamaBaru`='".$this->data['lamabaru']."' AND";
		}else{
			$status_lama="";
		} */
		
		if($this->data['tglakhir'] < $this->data['tglawal']){
			$this->session->set_flashdata('error', 'Tanggal Akhir yang di masukkan Harus Lebih Besar atau Sama dengan Tanggal Awal');	
			redirect(base_url('admision-byjenis-pasien.html'));
		}else{
			//$this->data['result']=$this->admision_panel_model->getPasienLamaBaru($followupx,$status_pasien,$status_lama,$this->data['tglawal'],$this->data['tglakhir']);
			$this->data['result']=$this->admision_panel_model->getPasienLamaBaru($followupx,$status_pasien,$this->data['tglawal'],$this->data['tglakhir']);
		
			$this->load->view('admision/pasien_jenis',$this->data);
		}
	}
	
	function daftarJenisPasienPenunjang()
	{
		$this->data['followup']=$this->input->post('followup');
		$this->data['statuspx']=$this->input->post('statuspx');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		//$this->data['lamabaru']=$this->input->post('lamabaru');
		
		if(! $this->data['followup']==''){
			$followupx="a.`FollowUp`='".$this->data['followup']."' AND";
		}else{
			$followupx="";
		}
		
		if(! $this->data['statuspx']==''){
			$status_pasien="a.`Pulang`='".$this->data['statuspx']."' AND";
		}else{
			$status_pasien="";
		}
		
		/* if(! $this->data['lamabaru']==''){
			$status_lama="a.`KategoriLamaBaru`='".$this->data['lamabaru']."' AND";
		}else{
			$status_lama="";
		} */
		
		if($this->data['tglakhir'] < $this->data['tglawal']){
			$this->session->set_flashdata('error', 'Tanggal Akhir yang di masukkan Harus Lebih Besar atau Sama dengan Tanggal Awal');	
			redirect(base_url('admision-pasien-penunjang-byjenis.html'));
		}else{
			//$this->data['result']=$this->admision_panel_model->getPasienLamaBaruPenunjang($followupx,$status_pasien,$status_lama,$this->data['tglawal'],$this->data['tglakhir']);
			$this->data['result']=$this->admision_panel_model->getPasienLamaBaruPenunjang($followupx,$status_pasien,$this->data['tglawal'],$this->data['tglakhir']);
		
			$this->load->view('admision/pasien_jenis_penunjang',$this->data);
		}
	}
	
	function daftarRekapPasienByPerujuk()
	{
		$this->data['followup']=$this->input->post('followup');
		$this->data['statuspx']=$this->input->post('statuspx');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		
		if(! $this->data['followup']==''){
			$followupx="a.`FollowUp`='".$this->data['followup']."' AND";
		}else{
			$followupx="";
		}
		
		if(! $this->data['statuspx']==''){
			$status_pasien="a.`Pulang`='".$this->data['statuspx']."' AND";
		}else{
			$status_pasien="";
		}
		
		if($this->data['tglakhir'] < $this->data['tglawal']){
			$this->session->set_flashdata('error', 'Tanggal Akhir yang di masukkan Harus Lebih Besar atau Sama dengan Tanggal Awal');	
			redirect(base_url('admision-pasien-byrujukan.html'));
		}else{
			$this->data['result']=$this->admision_panel_model->getPasienRekapByPerujuk($followupx,$status_pasien,$this->data['tglawal'],$this->data['tglakhir']);
		
			$this->load->view('admision/pasien_rekap_rukujan',$this->data);
		}
	}
	
	//perujuk Kontrol
	function getDaftarPasienByPerujuk()
	{
		if(isset($_POST['bProses'])){
			$this->data['tglaw']=$this->input->post('tglawal');
			$this->data['tglak']=$this->input->post('tglakhir');
		}else{
			$this->data['tglaw']=date("Y-m-d", time());
			$this->data['tglak']=date("Y-m-d", time());
		}
		
		
		$this->data['pasienr']=$this->admision_panel_model->getDataPxDaftarByPerujuk($this->data['tglaw'],$this->data['tglak']);
		$this->data['pasienterdaftar']=$this->admision_panel_model->getDataPxDaftarByPerujukTerdaftar($this->data['tglaw'],$this->data['tglak']);
		
		$this->load->view('admision/perujuk_data_pasien_terdaftar',$this->data);
	}
	
	function getLihatPxPerujukByID()
	{
		$idpx=base64_decode($this->input->get('key'));
		$datapx=$this->admision_panel_model->getPxRujukanByID($idpx);
		
		foreach($datapx as $dtpx){
			$this->data['ID']=$dtpx->ID;
			$this->data['idreg']=$dtpx->idreg;
			$this->data['nama']=$dtpx->Nama;
			$this->data['alamat']=$dtpx->Alamat;
			$this->data['propinsi']=$dtpx->namaprop;
			$this->data['kecamatan']=$dtpx->nmkecamatan;
			$this->data['kota']=$dtpx->namakab;
			$this->data['jkel']=$dtpx->JKel;
			$this->data['tmp_lhr']=$dtpx->TmpLahir;
			$this->data['tgl_lhr']=$dtpx->TglLahir;
			$this->data['no_telp']=$dtpx->NoTelp;
			$this->data['nik']=$dtpx->NIK;
			$this->data['tgl_masuk']=$dtpx->TanggalMasuk;
			$this->data['idpoli']=$dtpx->PintuMasuk;
			$this->data['poli']=$dtpx->poli;
			$this->data['pj']=$dtpx->penanggung_jawab;
			$this->data['hub_pj']=$dtpx->hub_pj;
			$this->data['nmdokter']=$dtpx->nmdokter;
			$this->data['dokterid']=$dtpx->Dokter;
			$this->data['idjadwakdok']=$dtpx->jadwalDokter;
			$this->data['jadwaldok']=$dtpx->hari." ".$dtpx->JamStart."-".$dtpx->JamFinish;			
			$this->data['idpenjamin']=$dtpx->JnsPenjamin;			
			$this->data['penjamin']=$dtpx->penjamin;			
			$this->data['idperusahaan']=$dtpx->PershID;			
			$this->data['perusahaan']=$dtpx->perusahaan;			
			$this->data['no_asuransi']=$dtpx->NoAsuransi;			
			$this->data['diagnosars']=$dtpx->diagnosa_rs;			
			
		}
		$this->load->view('admision/perujuk_lihat_pasien',$this->data);
	}
	
	function cetakDataPxRujukanByAdmision()
	{
		$idp=base64_decode($this->input->get('key'));
		$datap=$this->admision_panel_model->getPxRujukanByID($idp);
		
		foreach($datap as $dtpx){
			$this->data['idreg']=$dtpx->idreg;
			$this->data['nama']=$dtpx->Nama;
			$this->data['alamat']=$dtpx->Alamat;
			$this->data['propinsi']=$dtpx->namaprop;
			$this->data['kecamatan']=$dtpx->nmkecamatan;
			$this->data['kota']=$dtpx->namakab;
			$this->data['jkel']=$dtpx->JKel;
			$this->data['tmp_lhr']=$dtpx->TmpLahir;
			$this->data['tgl_lhr']=$dtpx->TglLahir;
			$this->data['no_telp']=$dtpx->NoTelp;
			$this->data['nik']=$dtpx->NIK;
			$this->data['tgl_masuk']=$dtpx->TanggalMasuk;
			$this->data['idpoli']=$dtpx->PintuMasuk;
			$this->data['poli']=$dtpx->poli;
			$this->data['pj']=$dtpx->penanggung_jawab;
			$this->data['hub_pj']=$dtpx->hub_pj;
			$this->data['nmdokter']=$dtpx->nmdokter;
			$this->data['dokterid']=$dtpx->Dokter;
			$this->data['idjadwakdok']=$dtpx->jadwalDokter;
			$this->data['jadwaldok']=$dtpx->hari." ".$dtpx->JamStart."-".$dtpx->JamFinish;			
			$this->data['idpenjamin']=$dtpx->JnsPenjamin;			
			$this->data['penjamin']=$dtpx->penjamin;			
			$this->data['idperusahaan']=$dtpx->PershID;			
			$this->data['perusahaan']=$dtpx->perusahaan;			
			$this->data['no_asuransi']=$dtpx->NoAsuransi;			
						
			
		}
		
		$this->load->view('admision/cetak_datapasien_rujukan',$this->data);
	}
	
	function updStatusPxPerujukByAdmision()
	{
		//print_r($_POST);exit();
		$noreg=$this->input->post('noreg');		
		$updt=array(
			'sts_daftar' => $this->input->post('sts_daftar'),
			//'tindakan' => $this->input->post('tindakan'),
			//'reward' => $this->input->post('reawrd'),
			'keterangan' => $this->input->post('ket'),
			'tgl_update' => date('Y-m-d H:i:s',time()),
			'petugas_admision' => $this->session->userdata('userid'),
		);
		
		$update=$this->admision_panel_model->updatePxRujukanByAdmision($noreg,$updt);
		if($update){
		$this->session->set_flashdata('pesan', 'Update Status Registrasi Pasien Berhasil[By Admision]');
		}else{
			$this->session->set_flashdata('error', 'Gagal Update Status Pasien[By Admision]');
		}
		
		redirect(base_url('perujuk-daftar-pasien.html'));
	}
}
