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

require_once(str_replace("\\","/",APPPATH).'helpers/Secure_area_adm.php');
class Ugd extends Secure_area_adm {

	public function __construct()
	{
		parent::__construct();
		$data['jenis_page'] = "front_office/";
		$data['controller_dir'] = 'ugd_dir/';
		$data['controller'] = 'ugd';
		$data['parent_controller'] = 'ugd';
		$data['active'] = 'ugd';
		$this->load->model('M_apotek');
		$this->load->model('M_general');
		//$data['smt_aktif'] = $this->db->get_where('pddikti_re_semester',array('a_smt_aktif'=>'1'))->row();
		$this->load->vars($data);
	}

	public function delete_foto($file)
	{
		$this->db->where('file',$file);
		$this->db->delete('bbmc_tr_laboratorium_dokumen');
		redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}

	/*
	public function index()
	{
		//echo $this->session->userdata('id_cabang');
		//echo $this->session->userdata('userid');
		$data['judul'] ='Poliklinik Umum';
		$data['page']  ='ugd/master';
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Poliklinik Umum';
		$data['active'] = 'ugd';
		$this->db->where('batal_periksa','0');
		$this->db->where('status_perawatan','1');
		$this->db->like('tgl_kunjungan',date('Y-m-d'));
		$this->db->order_by('tgl_kunjungan');
		$data['query'] = $this->Content_m->get_kunjungan_pasien();
		//echo $this->db->last_query();
		$data['breadcumb'][] = array('icon'=>'archive',
																 'link'=>'',
																 'judul'=>'Poliklinik Umum');

		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}
	*/

	public function index()
	{
		redirect('front_office/ugd_dir/ugd/umum');
	}


	public function umum($tgl_awal=null, $tgl_akhir=null)
	{
		if($tgl_awal=='null'){$tgl_awal=null;}
		if($tgl_akhir=='null'){$tgl_akhir=null;}
		$data['tgl_awal'] = $tgl_awal;
		$data['tgl_akhir'] = $tgl_akhir;
		$data['dari'] = 'umum';

		//echo $this->session->userdata('id_cabang');
		//echo $this->session->userdata('userid');
		$data['judul'] ='Poliklinik Umum';
		$data['page']  ='ugd/master';
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Poliklinik Umum';
		$data['active'] = 'ugd';
		$this->db->where('batal_periksa','0');
		$this->db->where('status_perawatan','1');
		//$this->db->like('tgl_kunjungan',date('Y-m-d'));
		if($tgl_awal != null){
			$this->db->where('tgl_kunjungan >=',$tgl_awal." 00:00:00");
			$this->db->where('tgl_kunjungan <=',$tgl_akhir." 23:59:59");
		}else{
			$this->db->like('tgl_kunjungan',date('Y-m-d'));
		}	

		$this->db->order_by('tgl_kunjungan');
		$data['query'] = $this->Content_m->get_kunjungan_pasien();
		//echo $this->db->last_query();
		$data['breadcumb'][] = array('icon'=>'archive',
										 'link'=>'',
										 'judul'=>'Poliklinik Umum');

		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}

	public function fillter()
	{
		extract($_GET);
		//var_dump($_GET);

		$tgl_awal = date('Y-m-d',strtotime($tgl_awal));
		$tgl_akhir = date('Y-m-d',strtotime($tgl_akhir));
		if($id_sub_spesialis != 'null'){
			redirect('front_office/ugd_dir/ugd/'.$dari.'/'.$id_sub_spesialis.'/'.$tgl_awal.'/'.$tgl_akhir);
		}else{
			redirect('front_office/ugd_dir/ugd/'.$dari.'/'.$tgl_awal.'/'.$tgl_akhir);
		}

		
	}

	public function gigi($tgl_awal=null, $tgl_akhir=null)
	{
		if($tgl_awal=='null'){$tgl_awal=null;}
		if($tgl_akhir=='null'){$tgl_akhir=null;}
		$data['tgl_awal'] = $tgl_awal;
		$data['tgl_akhir'] = $tgl_akhir;
		$data['dari'] = 'gigi';


		$data['judul'] ='Poliklinik Gigi';
		$data['page']  ='ugd/master';
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Poliklinik Gigi';
		
		$this->db->where('batal_periksa','0');
		$this->db->where('status_perawatan','2');
		if($tgl_awal != null){
			$this->db->where('tgl_kunjungan >=',$tgl_awal." 00:00:00");
			$this->db->where('tgl_kunjungan <=',$tgl_akhir." 23:59:59");
		}else{
			$this->db->like('tgl_kunjungan',date('Y-m-d'));
		}	
		
		$this->db->order_by('tgl_kunjungan');
		$data['query'] = $this->Content_m->get_kunjungan_pasien();
		$data['breadcumb'][] = array('icon'=>'address-book',
																 'link'=>'',
																 'judul'=>'Poliklinik Gigi');

		$data['active'] = 'gigi';
		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}

	public function spesialis($id_sub_spesialis, $tgl_awal=null, $tgl_akhir=null)
	{
		if($tgl_awal=='null'){$tgl_awal=null;}
		if($tgl_akhir=='null'){$tgl_akhir=null;}
		$data['tgl_awal'] = $tgl_awal;
		$data['tgl_akhir'] = $tgl_akhir;
		$data['dari'] = 'spesialis';



		$data['judul'] ='Poliklinik Spesialis';
		$data['page']  ='ugd/master';
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Poliklinik Spesialis';

		$where = "(status_perawatan = '3' or id_alasan_keluar = '3')";
		$this->db->where('batal_periksa','0');
		$this->db->where('id_sub_spesialis',$id_sub_spesialis);
		if($tgl_awal != null){
			$this->db->where('tgl_kunjungan >=',$tgl_awal." 00:00:00");
			$this->db->where('tgl_kunjungan <=',$tgl_akhir." 23:59:59");
		}else{
			$this->db->like('tgl_kunjungan',date('Y-m-d'));
		}	
		//$this->db->or_where('id_alasan_keluar','3');
		//$this->db->where('status_perawatan','3');
		$this->db->order_by('tgl_kunjungan');
		$this->db->where($where);
		$data['query'] = $this->Content_m->get_kunjungan_pasien();
		//echo $this->db->last_query();
		$data['breadcumb'][] = array('icon'=>'address-book',
																 'link'=>'',
																 'judul'=>'Poliklinik Spesialis');

		$data['id_sub_spesialis'] = $id_sub_spesialis;
		$data['active'] = 'subspesialis-'.$id_sub_spesialis;
		$data['sub_menu'] = 'spesialis';
		//echo $this->session->userdata('userid'); 
		$this->load->view('template',$data);
	}

	public function rawat_jalan($tgl_awal=null, $tgl_akhir=null)
	{
		if($tgl_awal=='null'){$tgl_awal=null;}
		if($tgl_akhir=='null'){$tgl_akhir=null;}
		$data['tgl_awal'] = $tgl_awal;
		$data['tgl_akhir'] = $tgl_akhir;
		$data['dari'] = 'rawat_jalan';


		$data['judul'] ='Rawat Jalan';
		$data['page']  ='ugd/master';
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Pasien Rawat Jalan';

		$this->db->where('batal_periksa','0');
		$this->db->where('type_perawatan','1');
		if($tgl_awal != null){
			$this->db->where('tgl_kunjungan >=',$tgl_awal." 00:00:00");
			$this->db->where('tgl_kunjungan <=',$tgl_akhir." 23:59:59");
		}else{
			$this->db->like('tgl_kunjungan',date('Y-m-d'));
		}	
		$this->db->order_by('tgl_kunjungan');
		$data['query'] = $this->Content_m->get_kunjungan_pasien();
		$data['breadcumb'][] = array('icon'=>'briefcase',
																 'link'=>'',
																 'judul'=>'Rawat Jalan');

		$data['active'] = 'rawat_jalan';
		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}

	public function rawat_inap($tgl_awal=null, $tgl_akhir=null)
	{
		if($tgl_awal=='null'){$tgl_awal=null;}
		if($tgl_akhir=='null'){$tgl_akhir=null;}
		$data['tgl_awal'] = $tgl_awal;
		$data['tgl_akhir'] = $tgl_akhir;
		$data['dari'] = 'rawat_inap';



		$data['judul'] ='Rawat Inap';
		$data['page']  ='ugd/master';
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Pasien Rawat Inap';

		$this->db->where('batal_periksa','0');
		$this->db->where('type_perawatan','2');
		if($tgl_awal != null){
			$this->db->where('tgl_kunjungan >=',$tgl_awal." 00:00:00");
			$this->db->where('tgl_kunjungan <=',$tgl_akhir." 23:59:59");
		}else{
			$this->db->like('tgl_kunjungan',date('Y-m-d'));
		}	
		
		$this->db->order_by('tgl_kunjungan');
		$data['query'] = $this->Content_m->get_kunjungan_pasien();
		$data['breadcumb'][] = array('icon'=>'briefcase',
																 'link'=>'',
																 'judul'=>'Rawat Inap');

		$data['active'] = 'rawat_inap';
		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}

	
	public function laboratorium($tgl_awal=null, $tgl_akhir=null, $tipe_pasien=null)
	{
		if($tgl_awal=='null'){$tgl_awal=null;}
		if($tgl_akhir=='null'){$tgl_akhir=null;}
		$data['tgl_awal'] = $tgl_awal;
		$data['tgl_akhir'] = $tgl_akhir;
		
		$data['judul'] ='Laboratorium';
		$data['page']  ='ugd/master';
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Pasien Perawatan Khusus Laboratorium';
		$data['dari'] = 'laboratorium';


		//echo $this->session->userdata('id_jabatan');
		//$where = "(batal_periksa = 0 or status_perawatan = 4)";
		$where = "(`status_perawatan` = '4' OR `pemeriksaan_khusus` LIKE '%cek_laboratorium%')";
		$this->db->where($where);
		$this->db->where('batal_periksa','0');
		if($tgl_awal != null){
			$this->db->where('tgl_kunjungan >=',$tgl_awal." 00:00:00");
			$this->db->where('tgl_kunjungan <=',$tgl_akhir." 23:59:59");
		}else{
			$this->db->like('tgl_kunjungan',date('Y-m-d'));
		}	

		
		if($tipe_pasien != null){
			$this->db->where('id_type_pasien',$tipe_pasien);
		}
		$this->db->order_by('tgl_kunjungan');
		$data['query'] = $this->Content_m->get_kunjungan_pasien();
		//echo $this->db->last_query()."<br>";
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium');
		
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'pemeriksaan_lab';
		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}


