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

class CatatanKehamilan extends CI_Controller
{

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

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

    public function ProsesPencatatan()
    {
      $caseID         = $this->input->post('caseID');
      $hpht           = $this->input->post('hpht');
      $htp            = $this->input->post('htp');
      $GolonganDarah  = $this->input->post('GolonganDarah');
      $kontrasepsi    = $this->input->post('kontrasepsi');
      $penyakitygdiderita  = $this->input->post('penyakitygdiderita');
      $riwayatalergi   = $this->input->post('riwayatalergi');
      $statusimunisasi = $this->input->post('statusimunisasi');
      $g              = $this->input->post('g');
      $p              = $this->input->post('p');
      $a              = $this->input->post('a');
      $tb             = $this->input->post('tb');

      $this->db->query(
        "INSERT INTO erm_catatanawalkehamilan (
            caseID, 
            hpht,
            htp,
            GolonganDarah,
            kontrasepsi,
            penyakitygdiderita,
            riwayatalergi,
            g,
            p,
            a,
            tb,
            statusimunisasi
        )VALUES (
            '$caseID', 
            '$hpht',
            '$htp',
            '$GolonganDarah',
            '$kontrasepsi',
            '$penyakitygdiderita',
            '$riwayatalergi',
            '$g',
            '$p',
            '$a',
            '$tb',
            '$statusimunisasi'
        )"
    );

