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

class Form 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_Pendaftaran');
        $this->load->model('M_rekamMedis');
        $this->load->helper('url');

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

    public function index()
    {
        date_default_timezone_set("Asia/Jakarta");
        $tgl = date('Y-m-d');
        $data['judul'] = "General Consent";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['cases'] = $this->db->query("select c.[Case ID],c.PatientCode,c.Description,c.Category,
        c.[Case Status],c.[Intake Date],c.[Intake Time],co.CompanyName
        from Cases c 
        join Company co on co.CompanyCode = c.CompanyCode
        where [Intake Date] ='$tgl'")->result_array();
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('form/index', $data);
        $this->load->view('properti/footer', $data);
    }

    public function AsesmentPrabedah()
    {
        date_default_timezone_set("Asia/Jakarta");
        $tgl = date('Y-m-d');
        $data['judul'] = "Asesment PraBedah";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['unit'] = $this->db->query("SELECT * FROM Utama")->row_array();
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('form/FormAsesmentPrabedah', $data);
        $this->load->view('properti/footer', $data);
    }

    public function prosesAsesmentPrabedah()
    {
        $caseID = $this->uri->segment(3);
        $jam = $this->input->post('jam');
        $subjektif = $this->input->post('subjektif');
        $objektif = $this->input->post('objektif');
        $estimasi = $this->input->post('estimasi');
        $rencanaoprasi = $this->input->post('rencanaoprasi');
        $deskripsi = $this->input->post('deskripsi');
        $ttd1 = $this->input->post('ttd1');
        $ttd2 = $this->input->post('ttd2');

        $folderPath = "./images/uploadsign/oprasi/";
        $TtdYangMenyatakan = $this->input->post('TtdYangMenyatakan');
        $TtdSaksi2 = $this->input->post('TtdSaksi2');

        // 1
        $filename_1 = $caseID . ' - TTD1 ';
        $image_parts_1 = explode(";base64,", $TtdYangMenyatakan);
        $image_type_aux_1 = explode("image/", $image_parts_1[0]);
        $image_type_1 = $image_type_aux_1[1];
        $image_base64_1 = base64_decode($image_parts_1[1]);
        $file_1 = $folderPath . $filename_1 . '.' . $image_type_1;
        file_put_contents($file_1, $image_base64_1);
        // 2
        $filename_2 = $caseID . ' - TTD2 ';
        $image_parts_2 = explode(";base64,", $TtdSaksi2);
        $image_type_aux_2 = explode("image/", $image_parts_2[0]);
        $image_type_2 = $image_type_aux_2[1];
        $image_base64_2 = base64_decode($image_parts_2[1]);
        $file_2 = $folderPath . $filename_2 . '.' . $image_type_2;
        file_put_contents($file_2, $image_base64_2);

        $this->db->query(
            "INSERT INTO erm_asesmentoprasi (
            case_id, 
            jam,
            datasubjektif,
            dataobjektif,
            estimasi,
            rencanaoprasi,
            deskripsi,
            petugas,
            pasien,
            ttd1,
            ttd2
            )VALUES (
                '$caseID', 
                '$jam',
                '$subjektif',
                '$objektif',
                '$estimasi',
                '$rencanaoprasi',
                '$deskripsi',
                '$ttd1',
                '$ttd2',
                '$filename_1',
                '$filename_2'
            )"
        );

        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Data Asesment Tersimpan.</div>');
        redirect(base_url('Form/AsesmentPrabedah/' . $caseID));
    }

    public function cetakasesmentbedah($id)
    {
        ob_start();
        $this->load->model('M_Utama');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['data'] = $this->db->query("select* from erm_asesmentoprasi where case_id = '$id'")->row_array();
        $this->load->view('form/cetakformasesment', $data);
    }

    public function monitoringbedah()
    {
        date_default_timezone_set("Asia/Jakarta");
        $tgl = date('Y-m-d');
        $data['judul'] = "Monitoring Tidakan Anestesi dan Bedah";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['unit'] = $this->db->query("SELECT * FROM Utama")->row_array();
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('form/MonitoringBedah', $data);
        $this->load->view('properti/footer', $data);
    }

    public function Simpanmonitoringbedah()
    {
        $caseID = $this->uri->segment(3);
        $Gcs = $this->input->post('Gcs');
        $Td = $this->input->post('Td');
        $N = $this->input->post('N');
        $RR = $this->input->post('RR');
        $Tax = $this->input->post('Tax');
        $Nyeri = $this->input->post('Nyeri');
        $Lain2 = $this->input->post('Lain2');
        $Tindakan = $this->input->post('Tindakan');
        $Gcsp = $this->input->post('Gcsp');
        $Tdp = $this->input->post('Tdp');
        $Np = $this->input->post('Np');
        $RRp = $this->input->post('RRp');
        $Taxp = $this->input->post('Taxp');
        $Nyerip = $this->input->post('Nyerip');
        $Lainlain = $this->input->post('Lainlain');
        $Tindakan1 = $this->input->post('Tindakan1');
        $Tindakan2 = $this->input->post('Tindakan2');
        $Tindakan3 = $this->input->post('Tindakan3');
        $ttd1 = $this->input->post('ttd1');
        $jenisanastesi = $this->input->post('jenisanastesi');

        $folderPath = "./images/uploadsign/monitoring/";
        $TtdYangMenyatakan = $this->input->post('TtdYangMenyatakan');

        // 1
        $filename_1 = $caseID . ' - TTD1 ';
        $image_parts_1 = explode(";base64,", $TtdYangMenyatakan);
        $image_type_aux_1 = explode("image/", $image_parts_1[0]);
        $image_type_1 = $image_type_aux_1[1];
        $image_base64_1 = base64_decode($image_parts_1[1]);
        $file_1 = $folderPath . $filename_1 . '.' . $image_type_1;
        file_put_contents($file_1, $image_base64_1);

        $this->db->query(
            "INSERT INTO erm_monitoringbedah(
            case_id, 
            Gcs,
            Td,
            N,
            RR,
            Tax,
            Nyeri,
            Lain2,
            Tindakan,
            Gcsp,
            Tdp,
            Np,
            RRp,
            Taxp,
            Nyerip,
            Lainlain,
            Tindakan1,
            Tindakan2,
            Tindakan3,
            Petugas,
            Ttd,
            jenisanastesi
            )VALUES (
                '$caseID', 
                '$Gcs',
                '$Td',
                '$N',
                '$RR',
                '$Tax',
                '$Nyeri',
                '$Lain2',
                '$Tindakan',
                '$Gcsp',
                '$Tdp',
                '$Np',
                '$RRp',
                '$Taxp',
                '$Nyerip',
                '$Lainlain',
                '$Tindakan1',
                '$Tindakan2',
                '$Tindakan3',
                '$ttd1',
                '$filename_1',
                '$jenisanastesi'
            )"
        );

        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Data Monitoring Tersimpan.</div>');
        redirect(base_url('Form/monitoringbedah/' . $caseID));
    }

    public function cetakmonitoringbedah($id)
    {
        ob_start();
        $this->load->model('M_Utama');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['data'] = $this->db->query("select* from erm_monitoringbedah where case_id = '$id'")->row_array();
        $this->load->view('form/cetakmonitoringbedah', $data);
    }

    public function asesmentanastesi()
    {
        date_default_timezone_set("Asia/Jakarta");
        $tgl = date('Y-m-d');
        $data['judul'] = "Monitoring Tidakan Anestesi dan Bedah";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['unit'] = $this->db->query("SELECT * FROM Utama")->row_array();
        $this->load->model('M_rekamMedis');
        $data['diagnosa'] = $this->M_rekamMedis->diagnosa();
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('form/Asesmenanastesi', $data);
        $this->load->view('properti/footer', $data);
    }

    public function SimpanAsesmentanastesi($caseID)
    {
        date_default_timezone_set("Asia/Jakarta");
        $tgl = date('Y-m-d');
        $Jam = date('H:i');
        $Rencanaop = $this->input->post('Rencanaop');
        $diagnosa = $this->input->post('diagnosa');
        $Medikasi = $this->input->post('Medikasi');
        $Perokok = $this->input->post('Perokok');
        $Obatobatan = $this->input->post('Obatobatan');
        $Keluarga = $this->input->post('Keluarga');
        $Makan = $this->input->post('Makan');
        $Alergi = $this->input->post('Alergi');
        $tgl1 = $this->input->post('tgl1');
        $tgl2 = $this->input->post('tgl2');
        $tgl3 = $this->input->post('tgl3');
        $tgl4 = $this->input->post('tgl4');
        $kardiovaskular = $this->input->post('kardiovaskular');
        $pernafasan = $this->input->post('pernafasan');
        $diabetes = $this->input->post('diabetes');
        $neurologis = $this->input->post('neurologis');
        $artritis = $this->input->post('artritis');
        $Ginjal = $this->input->post('Ginjal');
        $lainya1 = $this->input->post('lainya1');
        $TD = $this->input->post('TD');
        $Jantung = $this->input->post('Jantung');
        $Paru = $this->input->post('Paru');
        $Nafas = $this->input->post('Nafas');
        $N = $this->input->post('N');
        $Gula = $this->input->post('Gula');
        $Ureum = $this->input->post('Ureum');
        $Hbsag = $this->input->post('Hbsag');
        $Ct = $this->input->post('Ct');
        $Bt = $this->input->post('Bt');
        $Lainya2 = $this->input->post('Lainya2');
        $Ekg = $this->input->post('Ekg');
        $xfoto = $this->input->post('xfoto');
        $Lainya3 = $this->input->post('Lainya3');
        $invasive = $this->input->post('invasive');
        $Tehnik = $this->input->post('Tehnik');
        $Asa = $this->input->post('Asa');
        $Rencana = $this->input->post('Rencana');
        $Dosis = $this->input->post('Dosis');
        $Jenisanastesi = $this->input->post('Jenisanastesi');
        $carapemberian = $this->input->post('carapemberian');

        $this->db->query(
            "INSERT INTO erm_Asesmentanastesi(
            case_id, 
            Tanggal,
            Jam,
            Diagnosa,
            Rencanaop,
            Medikasi, 
            Perokok, 
            Obatobatan,
            Keluarga, 
            Makan, 
            Alergi, 
            tgl1, 
            tgl2, 
            tgl3, 
            tgl4, 
            kardiovaskular, 
            pernafasan, 
            diabetes,
            neurologis, 
            artritis, 
            Ginjal,
            lainya1, 
            TD, 
            Jantung, 
            Paru,
            Nafas,
            N,
            Gula,
            Ureum, 
            Hbsag,
            Ct, 
            Bt, 
            Lainya2, 
            Ekg,
            xfoto, 
            Lainya3, 
            invasive,
            Tehnik,
            Asa, 
	        Rencana,
            dosis,
            jenisanastesi,
            carapemakaian
            )VALUES (
            '$caseID',
            '$tgl',
            '$Jam',
            '$diagnosa',
            '$Rencanaop',
            '$Medikasi', 
            '$Perokok', 
            '$Obatobatan',
            '$Keluarga', 
            '$Makan', 
            '$Alergi', 
            '$tgl1', 
            '$tgl2', 
            '$tgl3', 
            '$tgl4', 
            '$kardiovaskular', 
            '$pernafasan', 
            '$diabetes',
            '$neurologis', 
            '$artritis', 
            '$Ginjal',
            '$lainya1', 
            '$TD', 
            '$Jantung', 
            '$Paru',
            '$Nafas',
            '$N',
            '$Gula',
            '$Ureum', 
            '$Hbsag',
            '$Ct', 
            '$Bt', 
            '$Lainya2', 
            '$Ekg',
            '$xfoto', 
            '$Lainya3', 
            '$invasive',
            '$Tehnik',
            '$Asa', 
            '$Rencana',
            '$Dosis',
            '$Jenisanastesi',
            '$carapemberian'
            )"
        );

        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Data Asesment Tersimpan.</div>');
        redirect(base_url('Form/asesmentanastesi/' . $caseID));
    }

    public function cetakasesmentanastesi($id)
    {
        ob_start();
        $this->load->model('M_Utama');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['data'] = $this->db->query("
        select [case_id]
            ,[Tanggal]
            ,[Jam]
            ,[Diagnosa]
            ,[Rencanaop]
            ,[Medikasi]
            ,[Perokok]
            ,[Obatobatan]
            ,[Keluarga]
            ,[Makan]
            ,[Alergi]
            ,[tgl1]
            ,[tgl2]
            ,[tgl3]
            ,[tgl4]
            ,[Kardiovaskular]
            ,[pernafasan]
            ,[diabetes]
            ,[neurologis]
            ,[artritis]
            ,[ginjal]
            ,[lainya1]
            ,[td]
            ,[jantung]
            ,[paru]
            ,[nafas]
            ,[n]
            ,[gula]
            ,[ureum]
            ,[hbsag]
            ,[ct]
            ,[bt]
            ,[lainya2]
            ,[ekg]
            ,[xfoto]
            ,[lainya3]
            ,[invasive]
            ,[tehnik]
            ,[asa]
            ,[rencana]
            ,[dosis]
            ,[jenisanastesi]
            ,[carapemakaian]
            ,c.Description
            ,c.PatientCode
            ,p.DOB,Ekstremitas
            ,td.tandatangan_1
            from erm_Asesmentanastesi ea join Cases c on ea.case_id = c.[Case ID]
            join Patient p on p.PatientCode = c.PatientCode
            join erm_ttdanastesi td on td.caseID = ea.case_id
            where ea.case_id = '$id'
        ")->row_array();
        $this->load->view('form/cetakAsesmentanastesi', $data);
    }

    public function ssc()
    {
        date_default_timezone_set("Asia/Jakarta");
        $tgl = date('Y-m-d');
        $data['judul'] = "Monitoring Tidakan Anestesi dan Bedah";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['unit'] = $this->db->query("SELECT * FROM Utama")->row_array();
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('form/Ssc', $data);
        $this->load->view('properti/footer', $data);
    }

    public function Prosessimpanssc($CaseID)
    {
        date_default_timezone_set("Asia/Jakarta");
        $tgl = date('Y-m-d');

        $perawat = $this->input->post('perawat');
        $dokter = $this->input->post('dokter');
        $prosedureop = $this->input->post('prosedureop');
        $verif = $this->input->post('verif');
        $tandaoprasi = $this->input->post('tandaoprasi');
        $bmhptersedia = $this->input->post('bmhptersedia');
        $riwayat = $this->input->post('riwayat');
        $kambuh = $this->input->post('kambuh');
        $riwayatjalaan = $this->input->post('riwayatjalaan');
        $riwayatalergi = $this->input->post('riwayatalergi');
        $jenisalergi = $this->input->post('jenisalergi');
        $resiko = $this->input->post('resiko');
        $implan = $this->input->post('implan');
        $keteranganimplan = $this->input->post('keteranganimplan');
        $tgl = $this->input->post('tgl');
        $time = $this->input->post('time');
        $tim = $this->input->post('tim');
        $Keterangantimop = $this->input->post('Keterangantimop');
        $membacakan = $this->input->post('membacakan');
        $resikotinggi = $this->input->post('resikotinggi');
        $berapajam = $this->input->post('berapajam');
        $antisipasidarah = $this->input->post('antisipasidarah');
        $asa = $this->input->post('asa');
        $perhatian = $this->input->post('perhatian');
        $peralatan = $this->input->post('peralatan');
        $seteril = $this->input->post('seteril');
        $kesiapanalat = $this->input->post('kesiapanalat');
        $fotorad = $this->input->post('fotorad');
        $antibiotik = $this->input->post('antibiotik');
        $halygperluperhatikan = $this->input->post('halygperluperhatikan');
        $perawatanverbal = $this->input->post('perawatanverbal');
        $kelengkapan = $this->input->post('kelengkapan');
        $bacaspecimen = $this->input->post('bacaspecimen');
        $masalahalat = $this->input->post('masalahalat');
        $throat = $this->input->post('throat');
        $cairantubuh = $this->input->post('cairantubuh');
        $keterangan = $this->input->post('keterangan');
        $jenisanastesi = $this->input->post('jenisanastesi');
        $dosis = $this->input->post('dosis');
        $carapemakaian = $this->input->post('carapemakaian');

        $this->db->query(
            "INSERT INTO erm_Ssc(
            case_id, 
            perawat,
            dokter,
            prosedureop,
            tanggal,
            verif,
            tandaoprasi, 
            bmhptersedia,
            riwayat,
            kambuh,
            riwayatjalaan, 
            riwayatalergi,
            jenisalergi,
            resiko,
            implan, 
            keteranganimplan,
            tgl,
            [time],
            tim,
            keterangantimop,
            membacakan,
            resikotinggi,
            berapajam,
            antisipasidarah,
            asa,
            perhatian,
            peralatan,
            seteril, 
            kesiapanalat,
            fotorad,
            antibiotik,
            halygperluperhatikan,
            perawatanverbal, 
            kelengkapan,
            bacaspecimen,
            masalahalat,
            throat,
            cairantubuh,
            keterangan,
            jenisanastesi,
            dosis,
            carapemakaian
            )VALUES (
                '$CaseID', 
                '$perawat',
                '$dokter',
                '$prosedureop',
                '$tgl',
                '$verif',
                '$tandaoprasi', 
                '$bmhptersedia',
                '$riwayat',
                '$kambuh',
                '$riwayatjalaan', 
                '$riwayatalergi',
                '$jenisalergi',
                '$resiko',
                '$implan', 
                '$keteranganimplan',
                '$tgl',
                '$time',
                '$tim',
                '$Keterangantimop',
                '$membacakan',
                '$resikotinggi',
                '$berapajam',
                '$antisipasidarah',
                '$asa',
                '$perhatian',
                '$peralatan',
                '$seteril', 
                '$kesiapanalat',
                '$fotorad',
                '$antibiotik',
                '$halygperluperhatikan',
                '$perawatanverbal', 
                '$kelengkapan',
                '$bacaspecimen',
                '$masalahalat',
                '$throat',
                '$cairantubuh',
                '$keterangan',
                '$jenisanastesi',
                '$dosis',
                '$carapemakaian'
            )"
        );

        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Data FormSSC Berhasil Tersimpan.</div>');
        redirect(base_url('Form/ssc/' . $CaseID));
    }

    public function cetakssc($id)
    {
        ob_start();
        $this->load->model('M_Utama');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['data'] = $this->db->query("select* from erm_ssc where case_id = '$id'")->row_array();
        $this->load->view('form/cetakssc', $data);
    }

    public function Resum($id)
    {
        date_default_timezone_set("Asia/Jakarta");
        $tgl = date('Y-m-d');
        $data['judul'] = "Resum Medis";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['unit'] = $this->db->query("SELECT * FROM Utama")->row_array();
        $data['pasien'] = $this->M_rekamMedis->pemeriksaan($id)->row_array();
        $data['hasil'] = $this->M_rekamMedis->hasilpemeriksaan($id)->row_array();
        $data['nonracik'] = $this->M_rekamMedis->Obatnonracik($id)->result_array();
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('form/FormResum', $data);
        $this->load->view('properti/footer', $data);
    }

    public function prosesResume($id)
    {
        $keluhan = $this->input->post('keluhan');
        $diagnosa = $this->input->post('diagnosa');
        $pemeriksaanfisik = $this->input->post('pemeriksaanfisik');
        $terapi = $this->input->post('terapi');
        $penunjang = $this->input->post('penunjang');
        $edukasi = $this->input->post('edukasi');
        $kontrol = $this->input->post('kontrol');
        $this->db->query(
            "INSERT INTO erm_formresum (
            case_id, 
            alasanberobat,
            diagnosa,
            pemeriksaanfisik,
            terapi,
            pemeriksaan,
            edukasi,
            kontrol
            )VALUES (
                '$id', 
                '$keluhan',
                '$diagnosa',
                '$pemeriksaanfisik',
                '$terapi',
                '$penunjang',
                '$edukasi',
                '$kontrol'
            )"
        );

        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Data Resume Tersimpan.</div>');
        redirect(base_url('Form/Resum/' . $id));
    }

    public function cetakresume($id)
    {
        ob_start();
        $this->load->model('M_Utama');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['unit'] = $this->db->query("SELECT * FROM Utama")->row_array();
        $data['data'] = $this->db->query("select* from erm_formresum where case_id = '$id'")->row_array();
        $this->load->view('form/cetakformresum', $data);
    }

    public function signatureanastesi()
    {
        $data['judul'] = "General Consent";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $this->load->view('form/signatureanastesi', $data);
    }

    public function simpansignature()
    {
        $data_uri = $_POST['foto'];
        $CaseID   = $_POST['caseid'];
        $namajelas   = $_POST['namajelas'];
        $image_parts_1 = explode(",", $data_uri)[1];
        $image_type_aux_1 = explode("image/", $image_parts_1[0]);
        $decoded_image = base64_decode($image_parts_1);
        file_put_contents("./images/uploadsign/anastesi/sig-" . $CaseID . ".png", $decoded_image);
        $ttd_1 = "sig-" . $CaseID . ".png";

        $this->db->query("INSERT INTO erm_ttdanastesi (CaseID, namajelas, tandatangan_1) VALUES ('$CaseID', '$namajelas', '$ttd_1')");
    }

    public function komunikaseEdukasi($caseid)
    {
        date_default_timezone_set("Asia/Jakarta");
        $tgl = date('Y-m-d');
        $data['judul'] = "Resum Medis";
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['unit'] = $this->db->query("SELECT * FROM Utama")->row_array();
        $data['cases'] = $this->db->query("SELECT [Case ID], Description, PatientCode FROM Cases WHERE [Case ID] = '$caseid'")->row_array();
        $data['form'] = $this->db->query("SELECT * FROM formKomunikasiEdukasi WHERE caseid = '$caseid'")->row_array();
        $data['cekform'] = $this->db->query("SELECT * FROM formKomunikasiEdukasi WHERE caseid = '$caseid'")->num_rows();
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('form/komunikasiEdukasi', $data);
        $this->load->view('properti/footer', $data);
    }

    public function prosesKomunikasiEdukasi($caseid)
    {
        $nama = $_POST['nama'];
        $norm = $_POST['norm'];
        $tanggal1 = $_POST['tanggal1'];
        $metode1 = $_POST['metode1'];

        $mengerti1 = $this->input->post('mengerti1');
        if ($mengerti1 == TRUE) {
            $vmengerti1 = "1";
        } else {
            $vmengerti1 = "0";
        }

        $ulang1 = $this->input->post('ulang1');
        if ($ulang1 == TRUE) {
            $vulang1 = "1";
        } else {
            $vulang1 = "0";
        }

        $tanggal2 = $_POST['tanggal2'];
        $metode2 = $_POST['metode2'];

        $mengerti2 = $this->input->post('mengerti2');
        if ($mengerti2 == TRUE) {
            $vmengerti2 = "1";
        } else {
            $vmengerti2 = "0";
        }

        $ulang2 = $this->input->post('ulang2');
        if ($ulang2 == TRUE) {
            $vulang2 = "1";
        } else {
            $vulang2 = "0";
        }

        $lainlain2 = $_POST['lainlain2'];
        $tanggal3 = $_POST['tanggal3'];
        $metode3 = $_POST['metode3'];

        $mengerti3 = $this->input->post('mengerti3');
        if ($mengerti3 == TRUE) {
            $vmengerti3 = "1";
        } else {
            $vmengerti3 = "0";
        }

        $ulang3 = $this->input->post('ulang3');
        if ($ulang3 == TRUE) {
            $vulang3 = "1";
        } else {
            $vulang3 = "0";
        }

        $this->db->query("INSERT INTO formKomunikasiEdukasi (caseid, nama, norm, tanggal1, metode1, mengerti1, ulang1, tanggal2, metode2, mengerti2, ulang2, lainlain2, tanggal3, metode3, mengerti3, ulang3) VALUES ('$caseid', '$nama', '$norm', '$tanggal1', '$metode1', '$vmengerti1', '$vulang1', '$tanggal2', '$metode2', '$vmengerti2', '$vulang2', '$lainlain2', '$tanggal3', '$metode3', '$vmengerti3', '$vulang3')");

        redirect($_SERVER['HTTP_REFERER']);
    }
}
