<?php

class Pengaturan_pemeriksaan_model extends CI_Model {
	
	private $_error = "";
	private $_table_name = "Pengaturan_pemeriksaan";
	private $_table_sql = "Pengaturan_pemeriksaan p_p";

	public function lihat_data()
	{
		$this->db->select('p_p.*');
		$this->db->from($this->_table_sql);
		
		return $this->db->get()->row();
	}

	public function update($context)
	{
		$this->bpjs_kdStatusPulang = $context['bpjs_kdStatusPulang'];
		$this->bpjs_nmStatusPulang = $context['bpjs_nmStatusPulang'];
		$this->bpjs_kdSadar = $context['bpjs_kdSadar'];
		$this->bpjs_nmSadar = $context['bpjs_nmSadar'];		
		$this->bpjs_alergiMakan = $context['bpjs_alergiMakan'];
		$this->bpjs_nm_alergiMakan = $context['bpjs_nm_alergiMakan'];
		$this->bpjs_alergiUdara = $context['bpjs_alergiUdara'];
		$this->bpjs_nm_alergiUdara = $context['bpjs_nm_alergiUdara'];
		$this->bpjs_alergiObat = $context['bpjs_alergiObat'];
		$this->bpjs_nm_alergiObat = $context['bpjs_nm_alergiObat'];
		$this->bpjs_kdPrognosa = $context['bpjs_kdPrognosa'];
		$this->bpjs_nmPrognosa = $context['bpjs_nmPrognosa'];

		if($context['bpjs_keluhan'] != ''){ $this->bpjs_keluhan = $context['bpjs_keluhan']; } else $this->bpjs_keluhan = '-';

		if($context['bpjs_anamnesa'] != ''){ $this->bpjs_anamnesa = $context['bpjs_anamnesa']; } else $this->bpjs_anamnesa = '-';

		if($context['bpjs_terapiObat'] != ''){ $this->bpjs_terapiObat = $context['bpjs_terapiObat']; } else $this->bpjs_terapiObat = '-';

		if($context['bpjs_terapiNonObat'] != ''){ $this->bpjs_terapiNonObat = $context['bpjs_terapiNonObat']; } else $this->bpjs_terapiNonObat = '-';

		if($context['bpjs_bmhp'] != ''){ $this->bpjs_bmhp = $context['bpjs_bmhp']; } else $this->bpjs_bmhp = '-';

		if($context['object'] != ''){ $this->object = $context['object']; } else $this->object = '-';
		
		if($context['plan'] != ''){ $this->plan = $context['plan']; } else $this->plan = '-';

		if($context['evaluasi'] != ''){ $this->evaluasi = $context['evaluasi']; } else $this->evaluasi = '-';

		$query = $this->db->where('id', $context['id'])->update($this->_table_name, $this);

		if(!$query) $this->_error .= '<br> '.$this->mysql_get_error(); 		

		if($this->_error == '')
		{
			$notif = array('eror' => 'success', 'pesan' => 'Update data berhasil');
		}
		else 
		{	
			$notif = array('eror' => 'warning', 'pesan' => $this->_error);
			$this->db->insert('_log_error', ['model' => 'Data_pendaftaran_model', 'detail' => $this->_error]);
		}

		return $notif;
	}

	//--------------------------------------------------------------------------------------------

	public function mysql_get_error()
	{
		$error = $this->db->error();

		switch ($error['code']) 
		{
			case '1062':
			$error_detail = 'Data sudah ada';
			break;

			default:
			$error_detail = "$error[code]: $error[message]";
			break;
		}

		return $error_detail;		
	}

}	