<?php

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



class Dashboard extends CI_Controller

{

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     * 		http://example.com/index.php/welcome
     *	- or -
     * 		http://example.com/index.php/welcome/index
     *	- or -
     * Sin
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/userguide3/general/urls.html
     */



    public function index()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }


        $akses = $this->session->userdata("kd_akses");

        $app = $this->session->userdata("kd_app");

        $user = $this->session->userdata("nm_akses");


        $data['akses'] = $akses;

        $data['app'] = $app;

        $data['user'] = $user;

        $akses_valid = ['1010', '1001', '1006', '9999', '999', '101', '112', '999', '1007', 'FARMASI', 'PT', 'DIR', 'RMI', 'IGD', 'ICU', 'AKT', 'GZI', '168', 'RAD', "MUTU", "1011"];



        if (in_array($akses, $akses_valid)) { //UBAH KODE APP nya disini aja kalo mau masuk halaman mana aja 

            $akses = $this->session->userdata("kd_akses");

            $app = $this->session->userdata("kd_app");


            $tgl_awal = date('d/m/Y');

            $tgl_akhir = date('d/m/Y');



            $datai["TANGGAL_AWAL"]    = $tgl_awal;

            $data["TANGGAL_PERIKSA"]    = $tgl_awal;

            $datai["TANGGAL_AKHIR"]    = $tgl_akhir;

            $curl = curl_init();



            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_smf',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => $datai

            ));



            $response = curl_exec($curl);



            curl_close($curl);

            $json =  str_replace('\r\n     ', "---0", $response);

            $json =  str_replace('\r\n', "---", $json);

            $json = json_decode($json);



            $curl = curl_init();



            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_smf_sum',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => $datai

            ));



            $response = curl_exec($curl);



            curl_close($curl);

            $jsoni =  str_replace('\r\n     ', "---0", $response);

            $jsoni =  str_replace('\r\n', "---", $jsoni);

            $jsoni = json_decode($jsoni);



            $curl = curl_init();



            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_inap_sum',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => $datai

            ));



            $response = curl_exec($curl);



            curl_close($curl);

            $jsono =  str_replace('\r\n     ', "---0", $response);

            $jsono =  str_replace('\r\n', "---", $jsono);

            $jsono = json_decode($jsono);



            $curl = curl_init();



            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd_sum',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => $datai

            ));



            $response = curl_exec($curl);



            curl_close($curl);

            $jsonu =  str_replace('\r\n     ', "---0", $response);

            $jsonu =  str_replace('\r\n', "---", $jsonu);

            $jsonu = json_decode($jsonu);



            $curl = curl_init();



            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => $datai

            ));



            $response = curl_exec($curl);



            curl_close($curl);

            $jsonoa =  str_replace('\r\n     ', "---0", $response);

            $jsonoa =  str_replace('\r\n', "---", $jsonoa);

            $jsonoa = json_decode($jsonoa);



            $curl = curl_init();



            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_inap',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => $datai

            ));



            $response = curl_exec($curl);



            curl_close($curl);

            $jsone =  str_replace('\r\n     ', "---0", $response);

            $jsone =  str_replace('\r\n', "---", $jsone);

            $jsone = json_decode($jsone);



            $curl = curl_init();

            //API DATA TAMPIL IGD LAMA-BARU

            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd_lama_baru',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => $datai

            ));



            $response = curl_exec($curl);



            curl_close($curl);

            $jsonf =  str_replace('\r\n     ', "---0", $response);

            $jsonf =  str_replace('\r\n', "---", $jsonf);

            $jsonf = json_decode($jsonf);



            $curl = curl_init();



            //API DATA TAMPIL POLI LAMA-BARU

            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_poli_lama_baru',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => $datai

            ));



            $response = curl_exec($curl);



            curl_close($curl);

            $jsong =  str_replace('\r\n     ', "---0", $response);

            $jsong =  str_replace('\r\n', "---", $jsong);

            $jsong = json_decode($jsong);



            $curl = curl_init();



            //API DATA TAMPIL KETERSEDIAN TEMPAT TIDUR

            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_ketersediaan_tempat_tidur',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => $datai

            ));



            $response = curl_exec($curl);



            curl_close($curl);

            $jsonh =  str_replace('\r\n     ', "---0", $response);

            $jsonh =  str_replace('\r\n', "---", $jsonh);

            $jsonh = json_decode($jsonh);



            // $curl = curl_init();



            $curl = curl_init();



            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/service_rs/daftar_online',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => $datai

            ));



            $response = curl_exec($curl);



            curl_close($curl);
            $jsond =  str_replace('\r\n     ', "---0", $response);
            $jsond =  str_replace('\r\n', "---", $jsond);
            $jsond = json_decode($jsond);


            $curl = curl_init();
            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/service_rs/inap_penjamin',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'POST',
                CURLOPT_POSTFIELDS => $datai

            ));

            $response = curl_exec($curl);

            curl_close($curl);
            $jsonp =  str_replace('\r\n     ', "---0", $response);
            $jsonp =  str_replace('\r\n', "---", $jsonp);
            $jsonp = json_decode($jsonp);


            $curl = curl_init();
            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/service_rs/inap_lama_baru',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'POST',
                CURLOPT_POSTFIELDS => $datai

            ));

            $response = curl_exec($curl);

            curl_close($curl);
            $jsoninap =  str_replace('\r\n     ', "---0", $response);
            $jsoninap =  str_replace('\r\n', "---", $jsoninap);
            $jsoninap = json_decode($jsoninap);



            $data["pasienrajal"]                    = $json;
            $data["pasienrajaltotal"]               = $jsoni;
            $data["pasienranap"]                    = $jsone;
            $data["pasienranaptotal"]               = $jsono;
            $data["pasieninaplamabaru"]             = $jsoninap;
            $data["inappenjamin"]                   = $jsonp;
            $data["pasienigdtotal"]                 = $jsonu;
            $data["pasienigd"]                      = $jsonoa;
            $data["pasienigdlamabaru"]              = $jsonf;
            $data["pasienpolilamabaru"]             = $jsong;
            $data["ketersediantt"]                  = $jsonh;
            $data["daftaronlinerekap"]              = $jsond;
            $data["akses"]                          = $akses;
            $data["app"]                            = $app;

            $data["tglawal"]                        = date('Y-m-d');
            $data["tglakhir"]                        = date('Y-m-d');
            $this->load->view('dashboard/header', $data);
            $this->load->view('dashboard/dashboardlayananan', $data);
        } else {

            $files = glob('./uploads/*.pdf'); // Ambil semua file PDF

            $file_data = [];



            foreach ($files as $file) {

                $file_name = basename($file); // Hanya nama file

                $file_data[] = [

                    'file_name' => $file_name,

                    'file_path' => base_url('uploads/' . $file_name),

                ];
            }

            $this->load->view('header', $data);

            $this->load->view('pdf', ['file_data' => $file_data]);
        }
    }





    public function menejemen()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('index', $data);
    }

    public function rujukan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('rujuk', $data);
    }



    public function demografiusia()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }



        $akses = $this->session->userdata("kd_akses");

        $app = $this->session->userdata("kd_app");



        $tgl_awal = date('d/m/Y');

        $tgl_akhir = date('d/m/Y');



        $datai["TANGGAL_AWAL"]    = $tgl_awal;

        $datai["TANGGAL_AKHIR"]    = $tgl_akhir;



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/demografi_kurang_satu_tahun',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsona =  str_replace('\r\n     ', "---0", $response);

        $jsona =  str_replace('\r\n', "---", $jsona);

        $jsona = json_decode($jsona);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/demografi_satu_sampai_tiga_tahun',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonb =  str_replace('\r\n     ', "---0", $response);

        $jsonb =  str_replace('\r\n', "---", $jsonb);

        $jsonb = json_decode($jsonb);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/demografi_tiga_sampai_lima_tahun',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonc =  str_replace('\r\n     ', "---0", $response);

        $jsonc =  str_replace('\r\n', "---", $jsonc);

        $jsonc = json_decode($jsonc);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/demografi_lima_sampai_delapanbelas_tahun',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsond =  str_replace('\r\n     ', "---0", $response);

        $jsond =  str_replace('\r\n', "---", $jsond);

        $jsond = json_decode($jsond);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/demografi_delapanbelas_sampai_limadepalan_tahun',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsone =  str_replace('\r\n     ', "---0", $response);

        $jsone =  str_replace('\r\n', "---", $jsone);

        $jsone = json_decode($jsone);





        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/demografi_lebihdari_limadepalan_tahun',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonf =  str_replace('\r\n     ', "---0", $response);

        $jsonf =  str_replace('\r\n', "---", $jsonf);

        $jsonf = json_decode($jsonf);



        $data["usiakurang1thn"]                    = $jsona;

        $data["usia1sampai3thn"]               = $jsonb;

        $data["usia3sampai5thn"]               = $jsonc;

        $data["usia5sampai18thn"]                 = $jsond;

        $data["usia18sampai58thn"]                 = $jsone;

        $data["usia58thnlebih"]                 = $jsonf;

        $data["akses"]               = $akses;

        $data["app"]               = $app;

        $data["tgl_awal"]        = date('Y-m-d');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('dashboard/header', $data);

        $this->load->view('dashboard/datademografi_view', $data);
    }





    public function datarekapigdkeuangan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $akses = $this->session->userdata("kd_akses");

        $app = $this->session->userdata("kd_app");



        $tgl_awal = date('d/m/Y');

        $tgl_akhir = date('d/m/Y');



        $datai["TANGGAL_AWAL"]    = $tgl_awal;

        $datai["TANGGAL_AKHIR"]    = $tgl_akhir;



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/demografi_kurang_satu_tahun',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsona =  str_replace('\r\n     ', "---0", $response);

        $jsona =  str_replace('\r\n', "---", $jsona);

        $jsona = json_decode($jsona);





        $data["IGDrawatjalan"]                    = $jsona;

        $data["akses"]               = $akses;

        $data["app"]               = $app;

        $data["tgl_awal"]        = date('Y-m-d');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('dashboard/header', $data);

        $this->load->view('dashboard/datarekapigd', $data);
    }



    public function demografialamat()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }



        $akses = $this->session->userdata("kd_akses");

        $app = $this->session->userdata("kd_app");



        $tgl_awal = date('d/m/Y');

        $tgl_akhir = date('d/m/Y');



        $datai["TANGGAL_AWAL"]    = $tgl_awal;

        $datai["TANGGAL_AKHIR"]    = $tgl_akhir;



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/demografi_kabupate_kota',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsona =  str_replace('\r\n     ', "---0", $response);

        $jsona =  str_replace('\r\n', "---", $jsona);

        $jsona = json_decode($jsona);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/demografi_kecamatan',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonb =  str_replace('\r\n     ', "---0", $response);

        $jsonb =  str_replace('\r\n', "---", $jsonb);

        $jsonb = json_decode($jsonb);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/demografi_desa',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonc =  str_replace('\r\n     ', "---0", $response);

        $jsonc =  str_replace('\r\n', "---", $jsonc);

        $jsonc = json_decode($jsonc);





        $data["demokabupatenkota"]                = $jsona;

        $data["demokecamatan"]               = $jsonb;

        $data["demodesa"]               = $jsonc;

        $data["akses"]               = $akses;

        $data["app"]               = $app;

        $data["tgl_awal"]        = date('Y-m-d');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('dashboard/header', $data);

        $this->load->view('dashboard/datademografi_view', $data);
    }



    public function dashboardpasienigd()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }



        $akses = $this->session->userdata("kd_akses");

        $app = $this->session->userdata("kd_app");



        $tgl_awal = date('d/m/Y');

        $tgl_akhir = date('d/m/Y');



        $datai["TANGGAL_AWAL"]    = $tgl_awal;

        $datai["TANGGAL_AKHIR"]    = $tgl_awal;



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd_lama_baru',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsona =  str_replace('\r\n     ', "---0", $response);

        $jsona =  str_replace('\r\n', "---", $jsona);

        $jsona = json_decode($jsona);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd_sum',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonb =  str_replace('\r\n     ', "---0", $response);

        $jsonb =  str_replace('\r\n', "---", $jsonb);

        $jsonb = json_decode($jsonb);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonc =  str_replace('\r\n     ', "---0", $response);

        $jsonc =  str_replace('\r\n', "---", $jsonc);

        $jsonc = json_decode($jsonc);





        $data["igdlamabaru"]                = $jsona;

        $data["igdhariinitotal"]               = $jsonb;

        $data["igdtampilhariini"]               = $jsonc;

        $data["akses"]               = $akses;

        $data["app"]               = $app;

        $data["tgl_awal"]        = date('Y-m-d');

        $this->load->view('dashboard/header', $data);

        $this->load->view('dashboard/dashboardpasienigd', $data);
    }





    public function tampildatarekapigd()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }



        $akses = $this->session->userdata("kd_akses");

        $app = $this->session->userdata("kd_app");



        $tgl_awal = date('d/m/Y');

        $tgl_akhir = $tgl_awal;



        $datai["TANGGAL_AWAL"]    = $tgl_awal;

        $datai["TANGGAL_AKHIR"]    = $tgl_akhir;



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsona =  str_replace('\r\n     ', "---0", $response);

        $jsona =  str_replace('\r\n', "---", $jsona);

        $jsona = json_decode($jsona);



        $data["tampilrekapigdpasien"]                = $jsona;

        $data["akses"]               = $akses;

        $data["app"]               = $app;

        $data["tgl_awal"]        = date('Y-m-d');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('dashboard/header', $data);

        $this->load->view('dashboard/datarekapigd', $data);
    }



    public function pasiensmfpoli()
    {
        if (!$this->session->userdata('berhasil_loginu')) {
            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $akses = $this->session->userdata("kd_akses");
        $app = $this->session->userdata("kd_app");

        // ==========================================================
        // PERBAIKAN: Tangkap POST dari form. Jika kosong, beri default
        // ==========================================================
        $post_awal = $this->input->post('tanggal_awal');
        $post_akhir = $this->input->post('tanggal_akhir');

        // Set default: Tanggal 1 bulan ini s/d Hari ini (agar data langsung muncul)
        $tgl_awal_raw = !empty($post_awal) ? $post_awal : date('Y-m-d');
        $tgl_akhir_raw = !empty($post_akhir) ? $post_akhir : date('Y-m-d');

        // Format ke d/m/Y untuk dikirim ke API
        $datai["TANGGAL_AWAL"]  = date('d/m/Y', strtotime($tgl_awal_raw));
        $datai["TANGGAL_AKHIR"] = date('d/m/Y', strtotime($tgl_akhir_raw));

        // ==========================================================
        // SISA KODE CURL ANDA TETAP SAMA TIDAK ADA YANG DIUBAH
        // ==========================================================

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_poli_lama_baru',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS =>  $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsona =  str_replace('\r\n     ', "---0", $response);
        $jsona =  str_replace('\r\n', "---", $jsona);
        $jsona = json_decode($jsona);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_smf_sum',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS =>  $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsonb =  str_replace('\r\n     ', "---0", $response);
        $jsonb =  str_replace('\r\n', "---", $jsonb);
        $jsonb = json_decode($jsonb);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_smf',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS =>  $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsonc =  str_replace('\r\n     ', "---0", $response);
        $jsonc =  str_replace('\r\n', "---", $jsonc);
        $jsonc = json_decode($jsonc);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/service_rs/poli_per_jam',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsonpjm =  str_replace('\r\n     ', "---0", $response);
        $jsonpjm =  str_replace('\r\n', "---", $jsonpjm);
        $jsonpjm = json_decode($jsonpjm);

        // ==========================================================
        $data["ratapoliperjam"]         = $jsonpjm;
        $data["pasienpolilamabaru"]     = $jsona;
        $data["pasienrajaltotal"]       = $jsonb;
        $data["tampilpasienrajal"]      = $jsonc;
        $data["akses"]                  = $akses;
        $data["app"]                    = $app;

        // PERBAIKAN: Kembalikan format Y-m-d ke view agar value form terisi
        $data["tgl_awal"]               = $tgl_awal_raw;
        $data["tgl_akhir"]              = $tgl_akhir_raw;

        $this->load->view('dashboard/header', $data);
        $this->load->view('dashboard/pasiensmfpoli', $data);
    }



    public function datarawatinap()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }



        $akses = $this->session->userdata("kd_akses");

        $app = $this->session->userdata("kd_app");



        $tgl_awal = date('d/m/Y');



        $datai["TANGGAL_AWAL"]    = $tgl_awal;

        $datai["TANGGAL_AKHIR"]    = $tgl_awal;



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_inap',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsona =  str_replace('\r\n     ', "---0", $response);

        $jsona =  str_replace('\r\n', "---", $jsona);

        $jsona = json_decode($jsona);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_inap_sum',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonb =  str_replace('\r\n     ', "---0", $response);

        $jsonb =  str_replace('\r\n', "---", $jsonb);

        $jsonb = json_decode($jsonb);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_ketersediaan_tempat_tidur',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS =>  $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonc =  str_replace('\r\n     ', "---0", $response);

        $jsonc =  str_replace('\r\n', "---", $jsonc);

        $jsonc = json_decode($jsonc);





        $data["pasieninap"]                = $jsona;

        $data["totalpasieninap"]               = $jsonb;

        $data["ketersediantt"]               = $jsonc;

        $data["akses"]               = $akses;

        $data["app"]               = $app;

        $data["tgl_awal"]        = date('Y-m-d');

        $this->load->view('dashboard/header', $data);

        $this->load->view('dashboard/pasienrawatinap', $data);
    }



    public function datajadwaloperasiikbs()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('jadwakoperasiikbs', $data);
    }



    public function datapasienmeninggal()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-d');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('datapasienmeninggal', $data);
    }

    public function datapasienISPA()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('dataispa_view', $data);
    }



    public function pasienigdtotal()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pasienigdtotal', $data);
    }



    public function pasienigdbatal()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pasienigdbatal', $data);
    }



    public function pasienigddilayani()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pasienigddilayani', $data);
    }



    public function pasienigdkeinap()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pasienigdkeinap', $data);
    }




    public function igdrespontime()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('datarespontimeigd', $data);
    }


    public function surveilanppi()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('ppipasanginfus', $data);
    }


    public function surveilanwaktutunggukasir()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('reratawaktupasienpulang', $data);
    }



    public function surveilanwaktutungguigd()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('reratapasiendilayaniigd', $data);
    }



    public function surveilanwaktutunggupoli()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('reratawaktutunggupoli', $data);
    }



    public function surveilanwaktudilayanidokter()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('reratawaktudilayanidokter', $data);
    }






    public function rajalhomecare()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('rajalhomecare', $data);
    }





    public function pasienrajaltotal()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pasienrajaltotal', $data);
    }



    public function jadwalpoliklinikrajal()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-d');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('jadwalpoliklinik', $data);
    }





    public function politotalkeuangan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('politotalkeuangan', $data);
    }



    public function polibatalkeuangan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('polibatalkeuangan', $data);
    }



    public function polidilayanikeuangan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('polidilayanikeuangan', $data);
    }


    public function polihomecarekeuangan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('polihomecarekeuangan', $data);
    }



    public function pasienrajalbatal()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pasienrajalbatal', $data);
    }



    public function pasienrajaldilayani()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pasienrajaldilayani', $data);
    }


    public function datarm_pasienrajaldilayani()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('rm_datarajal_dilayani_v', $data);
    }



    public function rajalperpolidilayani()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $data["kd_jenispoli"]  = $this->input->post('kd_jenispoli');

        $this->load->view('header', $data);

        $this->load->view('rajaldilayaniperpoli', $data);
    }


    public function rajalperdokter()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $data["kd_jenisdokter"]  = $this->input->post('kd_jenisdokter');

        $this->load->view('header', $data);

        $this->load->view('rajalperdokterdilayani', $data);
    }


    public function ranapperdokter()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        // $data["kd_jenisdokter"]  = $this->input->post('kd_jenisdokter');
        $this->load->view('header', $data);
        $this->load->view('ranapperdokter', $data);
    }



    public function pasientransfer()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pasienrajaltransfer', $data);
    }



    public function antreanpolirajal()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('antreanpoli', $data);
    }



    public function cekhfis()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-d');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('cekhfisdokter', $data);
    }



    //DEMOGRAFI USIA PER POLI
    public function demousiaperpoli()
    {

        if (!$this->session->userdata('berhasil_loginu')) {
            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_jenispoli"]  = $this->input->post('kd_jenispoli');

        $this->load->view('header', $data);
        $this->load->view('demousiaperpoli', $data);
    }

    public function datademoperpoli()
    {

        if (!$this->session->userdata('berhasil_loginu')) {
            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_jenispoli"]  = $this->input->post('kd_jenispoli');

        $this->load->view('header', $data);
        $this->load->view('datademografiperpoli_view', $data);
    }




    //DEMOGRAFI JENIS KELAMIN PER POLI
    public function demojeniskelperpoli()
    {

        if (!$this->session->userdata('berhasil_loginu')) {
            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_jenispoli"]  = $this->input->post('kd_jenispoli');
        $this->load->view('header', $data);
        $this->load->view('demojeniskelperpoli', $data);
    }

    public function databorlostoiruangan()

    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('databorlostoi_perruangan', $data);
    }




    public function rekapdemorawatjalan()

    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-d');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('rekapdemografirajal', $data);
    }

    public function datapolirujukrajal()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('datapolikonsul_view', $data);
    }


    public function datarekapdemografi()

    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-d');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('datademorekap_view', $data);
    }


    public function rekapdemorawatinap()

    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('rekapdemografiranap', $data);
    }


    public function rekapdatademoigd()

    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('rekapdemografiigd', $data);
    }





    public function demografipekerjaan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('demografipekerjaan', $data);
    }



    public function demografijeniskelamin()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('demografijeniskelamin', $data);
    }



    public function demografiasalkeinap()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('demografiasalkeinap', $data);
    }


    public function pesertasehatmenu()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pesertasehatvaksin', $data);
    }



    public function pesertasehattindakanmenu()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pesertasehattindakan', $data);
    }



    public function dokumen1()

    {

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");



        $files = glob('./uploads/*.pdf'); // Ambil semua file PDF

        $file_data = [];



        foreach ($files as $file) {

            $file_name = basename($file); // Hanya nama file

            $file_data[] = [

                'file_name' => $file_name,

                'file_path' => base_url('uploads/' . $file_name),

            ];
        }

        $this->load->view('header', $data);

        $this->load->view('pdf', ['file_data' => $file_data]);
    }

    public function dokumen()
    {
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app']   = $this->session->userdata("kd_app");

        // Tidak perlu pakai glob() lagi di sini karena file dipanggil lewat AJAX
        $this->load->view('header', $data);
        $this->load->view('pdf', $data);
    }


    public function file()
    {
        $tahun = preg_replace('/[^0-9]/', '', $this->input->get('tahun') ?: date('Y'));
        $pokja = preg_replace('/[^0-9]/', '', $this->input->get('pokja') ?: '1');
    
        $folder = FCPATH . 'uploads/dokumen/' . $tahun . '/pokja_' . $pokja . '/';
        $files  = [];
    
        if (is_dir($folder)) {
            // glob semua file, tidak hanya .pdf — untuk debug lihat apa yang sebenarnya ada
            foreach (glob($folder . '*') as $filepath) {
                // Hanya proses file (bukan subfolder)
                if (!is_file($filepath)) continue;
    
                $fname   = basename($filepath);
                $fsize   = filesize($filepath);
                $fdate   = date('d M Y', filemtime($filepath));
                $sizeFmt = $fsize < 1048576
                    ? round($fsize / 1024) . ' KB'
                    : round($fsize / 1048576, 1) . ' MB';
    
                $files[] = [
                    'file_name'   => $fname,
                    'file_path'   => base_url('uploads/dokumen/' . $tahun . '/pokja_' . $pokja . '/' . rawurlencode($fname)),
                    'file_size'   => $sizeFmt,
                    'upload_date' => $fdate,
                ];
            }
        }
    
        usort($files, fn($a, $b) => strcmp($a['file_name'], $b['file_name']));
    
        header('Content-Type: application/json');
        echo json_encode($files);
    }


    public function file_counts()
    {
        $tahun = $this->input->get('tahun') ?: date('Y');
        $tahun = preg_replace('/[^0-9]/', '', $tahun);
    
        $counts = [];
        for ($i = 1; $i <= 15; $i++) {
            $folder    = FCPATH . 'uploads/dokumen/' . $tahun . '/pokja_' . $i . '/';
            $counts[$i] = is_dir($folder) ? count(glob($folder . '*.pdf')) : 0;
        }
    
        echo json_encode($counts);
    }
        

    // POST upload
    // public function upload_pdf() {
    //     $tahun = $this->input->post('tahun');
    //     $pokja = $this->input->post('pokja');
    //     $dest  = FCPATH . 'uploads/dokumen/' . $tahun . '/pokja_' . $pokja . '/';
        
    //     $config = ['upload_path' => $dest, 'allowed_types' => 'pdf', 'max_size' => 2048];
    //     $this->load->library('upload', $config);
        
    //     if ($this->upload->do_upload('file')) {
    //         echo json_encode(['status' => 'success']);
    //     } else {
    //         echo json_encode(['status' => 'error', 'message' => $this->upload->display_errors()]);
    //     }
    // }

    public function upload_pdf()
    {
        $tahun = $this->input->post('tahun');
        $pokja = $this->input->post('pokja');
    
        // Sanitasi
        $tahun = preg_replace('/[^0-9]/', '', $tahun);
        $pokja = preg_replace('/[^0-9]/', '', $pokja);
    
        if (!$tahun || !$pokja) {
            echo json_encode(['status' => 'error', 'message' => 'Parameter tahun/pokja tidak valid.']);
            return;
        }
    
        $uploadPath = FCPATH . 'uploads/dokumen/' . $tahun . '/pokja_' . $pokja . '/';
    
        // Buat folder jika belum ada
        if (!is_dir($uploadPath)) {
            mkdir($uploadPath, 0755, true);
        }
    
        $config = [
            'upload_path'   => $uploadPath,
            'allowed_types' => 'pdf',
            'max_size'      => 2048, // KB = 2 MB
            'encrypt_name'  => FALSE, // Simpan nama asli; ganti TRUE jika ingin nama acak
        ];
    
        $this->load->library('upload', $config);
    
        if ($this->upload->do_upload('file')) {
            echo json_encode(['status' => 'success']);
        } else {
            echo json_encode([
                'status'  => 'error',
                'message' => strip_tags($this->upload->display_errors()),
            ]);
        }
    }

    // POST hapus
    public function hapus1()
    {
        $tahun    = $this->input->post('tahun');
        $pokja    = $this->input->post('pokja');
        $fileName = $this->input->post('file');
    
        // Sanitasi — hanya angka untuk tahun & pokja
        $tahun = preg_replace('/[^0-9]/', '', $tahun);
        $pokja = preg_replace('/[^0-9]/', '', $pokja);
    
        // Sanitasi nama file — larang path traversal
        $fileName = basename($fileName);
    
        if (!$tahun || !$pokja || !$fileName) {
            echo json_encode(['status' => 'error', 'message' => 'Parameter tidak lengkap.']);
            return;
        }
    
        $filePath = FCPATH . 'uploads/dokumen/' . $tahun . '/pokja_' . $pokja . '/' . $fileName;
    
        if (file_exists($filePath) && unlink($filePath)) {
            echo json_encode(['status' => 'success']);
        } else {
            echo json_encode(['status' => 'error', 'message' => 'File tidak ditemukan atau gagal dihapus.']);
        }
    }

    public function penjaminpoli()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('penjaminpoli', $data);
    }



    public function penjaminigd()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('penjaminigd', $data);
    }

    public function utama()
    {

        $akses = $this->session->userdata("kd_akses");
        $app = $this->session->userdata("kd_app");

        // ========================================================
        // PERBAIKAN 1 & 2: TANGKAP POST DAN KONVERSI FORMAT TANGGAL
        // ========================================================
        $post_tgl_awal = $this->input->post('tanggal_awal');
        $post_tgl_akhir = $this->input->post('tanggal_akhir');

        // Cek apakah ada data filter yang dikirim dari View
        if (!empty($post_tgl_awal) && !empty($post_tgl_akhir)) {
            // Konversi format Y-m-d (dari HTML) menjadi d/m/Y (untuk API)
            $tgl_awal_api  = date('d/m/Y', strtotime($post_tgl_awal));
            $tgl_akhir_api = date('d/m/Y', strtotime($post_tgl_akhir));

            // Simpan format asli untuk ditampilkan kembali di kotak input HTML
            $tgl_awal_view  = $post_tgl_awal;
            $tgl_akhir_view = $post_tgl_akhir;
        } else {
            // Jika baru pertama kali buka (belum filter), gunakan default hari ini
            $tgl_awal_api  = date('d/m/Y');
            $tgl_akhir_api = date('d/m/Y');

            $tgl_awal_view  = date('Y-m-d');
            $tgl_akhir_view = date('Y-m-d');
        }

        // Masukkan ke parameter array untuk dikirim ke API
        $datai["TANGGAL_AWAL"]  = $tgl_awal_api;
        $datai["TANGGAL_AKHIR"] = $tgl_akhir_api;
        // ========================================================

        // PROSES MENGAMBIL API (KODE ANDA TETAP SAMA)
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_smf',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $json =  str_replace('\r\n     ', "---0", $response);
        $json =  str_replace('\r\n', "---", $json);
        $json = json_decode($json);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_smf_sum',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsoni =  str_replace('\r\n     ', "---0", $response);
        $jsoni =  str_replace('\r\n', "---", $jsoni);
        $jsoni = json_decode($jsoni);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_inap_sum',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsono =  str_replace('\r\n     ', "---0", $response);
        $jsono =  str_replace('\r\n', "---", $jsono);
        $jsono = json_decode($jsono);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd_sum',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsonu =  str_replace('\r\n     ', "---0", $response);
        $jsonu =  str_replace('\r\n', "---", $jsonu);
        $jsonu = json_decode($jsonu);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsonoa =  str_replace('\r\n     ', "---0", $response);
        $jsonoa =  str_replace('\r\n', "---", $jsonoa);
        $jsonoa = json_decode($jsonoa);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_inap',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsone =  str_replace('\r\n     ', "---0", $response);
        $jsone =  str_replace('\r\n', "---", $jsone);
        $jsone = json_decode($jsone);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd_lama_baru',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsonf =  str_replace('\r\n     ', "---0", $response);
        $jsonf =  str_replace('\r\n', "---", $jsonf);
        $jsonf = json_decode($jsonf);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_poli_lama_baru',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsong =  str_replace('\r\n     ', "---0", $response);
        $jsong =  str_replace('\r\n', "---", $jsong);
        $jsong = json_decode($jsong);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_ketersediaan_tempat_tidur',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $jsonh =  str_replace('\r\n     ', "---0", $response);
        $jsonh =  str_replace('\r\n', "---", $jsonh);
        $jsonh = json_decode($jsonh);


        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/service_rs/dashboard_poli',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai // Menggunakan array body yang sama (TANGGAL_AWAL & TANGGAL_AKHIR)
        ));

        $response = curl_exec($curl);
        curl_close($curl);
        $response = str_replace('\r\n     ', "---0", $response);
        $response = str_replace('\r\n', "---", $response);
        $json_dashboardpoli = json_decode($response);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => '103.255.241.146/api/service_rs/inap_lama_baru',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $datai // Menggunakan array body yang sama (TANGGAL_AWAL & TANGGAL_AKHIR)
        ));

        $response = curl_exec($curl);
        curl_close($curl);
        $response = str_replace('\r\n     ', "---0", $response);
        $response = str_replace('\r\n', "---", $response);
        $json_inaplamabaru = json_decode($response);



        // Lalu lemparkan datanya ke View


        $data["pasienrajal"]            = $json;
        $data["pasienrajaltotal"]       = $jsoni;
        $data["dashboardpoli"]          = $json_dashboardpoli;
        $data["pasieninaplamabaru"]     = $json_inaplamabaru;
        $data["pasienranap"]            = $jsone;
        $data["pasienranaptotal"]       = $jsono;
        $data["pasienigdtotal"]         = $jsonu;
        $data["pasienigd"]              = $jsonoa;
        $data["pasienigdlamabaru"]      = $jsonf;
        $data["pasienpolilamabaru"]     = $jsong;
        $data["ketersediantt"]          = $jsonh;
        $data["akses"]                  = $akses;
        $data["app"]                    = $app;

        // ========================================================
        // PERBAIKAN 3: KIRIM TANGGAL AWAL DAN AKHIR KE VIEW 
        // ========================================================
        $data["tglawal"]                = $tgl_awal_view;
        $data["tglakhir"]               = $tgl_akhir_view;

        $this->load->view('header', $data);
        $this->load->view('dashboard/dashboardlayananan', $data);
    }





    public function penjamininap()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('penjamininap', $data);
    }



    public function pasieninapdpjp()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pasieninapdpjp', $data);
    }



    public function pasieninaptotal()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('pasieninaptotal', $data);
    }


    public function detailinapview()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('detail_px_inap_al_v', $data);
    }

    public function pasienbarudata()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data['user'] = $this->session->userdata("nm_akses");

        $this->load->view('header', $data);
        $this->load->view('px_baru_daftaronline_v', $data);
    }



    public function batalresumeranap()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $this->load->view('header', $data);

        $this->load->view('batalresume', $data);
    }



    public function batalsep()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $this->load->view('header', $data);

        $this->load->view('batalsep', $data);
    }


    public function updateseprm()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["nm_dokter"]  = $this->input->post('nm_dokter');
        $this->load->view('header', $data);
        $this->load->view('updatedatasep', $data);
    }



    // public function dashboardkeuangan()

    // {

    //     if (!$this->session->userdata('berhasil_loginu')) {

    //         redirect(''); // Jika tidak login, redirect ke halaman login

    //     }

    //     $data['akses'] = $this->session->userdata("kd_akses");

    //     $data['app'] = $this->session->userdata("kd_app");

    //     $data["tglawal"]        = date('Y-m-d');

    //     $data["tglakhir"]        = date('Y-m-d');

    //     $this->load->view('header', $data);

    //     $this->load->view('dashboardlayanankeuangan', $data);

    // }



    public function dashboardlayanankeuangan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $akses = $this->session->userdata("kd_akses");



        $app = $this->session->userdata("kd_app");

        $tgl_awal = date('d/m/Y');

        $tgl_akhir = date('d/m/Y');



        $datai["TANGGAL_AWAL"]    = $tgl_awal;

        $data["TANGGAL_PERIKSA"]    = $tgl_awal;

        $datai["TANGGAL_AKHIR"]    = $tgl_akhir;

        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_smf',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $json =  str_replace('\r\n     ', "---0", $response);

        $json =  str_replace('\r\n', "---", $json);

        $json = json_decode($json);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_smf_sum',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsoni =  str_replace('\r\n     ', "---0", $response);

        $jsoni =  str_replace('\r\n', "---", $jsoni);

        $jsoni = json_decode($jsoni);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_inap_sum',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsono =  str_replace('\r\n     ', "---0", $response);

        $jsono =  str_replace('\r\n', "---", $jsono);

        $jsono = json_decode($jsono);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd_sum',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonu =  str_replace('\r\n     ', "---0", $response);

        $jsonu =  str_replace('\r\n', "---", $jsonu);

        $jsonu = json_decode($jsonu);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonoa =  str_replace('\r\n     ', "---0", $response);

        $jsonoa =  str_replace('\r\n', "---", $jsonoa);

        $jsonoa = json_decode($jsonoa);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_inap',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsone =  str_replace('\r\n     ', "---0", $response);

        $jsone =  str_replace('\r\n', "---", $jsone);

        $jsone = json_decode($jsone);



        $curl = curl_init();

        //API DATA TAMPIL IGD LAMA-BARU

        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd_lama_baru',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonf =  str_replace('\r\n     ', "---0", $response);

        $jsonf =  str_replace('\r\n', "---", $jsonf);

        $jsonf = json_decode($jsonf);



        $curl = curl_init();



        //API DATA TAMPIL POLI LAMA-BARU

        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_poli_lama_baru',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsong =  str_replace('\r\n     ', "---0", $response);

        $jsong =  str_replace('\r\n', "---", $jsong);

        $jsong = json_decode($jsong);



        $curl = curl_init();



        //API DATA TAMPIL KETERSEDIAN TEMPAT TIDUR

        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_ketersediaan_tempat_tidur',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonh =  str_replace('\r\n     ', "---0", $response);

        $jsonh =  str_replace('\r\n', "---", $jsonh);

        $jsonh = json_decode($jsonh);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/daftar_online',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsond =  str_replace('\r\n     ', "---0", $response);

        $jsond =  str_replace('\r\n', "---", $jsond);

        $jsond = json_decode($jsond);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/inap_penjamin',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonp =  str_replace('\r\n     ', "---0", $response);

        $jsonp =  str_replace('\r\n', "---", $jsonp);

        $jsonp = json_decode($jsonp);







        $data["pasienrajal"]                    = $json;

        $data["pasienrajaltotal"]               = $jsoni;

        $data["pasienranap"]                    = $jsone;

        $data["pasienranaptotal"]               = $jsono;

        $data["inappenjamin"]                   = $jsonp;

        $data["pasienigdtotal"]                 = $jsonu;

        $data["pasienigd"]                      = $jsonoa;

        $data["pasienigdlamabaru"]              = $jsonf;

        $data["pasienpolilamabaru"]             = $jsong;

        $data["ketersediantt"]                  = $jsonh;

        $data["daftaronlinerekap"]              = $jsond;

        $data["akses"]                          = $akses;

        $data["app"]                            = $app;

        $data["tglawal"]                        = date('Y-m-d');

        $data["tglakhir"]                        = date('Y-m-d');

        $this->load->view('dashboard/header', $data);

        $this->load->view('dashboard/dashboardlayanankeuangan', $data);
    }



    public function dashboardutamacoba()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $akses = $this->session->userdata("kd_akses");



        $app = $this->session->userdata("kd_app");

        $tgl_awal = date('d/m/Y');

        $tgl_akhir = date('d/m/Y');



        $datai["TANGGAL_AWAL"]    = $tgl_awal;

        $data["TANGGAL_PERIKSA"]    = $tgl_awal;

        $datai["TANGGAL_AKHIR"]    = $tgl_akhir;

        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_smf',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $json =  str_replace('\r\n     ', "---0", $response);

        $json =  str_replace('\r\n', "---", $json);

        $json = json_decode($json);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_smf_sum',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsoni =  str_replace('\r\n     ', "---0", $response);

        $jsoni =  str_replace('\r\n', "---", $jsoni);

        $jsoni = json_decode($jsoni);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_inap_sum',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsono =  str_replace('\r\n     ', "---0", $response);

        $jsono =  str_replace('\r\n', "---", $jsono);

        $jsono = json_decode($jsono);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd_sum',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonu =  str_replace('\r\n     ', "---0", $response);

        $jsonu =  str_replace('\r\n', "---", $jsonu);

        $jsonu = json_decode($jsonu);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonoa =  str_replace('\r\n     ', "---0", $response);

        $jsonoa =  str_replace('\r\n', "---", $jsonoa);

        $jsonoa = json_decode($jsonoa);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien_inap',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsone =  str_replace('\r\n     ', "---0", $response);

        $jsone =  str_replace('\r\n', "---", $jsone);

        $jsone = json_decode($jsone);



        $curl = curl_init();

        //API DATA TAMPIL IGD LAMA-BARU

        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_igd_lama_baru',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonf =  str_replace('\r\n     ', "---0", $response);

        $jsonf =  str_replace('\r\n', "---", $jsonf);

        $jsonf = json_decode($jsonf);



        $curl = curl_init();



        //API DATA TAMPIL POLI LAMA-BARU

        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_poli_lama_baru',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsong =  str_replace('\r\n     ', "---0", $response);

        $jsong =  str_replace('\r\n', "---", $jsong);

        $jsong = json_decode($jsong);



        $curl = curl_init();



        //API DATA TAMPIL KETERSEDIAN TEMPAT TIDUR

        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/tampil_ketersediaan_tempat_tidur',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonh =  str_replace('\r\n     ', "---0", $response);

        $jsonh =  str_replace('\r\n', "---", $jsonh);

        $jsonh = json_decode($jsonh);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/daftar_online',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsond =  str_replace('\r\n     ', "---0", $response);

        $jsond =  str_replace('\r\n', "---", $jsond);

        $jsond = json_decode($jsond);



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/service_rs/inap_penjamin',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

            CURLOPT_POSTFIELDS => $datai

        ));



        $response = curl_exec($curl);



        curl_close($curl);

        $jsonp =  str_replace('\r\n     ', "---0", $response);

        $jsonp =  str_replace('\r\n', "---", $jsonp);

        $jsonp = json_decode($jsonp);







        $data["pasienrajal"]                    = $json;

        $data["pasienrajaltotal"]               = $jsoni;

        $data["pasienranap"]                    = $jsone;

        $data["pasienranaptotal"]               = $jsono;

        $data["inappenjamin"]                   = $jsonp;

        $data["pasienigdtotal"]                 = $jsonu;

        $data["pasienigd"]                      = $jsonoa;

        $data["pasienigdlamabaru"]              = $jsonf;

        $data["pasienpolilamabaru"]             = $jsong;

        $data["ketersediantt"]                  = $jsonh;

        $data["daftaronlinerekap"]              = $jsond;

        $data["akses"]                          = $akses;

        $data["app"]                            = $app;

        $data["tglawal"]                        = date('Y-m-d');

        $data["tglakhir"]                        = date('Y-m-d');

        $this->load->view('dashboard/header', $data);

        $this->load->view('dashboard/dashboarddinamis', $data);
    }



    //dashboard Tampilan GIZI 

    public function reportgizi()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data['user'] = $this->session->userdata("nm_akses");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('reportdatagizi', $data);
    }


    public function reportgizimalnutrisi()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data['user'] = $this->session->userdata("nm_akses");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('reportmallnutrisigizi', $data);
    }

    public function homecarebilling()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('rekapkeupasienhomecare', $data);
    }

    public function reportdatamcu()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data['user'] = $this->session->userdata("nm_akses");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_grupmcu"]  = $this->input->post('kd_grupmcu');
        $this->load->view('header', $data);
        $this->load->view('datahasilmcu', $data);
    }


    public function reportdatamcucoba()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data['user'] = $this->session->userdata("nm_akses");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["institusi_asal"]  = $this->input->post('institusi_asal');
        $this->load->view('header', $data);
        $this->load->view('cobadatamcu', $data);
    }



    public function dataicdrajal()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data['user'] = $this->session->userdata("nm_akses");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('icddatareport', $data);
    }




    public function datahunianinap()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data['user'] = $this->session->userdata("nm_akses");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('datahunianranap', $data);
    }

    public function farmasipenjualan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('farmasipenjualannew', $data);
    }



    public function farmasiwaktuserah()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('waktuserahfarmasi', $data);
    }

    public function datapenjualanperobt()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_obat"]     = $this->input->post('kd_obat');
        $this->load->view('header', $data);
        $this->load->view('farmasipenjualannew', $data);
    }


    public function farmasidatastock()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["kd_gudang"]     = $this->input->post('kd_gudang');
        $this->load->view('header', $data);
        $this->load->view('datafarmasistok', $data);
    }

    public function dataSOfarmasi()
    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["kd_opname"]     = $this->input->post('kd_opname');
        $this->load->view('header', $data);
        $this->load->view('datafarmasiSO_view', $data);
    }


    public function farmasiPOobat()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('dataPOfarmasi_view', $data);
    }

    public function farmasiobatkronis()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('obatkronis_view', $data);
    }

    public function dataSRBPOnek()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('dataSRBponek_view', $data);
    }


    public function datapembelianobatall()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('farmasipembeliannew', $data);
    }



    public function datapembelianperobat()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_obat"]     = $this->input->post('kd_obat');
        $this->load->view('header', $data);
        $this->load->view('farmasipembelianperobat', $data);
    }

    public function datapembelianperpabrik()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_pabrik"]     = $this->input->post('kd_pabrik');
        $this->load->view('header', $data);
        $this->load->view('farmasipembelianperobat', $data);
    }





    public function datapasienprb()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }



        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-d');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('datapasienprb', $data);
    }



    public function farmasidatanarkotika()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('farmasiobatnarkotika', $data);
    }


    public function farmasidatapsikotropika()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('farmasiobatpsiko', $data);
    }




    public function laboratoriumdatajual()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('laboratoriumdatajual', $data);
    }



    public function radiologidatajual()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('radiologidatajual', $data);
    }

    public function dataradiologi()

    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_group_bayar"]  = $this->input->post('kd_group_bayar');
        $this->load->view('header', $data);

        $this->load->view('dataradiologi_view', $data);
    }




    public function datawaktutunggupoli()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('waktutunggupoli', $data);
    }



    public function billingharian()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');

        $this->load->view('header', $data);

        $this->load->view('billingharian', $data);
    }


    public function databillinghariannew()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');
        $this->load->view('header', $data);
        $this->load->view('databilling_keuangan_view', $data);
    }

    public function billingharianpenjamin()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');

        $this->load->view('header', $data);

        $this->load->view('billingharianpenjamin', $data);
    }



    public function billingkeuanganall()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');

        $this->load->view('header', $data);

        $this->load->view('billingkeuanganall', $data);
    }



    public function billingkeuangannonbpjs()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');

        $this->load->view('header', $data);

        $this->load->view('billingkeuangannonbpjs', $data);
    }


    public function keubillingnonbpjs_umum()

    {
        if (!$this->session->userdata('berhasil_loginu')) {
            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');
        $this->load->view('header', $data);
        $this->load->view('billingkeuangannonbpjs_umum', $data);
    }


    public function keubillingnonbpjs_asuransi()

    {
        if (!$this->session->userdata('berhasil_loginu')) {
            redirect(''); // Jika tidak login, redirect ke halaman login
        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');
        $this->load->view('header', $data);
        $this->load->view('billingkeuangannonbpjs_asuransi', $data);
    }




    public function billingharianicu()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('billingharianicu', $data);
    }



    public function rekapsirusbpjs_nonbpjs()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');

        $this->load->view('header', $data);

        $this->load->view('rekapsirusbpjsnonbpjs', $data);
    }



    public function rekapkeubpjs()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');

        $this->load->view('header', $data);

        $this->load->view('rekapkeudata_view', $data);
    }


    public function rekapkeubpjs_detailtagihan()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_pembayaran"]     = "A12";
        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');
        $this->load->view('header', $data);
        $this->load->view('rekapkeubpjs_detail_view', $data);
    }



    public function rekapkeunonbpjs()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');

        $this->load->view('header', $data);

        $this->load->view('rekapkeunonbpjs', $data);
    }



    public function rekapkeunonbpjs_umum()

    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');
        $this->load->view('header', $data);
        $this->load->view('datarekapsirusbpjsumum', $data);
    }


    public function rekapkeuhomecare()

    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $this->load->view('header', $data);
        $this->load->view('rekapkeuhomecare_view', $data);
    }


    public function rekapkasir_belumtagih()

    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');
        $data["kd_pembayaran"]  = $this->input->post('kd_pembayaran');
        $this->load->view('header', $data);
        $this->load->view('datakasirbelumtagih', $data);
    }



    public function rekapkeunonbpjs_asuransi()
    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_jenis_pasien"]  = $this->input->post('kd_jenis_pasien');
        $this->load->view('header', $data);
        $this->load->view('rekapkeunonbpjs_asuransi', $data);
    }


    public function rekapasuransi_tahunan()
    {
        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }
        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y');
        $this->load->view('header', $data);
        $this->load->view('data_rekapkeu_asuransithn', $data);
    }



    public function billingkasirall() //KASIR ALL

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('datakasir_all', $data); // Data total KASIR
    }

    public function kasirperbank() //KASIR ALL

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_jenisbank"]     = $this->input->post('kd_jenisbank');

        $this->load->view('header', $data);

        $this->load->view('datakasir_perbank', $data); // Data total KASIR
    }



    public function menuikbs()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('pasienikbs', $data);
    }



    // public function penjaminpolikeuangan()

    // {

    //     if (!$this->session->userdata('berhasil_loginu')) {

    //         redirect(''); // Jika tidak login, redirect ke halaman login

    //     }

    //     $data['akses'] = $this->session->userdata("kd_akses");

    //     $data['app'] = $this->session->userdata("kd_app");

    //     $data["tgl_awal"]        = date('Y-m-01');

    //     $data["tgl_akhir"]        = date('Y-m-d');

    //     $this->load->view('header', $data);

    //     $this->load->view('penjaminpolikeuangan', $data);

    // }



    public function penjaminpolikeuangan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('penjaminpoli', $data);
    }





    public function radiologipenjualan()

    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");

        $data['app'] = $this->session->userdata("kd_app");

        $data["tgl_awal"]        = date('Y-m-01');

        $data["tgl_akhir"]        = date('Y-m-d');

        $this->load->view('header', $data);

        $this->load->view('radiologipenjualan', $data);
    }


    public function datalabpenjualan()
    {

        if (!$this->session->userdata('berhasil_loginu')) {

            redirect(''); // Jika tidak login, redirect ke halaman login

        }

        $data['akses'] = $this->session->userdata("kd_akses");
        $data['app'] = $this->session->userdata("kd_app");
        $data["tgl_awal"]        = date('Y-m-01');
        $data["tgl_akhir"]        = date('Y-m-d');
        $data["kd_group_bayar"]  = $this->input->post('kd_group_bayar');
        $this->load->view('header', $data);
        $this->load->view('datapenjualanlaborat', $data);
    }



    public function reproses_data()

    {

        if (isset($_POST['KD_JENIS_PASIEN']) && isset($_POST['TANGGAL_AWAL']) && isset($_POST['TANGGAL_AKHIR'])) {

            $kd_jenis_pasien = $_POST['KD_JENIS_PASIEN'];

            $tanggalawal = $_POST['TANGGAL_AWAL'];

            $tanggalakhir = $_POST['TANGGAL_AKHIR'];

            $tanggal_awal             = strtotime($tanggalawal);

            $tanggal_awal             = date('d/m/Y', $tanggal_awal);

            $tanggal_akhir             = strtotime($tanggalakhir);

            $tanggal_akhir             = date('d/m/Y', $tanggal_akhir);



            $curl = curl_init();



            curl_setopt_array($curl, array(

                CURLOPT_URL => '103.255.241.146/api/d_reg_online/tampil_pasien',

                CURLOPT_RETURNTRANSFER => true,

                CURLOPT_ENCODING => '',

                CURLOPT_MAXREDIRS => 10,

                CURLOPT_TIMEOUT => 0,

                CURLOPT_FOLLOWLOCATION => true,

                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                CURLOPT_CUSTOMREQUEST => 'POST',

                CURLOPT_POSTFIELDS => array(

                    'KD_JENIS_PASIEN' => $kd_jenis_pasien,

                    'TANGGAL_AWAL' => $tanggal_awal,

                    'TANGGAL_AKHIR' => $tanggal_akhir

                ),

            ));



            $response = curl_exec($curl);

            curl_close($curl);



            // Mengubah response menjadi array asosiatif

            $data = json_decode($response, true);



            // Mengecek jika data valid

            if (is_array($data)) {

                echo json_encode($data); // Mengembalikan data sebagai JSON

            } else {

                echo json_encode([]); // Jika tidak ada data, kembalikan array kosong

            }
        } else {

            // Jika parameter tidak valid

            echo json_encode(['error' => 'Parameter tidak lengkap.']);
        }
    }



    public function batal_seprm()

    {




        //$kd_registasi_input = $this->input->get('kd_registrasi');

        //$no_sep_input = $this->input->get('no_sep');



        // Pastikan method request adalah POST

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {



            $nm_user = $this->session->userdata('nm_user');

            $kd_user = $this->session->userdata('kd_user');

            // Ambil data dari permintaan POST

            $kd_registrasi = isset($_POST['kd_registrasi']) ? trim($_POST['kd_registrasi']) : '';

            $no_sep = isset($_POST['no_sep']) ? trim($_POST['no_sep']) : '';



            // Periksa apakah KD_REGISTRASI dan NO_SEP tidak kosong

            if (!empty($kd_registrasi) && !empty($no_sep)) {

                // Inisialisasi cURL

                $curl = curl_init();



                // Set parameter cURL

                curl_setopt_array($curl, array(

                    CURLOPT_URL => '103.255.241.146/api/d_reg_online/batal_sep', // Tambahkan protokol http://

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 30,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => http_build_query(array(

                        'KD_REGISTRASI' => $kd_registrasi,

                        'NO_SEP' => $no_sep

                    )),

                    CURLOPT_HTTPHEADER => array(

                        'Content-Type: application/x-www-form-urlencoded'

                    ),

                ));



                // Eksekusi permintaan cURL dan ambil respons dari API

                $response = curl_exec($curl);

                $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);



                // Periksa apakah ada error dalam eksekusi cURL

                if (curl_errno($curl)) {

                    $error_msg = curl_error($curl);

                    curl_close($curl);

                    echo json_encode(array('status' => false, 'message' => 'cURL Error: ' . $error_msg));

                    exit();
                }



                curl_close($curl);



                //log harian download

                $datai = [

                    "KD_REGISTRASI" => $kd_registrasi,

                    "NO_SEP" => $no_sep,

                    "NIP_PETUGAS" => $kd_user,

                    "CATATAN" => "Akun " . $nm_user . " Telah Menghapus SEP dengan NO SEP." . $no_sep

                ];

                $curl = curl_init();

                curl_setopt_array($curl, [

                    CURLOPT_URL => '103.255.241.146/api/service_rs/sinaran_batal_sep',

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 0,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => $datai,

                ]);



                $responsee = curl_exec($curl);

                curl_close($curl);



                // Periksa kode respons dari API

                if ($httpCode == 200) {

                    // Decode respons API

                    $response_data = json_decode($response, true);



                    // Periksa apakah API memberikan status sukses

                    if (isset($response_data['status']) && $response_data['status'] === true) {

                        echo json_encode(array('status' => true, 'message' => 'Berhasil membatalkan SEP.'));
                    } else {

                        echo json_encode(array('status' => false, 'message' => 'Gagal membatalkan SEP.', 'data' => $response_data));
                    }
                } else {

                    echo json_encode(array('status' => false, 'message' => 'Error: Respons API tidak benar (' . $httpCode . ')', 'response' => $response));
                }
            } else {

                // Jika KD_REGISTRASI atau NO_SEP kosong, kirimkan pesan kesalahan

                echo json_encode(array('status' => false, 'message' => 'KD_REGISTRASI atau NO_SEP tidak valid.'));
            }
        } else {

            // Jika request method bukan POST

            echo json_encode(array('status' => false, 'message' => 'Invalid request method.'));
        }
    }





    public function batal_serah()

    {

        // Pastikan method request adalah POST

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {

            // Ambil data KD_REGISTRASI dari permintaan POST

            $kd_registrasi = isset($_POST['kd_registrasi']) ? $_POST['kd_registrasi'] : '';



            // Periksa apakah KD_REGISTRASI telah diisi

            if (!empty($kd_registrasi)) {

                // Inisialisasi cURL

                $curl = curl_init();



                // Set parameter cURL

                curl_setopt_array($curl, array(

                    CURLOPT_URL => '103.255.241.146/api/d_reg_online/batal_serah',

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 0,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => array(

                        'KD_REGISTRASI' => $kd_registrasi, // Mengirim kode registrasi dari permintaan

                        'STATUS_SERAH' => '0' // Status untuk pembatalan serah

                    ),

                ));



                // Eksekusi permintaan cURL dan ambil respons dari API

                $response = curl_exec($curl);



                // Periksa apakah ada error dalam eksekusi cURL

                if (curl_errno($curl)) {

                    echo 'Error:' . curl_error($curl);
                } else {

                    // Tampilkan respons API

                    echo $response;
                }



                // Tutup cURL

                curl_close($curl);
            } else {

                // Jika KD_REGISTRASI kosong, kirimkan pesan kesalahan

                echo json_encode(array('status' => false, 'message' => 'KD_REGISTRASI tidak valid.'));
            }
        } else {

            // Jika request method bukan POST

            echo json_encode(array('status' => false, 'message' => 'Invalid request method.'));
        }
    }

    public function batal_resume()

    {

        // Pastikan method request adalah POST

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {

            // Ambil data KD_REGISTRASI dari permintaan POST

            $kd_registrasi = isset($_POST['kd_registrasi']) ? $_POST['kd_registrasi'] : '';

            $kd_jenis_pasien = isset($_POST['kd_jenis_pasien']) ? $_POST['kd_jenis_pasien'] : '';



            // Periksa apakah KD_REGISTRASI dan KD_JENIS_PASIEN saat kosong

            if (!empty($kd_registrasi) && !empty($kd_jenis_pasien)) {

                // Inisialisasi cURL

                $curl = curl_init();



                // Set parameter cURL

                curl_setopt_array($curl, array(

                    CURLOPT_URL => '103.255.241.146/api/d_reg_online/batal_resume',

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 0,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => array(

                        'KD_REGISTRASI' => $kd_registrasi, // Mengirim kode registrasi dari permintaan

                        'KD_JENIS_PASIEN' => $kd_jenis_pasien // Mengirim kode jenis pasien dari permintaan

                    ),

                ));



                // Eksekusi permintaan cURL dan ambil respons dari API

                $response = curl_exec($curl);



                // Periksa apakah ada error dalam eksekusi cURL

                if (curl_errno($curl)) {

                    echo 'Error:' . curl_error($curl);
                } else {

                    // Tampilkan respons API

                    echo $response;
                }



                // Tutup cURL

                curl_close($curl);
            } else {

                // Jika KD_REGISTRASI kosong, kirimkan pesan kesalahan

                echo json_encode(array('status' => false, 'message' => 'KD_REGISTRASI tidak valid.'));
            }
        } else {

            // Jika request method bukan POST

            echo json_encode(array('status' => false, 'message' => 'Invalid request method.'));
        }
    }



    public function batal_sep()

    {

        // Pastikan method request adalah POST

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {

            // Ambil data KD_REGISTRASI dari permintaan POST

            $kd_registrasi = isset($_POST['kd_registrasi']) ? $_POST['kd_registrasi'] : '';

            $keterangan = isset($_POST['keterangan']) ? $_POST['keterangan'] : '';



            // Periksa apakah KD_REGISTRASI dan KD_JENIS_PASIEN saat kosong

            if (!empty($kd_registrasi) && !empty($keterangan)) {

                // Inisialisasi cURL

                $curl = curl_init();



                // Set parameter cURL

                curl_setopt_array($curl, array(

                    CURLOPT_URL => '103.255.241.146/api/d_reg_online/batal_sep',

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 0,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => array(

                        'KD_REGISTRASI' => $kd_registrasi, // Mengirim kode registrasi dari permintaan

                        'NO_SEP' => '0142R033' . $keterangan // Mengirim NO SEP

                    ),

                ));



                // Eksekusi permintaan cURL dan ambil respons dari API

                $response = curl_exec($curl);



                // Periksa apakah ada error dalam eksekusi cURL

                if (curl_errno($curl)) {

                    echo 'Error:' . curl_error($curl);
                } else {

                    // Tampilkan respons API

                    echo $response;
                }



                // Tutup cURL

                curl_close($curl);
            } else {

                // Jika KD_REGISTRASI kosong, kirimkan pesan kesalahan

                echo json_encode(array('status' => false, 'message' => 'KD_REGISTRASI tidak valid.'));
            }
        } else {

            // Jika request method bukan POST

            echo json_encode(array('status' => false, 'message' => 'Invalid request method.'));
        }
    }



    public function reproses_kasir()

    {

        // Pastikan method request adalah POST

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {

            // Ambil data KD_REGISTRASI dari permintaan POST

            $kd_registrasi = isset($_POST['kd_registrasi']) ? $_POST['kd_registrasi'] : '';



            // Periksa apakah KD_REGISTRASI saat kosong

            if (!empty($kd_registrasi)) {

                // Inisialisasi cURL

                $curl = curl_init();



                // Set parameter cURL

                curl_setopt_array($curl, array(

                    CURLOPT_URL => '103.255.241.146/api/d_reg_online/batal_billing',

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 0,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => array(

                        'KD_REGISTRASI' => $kd_registrasi, // Mengirim kode registrasi dari permintaan

                    ),

                ));



                // Eksekusi permintaan cURL dan ambil respons dari API

                $response = curl_exec($curl);



                // Periksa apakah ada error dalam eksekusi cURL

                if (curl_errno($curl)) {

                    echo 'Error:' . curl_error($curl);
                } else {

                    // Tampilkan respons API

                    echo $response;
                }



                // Tutup cURL

                curl_close($curl);
            } else {

                // Jika KD_REGISTRASI kosong, kirimkan pesan kesalahan

                echo json_encode(array('status' => false, 'message' => 'KD_REGISTRASI tidak valid.'));
            }
        } else {

            // Jika request method bukan POST

            echo json_encode(array('status' => false, 'message' => 'Invalid request method.'));
        }
    }

    public function batal_kasir()

    {

        // Pastikan method request adalah POST

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {

            // Ambil data KD_REGISTRASI dari permintaan POST

            $kd_registrasi = isset($_POST['kd_registrasi']) ? $_POST['kd_registrasi'] : '';



            // Periksa apakah KD_REGISTRASI telah diisi

            if (!empty($kd_registrasi)) {

                // Inisialisasi cURL

                $curl = curl_init();



                // Set parameter cURL

                curl_setopt_array($curl, array(

                    CURLOPT_URL => '103.255.241.146/api/d_reg_online/batal_kasir',

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 0,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => array(

                        'KD_REGISTRASI' => $kd_registrasi, // Mengirim kode registrasi dari permintaan

                        'STATUS_BAYAR_PULANG' => '0' // Status untuk pembatalan kasir

                    ),

                ));



                // Eksekusi permintaan cURL dan ambil respons dari API

                $response = curl_exec($curl);



                // Periksa apakah ada error dalam eksekusi cURL

                if (curl_errno($curl)) {

                    echo 'Error:' . curl_error($curl);
                } else {

                    // Tampilkan respons API

                    echo $response;
                }



                // Tutup cURL

                curl_close($curl);
            } else {

                // Jika KD_REGISTRASI kosong, kirimkan pesan kesalahan

                echo json_encode(array('status' => false, 'message' => 'KD_REGISTRASI tidak valid.'));
            }
        } else {

            // Jika request method bukan POST

            echo json_encode(array('status' => false, 'message' => 'Invalid request method.'));
        }
    }



    public function dpjp()

    {

        // Ambil input pencarian dari parameter GET

        $search = $this->input->get('search');



        $curl = curl_init();



        curl_setopt_array($curl, array(

            CURLOPT_URL => '103.255.241.146/api/d_reg_online/ref_dokter',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 0,

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

        ));



        $response = curl_exec($curl);

        curl_close($curl);



        // Decode response dari API

        $data = json_decode($response, true);



        // Jika API mengembalikan data dengan sukses, filter berdasarkan pencarian

        if ($data['status'] && !empty($data['response']['list'])) {

            if ($search) {

                // Filter daftar dokter berdasarkan pencarian

                $data['response']['list'] = array_filter($data['response']['list'], function ($dokter) use ($search) {

                    return stripos($dokter['nm_dokter'], $search) !== false; // Kasus tidak sensitif

                });
            }

            echo json_encode($data); // Mengembalikan data dokter yang difilter

        } else {

            echo json_encode(['status' => false, 'message' => 'Gagal mengambil data dari API.']);
        }
    }



    public function tambah_dpjp()

    {

        // Pastikan method request adalah POST

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {

            // Ambil data KD_REGISTRASI dari permintaan POST

            $kd_registrasi = isset($_POST['kd_registrasi']) ? $_POST['kd_registrasi'] : '';

            $nip_petugas = isset($_POST['nip_petugas']) ? $_POST['nip_petugas'] : '';

            $nip_dokter = isset($_POST['nip_dokter']) ? $_POST['nip_dokter'] : '';

            $tanggal       = date('Y-m-d');

            $tanggal_now             = strtotime($tanggal);

            $tanggalnow             = date('d/m/Y', $tanggal_now);





            // Periksa apakah KD_REGISTRASI telah diisi

            if (!empty($kd_registrasi)) {

                // Inisialisasi cURL

                $curl = curl_init();



                // Set parameter cURL

                curl_setopt_array($curl, array(

                    CURLOPT_URL => '103.255.241.146/api/service_rs/tambah_dpjp',

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 0,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => array(

                        'KD_REGISTRASI' => $kd_registrasi, // Mengirim kode registrasi dari permintaan

                        'URT' => '0', // Status untuk pembatalan kasir

                        'NIP_DOKTER' => $nip_dokter,

                        'KD_JENIS_DPJP' => '1',

                        'TANGGAL_PERUBAHAN' => $tanggalnow,

                        'NIP_PETUGAS' => $nip_petugas,

                        'STATUS' => 'A',

                        'KETERANGAN' => 'DPJP Rawat Inap'

                    ),

                ));



                // Eksekusi permintaan cURL dan ambil respons dari API

                $response = curl_exec($curl);



                // Periksa apakah ada error dalam eksekusi cURL

                if (curl_errno($curl)) {

                    echo 'Error:' . curl_error($curl);
                } else {

                    // Tampilkan respons API

                    echo $response;
                }



                // Tutup cURL

                curl_close($curl);
            } else {

                // Jika KD_REGISTRASI kosong, kirimkan pesan kesalahan

                echo json_encode(array('status' => false, 'message' => 'KD_REGISTRASI tidak valid.'));
            }
        } else {

            // Jika request method bukan POST

            echo json_encode(array('status' => false, 'message' => 'Invalid request method.'));
        }
    }



    public function tambah_sep()

    {

        // Pastikan method request adalah POST

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {

            // Ambil data KD_REGISTRASI dari permintaan POST

            $kd_registrasi = isset($_POST['kd_registrasi']) ? $_POST['kd_registrasi'] : '';

            $keterangan = isset($_POST['keterangan']) ? $_POST['keterangan'] : '';



            // Periksa apakah KD_REGISTRASI dan KD_JENIS_PASIEN saat kosong

            if (!empty($kd_registrasi) && !empty($keterangan)) {

                // Inisialisasi cURL

                $curl = curl_init();



                // Set parameter cURL

                curl_setopt_array($curl, array(

                    CURLOPT_URL => '103.255.241.146/api/service_rs/tambah_sep',

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 0,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => array(

                        'KD_REGISTRASI' => $kd_registrasi, // Mengirim kode registrasi dari permintaan

                        'NO_SEP' => '0142R033' . $keterangan // Mengirim NO SEP

                    ),

                ));

                // Eksekusi permintaan cURL dan ambil respons dari API
                $response = curl_exec($curl);
                // Periksa apakah ada error dalam eksekusi cURL

                if (curl_errno($curl)) {

                    echo 'Error:' . curl_error($curl);
                } else {

                    // Tampilkan respons API

                    echo $response;
                }
                // Tutup cURL

                curl_close($curl);
            } else {

                // Jika KD_REGISTRASI kosong, kirimkan pesan kesalahan

                echo json_encode(array('status' => false, 'message' => 'KD_REGISTRASI tidak valid.'));
            }
        } else {

            // Jika request method bukan POST

            echo json_encode(array('status' => false, 'message' => 'Invalid request method.'));
        }
    }

    public function hapus_radlab()
    {

        // Pastikan method request adalah POST

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {

            // Ambil data permintaan POST

            $keterangan = isset($_POST['keterangan']) ? $_POST['keterangan'] : '';



            // Periksa apakah KD_REGISTRASI dan KD_JENIS_PASIEN saat kosong

            if (!empty($keterangan)) {

                // Inisialisasi cURL

                $curl = curl_init();



                // Set parameter cURL

                curl_setopt_array($curl, array(

                    CURLOPT_URL => '103.255.241.146/api/service_rs/hapus_kode_jual_radlab',

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 0,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => array(

                        'KD_JUAL' => $keterangan // Mengirim NO SEP

                    ),

                ));


                // Eksekusi permintaan cURL dan ambil respons dari API

                $response = curl_exec($curl);



                // Periksa apakah ada error dalam eksekusi cURL

                if (curl_errno($curl)) {

                    echo 'Error:' . curl_error($curl);
                } else {

                    // Tampilkan respons API

                    echo $response;
                }

                curl_close($curl);
            } else {

                // Jika KD_REGISTRASI kosong, kirimkan pesan kesalahan

                echo json_encode(array('status' => false, 'message' => 'KD_REGISTRASI tidak valid.'));
            }
        } else {

            // Jika request method bukan POST

            echo json_encode(array('status' => false, 'message' => 'Invalid request method.'));
        }
    }

    public function pembayaran()

    {

        // Ambil input pencarian dari parameter GET
        $search = $this->input->get('search');

        // Inisialisasi cURL
        $curl = curl_init();
        if ($curl === false) {

            echo json_encode(['status' => false, 'message' => 'Gagal menginisialisasi cURL']);

            return;
        }


        // Set options untuk cURL

        curl_setopt_array($curl, array(

            CURLOPT_URL => 'http://103.255.241.146/api/service_rs/ref_pembayaran',

            CURLOPT_RETURNTRANSFER => true,

            CURLOPT_ENCODING => '',

            CURLOPT_MAXREDIRS => 10,

            CURLOPT_TIMEOUT => 30, // Tambahkan timeout yang lebih lama jika perlu

            CURLOPT_FOLLOWLOCATION => true,

            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

            CURLOPT_CUSTOMREQUEST => 'POST',

        ));

        // Eksekusi cURL request

        $response = curl_exec($curl);

        // Cek apakah ada error saat eksekusi cURL

        if (curl_errno($curl)) {

            // Jika ada error, tampilkan pesan errornya

            echo json_encode(['status' => false, 'message' => 'cURL Error: ' . curl_error($curl)]);

            curl_close($curl);

            return;
        }



        // Tutup handle cURL setelah selesai

        curl_close($curl);



        // Debugging: Tampilkan respons API sebelum diproses

        echo '<pre>';

        print_r($response); // Menampilkan respons asli dari API

        echo '</pre>';



        // Decode response dari API

        $data = json_decode($response, true);



        // Debugging respons yang didecode

        echo '<pre>';

        print_r($data); // Menampilkan seluruh isi respons yang didecode

        echo '</pre>';



        // Pastikan ada data dan 'status' benar

        if (isset($data['metadata']) && isset($data['metadata']['code']) && $data['metadata']['code'] === 200) {

            // Proses data yang berhasil

            if (isset($data['response']) && !empty($data['response'])) {

                // Filter data berdasarkan parameter pencarian jika ada

                if (!empty($search)) {

                    $filtered_data = array_filter($data['response'], function ($item) use ($search) {

                        return stripos($item['nm_pembayaran'], $search) !== false; // Filter berdasarkan nama pembayaran

                    });
                } else {

                    $filtered_data = $data['response'];
                }



                // Mengembalikan data yang sudah difilter atau seluruh data

                echo json_encode(['status' => true, 'data' => array_values($filtered_data)]);
            } else {

                echo json_encode(['status' => false, 'message' => 'Tidak ada data yang ditemukan.']);
            }
        } else {

            // Jika status tidak sesuai atau ada masalah dengan API

            echo json_encode(['status' => false, 'message' => isset($data['message']) ? $data['message'] : 'Gagal mengambil data dari API atau data tidak valid.']);
        }
    }



    public function ubahpembayaran()

    {

        // Pastikan method request adalah POST

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {

            // Ambil data KD_REGISTRASI dari permintaan POST

            $kd_registrasi = isset($_POST['kd_registrasi']) ? $_POST['kd_registrasi'] : '';

            $kd_pembayaran = isset($_POST['kd_pembayaran']) ? $_POST['kd_pembayaran'] : '';

            // Periksa apakah KD_REGISTRASI telah diisi

            if (!empty($kd_registrasi)) {

                // Inisialisasi cURL

                $curl = curl_init();

                // Set parameter cURL

                curl_setopt_array($curl, array(

                    CURLOPT_URL => '103.255.241.146/api/service_rs/tambah_dpjp',

                    CURLOPT_RETURNTRANSFER => true,

                    CURLOPT_ENCODING => '',

                    CURLOPT_MAXREDIRS => 10,

                    CURLOPT_TIMEOUT => 0,

                    CURLOPT_FOLLOWLOCATION => true,

                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

                    CURLOPT_CUSTOMREQUEST => 'POST',

                    CURLOPT_POSTFIELDS => array(

                        'KD_REGISTRASI' => $kd_registrasi, // Mengirim kode registrasi dari permintaan

                        'KD_PEMBAYARAN' => $kd_pembayaran

                    ),

                ));



                // Eksekusi permintaan cURL dan ambil respons dari API

                $response = curl_exec($curl);



                // Periksa apakah ada error dalam eksekusi cURL

                if (curl_errno($curl)) {

                    echo 'Error:' . curl_error($curl);
                } else {

                    // Tampilkan respons API

                    echo $response;
                }



                // Tutup cURL

                curl_close($curl);
            } else {

                // Jika KD_REGISTRASI kosong, kirimkan pesan kesalahan

                echo json_encode(array('status' => false, 'message' => 'KD_REGISTRASI tidak valid.'));
            }
        } else {

            // Jika request method bukan POST

            echo json_encode(array('status' => false, 'message' => 'Invalid request method.'));
        }
    }



    public function get_files()

    {

        $files = array_diff(scandir('./uploads/'), array('..', '.'));

        $file_list = [];



        foreach ($files as $file) {

            $file_list[] = [

                'file_name' => $file,

                'file_path' => base_url('uploads/' . $file),

            ];
        }



        echo json_encode($file_list);
    }

    public function upload_pdf1()

    {

        $config['upload_path'] = './uploads/';

        $config['allowed_types'] = 'pdf';

        $config['max_size'] = 2048; // 2MB  



        // Check if the upload directory exists, if not create it  

        if (!is_dir($config['upload_path'])) {

            mkdir($config['upload_path'], 0755, true);
        }



        $this->load->library('upload', $config);



        // Debugging output  

        if (!$this->upload->do_upload('file')) {

            // Log the error  

            log_message('error', $this->upload->display_errors('', ''));



            $response = [

                'status' => 'error',

                'message' => $this->upload->display_errors('', ''),

            ];

            echo json_encode($response);

            return; // Exit after sending the response  

        } else {

            $data = $this->upload->data();

            $response = [

                'status' => 'success',

                'file_name' => $data['orig_name'],

                'file_path' => base_url('uploads/' . $data['orig_name']),

            ];
        }



        echo json_encode($response);
    }



    public function delete_file($file_name)

    {

        $file_path = './uploads/' . $file_name;



        // Check if the file exists  

        if (file_exists($file_path)) {

            // Attempt to delete the file  

            if (unlink($file_path)) {

                $response = [

                    'status' => 'success',

                    'message' => 'File deleted successfully.',

                ];
            } else {

                $response = [

                    'status' => 'error',

                    'message' => 'Failed to delete the file.',

                ];
            }
        } else {

            $response = [

                'status' => 'error',

                'message' => 'File does not exist.',

            ];
        }



        echo json_encode($response);
    }



    public function delete_file1()
    {
        // 1. Ambil nama file dari input POST dengan key 'file'
        $file_name = $this->input->post('file');

        // 2. Validasi jika nama file kosong atau tidak dikirim
        if (!$file_name) {
            // Set header ke 400 Bad Request dan kirim response error
            $this->output->set_status_header(400);
            echo json_encode(['status' => 'error', 'message' => 'Nama file tidak ditemukan dalam request.']);
            return;
        }

        // 3. Decode nama file untuk mengatasi karakter khusus seperti spasi (%20)
        $file_name_decoded = urldecode($file_name);
        $file_path = './uploads/' . $file_name_decoded;

        // Lanjutkan dengan logika penghapusan file
        if (file_exists($file_path)) {
            if (unlink($file_path)) {
                $response = [
                    'status' => 'success',
                    'message' => 'File berhasil dihapus.',
                ];
            } else {
                $response = [
                    'status' => 'error',
                    'message' => 'Gagal menghapus file dari server.',
                ];
            }
        } else {
            $response = [
                'status' => 'error',
                'message' => 'File tidak ada di server.',
            ];
        }

        // Mengatur header sebagai JSON dan mengirim response
        $this->output
            ->set_content_type('application/json')
            ->set_output(json_encode($response));
    }
}