	/*
	public function laboratorium($tgl=null, $tipe_pasien=null)
	{
		$data['judul'] ='Laboratorium';
		$data['page']  ='ugd/master';
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Pasien Perawatan Khusus Laboratorium';

		//$where = "(batal_periksa = 0 or status_perawatan = 4)";
		$where = "(`status_perawatan` = '4' OR `pemeriksaan_khusus` LIKE '%cek_laboratorium%')";
		$this->db->where($where);
		$this->db->where('batal_periksa','0');
		if($tgl==null){
			$this->db->like('tgl_kunjungan',date('Y-m-d'));
		}else{
			$this->db->like('tgl_kunjungan',$tgl);
		}	
		
		if($tipe_pasien != null){
			$this->db->where('id_type_pasien',$tipe_pasien);
		}
		$this->db->order_by('tgl_kunjungan');
		$data['query'] = $this->Content_m->get_kunjungan_pasien();
		//echo $this->db->last_query()."<br>";
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium');
		
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'pemeriksaan_lab';
		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}
	*/

	public function done($id_kunjungan=null)
	{
		$this->db->trans_start();

		$data['done_bhp_lab'] = '1';
		$this->db->where('id_re_kunjungan',$id_kunjungan);
		$this->db->update('bbmc_tr_kunjungan',$data);

		if($this->db->trans_complete()){ 
			$this->M_general->msg_box('success','<B>Update Entry Success</B>'); 
		}else{
			$this->M_general->msg_box('error','<B>Update Entry Failed, Please Contact IT Support</B>'); 
		}

		redirect($_SERVER['HTTP_REFERER'],'refresh');	

	}

	public function undone($id_kunjungan=null)
	{
		$this->db->trans_start();

		$data['done_bhp_lab'] = '0';
		$this->db->where('id_re_kunjungan',$id_kunjungan);
		$this->db->update('bbmc_tr_kunjungan',$data);

		if($this->db->trans_complete()){ 
			$this->M_general->msg_box('success','<B>Update Entry Success</B>'); 
		}else{
			$this->M_general->msg_box('error','<B>Update Entry Failed, Please Contact IT Support</B>'); 
		}

		redirect($_SERVER['HTTP_REFERER'],'refresh');	

	}

	public function laboratorium_penerimaan($tgl=null, $tipe_pasien=null)
	{
		$data['judul'] ='Laboratorium';
		$data['page']  ='laboratorium/lab_laporan_penerimaan';
		$data['desc_judul'] ='Menampilkan Penerimaan Laboratorium';

		
		
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium Penerimaan');
		
		$data['tgl'] = $tgl;
		$data['tipe_pasien'] = $tipe_pasien;
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'pemeriksaan_lab';
		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}

	public function laboratorium_pengeluaran($tgl=null, $tipe_pasien=null)
	{
		$data['judul'] ='Laboratorium';
		$data['page']  ='laboratorium/lab_laporan_pengeluaran';
		$data['desc_judul'] ='Menampilkan Pengeluaran Laboratorium';

		
		
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium Pengeluaran');
		
		$data['tgl'] = $tgl;
		$data['tipe_pasien'] = $tipe_pasien;
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'pemeriksaan_lab';
		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}

	public function laboratorium_stok()
	{
		$data['judul'] ='Laboratorium';
		$data['page']  ='laboratorium/lab_laporan_stok';
		$data['desc_judul'] ='Menampilkan Stok BHP';

		
		
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium Stok');
		

		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'stok_lab';
		$this->load->view('template',$data);
	}

	public function laboratorium_penyesuaian_stok()
	{
		$data['judul'] ='Laboratorium';
		$data['page']  ='laboratorium/lab_laporan_penyesuaian_stok';
		$data['desc_judul'] ='Menampilkan Penyesuaian Stok BHP';

		
		
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium Penyesuaian STOK');
		

		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'stok_lab';
		$this->load->view('template',$data);
	}

	public function laboratorium_penyesuaian_stok_update($id)
	{
		$data['judul'] ='Laboratorium';
		$data['page']  ='laboratorium/lab_laporan_penyesuaian_stok_update';
		$data['desc_judul'] ='Menampilkan Penyesuaian BHP';

		
		
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium Penyesuaian BHP');
		$get = $this->M_general->get_row_custom('bbmc_tr_laboratorium_penyesuaian_stok','id_laboratorium_penyesuaian_stok',$id);

		$data['id'] = $id;
		$data['tgl'] = @$get->tgl;
		$data['id_bhp'] = @$get->id_bhp;
		$data['qty'] = @$get->qty;
		$data['keterangan'] = @$get->keterangan;
		
		
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'stok_lab';
		$this->load->view('template',$data);
	}

