120 lines
3.2 KiB
PHP
120 lines
3.2 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
date_default_timezone_set('Asia/Jakarta');
|
|
class Pasien extends CI_Controller
|
|
{
|
|
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('M_pasien');
|
|
$this->load->model('M_kategori_pasien');
|
|
$this->load->helper('url');
|
|
$this->load->library('form_validation');
|
|
|
|
if ($this->session->userdata('status') != "login") {
|
|
redirect(base_url("Auth"));
|
|
}
|
|
}
|
|
|
|
//TAMPIL PASIEN
|
|
public function index()
|
|
{
|
|
$id_kategori = $this->input->get('id_kategori');
|
|
$data['data'] = $this->M_pasien->list_data($id_kategori)->result();
|
|
$data['kategori_pasien'] = $this->M_kategori_pasien->get_all()->result();
|
|
$this->load->view('pasien', $data);
|
|
}
|
|
|
|
// TAMBAH PASIEN
|
|
function save()
|
|
{
|
|
|
|
$this->form_validation->set_rules('nama', 'Nama Pasien', 'required|is_unique[pasien.nama]');
|
|
if ($this->form_validation->run() == true) {
|
|
$nama = $this->input->post('nama');
|
|
$tempat_lahir = $this->input->post('tempat_lahir');
|
|
$tgl_lahir = $this->input->post('tgl_lahir');
|
|
$no_telp = $this->input->post('no_telp');
|
|
$alamat = $this->input->post('alamat');
|
|
$ortu = $this->input->post('ortu');
|
|
$jenkel = $this->input->post('jenkel');
|
|
$id_kategori_pasien = $this->input->post('id_kategori_pasien');
|
|
|
|
$data = array(
|
|
'nama' => $nama,
|
|
'tempat_lahir' => $tempat_lahir,
|
|
'tgl_lahir' => $tgl_lahir,
|
|
'jenkel' => $jenkel,
|
|
'no_telp' => $no_telp,
|
|
'alamat' => $alamat,
|
|
'ortu' => $ortu,
|
|
'id_kategori_pasien' => $id_kategori_pasien,
|
|
'created_at' => date('Y-m-d H:i:s')
|
|
);
|
|
|
|
$this->session->set_flashdata('success', 'Data berhasil disimpan !');
|
|
$this->M_pasien->insert($data, 'pasien');
|
|
redirect('Pasien');
|
|
} else {
|
|
redirect('Pasien');
|
|
}
|
|
}
|
|
|
|
// EDIT PASIEN
|
|
function edit($id)
|
|
{
|
|
$where = array('id' => $id);
|
|
$data['data'] = $this->M_pasien->edit($where, 'pasien')->row_array();
|
|
echo json_encode($data);
|
|
}
|
|
|
|
// UPDATE PASIEN
|
|
function update()
|
|
{
|
|
$this->form_validation->set_rules('nama', 'Nama Pasien', 'required');
|
|
if ($this->form_validation->run() == true) {
|
|
$id = $this->input->post('id');
|
|
$nama = $this->input->post('nama');
|
|
$tempat_lahir = $this->input->post('tempat_lahir');
|
|
$tgl_lahir = $this->input->post('tgl_lahir');
|
|
$no_telp = $this->input->post('no_telp');
|
|
$alamat = $this->input->post('alamat');
|
|
$ortu = $this->input->post('ortu');
|
|
$jenkel = $this->input->post('jenkel');
|
|
$id_kategori_pasien = $this->input->post('id_kategori_pasien');
|
|
|
|
$data = array(
|
|
'nama' => $nama,
|
|
'tempat_lahir' => $tempat_lahir,
|
|
'tgl_lahir' => $tgl_lahir,
|
|
'jenkel' => $jenkel,
|
|
'no_telp' => $no_telp,
|
|
'alamat' => $alamat,
|
|
'ortu' => $ortu,
|
|
'id_kategori_pasien' => $id_kategori_pasien,
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
);
|
|
|
|
$where = array(
|
|
'id' => $id
|
|
);
|
|
|
|
$this->session->set_flashdata('success', 'Data berhasil diubah !');
|
|
$this->M_pasien->update($where, $data, 'pasien');
|
|
redirect('Pasien');
|
|
} else {
|
|
redirect('Pasien');
|
|
}
|
|
}
|
|
|
|
// HAPUS PASIEN
|
|
public function delete($id)
|
|
{
|
|
$where = array('id' => $id);
|
|
$this->M_pasien->delete($where, 'pasien');
|
|
$this->session->set_flashdata('hapus', 'Data berhasil dihapus !');
|
|
redirect('Pasien');
|
|
}
|
|
}
|