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

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

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

    public function ViewPemeriksaan($id)
    {
        // ---------------------------------------------------------------------
        $data['judul'] = "Klinik";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        // ---------------------------------------------------------------------
        $data['datahasil'] = $this->db->query("SELECT * from erm_hasilpemeriksaangigi e JOIN erm_warnagigi g on e.pemeriksaan = g.id WHERE e.CaseID = '$id' ")->result_array();
        // $data['']

        //print_r($data['datahasil']);exit();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('rekamMedis/viewpemeriksaangigi', $data);
        $this->load->view('properti/footer', $data);
    }

    public function Addpemeriksaan()
    {
        // ---------------------------------------------------------------------
        $data['judul'] = "Klinik";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        // ---------------------------------------------------------------------
        $data['jenis'] = $this->db->query("Select * From erm_warnagigi")->result_array();

        // $data['']
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('rekamMedis/Addpemeriksaangigi', $data);
        $this->load->view('properti/footer', $data);
    }

    public function Simpan()
    {
        $kodepriksa = $this->uri->segment(4);
        $kode = substr($kodepriksa,0,3);
        $code = substr($kodepriksa,4);
        $caseid = $this->input->post('caseid');
        $namapasien = $this->input->post('namapasien');
        $tglpriksa = $this->input->post('tglpriksa');
        $kodegigi = $this->input->post('kodegigi');
        $jenis = $this->input->post('jenis');
        $keterangan = $this->input->post('keterangan');

        $this->db->query(
            "INSERT INTO erm_hasilpemeriksaangigi (
            CaseID, 
            Tanggal,
            Pasien,
            Gigi,
            Pemeriksaan,
            Keterangan,
            kode,
            kodeperiksa
            )VALUES (
                '$caseid', 
                '$tglpriksa',
                '$namapasien',
                '$kodegigi',
                '$jenis',
                '$keterangan',
                '$code',
                '$kode'
            )"
        );

        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Data Tersimpan.</div>');
        redirect(base_url('PemeriksaanGigi/ViewPemeriksaan/' . $caseid));
    }
}
