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

class CetakFR extends CI_Controller
{

    // CONSTRUCT

    public function resume($id)
    {

        // ===================================================================================

        ob_start();
        $this->load->view('cetakFR/resume');
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '115';
            $height_in_mm = '170';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en');
            $html2pdf = new HTML2PDF('P', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 10, 2, 10));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakObat($tr, $id)
    {
        $this->load->model('M_Utama');
        $this->load->model('M_rekamMedis');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        ob_start();
        $data['id'] = $this->db->query("SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan, P.DOB AS TTL, D.[FirstName] AS Dokter, CA.Unit AS Poli, C.CompanyCode FROM Cases C, CaseAdmin CA, Doctor D, Patient P WHERE C.[Case ID] = '$id' AND C.[Case ID]=CA.[Case ID] AND CA.[DoctorID] = D.[DoctorID] AND C.[PatientCode]=P.[PatientCode]")->row_array();
        $data['hasilpemeriksaan'] = $this->M_rekamMedis->pemeriksaan($id)->row_array();
        $data['hasilpreksa'] = $this->M_rekamMedis->hasilpemeriksaan($id)->row_array();
        $this->load->view('cetakFR/cetakObat', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '80';
            $height_in_mm = '215';

            //$html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 5, 2));
            $html2pdf = new HTML2PDF('P', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 10, 2, 10));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakObatRacikan($tr, $id)
    {
        ob_start();
        $data['id'] = $this->db->query("SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan, P.DOB AS TTL, D.[FirstName] AS Dokter, CA.Unit AS Poli, C.CompanyCode FROM Cases C, CaseAdmin CA, Doctor D, Patient P WHERE C.[Case ID] = '$id' AND C.[Case ID]=CA.[Case ID] AND CA.[DoctorID] = D.[DoctorID] AND C.[PatientCode]=P.[PatientCode]")->row_array();
        $this->load->view('cetakFR/cetakObatRacikan', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            // $width_in_mm = '60';
            // $height_in_mm = '60';

            $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 5, 2));
            // $html2pdf = new HTML2PDF('P', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 10, 2, 10));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakTiket($id)
    {
        ob_start();
        $data['id'] = $this->db->query("SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan, P.DOB AS TTL, D.[FirstName] AS Dokter, CA.Unit AS Poli, C.CompanyCode FROM Cases C, CaseAdmin CA, Doctor D, Patient P WHERE C.[Case ID] = '$id' AND C.[Case ID]=CA.[Case ID] AND CA.[DoctorID] = D.[DoctorID] AND C.[PatientCode]=P.[PatientCode]")->row_array();
        $data['Obat'] = $this->db->query("SELECT * FROM [Activity Apotik]  AA, Pharmacy P WHERE AA.DrugsID=P.PharmacyCode AND ID = '$id'")->row_array();
        $this->load->view('cetakFR/cetakTiket', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '60';
            $height_in_mm = '60';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('P', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 2, 1, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakAllObat($trx, $id)
    {
        ob_start();
        $data['id'] = $this->db->query("SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan, P.DOB AS TTL, D.[FirstName] AS Dokter, CA.Unit AS Poli, C.CompanyCode FROM Cases C, CaseAdmin CA, Doctor D, Patient P WHERE C.[Case ID] = '$id' AND C.[Case ID]=CA.[Case ID] AND CA.[DoctorID] = D.[DoctorID] AND C.[PatientCode]=P.[PatientCode]")->row_array();
        $data['Obat'] = $this->db->query("SELECT AA.Dosis,AA.Cara,AA.Ket,AA.Unit,p.Indikasi,p.Description,AA.Qty FROM [Activity Drugs] AA JOIN Pharmacy P on AA.DrugsID = p.PharmacyCode 
        where Aa.[Case ID] = '$id' and AA.TransactionID = '$trx'")->result_array();
        $this->load->view('cetakFR/cetakAllTiket', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '70';
            $height_in_mm = '38';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('L', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 2, 1, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakTiketKecil($id)
    {
        ob_start();
        $data['id'] = $this->db->query("SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan, P.DOB AS TTL, D.[FirstName] AS Dokter, CA.Unit AS Poli, C.CompanyCode FROM Cases C, CaseAdmin CA, Doctor D, Patient P WHERE C.[Case ID] = '$id' AND C.[Case ID]=CA.[Case ID] AND CA.[DoctorID] = D.[DoctorID] AND C.[PatientCode]=P.[PatientCode]")->row_array();
        $data['Obat'] = $this->db->query("SELECT * FROM [Activity Drugs]  AA, Pharmacy P WHERE AA.DrugsID=P.PharmacyCode AND ID = '$id'")->row_array();
        $this->load->view('cetakFR/cetakTiketKecil', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '60';
            $height_in_mm = '40';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('L', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 1, 1, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }
    public function cetakTiketKecilB($id)
    {
        ob_start();
        $data['id'] = $this->db->query("SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan, P.DOB AS TTL, D.[FirstName] AS Dokter, CA.Unit AS Poli, C.CompanyCode FROM Cases C, CaseAdmin CA, Doctor D, Patient P WHERE C.[Case ID] = '$id' AND C.[Case ID]=CA.[Case ID] AND CA.[DoctorID] = D.[DoctorID] AND C.[PatientCode]=P.[PatientCode]")->row_array();
        $data['Obat'] = $this->db->query("SELECT * FROM [Activity Apotik]  AA, Pharmacy P WHERE AA.DrugsID=P.PharmacyCode AND ID = '$id'")->row_array();
        $this->load->view('cetakFR/cetakTiketKecilB', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '70';
            $height_in_mm = '38';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('L', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 3, 1, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakTiketKecilRacikan($id)
    {
        ob_start();
        $data['id'] = $this->db->query("SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan, P.DOB AS TTL, D.[FirstName] AS Dokter, CA.Unit AS Poli, C.CompanyCode FROM Cases C, CaseAdmin CA, Doctor D, Patient P WHERE C.[Case ID] = '$id' AND C.[Case ID]=CA.[Case ID] AND CA.[DoctorID] = D.[DoctorID] AND C.[PatientCode]=P.[PatientCode]")->row_array();
        $data['id'] = $this->db->query("SELECT * FROM Resep_Racikan_H WHERE ResepId = '$id'")->row_array();
        $this->load->view('cetakFR/cetakTiketKecilRacikan', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '60';
            $height_in_mm = '40';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('L', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 1, 1, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakTiketKecilRacikanA($id)
    {
        ob_start();
        $data['id'] = $this->db->query("SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan, P.DOB AS TTL, D.[FirstName] AS Dokter, CA.Unit AS Poli, C.CompanyCode FROM Cases C, CaseAdmin CA, Doctor D, Patient P WHERE C.[Case ID] = '$id' AND C.[Case ID]=CA.[Case ID] AND CA.[DoctorID] = D.[DoctorID] AND C.[PatientCode]=P.[PatientCode]")->row_array();
        $data['id'] = $this->db->query("SELECT * FROM Resep_Racikan_H WHERE ResepId = '$id'")->row_array();
        $this->load->view('cetakFR/cetakTiketKecilRacikanA', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '95';
            $height_in_mm = '39';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('L', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 1, 1, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakTiketRacikan($id)
    {
        ob_start();
        $data['id'] = $this->db->query("SELECT * FROM Resep_Racikan_H WHERE ResepId = '$id'")->row_array();
        $this->load->view('cetakFR/cetakTiketRacikan', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '60';
            $height_in_mm = '60';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('P', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(0, 0, 0, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }


    public function cetakGelangDewasa($id)
    {
        ob_start();
        $data['id'] = $id = $this->db->query("SELECT * FROM Cases WHERE [Case ID] = '$id'")->row_array();
        $pasien = $id['PatientCode'];
        $company = $id['CompanyCode'];
        $data['pasien'] = $this->db->query("SELECT * FROM Patient WHERE PatientCode = '$pasien'")->row_array();
        $data['company'] = $this->db->query("SELECT * FROM Company WHERE CompanyCode = '$company'")->row_array();
        $this->load->view('cetakFR/cetakGelangDewasa', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '25';
            $height_in_mm = '278';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('L', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(3, 4, 5, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakGelangAnak($id)
    {
        ob_start();
        $data['id'] = $id = $this->db->query("SELECT * FROM Cases WHERE [Case ID] = '$id'")->row_array();
        $pasien = $id['PatientCode'];
        $company = $id['CompanyCode'];
        $data['pasien'] = $this->db->query("SELECT * FROM Patient WHERE PatientCode = '$pasien'")->row_array();
        $data['company'] = $this->db->query("SELECT * FROM Company WHERE CompanyCode = '$company'")->row_array();
        $this->load->view('cetakFR/cetakGelangAnak', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '20';
            $height_in_mm = '215.9';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('L', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(3, 4, 5, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function laporanAdm()
    {
        extract($_GET);
        $userT = str_replace("vrs-", "", $user);
        $data['tanggal'] = $tanggal;
        $data['user'] = $this->db->get_where('userV2', ['UserName' => $userT])->row_array();
        $data['dataAdmOP'] = $this->db->query("SELECT * FROM Cases WHERE [Intake Date] = '$tanggal' AND UserCreated = '$user' AND [Category] = 'OP'")->result_array();
        $data['dataAdmIP'] = $this->db->query("SELECT * FROM Cases WHERE [Intake Date] = '$tanggal' AND UserCreated = '$user' AND [Category] = 'IP'")->result_array();
        $data['judul'] = "Laporan Admision";
        $this->load->view('cetakBerkas/cetakLaporanAdm', $data);
    }

    public function resumeMedis($case_id)
    {
        ob_start();
        $data['case'] = $this->db->query("SELECT * FROM Cases WHERE [Case ID] = '$case_id'")->row_array();
        $this->load->view('cetakFR/resumeMedis', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(20, 10, 15, 10));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('resume.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakAllRacikan($trx, $id)
    {
        ob_start();
        $idracikan = $this->uri->segment(5);
        $data['id'] = $this->db->query("SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan, P.DOB AS TTL, D.[FirstName] AS Dokter, CA.Unit AS Poli, C.CompanyCode FROM Cases C, CaseAdmin CA, Doctor D, Patient P WHERE C.[Case ID] = '$id' AND C.[Case ID]=CA.[Case ID] AND CA.[DoctorID] = D.[DoctorID] AND C.[PatientCode]=P.[PatientCode]")->row_array();
        $data['daTa'] = $this->db->query("SELECT AA.Dosis,AA.Cara,AA.Ket,AA.Unit,p.Indikasi,p.Description,AA.Qty FROM [Activity Drugs] AA JOIN Pharmacy P on AA.DrugsID = p.PharmacyCode 
        where Aa.[Case ID] = '$id' and AA.TransactionID = '$trx'")->row_array();
        $data['Racik'] = $this->db->query("Select * from Resep_Racikan_H where IdRacikan = '$idracikan'")->row_array();
        $this->load->view('cetakFR/cetakAllTiketRacik', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '70';
            $height_in_mm = '38';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('L', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 2, 1, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function cetakKartu($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['pasien'] = $this->db->query("Select * From Patient where PatientCode = '$id'")->row_array();
        $this->load->view('cetak/cetakKartu', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            $width_in_mm = '100';
            $height_in_mm = '58';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 2, 10));
            $html2pdf = new HTML2PDF('L', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 2, 1, 0));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('kartu Pasien.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }
}
