<?php
class Xmo_model extends CI_Model{
	public function __construct(){
		parent::__construct();
	}

	public function listar($texto = ''){
		$where 	= ($texto!='')?" AND med_descripcion LIKE '%$texto%'":"";
		$query 	= "	SELECT med_id, med_descripcion, med_estado
					FROM medicamento
					WHERE med_estado = 0 {$where}
					ORDER BY med_descripcion ASC";
		return 	$this->db->query($query);
	}

	public function validar($descripcion){
		$this->db->select('med_id')->from('medicamento')->where('med_estado', 0);
		$this->db->where('med_descripcion', $descripcion);
		$query 	= $this->db->get();
		return 	$query->row();
	}

	public function insertar($data){
		$this->db->insert('medicamento', $data);
	}

	public function editar($id, $data){
		$this->db->where('med_id', $id);
		$this->db->update('medicamento', $data);
	}
}