	public function del_penyesuaian($id,$id_bhp)
	{
		$this->db->trans_start();

		$data['deleted'] = '1';
		$this->db->where('id_laboratorium_penyesuaian_stok',$id);
		$this->db->update('bbmc_tr_laboratorium_penyesuaian_stok',$data);

		if($this->db->trans_complete()){ 
			$this->M_general->msg_box('success','<B>Delete Entry Success</B>'); 
		}else{
			$this->M_general->msg_box('error','<B>Delete Entry Failed, Please Contact IT Support</B>'); 
		}

		redirect('front_office/ugd_dir/ugd/laboratorium_stok_detail/'.$id_bhp);
		//redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}


	public function laboratorium_stok_detail($id_bhp)
	{
		$data['judul'] ='Laboratorium';
		$data['page']  ='laboratorium/lab_laporan_stok_detail';
		$data['desc_judul'] ='Menampilkan Stok BHP';

		
		
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium Stok');
		
		$data['id_bhp'] = $id_bhp;
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'stok_lab';
		$this->load->view('template',$data);
	}

	public function laboratorium_penggunaan()
	{
		$data['judul'] ='Laboratorium';
		$data['page']  ='laboratorium/lab_laporan_penggunaan';
		$data['desc_judul'] ='Menampilkan Penggunaan BHP';

		
		
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium Penggunaan BHP');
		

		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'penggunaan_lab';
		$this->load->view('template',$data);
	}

	public function del_penggunaan($id)
	{
		$this->db->trans_start();

		$data['deleted'] = '1';
		$this->db->where('id_laboratorium_pengeluaran_stok',$id);
		$this->db->update('bbmc_tr_laboratorium_pengeluaran_stok',$data);

		if($this->db->trans_complete()){ 
			$this->M_general->msg_box('success','<B>Delete Entry Success</B>'); 
		}else{
			$this->M_general->msg_box('error','<B>Delete Entry Failed, Please Contact IT Support</B>'); 
		}


		redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}

	public function laboratorium_penggunaan_tambah($id_kunjungan=null)
	{
		$data['judul'] ='Laboratorium';
		$data['page']  ='laboratorium/lab_laporan_penggunaan_tambah';
		$data['desc_judul'] ='Menampilkan Penggunaan BHP';

		
		
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium Penggunaan BHP');
		

		$data['id_kunjungan'] = $id_kunjungan;
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'penggunaan_lab';
		$this->load->view('template',$data);
	}

	public function update_penggunaan($id)
	{
		$data['judul'] ='Laboratorium';
		$data['page']  ='laboratorium/lab_laporan_penggunaan_update';
		$data['desc_judul'] ='Menampilkan Penggunaan BHP';

		
		
		$data['breadcumb'][] = array('icon'=>'flask',
																 'link'=>'',
																 'judul'=>'Laboratorium Penggunaan BHP');
		$get = $this->M_general->get_row_custom('bbmc_tr_laboratorium_pengeluaran_stok','id_laboratorium_pengeluaran_stok',$id);

		$data['id'] = $id;
		$data['tgl'] = @$get->tgl;
		$data['id_bhp'] = @$get->id_bhp;
		$data['id_re_kunjungan'] = @$get->id_re_kunjungan;
		$data['qty'] = @$get->qty;
		$data['keterangan'] = @$get->keterangan;
		
		
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'penggunaan_lab';
		$this->load->view('template',$data);
	}


	public function update_penyesuaian_tambah()
	{
		extract($_POST);

		$this->db->trans_start();

		$data = array(
			'tgl'=>$tgl,
			'id_bhp'=>$id_bhp,
			'qty'=>$qty,
			'keterangan'=>$keterangan
		);
		$this->db->where('id_laboratorium_penyesuaian_stok',$id);
		$this->db->update('bbmc_tr_laboratorium_penyesuaian_stok',$data);



		if($this->db->trans_complete()){ 
			$this->M_general->msg_box('success','<B>Submit Entry Success</B>'); 
		}else{
			$this->M_general->msg_box('error','<B>Submit Entry Failed, Please Contact IT Support</B>'); 
		}


		//redirect('front_office/ugd_dir/ugd/laboratorium_penggunaan');	
		redirect('front_office/ugd_dir/ugd/laboratorium_stok_detail/'.$id_bhp);
	}

	public function save_penyesuaian_tambah()
	{
		extract($_POST);

		$this->db->trans_start();

		$data = array(
			'tgl'=>$tgl,
			'id_bhp'=>$id_bhp,
			'qty'=>$qty,
			'keterangan'=>$keterangan
		);
		$this->db->insert('bbmc_tr_laboratorium_penyesuaian_stok',$data);



		if($this->db->trans_complete()){ 
			$this->M_general->msg_box('success','<B>Submit Entry Success</B>'); 
		}else{
			$this->M_general->msg_box('error','<B>Submit Entry Failed, Please Contact IT Support</B>'); 
		}


		//redirect('front_office/ugd_dir/ugd/laboratorium_penggunaan');	
		redirect('front_office/ugd_dir/ugd/laboratorium_stok_detail/'.$id_bhp);
		
	}

	public function save_penggunaan_tambah()
	{	
		/*
		extract($_POST);

		$this->db->trans_start();

		$data = array(
			'tgl'=>date('Y-m-d'),
			'id_bhp'=>$id_bhp,
			'id_re_kunjungan'=>$id_re_kunjungan,
			'qty'=>$qty,
			'keterangan'=>$keterangan
		);
		$this->db->insert('bbmc_tr_laboratorium_pengeluaran_stok',$data);



		if($this->db->trans_complete()){ 
			$this->M_general->msg_box('success','<B>Submit Entry Success</B>'); 
		}else{
			$this->M_general->msg_box('error','<B>Submit Entry Failed, Please Contact IT Support</B>'); 
		}


		redirect('front_office/ugd_dir/ugd/laboratorium_penggunaan');	
		*/

		extract($_POST);
		$this->db->trans_start();

		if(isset($id_re_kunjungan)){

			$this->db->where('id_re_kunjungan',$id_re_kunjungan);
			$this->db->delete('bbmc_tr_laboratorium_pengeluaran_stok');

			foreach ($id_bhp as $key => $value) {
				if($value != ''){
					$data = array(
						'tgl'=>$tgl,
						'id_bhp'=>$value,
						'id_re_kunjungan'=>$id_re_kunjungan,
						'qty'=>$qty[$key],
						'keterangan'=>$keterangan
					);
					$this->db->insert('bbmc_tr_laboratorium_pengeluaran_stok',$data);
				}
			}


			$data1['done_bhp_lab'] = '1';
			$this->db->where('id_re_kunjungan',$id_re_kunjungan);
			$this->db->update('bbmc_tr_kunjungan',$data1);


			if($this->db->trans_complete()){ 
				$this->M_general->msg_box('success','<B>Submit Entry Success</B>'); 
			}else{
				$this->M_general->msg_box('error','<B>Submit Entry Failed, Please Contact IT Support</B>'); 
			}
		}
		



		//echo "<pre>";
		//var_dump($_POST);
		//echo "</pre>";


		redirect('front_office/ugd_dir/ugd/laboratorium_penggunaan');	
		//redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}

	public function update_penggunaan_tambah()
	{
		extract($_POST);

		$this->db->trans_start();

		$data = array(
			'tgl'=>$tgl,
			'id_bhp'=>$id_bhp,
			'id_re_kunjungan'=>$id_re_kunjungan,
			'qty'=>$qty,
			'keterangan'=>$keterangan
		);
		$this->db->where('id_laboratorium_pengeluaran_stok',$id_laboratorium_pengeluaran_stok);
		$this->db->update('bbmc_tr_laboratorium_pengeluaran_stok',$data);



		if($this->db->trans_complete()){ 
			$this->M_general->msg_box('success','<B>Update Entry Success</B>'); 
		}else{
			$this->M_general->msg_box('error','<B>Update Entry Failed, Please Contact IT Support</B>'); 
		}


		redirect('front_office/ugd_dir/ugd/laboratorium_penggunaan');	
	}

	public function laboratorium_setting()
  	{
  		$data['judul']='Laboratorium Setting';
		$data['desc_judul']='';
		$data['page'] = 'setting/laboratorium_setting';

		$data['breadcumb'][]=array('icon' =>'area-chart',
															 'link' =>'',
															 'judul'=>'Setting');
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'setting_lab';
		$this->load->view('template',$data);
  	}

  	public function laboratorium_laporan()
  	{
  		$data['judul']='Laboratorium Laporan';
		$data['desc_judul']='';
		$data['page'] = 'laboratorium/lab_laporan';

		$data['breadcumb'][]=array('icon' =>'area-chart',
															 'link' =>'',
															 'judul'=>'Laporan');
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'laporan_lab';
		$this->load->view('template',$data);
  	}

  	public function laboratorium_laporan_detail($tipe_pasien, $tgl_awal=null, $tgl_akhir=null)
  	{
  		$data['judul']='Laboratorium Laporan';
		$data['desc_judul']='';
		$data['page'] = 'laboratorium/lab_laporan_detail';

		$data['breadcumb'][]=array('icon' =>'area-chart',
															 'link' =>'',
															 'judul'=>'Laporan Detail');
		
		if($tgl_awal==null){$tgl_awal = date('m/01/Y');}
		if($tgl_akhir==null){$tgl_akhir = date('m/d/Y');}

		$data['tgl_awal'] = $tgl_awal;
		$data['tgl_akhir'] = $tgl_akhir;
		$data['tipe_pasien'] = $tipe_pasien;
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'laporan_lab';
		$this->load->view('template',$data);
  	}

  	public function fillter_date_lab($tipe_pasien)
  	{
  		extract($_POST);

  		$tgl_awal = date('Y-m-d',strtotime($tgl_awal));
  		$tgl_akhir = date('Y-m-d',strtotime($tgl_akhir));

  		//echo $tgl_akhirs;
  		redirect('front_office/ugd_dir/ugd/laboratorium_laporan_detail/'.$tipe_pasien.'/'.$tgl_awal.'/'.$tgl_akhir);

  	}
  	
  	public function laboratorium_setting_paket()
  	{
  		$data['judul']='Laboratorium Setting Paket';
		$data['desc_judul']='';
		$data['page'] = 'setting/laboratorium_setting_paket';

		$data['breadcumb'][]=array('icon' =>'area-chart',
															 'link' =>'',
															 'judul'=>'Setting');
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'setting_lab';
		$this->load->view('template',$data);
  	}

  	public function del_laboratorium_paket($tindakan_lab)
  	{
  		$data['deleted'] = '1';
		$this->db->where('tindakan_lab',$tindakan_lab);
		$this->db->update('bbmc_re_laboratorium_paket',$data);
		//echo $this->db;
		redirect($_SERVER['HTTP_REFERER'],'refresh');	
  	}

  	public function save_laboratorium_paket()
  	{
  		extract($_POST);


		$this->db->trans_start();
		$arr = array();

		foreach ($item_paket as $key =>$value) {
			if($value != ''){
				$data = array(
					'tindakan_lab'=>$tindakan_lab,
					'item_paket'=>$value
				);
				array_push($arr, $data);
				echo $value;
			}
		}

		if(@$arr){
			$this->db->insert_batch('bbmc_re_laboratorium_paket',$arr);
		}

		
		if($this->db->trans_complete()){ 
			$this->M_general->msg_box('success','<B>Insert Entry Success</B>'); 
		}else{
			$this->M_general->msg_box('error','<B>Insert Entry Failed, Please Contact IT Support</B>'); 
		}

		
	
		redirect('front_office/ugd_dir/ugd/laboratorium_setting_paket');

  	}

  	public function laboratorium_setting_template()
  	{
  		$data['judul']='Laboratorium Setting Paket';
		$data['desc_judul']='';
		$data['page'] = 'setting/laboratorium_setting_template';

		$data['breadcumb'][]=array('icon' =>'area-chart',
															 'link' =>'',
															 'judul'=>'Setting');
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'setting_lab';
		$this->load->view('template',$data);
  	}

  	public function del_laboratorium_template($tindakan_lab)
  	{
  		$data['deleted'] = '1';
		$this->db->where('tindakan_lab',$tindakan_lab);
		$this->db->update('bbmc_re_laboratorium_template',$data);
		//echo $this->db;
		redirect($_SERVER['HTTP_REFERER'],'refresh');	
  	}

  
 	public function add_laboratorium_setting_paket()
 	{
 		$data['judul']='Laboratorium Setting Paket';
		$data['title'] = 'Add Paket';
		$data['desc_judul']='';
		$data['page'] = 'setting/laboratorium_setting_paket_add';
		$data['breadcumb'][]=array('icon'=>'bookmark',
        									'link'=>'',
        									'judul'=>'Amprahan');
		
		$data['sub_menu'] = 'laboratorium';
		$data['active'] = 'setting_lab';
		$data['dyn_form'] = TRUE;
		$this->load->view('template',$data);
 	}

	public function radiologi()
	{
		$data['judul'] ='Radiologi';
		$data['page']  ='ugd/master';
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Pasien Perawatan Khusus Radiologi';

		$this->db->where('batal_periksa','0');
		//$this->db->like('pemeriksaan_khusus','cek_radiologi');
		$this->db->where('status_perawatan','5');
		$this->db->like('tgl_kunjungan',date('Y-m-d'));
		$this->db->order_by('tgl_kunjungan');
		$data['query'] = $this->Content_m->get_kunjungan_pasien();
		$data['breadcumb'][] = array('icon'=>'cab',
																 'link'=>'',
																 'judul'=>'Radiologi');

		$data['active'] = 'radiologi';
		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}

	public function tipe_pasien($id_tipe_pasien, $id_re_pasien=null)
	{
		$data['judul'] ='Asuransi';
		$data['page']  ='ugd/master';
		$tipe_pasien = $this->Content_m->get_value('bbmc_re_tipe_pasien','id_tipe_pasien',$id_tipe_pasien,'tipe_pasien');
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Pasien '.$tipe_pasien;

		$this->db->where('batal_periksa','0');
		$this->db->where('id_type_pasien',$id_tipe_pasien);
		if($id_re_pasien != null){
			$this->db->where('p.id_re_pasien',$id_re_pasien);
		}
		$data['query'] = $this->Content_m->get_kunjungan_pasien();
		//echo $this->db->last_query();
		$data['breadcumb'][] = array('icon'=>'book',
																 'link'=>'',
																 'judul'=>$tipe_pasien);
		$data['tipe_pasien'] = $id_tipe_pasien;
		$data['sub_menu'] = 'asuransi';
		$data['active'] = 'asuransi-'.$id_tipe_pasien;
		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}

	public function tipe_pasien_new($id_tipe_pasien)
	{
		$data['judul'] ='Asuransi';
		$data['page']  ='ugd/master_tipe_pasien';
		$tipe_pasien = $this->Content_m->get_value('bbmc_re_tipe_pasien','id_tipe_pasien',$id_tipe_pasien,'tipe_pasien');
		$data['desc_judul'] ='Menampilkan dan Mengelola Data Pasien '.$tipe_pasien;

		
		$this->db->select('k.tgl_kunjungan, p.nrm, p.nama_pasien, p.id_type_pasien, p.alamat, k.active, k.deleted, p.deleted, p.id_re_pasien, k.id_re_kunjungan, count(p.id_re_pasien) as ttl');
        $this->db->from('bbmc_tr_pasien p');
        $this->db->join('bbmc_tr_kunjungan k','k.id_re_pasien = p.id_re_pasien');
        $this->db->where('k.deleted','0');
        $this->db->where('p.deleted','0');
        $this->db->where('batal_periksa','0');
		$this->db->where('id_type_pasien',$id_tipe_pasien);
		$this->db->group_by('p.id_re_pasien');
        $q = $this->db->get();
		$data['query'] = $q;

		//echo $this->db->last_query();
		$data['breadcumb'][] = array('icon'=>'book',
																 'link'=>'',
																 'judul'=>$tipe_pasien);
		$data['tipe_pasien'] = $id_tipe_pasien;
		$data['sub_menu'] = 'asuransi';
		$data['active'] = 'asuransi-'.$id_tipe_pasien;
		//echo $this->session->userdata('userid');
		$this->load->view('template',$data);
	}

	public function batal_pemeriksaan($id_re_kunjungan)
	{

		$data['batal_periksa'] = '1';
		$this->db->where('id_re_kunjungan',$id_re_kunjungan);
		$this->db->update('bbmc_tr_kunjungan',$data);
		//echo $this->db;
		redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}

	public function info_pasien_diperiksa($id_re_pasien, $id_re_kunjungan, $active)
	{
		$data['re_pasien'] = $this->db->get_where('bbmc_tr_pasien', array('id_re_pasien'=>$id_re_pasien))->row();
		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['re_pasien'] && $data['get_kunjungan'])
		{				

			$sm = explode("-", $active);
			if(count($sm) == '2'){
				$data['sub_menu'] = $sm[0];
			}

			$data['active'] = $active;
			$data['method'] = 'info_pasien_diperiksa';
			$data['judul'] = 'Informasi Pasien';
			$data['desc_judul'] = 'Detail Informasi Pasien yang Diperiksa';
			$data['info_tab'] = 'Informasi Pasien';
			$data['page'] = 'ugd/periksa/template_detail';
			$data['page_tab'] = 'registrasi/edit';
			$data['disabled'] = 'disabled';
			/*
			$data['breadcumb'][] = array('icon'=>'bookmark',
																	 'link'=>site_url('front_office/ugd_dir/ugd/'.$active),
																	 'judul'=>''.ucwords(strtolower(str_replace("_", " ", $active))));
			*/

			$data['breadcumb'][] = array('icon'=>'info-circle',
																	 'link'=>'',
																	 'judul'=>'Informasi Pasien');		
		
			$data['get'] = $this->Content_m->get_row('bbmc_tr_pasien','id_re_pasien',$id_re_pasien);
			$data['id_re_pasien'] = $id_re_pasien;
			$data['id_re_kunjungan'] = $id_re_kunjungan;

			$this->db->select('id_agama as id, nm_agama text');
			$this->db->where('id_agama!=', '98');
			$this->db->where('deleted','0');
			$data['agama']=json_encode($this->db->get('bbmc_re_agama')->result());		

			$this->db->select('id_pekerjaan as id, nm_pekerjaan text');
			$this->db->where('deleted','0');
			$data['pekerjaan']=json_encode($this->db->get('bbmc_re_pekerjaan')->result());

			$this->db->select('id_jenj_didik as id, nm_jenj_didik text');
			$this->db->where('deleted','0');
			$data['pendidikan']=json_encode($this->db->get('bbmc_re_jenjang_pendidikan')->result());		

			$this->db->select('kec.id_wil as id, kec.nm_wil as text');
			$this->db->join('bbmc_re_wilayah kab', 'kec.id_induk_wilayah = kab.id_wil and kab.id_level_wil="2"');
			$this->db->join('bbmc_re_wilayah prov', 'kab.id_induk_wilayah = prov.id_wil and prov.id_level_wil="1"');
			$this->db->where(array('kec.id_level_wil'=>'3','kec.id_wil'=>$data['re_pasien']->id_kecamatan));
			$data['wilayah_kec']=$this->db->get('bbmc_re_wilayah kec')->row();

			$this->db->select('kab.id_wil as id, kab.nm_wil as text');
			$this->db->join('bbmc_re_wilayah kab', 'kec.id_induk_wilayah = kab.id_wil and kab.id_level_wil="2"');
			$this->db->join('bbmc_re_wilayah prov', 'kab.id_induk_wilayah = prov.id_wil and prov.id_level_wil="1"');
			$this->db->where(array('kec.id_level_wil'=>'3','kec.id_wil'=>$data['re_pasien']->id_kecamatan));
			$data['wilayah_kab']=$this->db->get('bbmc_re_wilayah kec')->row();

			$this->db->select('prov.id_wil as id, prov.nm_wil as text');
			$this->db->join('bbmc_re_wilayah kab', 'kec.id_induk_wilayah = kab.id_wil and kab.id_level_wil="2"');
			$this->db->join('bbmc_re_wilayah prov', 'kab.id_induk_wilayah = prov.id_wil and prov.id_level_wil="1"');
			$this->db->where(array('kec.id_level_wil'=>'3','kec.id_wil'=>$data['re_pasien']->id_kecamatan));
			$data['wilayah_prov']=$this->db->get('bbmc_re_wilayah kec')->row();	

			$this->load->view('template',$data);
		} else
				show_404();		
	}
	
	public function perawat_dokter_pemeriksa($id_re_pasien, $id_re_kunjungan, $active)
	{
		$data['re_pasien'] = $this->db->get_where('bbmc_tr_pasien', array('id_re_pasien'=>$id_re_pasien))->row();
		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['re_pasien'] && $data['get_kunjungan'])
		{		

			$sm = explode("-", $active);
			if(count($sm) == '2'){
				$data['sub_menu'] = $sm[0];
			}

			$datas['bell'] = '0';
			$this->db->where('id_re_kunjungan',$id_re_kunjungan);
			$this->db->update('bbmc_tr_kunjungan',$datas);


			$data['parent_controller'] = 'ugd_pemeriksa';
			$data['active'] = $active;
			$data['id_re_pasien'] = $id_re_pasien;
			$data['id_re_kunjungan'] = $id_re_kunjungan;
			$data['method'] = 'perawat_dokter_pemeriksa';
			$data['judul'] = 'Periksa Pasien';
			$data['desc_judul'] = 'Detail Informasi Perawat & Dokter Pemeriksa Pasien';
			$data['info_tab'] = 'Perawat & Dokter Pemeriksa';
			$data['page'] = 'ugd/periksa/template_detail';
			
			
			if($active =='gigi'){
				$data['page_tab'] = 'ugd/periksa/tab_dokterperawat_pemeriksa_gigi';
			}else{
				$data['page_tab'] = 'ugd/periksa/tab_dokterperawat_pemeriksa';
			}
			
			/*
			$data['breadcumb'][] = array('icon'=>'ambulance',
																	 'link'=>site_url('front_office/ugd_dir/ugd'),
																	 'judul'=>'Poli Umum');
			*/												 
			$data['breadcumb'][] = array('icon'=>'user-md',
																	 'link'=>'',
																	 'judul'=>'Perawat & Dokter Pemeriksa');		

			$this->load->view('template',$data);
		} else
				show_404();		
	}



