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

class MKonsultasi extends CI_Model{

  public function __construct()
  {
    parent::__construct();
    //Codeigniter : Write Less Do More
  }

  public function KonsultasiTerbaru($idnakes)
  {
    $status = array('1', '2');
    $this->db->where_in('konsultasi.status_konsultasi', $status);
    $this->db->where("konsultasi.nakes_idnakes",$idnakes);
    $this->db->join("nakes", "nakes.idnakes = konsultasi.nakes_idnakes");
    $this->db->join("data_user","data_user.iddata_user = konsultasi.data_user_iddata_user");
    return $this->db->get("konsultasi");
  }

  public function DetailKonsultasi($idkonsultasi)
  {
    $this->db->where("idkonsultasi",$idkonsultasi);
    $this->db->join("nakes", "nakes.idnakes = konsultasi.nakes_idnakes");
    $this->db->join("data_user","data_user.iddata_user = konsultasi.data_user_iddata_user");
    return $this->db->get("konsultasi");
  }

  public function RiwayatKonsultasi($idnakes, $start, $end, $status = null)
  {
    $this->db->where("konsultasi.nakes_idnakes",$idnakes);
    $this->db->where('date(konsultasi.waktu) BETWEEN "'. date('Y-m-d', strtotime($start)). '" and "'. date('Y-m-d', strtotime($end)).'"');
    if ($status != null) {
      $this->db->where("konsultasi.status_konsultasi", $status);
    }
    $this->db->join("nakes", "nakes.idnakes = konsultasi.nakes_idnakes");
    $this->db->join("data_user","data_user.iddata_user = konsultasi.data_user_iddata_user");
    return $this->db->get("konsultasi");
  }

}