    $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Berhasil Tersimpan.</div>');
    redirect($_SERVER['HTTP_REFERER']); 

    
    }

    public function Prosescatatankehamilan()
    {
        $CaseID = $this->input->post('CaseID');
        $Gs = $this->input->post('Gs');
        $in1 = $this->input->post('in1');
        $Fe = $this->input->post('Fe');
        $Tu = $this->input->post('Tu');
        $Ys = $this->input->post('Ys');
        $Fhr = $this->input->post('Fhr');
        $Crl = $this->input->post('Crl');
        $Nt = $this->input->post('Nt');
        $frekuensi = $this->input->post('frekuensi');
        $minggu = $this->input->post('minggu');
        $kesimpulan = $this->input->post('kesimpulan');
        $Bpd = $this->input->post('Bpd');
        $Hc = $this->input->post('Hc');
        $Ac = $this->input->post('Ac');
        $Uk = $this->input->post('Uk');
        $Fl = $this->input->post('Fl');
        $Tp = $this->input->post('Tp');
        $fudus = $this->input->post('fudus');
        $ica = $this->input->post('ica');
        $oui = $this->input->post('oui');
        $fhr1 = $this->input->post('fhr1');
        $jenis = $this->input->post('jenis');
        $kesimpulan2 = $this->input->post('kesimpulan2');
        $Af = $this->input->post('Af');
        $Membesar = $this->input->post('Membesar');
        $m1 = $this->input->post('m1');
        $m2 = $this->input->post('m2');
        $m3 = $this->input->post('m3');
        $ovakanan = $this->input->post('ovakanan');
        $ovakiri = $this->input->post('ovakiri');
        $massa = $this->input->post('massa');
        $kesimpulan3 = $this->input->post('kesimpulan3');
        $gerakjanin = $this->input->post('gerakjannin');
        $tbj = $this->input->post('tbj');

        $this->db->query(
            "INSERT INTO erm_catatanhamil (
                    CaseID,
                    Gs,
                    in1,
                    Fe,
                    Tu,
                    Ys,
                    Fhr,
                    Crl,
                    Nt,
                    frekuensi,
                    minggu,
                    kesimpulan,
                    Bpd,
                    Hc,
                    Ac,
                    Uk,
                    Fl,
                    Tp,
                    fudus,
                    oui,
                    fhr1,
                    jenis,
                    kesimpulan2,
                    Af,
                    Membesar,
                    m1,
                    m2,
                    m3,
                    ovakanan,
                    ovakiri,
                    massa,
                    kesimpulan3,
                    ica,
                    gerakjanin,
                    tbj
            )VALUES (
                '$CaseID',
                '$Gs',
                '$in1',
                '$Fe',
                '$Tu',
                '$Ys',
                '$Fhr',
                '$Crl',
                '$Nt',
                '$frekuensi',
                '$minggu',
                '$kesimpulan',
                '$Bpd',
                '$Hc',
                '$Ac',
                '$Uk',
                '$Fl',
                '$Tp',
                '$fudus',
                '$oui',
                '$fhr1',
                '$jenis',
                '$kesimpulan2',
                '$Af',
                '$Membesar',
                '$m1',
                '$m2',
                '$m3',
                '$ovakanan',
                '$ovakiri',
                '$massa',
                '$kesimpulan3',
                '$ica',
                '$gerakjanin',
                '$tbj'
            )"
        );

        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Catatan Kehamilan Tersimpan.</div>');
        redirect($_SERVER['HTTP_REFERER']); 
    }

    public function prosescatatankb()
    {
        $CaseID  = $this->input->post('CaseID');
        $menerche  = $this->input->post('menerche');
        $lamanya  = $this->input->post('lamanya');
        $banyaknya  = $this->input->post('banyaknya');
        $dysmenore  = $this->input->post('dysmenore');
        $haid_terakhir  = $this->input->post('haid_terakhir');
        $Jantung  = $this->input->post('Jantung');
        $Paru  = $this->input->post('Paru');
        $Hipertensi  = $this->input->post('Hipertensi');
        $Diabet  = $this->input->post('Diabet');
        $Pms  = $this->input->post('Pms');
        $metode_kb  = $this->input->post('metode_kb');
        $lamanya1  = $this->input->post('lamanya1');
        $keluhan  = $this->input->post('keluhan');
        $kbpilihan  = $this->input->post('kbpilihan');

        $this->db->query(
            "INSERT INTO erm_catatankb (
                CaseID,
                menerche,
                lamanya,
                banyaknya,
                dysmenore,
                haid_terakhir,
                Jantung,
                Paru,
                Hipertensi,
                Diabet,
                Pms,
                metode_kb,
                lamanya1,
                keluhan,
                kbpilihan
            )VALUES (
                '$CaseID',
                '$menerche',
                '$lamanya',
                '$banyaknya',
                '$dysmenore',
                '$haid_terakhir',
                '$Jantung',
                '$Paru',
                '$Hipertensi',
                '$Diabet',
                '$Pms',
                '$metode_kb',
                '$lamanya1',
                '$keluhan',
                '$kbpilihan'
            )"
        );

        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Catatan KB Tersimpan.</div>');
        redirect($_SERVER['HTTP_REFERER']); 
    }

    public function ViewCatatanawal($id){
        $tgl = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['catatanawal'] = $this->db->query("select * from erm_catatanawalkehamilan cah join Cases c on c.[Case ID] = cah.CaseID where c.PatientCode = '$id'")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('catatankehamilan/page/ViewCatatanawal', $data);
        $this->load->view('properti/footer', $data);
    }

    public function ViewCatatanhamil($id){
        $tgl = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['catatanhamil'] = $this->db->query("select * from erm_catatanhamil cah join Cases c on c.[Case ID] = cah.CaseID where c.PatientCode ='$id'")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('catatankehamilan/page/ViewCatatanhamil', $data);
        $this->load->view('properti/footer', $data);
    }

    public function ViewCatatanKb($id){
        $tgl = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['catatanhamil'] = $this->db->query("select * from erm_catatankb cah join Cases c on c.[Case ID] = cah.CaseID where c.PatientCode ='$id'")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('catatankehamilan/page/ViewCatatanKb', $data);
        $this->load->view('properti/footer', $data);
    }

    public function cetakKb($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['catatanKb'] = $this->db->query("SELECT [CaseID],c.PatientCode,c.Description,[menerche],[lamanya],[banyaknya],[dysmenore],[haid_terakhir]
        ,[Jantung]
        ,[Paru]
        ,[Hipertensi]
        ,[Diabet]
        ,[Pms]
        ,[metode_kb]
        ,[lamanya1]
        ,[keluhan]
        ,[kbpilihan]
        ,p.DOB
        ,p.HomeAddress1
        FROM erm_catatanKb kb INNER JOIN Cases c ON c.[Case ID] = kb.CaseID
        INNER JOIN Patient p on p.PatientCode = c.PatientCode where kb.CaseID = '$id'")->row_array();
        $this->load->view('cetak/cetakKB', $data);

    }

    public function cetakcatatanhamil($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['datahamil'] = $this->db->query("SELECT [CaseID],c.PatientCode,c.Description,[CaseID]
        ,[Gs], [in1] ,[Fe] ,[Tu] ,[Ys],[Fhr],[Crl],[Nt],[frekuensi],[minggu],[kesimpulan],[Bpd]
        ,[Hc],[Ac],[Uk],[Fl],[Tp],[fudus],[oui],[fhr1]
        ,[jenis],[kesimpulan2],[ica],tbj,gerakjanin
        ,[Af],[Membesar],[m1],[m2],[m3],[ovakanan],[ovakiri],[massa]
        ,[kesimpulan3],p.DOB ,p.HomeAddress1
        FROM erm_catatanhamil kb INNER JOIN Cases c ON c.[Case ID] = kb.CaseID
        INNER JOIN Patient p on p.PatientCode = c.PatientCode where kb.CaseID = '$id'")->row_array();
        $this->load->view('cetak/cetakcatatanhamil', $data);

    }

    public function cetakawalhamil($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['datahamil'] = $this->db->query("SELECT [CaseID],c.PatientCode,c.Description,
            [hpht],[htp],d.[GolonganDarah],k.namakontrasepsi,[penyakitygdiderita],[riwayatalergi],
            [g],[p],[a],[tb],[CaseID],[statusimunisasi],p.DOB ,p.HomeAddress1
            FROM erm_catatanawalkehamilan kb INNER JOIN Cases c ON c.[Case ID] = kb.CaseID
            INNER JOIN Patient p on p.PatientCode = c.PatientCode
			INNER JOIN erm_GolonganDarah d on d.idGolongan = kb.GolonganDarah
			inner join erm_kontrasepsi k on k.idkontrasepsi = kb.kontrasepsi
            where CaseID = '$id'")->row_array();
            $this->load->view('cetak/cetakawalhamil', $data);
        }


}
