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

	public function listar($xan){
		$query 	= "	SELECT
						atencion_examen.aex_id,
						atencion_examen.aex_indicacion,
						atencion_examen.ate_id,
						atencion_examen.exa_id,
						atencion_examen.hc_id,
						examen.exa_descripcion
					FROM
						atencion_examen
					INNER JOIN examen ON atencion_examen.exa_id = examen.exa_id
					WHERE atencion_examen.ate_id = $xan";
		return 	$this->db->query($query);
	}

	public function insertar($xen, $xan, $indi){
		$query 	= "SELECT aex_id FROM atencion_examen WHERE exa_id = '$xen' AND ate_id = $xan";
		$query 	= $this->db->query($query);
		$ds 	= $query->row();
		if(!$ds){
			$this->db->set('exa_id', $xen);
			$this->db->set('ate_id', $xan);
			$this->db->set('aex_indicacion', $indi);
			$this->db->insert('atencion_examen');
		}
	}

	public function eliminar($id){
		$this->db->where('aex_id', $id);
		$this->db->delete('atencion_examen');
	}
}