	public function diagnosa($id_re_pasien, $id_re_kunjungan, $active)
	{
		$data['re_pasien'] = $this->db->get_where('bbmc_tr_pasien', array('id_re_pasien'=>$id_re_pasien))->row();
		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['re_pasien'] && $data['get_kunjungan'])
		{		

			$sm = explode("-", $active);
			if(count($sm) == '2'){
				$data['sub_menu'] = $sm[0];
			}
			
			if($active == 'gigi'){
				$odontogram = $this->db->get_where('bbmc_tr_odontogram', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
				$data['get_o'] = $odontogram;
			}
			$data['parent_controller'] = 'ugd_diagnosa';
			$data['active'] = $active;
			$data['id_re_pasien'] = $id_re_pasien;
			$data['id_re_kunjungan'] = $id_re_kunjungan;
			$data['method'] = 'diagnosa';
			$data['judul'] = 'Periksa Pasien';
			$data['desc_judul'] = 'Detail Informasi Diagnosa Pasien';
			$data['info_tab'] = 'Diagnosaa';
			$data['page'] = 'ugd/periksa/template_detail';
			$data['page_tab'] = 'ugd/periksa/tab_diagnosa_pasien';
			
			/*
			$data['breadcumb'][] = array('icon'=>'ambulance',
																	 'link'=>site_url('front_office/ugd_dir/ugd'),
																	 'judul'=>'Poli Umum');
			*/						
																	 
									 
			$data['breadcumb'][] = array('icon'=>'user-md',
																	 'link'=>'',
																	 'judul'=>'Perawat & Dokter Pemeriksa');		

			$this->load->view('template',$data);
		} else
				show_404();		
	}

