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

class Cari extends CI_Controller
{

    // CONSTRUCT
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->model('M_rekamMedis');
        $this->load->model('M_user');
        $this->load->model('M_anamnesa');
        $this->load->model('M_Utama');
        $this->load->helper('url');

        if (!$this->session->userdata('username')) {
            redirect('login');
        }
    }

    public function kunjungan()
	{
		extract($_GET);
		// ---------------------------------------------------------------------
        date_default_timezone_set("Asia/Jakarta");
        $tanggal = date('Y-m-d');
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $user = $this->M_user->getUserSession()->row_array();
        $data['judul'] = "Klinik";
        // =================================================================================
        if ($user['dept'] == 1 || $user['dept'] == 13 || $user['dept'] == 4) {
            $data['record'] = $this->db->query("SELECT s.[Case ID],s.Description,s.RegStatus,m.CompanyName,s.[Case Status],ca.Unit,d.FirstName as dokter,d.LastName,c.PatientCode, er.StatusResume,er.diagnosa_primer   
            FROM tabelCaseDetail c, Cases s, Company m, CaseAdmin ca, Doctor d, erm_pemeriksaan_fisik er WHERE c.[Case ID]=s.[Case ID] AND s.CompanyCode=m.CompanyCode AND
            ca.[Case ID] = s.[Case ID] and d.DoctorID = ca.DoctorID AND
            er.case_id = s.[Case ID] AND c.[Case ID] = '$src' ORDER BY s.[Case ID] DESC")->result_array();
        } else if ($user['dept'] == 2) {
            $data['record'] = $this->db->query("SELECT s.[Case ID],s.Description,s.RegStatus,m.CompanyName,s.[Case Status],ca.Unit,d.FirstName as dokter,d.LastName,c.PatientCode, er.StatusResume, er.diagnosa_primer   
            FROM tabelCaseDetail c, Cases s, Company m, CaseAdmin ca, Doctor d, erm_pemeriksaan_fisik er WHERE c.[Case ID]=s.[Case ID] AND s.CompanyCode=m.CompanyCode AND
            ca.[Case ID] = s.[Case ID] and d.DoctorID = ca.DoctorID AND
            er.case_id = s.[Case ID] AND c.[Case ID] = '$src' ORDER BY s.[Case ID] DESC")->result_array();
        }
        // =================================================================================
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('rekamMedis/record', $data);
        $this->load->view('properti/footer', $data);
	}

    public function kunjunganlab()
	{
		extract($_GET);
		// ---------------------------------------------------------------------
        date_default_timezone_set("Asia/Jakarta");
        $tanggal = date('Y-m-d');
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $user = $this->M_user->getUserSession()->row_array();
        $data['judul'] = "Klinik";
        // =================================================================================
        if ($user['dept'] == 1 || $user['dept'] == 13 || $user['dept'] == 4) {
            $data['record'] = $this->db->query("SELECT s.[Case ID],s.Description,s.RegStatus,m.CompanyName,s.[Case Status],ca.Unit,d.FirstName as dokter,d.LastName,c.PatientCode,er.StatusResume  
            FROM tabelCaseDetail c, Cases s, Company m, CaseAdmin ca, Doctor d,erm_pemeriksaan_fisik er WHERE c.[Case ID]=s.[Case ID] AND s.CompanyCode=m.CompanyCode AND
            ca.[Case ID] = s.[Case ID] and d.DoctorID = ca.DoctorID AND er.case_id = s.[Case ID]
            AND c.[Case ID] = '$src' ORDER BY s.[Case ID] DESC")->result_array();
        } else if ($user['dept'] == 2) {
            $data['record'] = $this->db->query("SELECT s.[Case ID],s.Description,s.RegStatus,m.CompanyName,s.[Case Status],ca.Unit,d.FirstName as dokter,d.LastName,c.PatientCode,er.StatusResume  
            FROM tabelCaseDetail c, Cases s, Company m, CaseAdmin ca, Doctor d, erm_pemeriksaan_fisik er WHERE c.[Case ID]=s.[Case ID] AND s.CompanyCode=m.CompanyCode AND
            ca.[Case ID] = s.[Case ID] and d.DoctorID = ca.DoctorID AND
            er.case_id = s.[Case ID] AND c.[Case ID] = '$src' ORDER BY s.[Case ID] DESC")->result_array();
        }
        // =================================================================================
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('Laboratorium/record', $data);
        $this->load->view('properti/footer', $data);
	}

    public function nomrlab()
	{
		extract($_GET);
		// ---------------------------------------------------------------------
        date_default_timezone_set("Asia/Jakarta");
        $tanggal = date('Y-m-d');
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $user = $this->M_user->getUserSession()->row_array();
        $data['judul'] = "Klinik";
        // =================================================================================
        if ($user['dept'] == 1 || $user['dept'] == 13 || $user['dept'] == 4) {
            $data['record'] = $this->db->query("SELECT s.[Case ID],s.Description,s.RegStatus,m.CompanyName,s.[Case Status],ca.Unit,d.FirstName as dokter,d.LastName,c.PatientCode,er.StatusResume  
            FROM tabelCaseDetail c, Cases s, Company m, CaseAdmin ca, Doctor d,erm_pemeriksaan_fisik er WHERE c.[Case ID]=s.[Case ID] AND s.CompanyCode=m.CompanyCode AND
            ca.[Case ID] = s.[Case ID] and d.DoctorID = ca.DoctorID AND er.case_id = s.[Case ID]
            AND c.PatientCode = '$src' ORDER BY s.[Case ID] DESC")->result_array();
        } else if ($user['dept'] == 2) {
            $data['record'] = $this->db->query("SELECT s.[Case ID],s.Description,s.RegStatus,m.CompanyName,s.[Case Status],ca.Unit,d.FirstName as dokter,d.LastName,c.PatientCode,er.StatusResume  
            FROM tabelCaseDetail c, Cases s, Company m, CaseAdmin ca, Doctor d, erm_pemeriksaan_fisik er WHERE c.[Case ID]=s.[Case ID] AND s.CompanyCode=m.CompanyCode AND
            ca.[Case ID] = s.[Case ID] and d.DoctorID = ca.DoctorID AND
            er.case_id = s.[Case ID] AND c.PatientCode = '$src' ORDER BY s.[Case ID] DESC")->result_array();
        }
        // =================================================================================
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('Laboratorium/record', $data);
        $this->load->view('properti/footer', $data);
	}

    public function tglLab()
	{
		extract($_GET);
		// ---------------------------------------------------------------------
        date_default_timezone_set("Asia/Jakarta");
        $tanggal = date('Y-m-d');
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $user = $this->M_user->getUserSession()->row_array();
        $data['judul'] = "Klinik";
        // =================================================================================
        if ($user['dept'] == 1 || $user['dept'] == 13 || $user['dept'] == 4) {
            $data['record'] = $this->db->query("SELECT s.[Case ID],s.Description,s.RegStatus,m.CompanyName,s.[Case Status],ca.Unit,d.FirstName as dokter,d.LastName,c.PatientCode,er.StatusResume  
            FROM tabelCaseDetail c, Cases s, Company m, CaseAdmin ca, Doctor d,erm_pemeriksaan_fisik er WHERE c.[Case ID]=s.[Case ID] AND s.CompanyCode=m.CompanyCode AND
            ca.[Case ID] = s.[Case ID] and d.DoctorID = ca.DoctorID AND er.case_id = s.[Case ID]
            AND c.[Intake Date] = '$src' ORDER BY s.[Case ID] DESC")->result_array();
        } else if ($user['dept'] == 2) {
            $data['record'] = $this->db->query("SELECT s.[Case ID],s.Description,s.RegStatus,m.CompanyName,s.[Case Status],ca.Unit,d.FirstName as dokter,d.LastName,c.PatientCode,er.StatusResume  
            FROM tabelCaseDetail c, Cases s, Company m, CaseAdmin ca, Doctor d, erm_pemeriksaan_fisik er WHERE c.[Case ID]=s.[Case ID] AND s.CompanyCode=m.CompanyCode AND
            ca.[Case ID] = s.[Case ID] and d.DoctorID = ca.DoctorID AND
            er.case_id = s.[Case ID] AND c.[Intake Date] = '$src' ORDER BY s.[Case ID] DESC")->result_array();
        }
        // =================================================================================
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('Laboratorium/record', $data);
        $this->load->view('properti/footer', $data);
	}

    public function status()
	{
		extract($_GET);
		// ---------------------------------------------------------------------
        date_default_timezone_set("Asia/Jakarta");
        $tanggal = date('Y-m-d');
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $user = $this->M_user->getUserSession()->row_array();
        $data['judul'] = "Klinik";
        // =================================================================================
        if ($user['dept'] == 1 || $user['dept'] == 13 || $user['dept'] == 4) {
            $data['record'] = $this->db->query("SELECT * FROM tabelCaseDetail c, Cases s, Company m WHERE c.[Case ID]=s.[Case ID] AND s.CompanyCode=m.CompanyCode AND s.[Case Status] = '$src' AND s.[Intake Date] = '$tgl' ORDER BY s.[Case ID] DESC")->result_array();
        } else if ($user['dept'] == 2) {
            $data['record'] = $this->db->query("SELECT * FROM tabelCaseDetail c, Cases s, Company m WHERE c.[Case ID]=s.[Case ID] AND s.CompanyCode=m.CompanyCode AND s.[Case Status] = '$src' AND s.[Intake Date] = '$tgl' AND ORDER BY s.[Case ID] DESC")->result_array();
        }
        // =================================================================================
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('rekamMedis/record', $data);
        $this->load->view('properti/footer', $data);
	}

    public function list()
	{
		extract($_GET);
		// ---------------------------------------------------------------------
        date_default_timezone_set("Asia/Jakarta");
        $tanggal = date('Y-m-d');
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $user = $this->M_user->getUserSession()->row_array();
        $data['judul'] = "Klinik";
        // =================================================================================
        if ($user['dept'] == 1 || $user['dept'] == 13 || $user['dept'] == 4) {
            $data['record'] = $this->db->query("SELECT s.[Case ID],s.Description,s.RegStatus,m.CompanyName,s.[Case Status],ca.Unit,d.FirstName as dokter,d.LastName,s.PatientCode,er.diagnosa_primer  
            FROM  Cases s, Company m, CaseAdmin ca, Doctor d,erm_pemeriksaan_fisik er WHERE s.CompanyCode=m.CompanyCode AND
            ca.[Case ID] = s.[Case ID] and d.DoctorID = ca.DoctorID AND er.case_id = s.[Case ID] AND s.[Intake Date] = '$tgl' ORDER BY s.[Case ID] DESC")->result_array();
        } else if ($user['dept'] == 2) {
            $data['record'] = $this->db->query("SELECT s.[Case ID],s.Description,s.RegStatus,m.CompanyName,s.[Case Status],ca.Unit,d.FirstName as dokter,d.LastName,s.PatientCode  
            FROM Cases s, Company m, CaseAdmin ca, Doctor d,erm_pemeriksaan_fisik er WHERE s.CompanyCode=m.CompanyCode AND
            ca.[Case ID] = s.[Case ID] and d.DoctorID = ca.DoctorID AND er.case_id = s.[Case ID] AND s.[Intake Date] = '$tgl' ORDER BY s.[Case ID] DESC")->result_array();
        }
        // =================================================================================
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('rekamMedis/record', $data);
        $this->load->view('properti/footer', $data);
	}

    public function CaseIDtrx($statusParam = "")
	{
        $statusParam = strtoupper($statusParam);
        $where = ""; 
        if(!empty($statusParam)){
            $where = "and c.[Case Status] = '$statusParam' ";
        }
		extract($_GET);
		// ---------------------------------------------------------------------
        date_default_timezone_set("Asia/Jakarta");
        $tanggal = date('Y-m-d');
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $user = $this->M_user->getUserSession()->row_array();
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        // =================================================================================
        $data['pasien'] = $this->db->query("SELECT *, d.FirstName as namaDokter , d.LastName as lasNameDokter,c.[Case Status] FROM Cases c join company cp on cp.CompanyCode = c.CompanyCode 
        join CaseDetail cd on cd.[Case ID] = c.[Case ID] 
        join CaseAdmin ca on ca.[Case ID] = c.[Case ID] 
        join Doctor d on d.DoctorID = ca.DoctorID 
        WHERE  c.[Case ID] = '$src' " . $where)->result_array();
        // =================================================================================
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('Transaction/index', $data);
        $this->load->view('properti/footer', $data);
	}

    public function CaritglTrx($statusParam = "")
    {
        $statusParam = strtoupper($statusParam);
        $where = ""; 
        if(!empty($statusParam)){
            $where = "and c.[Case Status] = '$statusParam' ";
        }
        extract($_GET);
		// ---------------------------------------------------------------------
        date_default_timezone_set("Asia/Jakarta");
        $tanggal = date('Y-m-d');
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $user = $this->M_user->getUserSession()->row_array();
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        // =================================================================================
        $data['pasien'] = $this->db->query("SELECT *, d.FirstName as namaDokter , d.LastName as lasNameDokter,c.[Case Status] FROM Cases c join company cp on cp.CompanyCode = c.CompanyCode 
        join CaseDetail cd on cd.[Case ID] = c.[Case ID] 
        join CaseAdmin ca on ca.[Case ID] = c.[Case ID] 
        join Doctor d on d.DoctorID = ca.DoctorID 
        WHERE  c.[Intake Date] = '$tgl' ". $where)->result_array();
        // =================================================================================
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('Transaction/index', $data);
        $this->load->view('properti/footer', $data);
    }

    public function CariMrTrx($statusParam = "")
    {
        $statusParam = strtoupper($statusParam);
        $where = ""; 
        if(!empty($statusParam)){
            $where = "and c.[Case Status] = '$statusParam' ";
        }

        extract($_GET); 
		// ---------------------------------------------------------------------
        date_default_timezone_set("Asia/Jakarta");
        $tanggal = date('Y-m-d');
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $user = $this->M_user->getUserSession()->row_array();
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        // =================================================================================
        $data['pasien'] = $this->db->query("SELECT *, d.FirstName as namaDokter , d.LastName as lasNameDokter,c.[Case Status] FROM Cases c join company cp on cp.CompanyCode = c.CompanyCode 
        join CaseDetail cd on cd.[Case ID] = c.[Case ID] 
        join CaseAdmin ca on ca.[Case ID] = c.[Case ID] 
        join Doctor d on d.DoctorID = ca.DoctorID 
        WHERE  c.PatientCode = '$mr'  ". $where)->result_array();
        // =================================================================================
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('Transaction/index', $data);
        $this->load->view('properti/footer', $data);
    }

    public function listcari()
    {
        extract($_GET);
        $data['judul'] = "Klinik";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['pasien'] = $this->M_anamnesa->caripasien($cari)->result_array();
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('anamnesa/listpasienanamnesa', $data);
        $this->load->view('properti/footer', $data);
    }

    public function listcarimr()
    {
        extract($_GET);
        $data['judul'] = "Klinik";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['pasien'] = $this->M_anamnesa->caripasienmr($cari)->result_array();
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('anamnesa/listpasienanamnesa', $data);
        $this->load->view('properti/footer', $data);
    }

    public function listcaritgl()
    {
        extract($_GET);
        $data['judul'] = "Klinik";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['pasien'] = $this->M_anamnesa->caripasientgl($cari)->result_array();
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('anamnesa/listpasienanamnesa', $data);
        $this->load->view('properti/footer', $data);
    }

}