<?php
defined('BASEPATH') or exit('No direct script access allowed');
class M_anamnesa extends CI_Model
{
    public function pasien()
    {
        date_default_timezone_set("Asia/jakarta");
        $tgl = date('Y-m-d');
        return $this->db->query("SELECT *, c.Note as noteCases FROM Cases c, Company n WHERE c.[CompanyCode]=n.[CompanyCode] AND [Intake Date] = '$tgl' AND CaseDetail = '0' AND [Case Status] = 'OPEN'");
    }

    public function pasienmr($src)
    {
        date_default_timezone_set("Asia/jakarta");
        $tgl = date('Y-m-d');
        return $this->db->query("SELECT * FROM Cases c, Company n WHERE c.[CompanyCode]=n.[CompanyCode] AND [PatientCode] = '$src' AND CaseDetail = '0' AND [Case Status] = 'OPEN'");
    }

    public function pasientgl($tgl)
    {
        date_default_timezone_set("Asia/jakarta");
        $tgl = date('Y-m-d');
        return $this->db->query("SELECT * FROM Cases c, Company n WHERE c.[CompanyCode]=n.[CompanyCode] AND [Intake Date] = '$tgl' AND CaseDetail = '0' AND [Case Status] = 'OPEN'");
    }

    public function poli()
    {
        return $this->db->query("SELECT * FROM Antrian");
    }
    public function dokter()
    {
        return $this->db->query("SELECT * FROM Doctor WHERE Active = 'T'");
    }

    public function Mjkn()
    {
        $tgl = date('Y-m-d');
        return $this->db->query("select p.PatientCode,p.FirstName,p.CompanyCode,co.CompanyName,po.kodePoli,po.description,b.Keluhan,b.NomorAntrean,b.NomorKartu,b.TanggalPeriksa, b.isBatal
        from BPJS_Antrian b join Patient p on b.NomorKartu = p.EmployeeID
        join Poli po on po.kodePoli = b.KodePoli
        join Company co on co.CompanyCode = p.CompanyCode
		where b.isBatal is null AND b.TanggalPeriksa ='$tgl' and b.isCaseDetail is null  and b.CaseID is null");
    }

    public function Mjknnomr()
    {
        $tgl = date('Y-m-d');
        return $this->db->query("Select p.NIK,b.NomorKartu,b.Keluhan,b.KodePoli,b.NamaPoli,b.NomorAntrean,b.TanggalPeriksa,b.isBatal from BPJS_Antrian b 
        left join Patient p on b.NomorKartu = p.EmployeeID 
		where p.EmployeeID is null and b.isBatal is null  AND b.TanggalPeriksa ='$tgl'");
    }

  public function apigetperawat()
    {
        $abdulradjak = $this->db->query("SELECT TOP 1 * FROM BPJS_ID")->row_array();
        $ch = curl_init();
        $dataA = array(
            'rowDataAwal' => "0",
            'limit' => "100"
        );
        $payload = json_encode($dataA);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        curl_setopt($ch, CURLOPT_URL, $abdulradjak['IP_WS_Layanan'] . "pcare/dokter/getdokter");
        $result = curl_exec($ch);
        curl_close($ch);
        return json_decode($result, true);
    }

    public function apigetdokter($kdpoli)
    {
        $abdulradjak = $this->db->query("SELECT TOP 1 * FROM BPJS_ID")->row_array();
        $ch = curl_init();
        $tglsekarang = date('Y-m-d');
        $dataA = array(
            'tanggal' => $tglsekarang,
            'kodePoli' => "$kdpoli"
        );
        $payload = json_encode($dataA);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        curl_setopt($ch, CURLOPT_URL, $abdulradjak['IP_WS_Layanan'] . "WsBpjsAntreanFktp/referensiDokter");
        $result = curl_exec($ch);
        curl_close($ch);
        return json_decode($result, true);
    }

    public function apigetalergi($type)
    {
        $abdulradjak = $this->db->query("SELECT TOP 1 * FROM BPJS_ID")->row_array();
        $ch = curl_init();
        $dataA = array(
            'type' => $type
        );
        $payload = json_encode($dataA);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        curl_setopt($ch, CURLOPT_URL, $abdulradjak['IP_WS_Layanan'] . "pcare/alergi/getalergi");
        $result = curl_exec($ch);
        curl_close($ch);
        return json_decode($result, true);
    }

    public function apigetprognosa()
    {
        $abdulradjak = $this->db->query("SELECT TOP 1 * FROM BPJS_ID")->row_array();
        $ch = curl_init();
        //$payload = json_encode($dataA);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "");
        curl_setopt($ch, CURLOPT_URL, $abdulradjak['IP_WS_Layanan'] . "pcare/prognosa/Getprognosa");
        $result = curl_exec($ch);
        curl_close($ch);
        return json_decode($result, true);
    }
    public function caripasien($cari)
    {
        date_default_timezone_set("Asia/jakarta");
        $tgl = date('Y-m-d');
        return $this->db->query("SELECT *, d.FirstName as namaDokter , d.LastName as lasNameDokter 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  [Intake Date] = '$tgl'  AND CaseDetail = '1' And c.[Case ID] = '$cari'");
    }

    public function caripasienmr($cari)
    {
        date_default_timezone_set("Asia/jakarta");
        $tgl = date('Y-m-d');
        return $this->db->query("SELECT *, d.FirstName as namaDokter , d.LastName as lasNameDokter 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  [Intake Date] = '$tgl'  AND CaseDetail = '1' And c.[PatientCode] = '$cari'");
    }

    public function caripasientgl($cari)
    {
        date_default_timezone_set("Asia/jakarta");
        $tgl = date('Y-m-d');
        return $this->db->query("SELECT *, d.FirstName as namaDokter , d.LastName as lasNameDokter 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  [Intake Date] = '$cari'  AND CaseDetail = '1'");
    }

}