	public function tmbh_pemeriksaan($id_re_pasien, $id_re_kunjungan, $active)
	{
		$data['re_pasien'] = $this->db->get_where('bbmc_tr_pasien', array('id_re_pasien'=>$id_re_pasien))->row();
		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['re_pasien'] && $data['get_kunjungan'])
		{		

			if($this->session->userdata('id_jabatan') == '8'){
				$datas['bell'] = '0';
				$where = "(`status_perawatan` = '4' OR `pemeriksaan_khusus` LIKE '%cek_laboratorium%')";
				$this->db->where($where);
				$this->db->where('id_re_kunjungan',$id_re_kunjungan);
				$this->db->update('bbmc_tr_kunjungan',$datas);
			}else if($this->session->userdata('id_jabatan') == '10'){
				$datas['bell'] = '0';
				$this->db->where('status_perawatan','2');
				$this->db->where('id_re_kunjungan',$id_re_kunjungan);
				$this->db->update('bbmc_tr_kunjungan',$datas);
			}

			$sm = explode("-", $active);
			if(count($sm) == '2'){
				$data['sub_menu'] = $sm[0];
			}
			
			$data['parent_controller'] = 'ugd_tmbh_pemeriksaan';
			$data['active'] = $active;
			$data['id_re_pasien'] = $id_re_pasien;
			$data['id_re_kunjungan'] = $id_re_kunjungan;
			$data['method'] = 'tmbh_pemeriksaan';
			$data['judul'] = 'Periksa Pasien';
			$data['desc_judul'] = 'Detail Pemeriksaan Penunjang untuk Pasien';
			$data['info_tab'] = 'Pemeriksaan Penunjang';
			$data['page'] = 'ugd/periksa/template_detail';
			$data['page_tab'] = 'ugd/periksa/tab_pemeriksaan_penunjang';

			/*
			$data['breadcumb'][] = array('icon'=>'ambulance',
																	 'link'=>site_url('front_office/ugd_dir/ugd'),
																	 'judul'=>'Poli Umum');
			*/		

			$data['breadcumb'][] = array('icon'=>'stethoscope',
																	 'link'=>'',
																	 'judul'=>'Pemeriksaan Penunjang');																				 

			$this->load->view('template',$data);
		} else
				show_404();		
	}	

	public function delete_file($file)
	{
		$this->db->trans_start();


		$data['deleted'] = '1';
		$this->db->where('file',$file);
		$this->db->update('bbmc_tr_laboratorium_dokumen',$data);
		if($this->db->trans_complete()){
			redirect($_SERVER['HTTP_REFERER'],'refresh');	
		}
	}


	public function biaya_pemeriksaan($id_re_pasien, $id_re_kunjungan, $active)
	{
		$data['re_pasien'] = $this->db->get_where('bbmc_tr_pasien', array('id_re_pasien'=>$id_re_pasien))->row();
		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['re_pasien'] && $data['get_kunjungan'])
		{		

			$sm = explode("-", $active);
			if(count($sm) == '2'){
				$data['sub_menu'] = $sm[0];
			}
			

			$data['active'] = $active;
			$data['id_re_pasien'] = $id_re_pasien;
			$data['id_re_kunjungan'] = $id_re_kunjungan;
			$data['method'] = 'biaya_pemeriksaan';
			$data['judul'] = 'Periksa Pasien';
			$data['desc_judul'] = 'Detail Biaya Pemeriksaan Pasien';
			$data['info_tab'] = 'Biaya Pemeriksaan';
			$data['page'] = 'ugd/periksa/template_detail';
			$data['page_tab'] = 'ugd/periksa/tab_biaya_pemeriksaan';

			/*
			$data['breadcumb'][] = array('icon'=>'ambulance',
																	 'link'=>site_url('front_office/ugd_dir/ugd'),
																	 'judul'=>'Poli Umum');
			*/												 
			$data['breadcumb'][] = array('icon'=>'money',
																	 'link'=>'',
																	 'judul'=>'Biaya Pemeriksaan');																			 

			$this->load->view('template',$data);
		} else
				show_404();		
	}

	public function obat($id_re_pasien, $id_re_kunjungan, $active)
	{
		$data['re_pasien'] = $this->db->get_where('bbmc_tr_pasien', array('id_re_pasien'=>$id_re_pasien))->row();
		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['re_pasien'] && $data['get_kunjungan'])
		{	

			$sm = explode("-", $active);
			if(count($sm) == '2'){
				$data['sub_menu'] = $sm[0];
			}
			
			$data['parent_controller'] = 'ugd_obat';
			$data['active'] = $active;	
			$data['id_re_pasien'] = $id_re_pasien;
			$data['id_re_kunjungan'] = $id_re_kunjungan;
			$data['method'] = 'obat';
			$data['judul'] = 'Periksa Pasien';
			$data['desc_judul'] = 'Detail Medikasi / Obat Pasien';
			$data['info_tab'] = 'Medikasi / Obat';
			$data['page'] = 'ugd/periksa/template_detail';
			$data['page_tab'] = 'ugd/periksa/tab_obat';

			/*
			$data['breadcumb'][] = array('icon'=>'ambulance',
																	 'link'=>site_url('front_office/ugd_dir/ugd'),
																	 'judul'=>'Poli Umum');
			*/											 
			$data['breadcumb'][] = array('icon'=>'medkit',
																	 'link'=>'',
																	 'judul'=>'Biaya Pemeriksaan');																		 

			$this->load->view('template',$data);
		} else
				show_404();		

	}

	public function foto($id_re_pasien, $id_re_kunjungan, $active)
	{
		$data['re_pasien'] = $this->db->get_where('bbmc_tr_pasien', array('id_re_pasien'=>$id_re_pasien))->row();
		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['re_pasien'] && $data['get_kunjungan'])
		{	

			$sm = explode("-", $active);
			if(count($sm) == '2'){
				$data['sub_menu'] = $sm[0];
			}
			
			$data['parent_controller'] = 'ugd_obat';
			$data['active'] = $active;	
			$data['id_re_pasien'] = $id_re_pasien;
			$data['id_re_kunjungan'] = $id_re_kunjungan;
			$data['method'] = 'foto';
			$data['judul'] = 'Periksa Pasien';
			$data['desc_judul'] = 'Detail Medikasi / Obat Pasien';
			$data['info_tab'] = 'Medikasi / Obat';
			$data['page'] = 'ugd/periksa/template_detail';
			$data['page_tab'] = 'ugd/periksa/tab_foto';

			/*
			$data['breadcumb'][] = array('icon'=>'ambulance',
																	 'link'=>site_url('front_office/ugd_dir/ugd'),
																	 'judul'=>'Poli Umum');
			*/											 
			$data['breadcumb'][] = array('icon'=>'medkit',
																	 'link'=>'',
																	 'judul'=>'Biaya Pemeriksaan');																		 

			$this->load->view('template',$data);
		} else
				show_404();		
	}


	public function summary_progress($id_re_pasien, $id_re_kunjungan, $active)
	{
		$data['re_pasien'] = $this->db->get_where('bbmc_tr_pasien', array('id_re_pasien'=>$id_re_pasien))->row();
		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['re_pasien'] && $data['get_kunjungan'])
		{	
			
			$sm = explode("-", $active);
			if(count($sm) == '2'){
				$data['sub_menu'] = $sm[0];
			}
			
			$data['active'] = $active;	
			$data['id_re_pasien'] = $id_re_pasien;
			$data['id_re_kunjungan'] = $id_re_kunjungan;
			$data['method'] = 'summary_progress';
			$data['judul'] = 'Ringkasan Tindakan';
			$data['desc_judul'] = 'Menambahkan Ringkasan Tindakan Pasien';
			$data['info_tab'] = 'Ringkasan Tindakan';
			$data['page'] = 'ugd/periksa/template_detail';
			$data['page_tab'] = 'ugd/periksa/tab_summary_progress';

 										 
			$data['breadcumb'][] = array('icon'=>'area-chart',
																	 'link'=>'',
																	 'judul'=>'Ringkasan Tindakan');															 

			$this->load->view('template',$data);
		} else
				show_404();	
	}

	public function tmbh_biaya($id_re_pasien, $id_re_kunjungan, $active)
	{
		$data['re_pasien'] = $this->db->get_where('bbmc_tr_pasien', array('id_re_pasien'=>$id_re_pasien))->row();
		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['re_pasien'] && $data['get_kunjungan'])
		{	
			
			$sm = explode("-", $active);
			if(count($sm) == '2'){
				$data['sub_menu'] = $sm[0];
			}
			
			$data['active'] = $active;	
			$data['id_re_pasien'] = $id_re_pasien;
			$data['id_re_kunjungan'] = $id_re_kunjungan;

			$data['method'] = 'biaya_pemeriksaan';
			$data['judul'] = 'Periksa Pasien';
			$data['desc_judul'] = 'Menambahkan Biaya Pemeriksaan Pasien';
			$data['info_tab'] = 'Tambah Biaya Pasien';
			$data['page'] = 'ugd/periksa/template_detail';
			$data['page_tab'] = 'ugd/periksa/tab_tmbh_biaya_pemeriksaan';

			$data['breadcumb'][] = array('icon'=>'ambulance',
																	 'link'=>site_url('front_office/ugd_dir/ugd'),
																	 'judul'=>'Poli Umum');

			$data['breadcumb'][] = array('icon'=>'money',
																	 'link'=>site_url('front_office/ugd_dir/ugd/biaya_pemeriksaan'),
																	 'judul'=>'Biaya Pemeriksaan');																		 
																	 
			$data['breadcumb'][] = array('icon'=>'plus',
																	 'link'=>'',
																	 'judul'=>'Menambahkan Biaya Pemeriksaan');															 

			$this->load->view('template',$data);
		} else
				show_404();		
	}

	// public function tambah_data() 
	// {
	// 	$data['judul'] = 'Registrasi Pasien Baru';
	// 	$data['desc_judul'] = 'Menambahkan Data Pasien Baru';
	// 	$data['page'] = 'registrasi/add';

	// 	$data['breadcumb'][]=array('icon'=>'ambulance',
	// 											 			 'link'=>site_url('front_office/reg_dir/registrasi'),
	// 														 'judul'=>'Registrasi');

	// 	$data['breadcumb'][]=array('icon'=>'plus',
	// 														 'link'=>'',
	// 														 'judul'=>$data['judul']);

	// 	$this->db->select('id_agama as id, nm_agama text');
	// 	$this->db->where('id_agama!=', '98');
	// 	$this->db->where('deleted','0');
	// 	$data['agama']=json_encode($this->db->get('pddikti_re_agama')->result());		

	// 	$this->db->select('id_pekerjaan as id, nm_pekerjaan text');
	// 	$this->db->where('deleted','0');
	// 	$data['pekerjaan']=json_encode($this->db->get('pddikti_re_pekerjaan')->result());

	// 	$this->db->select('id_jenj_didik as id, nm_jenj_didik text');
	// 	$this->db->where('deleted','0');
	// 	$data['pendidikan']=json_encode($this->db->get('pddikti_re_jenjang_pendidikan')->result());		

	// 	$this->load->view('template',$data);
	// }

	// public function edit_data()
	// {
	// 	$data['judul'] = 'Edit Data Pasien';
	// 	$data['desc_judul'] = 'Mengubah Data Pasien';
	// 	$data['page'] = 'registrasi/edit';

	// 	$data['breadcumb'][]=array('icon'=>'ambulance',
	// 											 			 'link'=>site_url('front_office/reg_dir/registrasi'),
	// 														 'judul'=>'Registrasi');

	// 	$data['breadcumb'][]=array('icon'=>'edit',
	// 														 'link'=>'',
	// 														 'judul'=>$data['judul']);													 

	// 	$this->db->select('id_agama as id, nm_agama text');
	// 	$this->db->where('id_agama!=', '98');
	// 	$this->db->where('deleted','0');
	// 	$data['agama']=json_encode($this->db->get('pddikti_re_agama')->result());		

	// 	$this->db->select('id_pekerjaan as id, nm_pekerjaan text');
	// 	$this->db->where('deleted','0');
	// 	$data['pekerjaan']=json_encode($this->db->get('pddikti_re_pekerjaan')->result());

	// 	$this->db->select('id_jenj_didik as id, nm_jenj_didik text');
	// 	$this->db->where('deleted','0');
	// 	$data['pendidikan']=json_encode($this->db->get('pddikti_re_jenjang_pendidikan')->result());		

	// 	$this->load->view('template',$data);		
	// }

	// public function tambah_kunjungan() 
	// {
	// 	$data['judul'] = 'Tambah Kunjungan Pasien';
	// 	$data['desc_judul'] = 'Menambahkan Data Kunjungan Pasien';
	// 	$data['page'] = 'registrasi/tambah_kunjungan';

	// 	$data['breadcumb'][]=array('icon'=>'ambulance',
	// 											 			 'link'=>site_url('front_office/reg_dir/registrasi'),
	// 														 'judul'=>'Registrasi');

	// 	$data['breadcumb'][]=array('icon'=>'plus',
	// 														 'link'=>'',
	// 														 'judul'=>$data['judul']);

	// 	$this->db->select('id_agama as id, nm_agama text');
	// 	$this->db->where('id_agama!=', '98');
	// 	$this->db->where('deleted','0');
	// 	$data['agama']=json_encode($this->db->get('pddikti_re_agama')->result());		

	// 	$this->db->select('id_pekerjaan as id, nm_pekerjaan text');
	// 	$this->db->where('deleted','0');
	// 	$data['pekerjaan']=json_encode($this->db->get('pddikti_re_pekerjaan')->result());

	// 	$this->db->select('id_jenj_didik as id, nm_jenj_didik text');
	// 	$this->db->where('deleted','0');
	// 	$data['pendidikan']=json_encode($this->db->get('pddikti_re_jenjang_pendidikan')->result());		

	// 	$this->load->view('template',$data);
	// }	


	public function update_data_kunjungan()
	{
		extract($_POST);

		
		if($this->validasi())
		{
			$p='';
			if(isset($pemeriksaan_khusus)){
				if(count($pemeriksaan_khusus) == '2'){
					$p = $pemeriksaan_khusus[0].",".$pemeriksaan_khusus[1];
				}else{
					$p = $pemeriksaan_khusus[0];
				}
			}

			date_default_timezone_set('Asia/Makassar');
			

			foreach ($_POST as $key => $value) {
				$data[$key]=$value!=''?$value:null;
			}
			unset($data['pemeriksaan_khusus']);
			$data['pemeriksaan_khusus'] = $p;
			
			
			$data['date_modified'] = date('Y-m-d h:i:s');
			$data['modified_by'] = $this->session->userdata('userid');
			$this->db->update('bbmc_tr_kunjungan',$data,array("id_re_kunjungan"=>$data['id_re_kunjungan']));

			echo json_encode(array("status"=>"1", "title"=>"Sukses !", "message"=>"Data Berhasil Diperbarui"));
		} 
		

		/*
		$p='';
		if(isset($pemeriksaan_khusus)){
			if(count($pemeriksaan_khusus) == '2'){
				$p = $pemeriksaan_khusus[0].",".$pemeriksaan_khusus[1];
			}else{
				$p = $pemeriksaan_khusus[0];
			}
		}

		date_default_timezone_set('Asia/Makassar');
		

		foreach ($_POST as $key => $value) {
			$data[$key]=$value!=''?$value:null;
		}
		unset($data['pemeriksaan_khusus']);
		$data['pemeriksaan_khusus'] = $p;
		
		
		$data['date_modified'] = date('Y-m-d h:i:s');
		$data['modified_by'] = $this->session->userdata('userid');
		$this->db->update('bbmc_tr_kunjungan',$data,array("id_re_kunjungan"=>$data['id_re_kunjungan']));
		*/
	}

	public function update_hasil_pemeriksaan()
	{
		extract($_POST);

		//echo "<pre>";
		//var_dump($_POST);
		//echo "</pre>";

		//echo $id_re_laboratorium."<br>";
		//echo $tindakan_lab."<br>";
		$da['admin_lab'] = $this->session->userdata('userid');
		$this->db->where('id_re_kunjungan',$id_re_kunjungan);
		$this->db->update('bbmc_tr_kunjungan',$da);

		$this->db->where('id_re_laboratorium',$id_re_laboratorium);
		$this->db->where('tindakan_lab',$tindakan_lab);
		$this->db->delete('bbmc_tr_laboratorium_hasil');
		$i=0;
		foreach ($text1 as $key ) {
			//echo @$key." ".@$text2[$i]." ".@$text3[$i]." ".@$text4[$i]." ".@$text5[$i]."<br>";

			$data_insert = array(
				'id_re_laboratorium'=>$id_re_laboratorium,
				'tindakan_lab'=>$tindakan_lab,
				'text1'=>$key,
				'text2'=>@$text2[$i],
				'text3'=>@$text3[$i],
				'text4'=>@$text4[$i],
				'text5'=>@$text5[$i]
			);

			$this->db->insert('bbmc_tr_laboratorium_hasil',$data_insert);

			$i++;

		}

		redirect('front_office/ugd_dir/ugd/tmbh_pemeriksaan/'.$id_re_pasien.'/'.$id_re_kunjungan.'/pemeriksaan_lab');
	}



	public function update_data_kunjungan_penunjang()
	{
		extract($_POST);
		if($this->validasi_penunjang())
		{
			date_default_timezone_set('Asia/Makassar');
			
			
			$data['id_re_kunjungan'] = $id_re_kunjungan;
			$data['tindak_lanjut_pemeriksaan'] = $tindak_lanjut_pemeriksaan;
			$data['hasil_ovservasi_ugd'] = $hasil_ovservasi_ugd;
			$data['date_modified'] = date('Y-m-d h:i:s');
			$data['modified_by'] = $this->session->userdata('userid');
			$this->db->update('bbmc_tr_kunjungan',$data,array("id_re_kunjungan"=>$data['id_re_kunjungan']));

			
			/*
			$data_lab_deleted['deleted'] = '1';
			$data_lab_deleted['modified_by'] = $this->session->userdata('userid');
			$data_lab_deleted['date_modified'] = date('Y-m-d h:i:s');
			$this->db->update('bbmc_tr_laboratorium',$data_lab_deleted,array("id_re_kunjungan"=>$data['id_re_kunjungan']));
			*/
			//echo "gas";


			$this->load->library('upload');
			$datax = array();
		    $files = $_FILES;
		    
		    /*
		    $cpt = count($_FILES['files']['name']);
		    $data_lab['file'] = '';
		    //echo $cpt;
		    for($i=0; $i<$cpt; $i++)
		    {           
		    	
	        	//echo $this->upload->display_errors();
		    }
		    */




			
			for ($i=0; $i < count($tindakan_lab); $i++) { 

				if($tindakan_lab[$i] != ''){
					//echo $i."<br>";
					/*
					
		        	*/

					$data_lab['id_re_kunjungan'] = $data['id_re_kunjungan'];
					$data_lab['id_staff_medis'] = $id_staff_medis;
					$data_lab['tgl_periksa'] = $tgl_periksa[$i];
					//$data_lab['no_lab'] = $no_lab[$i];
					$data_lab['tindakan_lab'] = $tindakan_lab[$i];
					$data_lab['hasil_lab'] = @$hasil_lab[$i];
					$data_lab['added_by'] = $this->session->userdata('userid');
					$data_lab['date_added'] = date('Y-m-d h:i:s');

					if($id_re_laboratorium[$i] != 'tidakada'){

						/*
						if(@$files['files']['name'][$i]){
				        	$_FILES['files']['name']= @$files['files']['name'][$i];
					        $_FILES['files']['type']= @$files['files']['type'][$i];
					        $_FILES['files']['tmp_name']= @$files['files']['tmp_name'][$i];
					        $_FILES['files']['error']= @$files['files']['error'][$i];
					        $_FILES['files']['size']= @$files['files']['size'][$i];    

					        $config = array();
					        $file_ext = pathinfo(@$files['files']['name'][$i], PATHINFO_EXTENSION);
					        $config['file_name'] = $id_re_pasien."-".$id_re_laboratorium[$i]."".($i+1).'.'.$file_ext;
						    $config['upload_path']          = './media/upload/file/';
					        $config['allowed_types']        = 'pdf|jpg|jpeg|png|doc|docx';
					        $config['max_size']             = 0;
					        $config['max_width']            = 0;
					        $config['max_height']           = 0;
					        $config['overwrite'] = TRUE;
					        $this->upload->initialize($config);
					        //echo $config['upload_path']."<br>";
					        //echo $config['file_name']."<br>";
					        if($this->upload->do_upload('files')){
					        	//echo "string";
					        	//echo "string";
				        		$data_lab['file'] = $config['file_name'];
				        
				        	}else{
				        		//echo $this->upload->display_errors();
				        		//$data['file_passport'] = '';
				        	}
			        	}
			        	*/


						$this->db->where('id_re_laboratorium',$id_re_laboratorium[$i]);
						$this->db->update('bbmc_tr_laboratorium',$data_lab);
					}else{
						$this->db->insert('bbmc_tr_laboratorium',$data_lab);
					}
				}

				
			}

			for ($i=0; $i < count($tindakan_radiologi); $i++) { 
				if($tindakan_radiologi[$i] != ''){
					$data_radiologi['id_re_kunjungan'] = $data['id_re_kunjungan'];
					$data_radiologi['id_staff_medis'] = $id_staff_medis;
					$data_radiologi['tgl_periksa'] = $tgl_periksa[$i];
					$data_radiologi['tindakan_radiologi'] = $tindakan_radiologi[$i];
					$data_radiologi['hasil_radiologi'] = $hasil_radiologi[$i];
					$data_radiologi['added_by'] = $this->session->userdata('userid');
					$data_radiologi['date_added'] = date('Y-m-d h:i:s');
					
					if($id_re_radiologi[$i] != 'tidakada'){
						$this->db->where('id_re_radiologi',$id_re_radiologi[$i]);
						$this->db->update('bbmc_tr_radiologi',$data_radiologi);
					}else{
						$this->db->insert('bbmc_tr_radiologi',$data_radiologi);
					}
				}
			}

			//$this->db->insert_batch('bbmc_tr_laboratorium',$array_lab);


			echo json_encode(array("status"=>"1", "title"=>"Sukses !", "message"=>"Data Berhasil Diperbarui"));
		} 
	}

	public function update_data_icd()
	{
		


		extract($_POST);
		/*
		if(@$odontogram)
			{
				foreach ($_POST as $key => $value) {
					$data_odontogram[$key]=$value!=''?$value:null;
				}
				unset($data_odontogram['id_re_icd']);
				unset($data_odontogram['id_icd']);
				unset($data_odontogram['id_re_tindakan']);
				unset($data_odontogram['tindakan']);
				unset($data_odontogram['odontogram']);
				unset($data_odontogram['cuadro']);
				
				
				$this->db->where('id_re_kunjungan',$data_odontogram['id_re_kunjungan']);
				$this->db->delete('bbmc_tr_odontogram');
				$data['date_added'] = date('Y-m-d h:i:s');
				$data['added_by'] = $this->session->userdata('userid');
				$this->db->insert('bbmc_tr_odontogram',$data_odontogram);

			}
			echo "<pre>";
			var_dump($data_odontogram);
			echo "</pre>";
		*/
		
		if($this->validasi_penunjang())
		{
			date_default_timezone_set('Asia/Makassar');
			
			
			
			for ($i=0; $i < count(@$id_icd); $i++) { 
				if($id_icd[$i] != ''){
					$data_icd['id_re_kunjungan'] = $id_re_kunjungan;
					$data_icd['id_icd'] = $id_icd[$i];
					$data_icd['gigi_icd'] = @$gigi_icd[$i];
					$data_icd['added_by'] = $this->session->userdata('userid');
					$data_icd['date_added'] = date('Y-m-d h:i:s');
					
					if($id_re_icd[$i] != 'tidakada'){
						$this->db->where('id_re_icd',$id_re_icd[$i]);
						$this->db->update('bbmc_tr_icd',$data_icd);
					}else{
						$this->db->insert('bbmc_tr_icd',$data_icd);
					}
				}
			}

			for ($i=0; $i < count(@$tindakan); $i++) { 
				if($tindakan[$i] != ''){
					$data_tindakan['id_re_kunjungan'] = $id_re_kunjungan;
					$data_tindakan['tindakan'] = $tindakan[$i];
					$data_tindakan['gigi'] = @$gigi[$i];
					$data_tindakan['keterangan'] = @$keterangan[$i];
					$data_tindakan['added_by'] = $this->session->userdata('userid');
					$data_tindakan['date_added'] = date('Y-m-d h:i:s');
					
					if($id_re_tindakan[$i] != 'tidakada'){
						$this->db->where('id_re_tindakan',$id_re_tindakan[$i]);
						$this->db->update('bbmc_tr_tindakan',$data_tindakan);
					}else{
						$this->db->insert('bbmc_tr_tindakan',$data_tindakan);
					}
				}
			}

			
			
			if(@$odontogram)
			{
				foreach ($_POST as $key => $value) {
					$data_odontogram[$key]=$value!=''?$value:null;
				}
				unset($data_odontogram['id_re_icd']);
				unset($data_odontogram['id_icd']);
				unset($data_odontogram['id_re_tindakan']);
				unset($data_odontogram['tindakan']);
				unset($data_odontogram['odontogram']);
				unset($data_odontogram['cuadro']);
				unset($data_odontogram['gigi']);
				unset($data_odontogram['gigi_icd']);
				unset($data_odontogram['keterangan']);
				
				
				$this->db->where('id_re_kunjungan',$data_odontogram['id_re_kunjungan']);
				$this->db->delete('bbmc_tr_odontogram');
				$data['date_added'] = date('Y-m-d h:i:s');
				$data['added_by'] = $this->session->userdata('userid');
				$this->db->insert('bbmc_tr_odontogram',$data_odontogram);

			}
			
			

		
			echo json_encode(array("status"=>"1", "title"=>"Sukses !", "message"=>"Data Berhasil Diperbarui"));
		} 
		
		
		

			

	}

	/*
	public function update_data_pengobatan()
	{
		extract($_POST);
		if($this->validasi_penunjang())
		{
			date_default_timezone_set('Asia/Makassar');
			
			
			$a='Data Berhasil Diperbarui';
			for ($i=0; $i < count($id_obat); $i++) { 
				if($id_obat[$i] != ''){
					$data_pengobatan['id_re_kunjungan'] = $id_re_kunjungan;
					$data_pengobatan['id_obat'] = $id_obat[$i];
					$data_pengobatan['cara_pemakaian'] = $cara_pemakaian[$i];
					$data_pengobatan['qty'] = $qty[$i];
					$data_pengobatan['added_by'] = $this->session->userdata('userid');
					$data_pengobatan['date_added'] = date('Y-m-d h:i:s');
					
					if($id_re_pengobatan[$i] != 'tidakada'){
						$this->db->where('id_re_pengobatan',$id_re_pengobatan[$i]);
						$this->db->update('bbmc_tr_pengobatan',$data_pengobatan);
					}else{
						$this->db->insert('bbmc_tr_pengobatan',$data_pengobatan);
						//$a = $this->db->last_query();
					}
				}
			}

			

		
			echo json_encode(array("status"=>"1", "title"=>"Sukses !", "message"=>$a));
		} 
	}
	*/

	public function update_data_pengobatan()
	{
		extract($_POST);
		if($this->validasi_penunjang())
		{
			date_default_timezone_set('Asia/Makassar');
			
			
			$aa='Data Berhasil Diperbarui';
			//echo count($id_obat)."<br>";
			$i=1;
			$a=0;


			if($status_resep == '0'){
				$data_status_resep['status_resep'] = '1';
				$this->db->where('id_re_kunjungan', $id_re_kunjungan);
				$this->db->update('bbmc_tr_kunjungan',$data_status_resep);
			}

			$this->db->where('id_re_kunjungan',$id_re_kunjungan);
			$this->db->delete('bbmc_tr_pengobatan');

			$this->db->where('id_re_kunjungan',$id_re_kunjungan);
			$this->db->delete('bbmc_tr_pengobatan_pasien');

			$e1 = 1;
			
			foreach ($id_obat as $key ) {
				$cek=0;
				//echo $i.". ";
				$e2 = 0;
				foreach ($key as $keyp ) {
					if($keyp != ''){
						if($cek == 0){
							
							//$data_pengobatan['id_re_kunjungan'] = $id_re_kunjungan;
							//$this->db->insert('bbmc_tr_pengobatan',$data_pengobatan);

							$data_pengobatan['id_re_kunjungan'] = $id_re_kunjungan;
							$data_pengobatan['added_by'] = $this->session->userdata('userid');
							$data_pengobatan['date_added'] = date('Y-m-d h:i:s');
							$this->db->insert('bbmc_tr_pengobatan',$data_pengobatan);
							$id_pengobatan = $this->db->insert_id();
							$cek=1;
						}
						//echo $keyp.",";

						
						//echo "insert pengobatan pasien";
						$data_pengobatan_pasien['id_pengobatan'] = $id_pengobatan;
						$data_pengobatan_pasien['id_re_kunjungan'] = $id_re_kunjungan;
						$data_pengobatan_pasien['id_obat'] = $keyp;
						$data_pengobatan_pasien['qty'] = $qty[$e1][$e2];
						$data_pengobatan_pasien['cara_pemakaian'] = $cara_pemakaian[$e1][$e2];
						$data_pengobatan_pasien['keterangan_obat'] = $keterangan_obat[$e1][$e2];
						$this->db->insert('bbmc_tr_pengobatan_pasien',$data_pengobatan_pasien);
						
					}
					$e2++;
				}
				//echo "<br>";
				$i++;
				$a++;
				$e1++;
			}

			

		
			echo json_encode(array("status"=>"1", "title"=>"Sukses !", "message"=>$aa));
		} 
	}




	public function hasil_pemeriksaan_lab($id_re_pasien, $id_re_laboratorium, $id_re_kunjungan, $tindakan_lab, $keterangan=null)
	{
		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['get_kunjungan'])
		{
			$pemeriksaan = $this->Content_m->get_value('siak_re_account_chart','id',$tindakan_lab,'name');
			$data['parent_controller'] = '';
			$data['active'] = 'laboratorium';	

			$data['method'] = '';
			$data['judul'] = '';
			$data['desc_judul'] = '';

			$data['page'] = 'ugd/periksa/hasil_lab/hasil';

			
			$data['breadcumb'][] = array('icon'=>'stethoscope',
												 'link'=>site_url('front_office/ugd_dir/ugd/tmbh_pemeriksaan/'.$id_re_pasien.'/'.$id_re_kunjungan.'/pemeriksaan_lab'),
												 'judul'=>'Pemeriksaan Penunjang');		

			$data['breadcumb'][] = array('icon'=>'medkit',
																	 'link'=>'',
																	 'judul'=>'Hasil Pemeriksaan Lab');																		 
			$data['id_re_kunjungan'] = $id_re_kunjungan;
			$data['id_re_laboratorium'] = $id_re_laboratorium;
			$data['tindakan_lab'] = $tindakan_lab;
			$data['id_re_pasien'] = $id_re_pasien;
			$data['keterangan'] = $keterangan;
	 		$this->load->view('template',$data);

		}
		else
		{
			show_404();		
		}
	}

	public function set_pemeriksaan_lab($id_re_pasien, $id_re_laboratorium, $id_re_kunjungan, $tindakan_lab, $keterangan=null)
	{

		$data['get_kunjungan'] = $this->db->get_where('bbmc_tr_kunjungan', array('id_re_kunjungan'=>$id_re_kunjungan))->row();
		if($data['get_kunjungan'])
		{
			$pemeriksaan = $this->Content_m->get_value('siak_re_account_chart','id',$tindakan_lab,'name');
			$data['parent_controller'] = '';
			$data['active'] = 'pemeriksaan_lab';	

			$data['method'] = '';
			$data['judul'] = 'Hasil Pemeriksaan Lab - '.$pemeriksaan;
			$data['desc_judul'] = '';

			$data['page'] = 'ugd/periksa/hasil_lab/set_widal';

			
			$data['breadcumb'][] = array('icon'=>'stethoscope',
												 'link'=>site_url('front_office/ugd_dir/ugd/tmbh_pemeriksaan/'.$id_re_pasien.'/'.$id_re_kunjungan.'/pemeriksaan_lab'),
												 'judul'=>'Pemeriksaan Penunjang');						

			$data['breadcumb'][] = array('icon'=>'medkit',
												 'link'=>'',
												 'judul'=>'Pemeriksaan Lab');		

			$data['id_re_kunjungan'] = $id_re_kunjungan;
			$data['id_re_laboratorium'] = $id_re_laboratorium;
			$data['tindakan_lab'] = $tindakan_lab;
			$data['id_re_pasien'] = $id_re_pasien;
			$data['keterangan'] = $keterangan;
	 		$this->load->view('template',$data);
		}
		else
		{
			show_404();		
		}
	}

	public function edit_pemeriksaan_lab($ket)
	{
		$data['parent_controller'] = '';
		$data['active'] = 'pemeriksaan_lab';	

		$data['method'] = '';
		$data['judul'] = 'Hasil Pemeriksaan Lab';
		$data['desc_judul'] = '';

		$data['page'] = 'ugd/periksa/hasil_lab/edit_widal';

		
		$data['breadcumb'][] = array('icon'=>'stethoscope',
											 'link'=>'',
											 'judul'=>'Edit Pemeriksaan Lab');						

	

		$data['keterangan'] = $ket;
 		$this->load->view('template',$data);
	}
	

	public function del_pemeriksaan_lab($id_re_laboratorium, $id_re_kunjungan)
	{
		$data_lab_deleted['deleted'] = '1';
		$data_lab_deleted['modified_by'] = $this->session->userdata('userid');
		$data_lab_deleted['date_modified'] = date('Y-m-d h:i:s');
		$this->db->update('bbmc_tr_laboratorium',$data_lab_deleted,array("id_re_laboratorium"=>$id_re_laboratorium));
		
		redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}


	public function del_pemeriksaan_radiologi($id_re_radiologi, $id_re_kunjungan)
	{
		$data_lab_deleted['deleted'] = '1';
		$data_lab_deleted['modified_by'] = $this->session->userdata('userid');
		$data_lab_deleted['date_modified'] = date('Y-m-d h:i:s');
		$this->db->update('bbmc_tr_radiologi',$data_lab_deleted,array("id_re_radiologi"=>$id_re_radiologi));
		
		redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}

	public function del_icd($id_re_icd, $id_re_kunjungan)
	{
		$data_lab_deleted['deleted'] = '1';
		$data_lab_deleted['modified_by'] = $this->session->userdata('userid');
		$data_lab_deleted['date_modified'] = date('Y-m-d h:i:s');
		$this->db->update('bbmc_tr_icd',$data_lab_deleted,array("id_re_icd"=>$id_re_icd));
		
		redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}

	public function del_tindakan($id_re_tindakan, $id_re_kunjungan)
	{
		$data_lab_deleted['deleted'] = '1';
		$data_lab_deleted['modified_by'] = $this->session->userdata('userid');
		$data_lab_deleted['date_modified'] = date('Y-m-d h:i:s');
		$this->db->update('bbmc_tr_tindakan',$data_lab_deleted,array("id_re_tindakan"=>$id_re_tindakan));
		
		redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}

	/*
	public function del_pengobatan($id_re_pengobatan, $id_re_kunjungan)
	{
		$data_lab_deleted['deleted'] = '1';
		$data_lab_deleted['modified_by'] = $this->session->userdata('userid');
		$data_lab_deleted['date_modified'] = date('Y-m-d h:i:s');
		$this->db->update('bbmc_tr_pengobatan',$data_lab_deleted,array("id_re_pengobatan"=>$id_re_pengobatan));
		
		redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}
	*/

	public function del_pengobatan($id_re_pengobatan, $id_re_kunjungan)
	{	

		$this->db->where('id_re_pengobatan',$id_re_pengobatan);
		$this->db->where('id_re_kunjungan',$id_re_kunjungan);
		$this->db->delete('bbmc_tr_pengobatan');

		$this->db->where('id_pengobatan',$id_re_pengobatan);
		$this->db->where('id_re_kunjungan',$id_re_kunjungan);
		$this->db->delete('bbmc_tr_pengobatan_pasien');

		redirect($_SERVER['HTTP_REFERER'],'refresh');	
	}

	public function validasi()
	{
		$this->form_validation->set_rules('id_dokter_jaga', 'Dokter Jaga', 'trim|required');
		$this->form_validation->set_rules('id_perawat_bidan_jaga', 'Perawat / Bidan Jaga', 'trim|required');
		$this->form_validation->set_rules('id_alasan_keluar', 'Dengan Alasan Keluar', 'trim|required');
		$this->form_validation->set_message('required', '{field} harus diisi!');
		$this->form_validation->set_message('numeric', '{field} harus berupa angka!');
		$this->form_validation->set_message('max_length', '{field} tidak boleh lebih dari {param} karakter!');
		$this->form_validation->set_message('min_length', '{field} tidak boleh kurang dari {param} karakter!');
		$this->form_validation->set_message('valid_email', '{field} tidak valid!');

		$valid = $this->form_validation->run();
		if($valid)
		{
			return $valid;
		}
		else
		{
			echo json_encode(array("status"=>"2", "title"=>"Error!", "message"=>"Terjadi kesalahan, silahkan periksa kembali data yang diinputkan", "detail_error"=>$this->form_validation->field_data()));
		}
	}	

	public function validasi_penunjang()
	{
		$this->form_validation->set_rules('id_dokter_jaga', 'Dokter Jaga', 'trim');
		$this->form_validation->set_message('required', '{field} harus diisi!');
		$this->form_validation->set_message('numeric', '{field} harus berupa angka!');
		$this->form_validation->set_message('max_length', '{field} tidak boleh lebih dari {param} karakter!');
		$this->form_validation->set_message('min_length', '{field} tidak boleh kurang dari {param} karakter!');
		$this->form_validation->set_message('valid_email', '{field} tidak valid!');

		$valid = $this->form_validation->run();
		if($valid)
		{
			return $valid;
		}
		else
		{
			echo json_encode(array("status"=>"2", "title"=>"Error!", "message"=>"Terjadi kesalahan, silahkan periksa kembali data yang diinputkan", "detail_error"=>$this->form_validation->field_data()));
		}
	}	
  	

}