<?php
date_default_timezone_set("Asia/Jakarta");
$caseID = $this->uri->segment(3);
$cekid = $this->db->query("select* from erm_Pengkajiansbar where CaseID = '$caseID'")->row_array();
$d = $this->db->query("Select * from Patient p join Cases c on p.PatientCode = c.PatientCode where c.[Case ID] = '$caseID' ")->row_array();
$tgll = date('Y-m-d', strtotime(@$d['DOB']));
$tanggal_lahir = new DateTime($tgll);
$sekarang = new DateTime("today");
if ($tanggal_lahir > $sekarang) {
    $thn = "0";
    $bln = "0";
    $tgl = "0";
}
$thn = $sekarang->diff($tanggal_lahir)->y;
$bln = $sekarang->diff($tanggal_lahir)->m;
$tgl = $sekarang->diff($tanggal_lahir)->d;
?>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Resum Medis
            <?php
            if ($cekid > 0) {
            ?>
                - <a href="<?= base_url('Formkomunikasi/cetakformkomunikasi/' . $this->uri->segment(3)) ?>" target="_blank" class="btn btn-primary"><i class="fa fa-print"></i> Cetak </a><br>
            <?php } else { ?>

            <?php } ?>
        </h1>
        <ol class="breadcrumb">
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="card" style="padding: 15px; background-color: white;border-radius: 5px;">
            <div class="card-body">
                <?php
                // Session 
                if ($this->session->flashdata('message')) {
                    echo $this->session->flashdata('message');
                }
                ?>
                <div class="row text-center">
                    <div class="col-md-2"></div>
                    <div class="col-md-2">
                        <img src="<?= base_url('images/logo.png'); ?>" height="80px">
                    </div>
                    <div class="col-md-6">
                        <h4 style="font-weight: bold;">
                            <?= $unit['NamaPerusahaan']; ?><br>
                            FORM KOMUNIKASI EFEKTIF SBAR TBK
                        </h4>
                    </div>
                    <div class="col-md-2"></div>
                </div>
                <div class="row text-center">
                    <div class="col-md-2"></div>
                    <div class="col-md-8">
                        <hr>
                    </div>
                    <div class="col-md-2"></div>
                </div>
                <table class="table table-striped table-hover" id="example1" style="border-collapse: collapse;text-align:left width:100%;">
                    <tr>
                        <td>No.MR</td>
                        <td>:</td>
                        <td><?= $d['PatientCode']; ?></td>
                    </tr>
                    <tr>
                        <td>No.Reg</td>
                        <td>:</td>
                        <td><?= $d['Case ID']; ?></td>
                    </tr>
                    <tr>
                        <td>Nama</td>
                        <td>:</td>
                        <td><?= $d['Description']; ?></td>
                    </tr>
                    <tr>
                        <td>Kunjungan</td>
                        <td>:</td>
                        <td><?= date('d-m-Y', strtotime($d['Intake Date'])); ?></td>
                    </tr>
                    <tr>
                        <td>Jenis Kelamin</td>
                        <td>:</td>
                        <?php
                        if ($d['Sex'] == 1) {
                            $Jenis = "Perempuan";
                        } else {
                            $Jenis = "Laki - Laki";
                        }
                        ?>
                        <td><?= $Jenis; ?></td>
                    </tr>
                    <tr>
                        <td>Tanggal Lahir</td>
                        <td>:</td>
                        <td>
                            <?php
                            if ($d['DOB'] == '') {
                            } else {
                                echo date('d-m-Y', strtotime($d['DOB']));
                            }
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td>Umur</td>
                        <td>:</td>
                        <td><?= $thn . ' th ' . $bln . ' bulan ' . $tgl . ' hari'; ?></td>
                    </tr>
                    <tr>
                        <td>Alamat</td>
                        <td>:</td>
                        <td><?= $d['HomeAddress1']; ?></td>
                    </tr>
                </table>
                <hr><br>
                <form action="<?= base_url('Formkomunikasi/proses/' . $this->uri->segment(3)); ?>" method="post">
                    <p style="text-align: center;"><b>RESUM MEDIS</b></p>
                    <table class="table table-striped" id="example1" style="border-collapse: collapse;text-align:left width:100%;">
                    <tr>
                        <td>TULISKANANALISAPENGKAJIAN</td>
                        <td>:</td>
                        <td><textarea class="form-control" name="pengkajian" cols="50" rows="8" placeholder="TULISKANANALISAPENGKAJIAN"></textarea></td>
                    </tr>
                    <tr>
                        <td>RECOMMENDATION</td>
                        <td>:</td>
                        <td><textarea class="form-control" name="recomendation" cols="50" rows="10" placeholder="RECOMMENDATION"></textarea></td>
                    </tr>
                    <tr>
                        <td>TULISLENGKAPADVISDOKTER</td>
                        <td>:</td>
                        <td><textarea class="form-control" name="tulisdokter"  cols="50" rows="10" placeholder="TULISLENGKAPADVISDOKTER"></textarea></td>
                    </tr>
                    <tr>
                        <td>BACAULANGADVISDOKTER</td>
                        <td>:</td>
                        <td><textarea class="form-control" name="bacaulang"  cols="50" rows="10" placeholder="BACAULANGADVISDOKTER"></textarea></td>
                    </tr>
                    <tr>
                        <td>KONFIRMASI</td>
                        <td>:</td>
                        <td><textarea class="form-control" name="konfirmasi" cols="50" rows="10" placeholder="KONFIRMASI"></textarea></td>
                    </tr>
                    <tr>
                        <td>TTD SBAR</td>
                        <td>:</td>
                        <td><a href="#" onclick="openWin()" class="btn btn-success">Tanda Tangan</a></td>

                        <td>TTD TBK</td>
                        <td>:</td>
                        <td><a href="#" onclick="openWin1()" class="btn btn-primary">Tanda Tangan</a></td>
                    </tr>
                    </table>
                    <br>
                    <div class="row">
                        <div class="col-md-12">
                            <?php
                            if ($cekid > 0) {
                            ?>
                                <button type="submit" class="btn btn-sm btn-danger" style="width: 100%;" disabled>Data Sudah Di Input</button>
                            <?php } else { ?>
                                <button onclick="return confirm('Apakah pengisian sudah benar?')" type="submit" class="btn btn-sm btn-primary" style="width: 100%;">Simpan</button>
                            <?php } ?>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>

<script>
    let myWindow;

    function openWin() {
        myWindow = window.open("<?= base_url('Formkomunikasi/signature_1/' . $this->uri->segment(3)); ?>", "_blank", "width=1000, height=800");
    }

    function closeWin() {
        myWindow.close();
    }

    function openWin1() {
        myWindow = window.open("<?= base_url('Formkomunikasi/signature_2/' . $this->uri->segment(3)); ?>", "_blank", "width=1000, height=800");
    }

    function closeWin1() {
        myWindow.close();
    }
</script>