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

class ICare extends CI_Controller
{

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

        if (!$this->session->userdata('username')) {
            redirect('login');
        }
    }
    public function cekRiwayatPelayanan($noka = '')
    {
        if(empty($noka)){
            echo 'No Kartu Tidak Ditemukan';
            exit();
        }

        // ---------------------------------------------------------------------
        $data['abdulradjak'] = $abdulradjak = $this->db->query("SELECT TOP 1 * FROM Utama")->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        // ---------------------------------------------------------------------
        date_default_timezone_set("Asia/Jakarta");
        $tgl = date('Y-m-d');
        $getRiwayatPelayanan = $this->riwayatPelayanan($noka);
        $kode = $getRiwayatPelayanan['metaData']['code'];
        $pesan = $getRiwayatPelayanan['metaData']['message'];
        //print_r($getRiwayatPelayanan);exit();
        // $data['riwayatPelayanan'] = $getRiwayatPelayanan['response']['list']['url'];
        if ($kode == 200) {
            redirect($getRiwayatPelayanan['response']['list']['url']);
        } else {
            $this->session->set_flashdata("error", "$pesan");
            redirect($_SERVER['HTTP_REFERER']);
        }
    }

    public function riwayatPelayanan($noka)
    {
        extract($_GET);
        $abdulradjak = $this->db->query("SELECT TOP 1 * FROM Utama")->row_array();
        $ch = curl_init();
        $dataA = array(
            // "param" => "0001011257008",
            // "kodedokter" => 38538
            "param" => $noka
        );
        $payload = json_encode($dataA);
        // echo $payload;
        // exit;
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        curl_setopt($ch, CURLOPT_URL, $abdulradjak['IP_WS_Layanan'] . "icare/icare/Fktp");
        // curl_setopt($ch, CURLOPT_URL, "103.177.176.62/api/icare/icare/Fkrtl");
        $result = curl_exec($ch);
        //print_r($result);exit();
        curl_close($ch);
        return json_decode($result, true);
    }

}