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

	public function listar($xan){
		$query 	= "	SELECT
						atencion_diagnostico.atdx_id,
						atencion_diagnostico.ate_id,
						atencion_diagnostico.diag_codigo,
						atencion_diagnostico.atdx_tipo,
						atencion_diagnostico.atdx_randon,
						diagnostico.diag_descripcion
					FROM
						atencion_diagnostico
					INNER JOIN diagnostico ON atencion_diagnostico.diag_codigo = diagnostico.diag_codigo
					WHERE atencion_diagnostico.ate_id = $xan";
		return 	$this->db->query($query);
	}

	public function insertar($xdo, $xan){
		$query 	= "SELECT atdx_id FROM atencion_diagnostico WHERE diag_codigo = '$xdo' AND ate_id = $xan";
		$query 	= $this->db->query($query);
		$ds 	= $query->row();
		if(!$ds){
			$this->db->set('diag_codigo', $xdo);
			$this->db->set('ate_id', $xan);
			$this->db->insert('atencion_diagnostico');
		}
	}

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