<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Detai Data Pasien
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Kalideres</a></li>
            <li class="active">Data Pasien</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <!-- Default box -->
        <div class="box">
            <div class="box-body">
                <a href="" data-toggle="modal" data-target="#baru" class="btn btn-sm btn-primary bg-blue-gradient"><i class="fa fa-fw fa-plus"></i> Pasien Baru</a>
                <a href="" data-toggle="modal" data-target="#caripasien" class="btn btn-sm btn-success bg-green-gradient"><i class="fa fa-fw fa-search"></i> Cari</a>
                <a href="" data-toggle="modal" data-target="#kartu<?= @$detail['PatientCode']; ?>" class="btn btn-sm btn-warning bg-yellow-gradient"><i class="fa fa-fw fa-print"></i> Cetak Kartu Pasien</a>
                <a href="<?= base_url('pendaftaran/pendaftaran?nomr=' . @$detail['PatientCode']); ?>" class="btn btn-sm btn-info bg-aqua-gradient"><i class="fa fa-fw fa-edit"></i> Daftar</a>
            </div><!-- /.box-body -->
        </div><!-- /.box -->

    </section><!-- /.content -->

    <!-- Main content -->
    <section class="content" style="margin-top: -180px;">
        <!-- Default box -->
        <div class="box">
            <div class="box-body">

                <div class="row" style="margin-top: 20px;">
                    <div class="col-md-4" align="center">
                        <?php
                        if (@$detail['Sex'] == 1) {
                        ?>
                            <img style="margin-top: 35px;" src="<?= base_url('images/female.png'); ?>" class="img img-responsive">
                        <?php
                        } else {
                        ?>
                            <img style="margin-top: 35px;" src="<?= base_url('images/male.png'); ?>" class="img img-responsive">
                        <?php
                        }
                        ?>
                    </div>
                    <div class="col-md-8">
                        <table class="table table-striped">
                            <tr>
                                <?php
                                $mr = @$detail['PatientCode'];
                                $count = $this->db->query("SELECT PatientCode FROM Cases WHERE PatientCode = '$mr'")->num_rows();
                                ?>
                                <td colspan="3">
                                    <h4 style="font-weight: bold;" class="text-primary">MR.<?= @$mr; ?> ( <?= $count; ?> x Kunjungan ) </h4>
                                </td>
                            </tr>
                            <tr>
                                <td width="20%">Nama</td>
                                <td width="5%">:</td>
                                <td><?= @$detail['FirstName'] . ' ' . @$detail['LastName']; ?></td>

                            </tr>
                            <tr>
                                <td width="20%">Jenis Kelamin</td>
                                <td width="5%">:</td>
                                <td>
                                    <?php
                                    if (@$detail['Sex'] == 1) {
                                        echo "Perempuan";
                                    } else {
                                        echo "Laki-laki";
                                    }
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td width="20%">TTL</td>
                                <td width="5%">:</td>
                                <td><?= @$detail['DOBPlace'] . ', ' . date('d F Y', strtotime(@$detail['DOB'])); ?></td>
                            </tr>
                            <tr>
                                <td width="20%">Usia</td>
                                <td width="5%">:</td>
                                <td>
                                    <?php
                                    $tgll = date('Y-m-d', strtotime(@$detail['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;
                                    echo $thn . " tahun " . $bln . " bulan " . $tgl . " hari";
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td>No.HP</td>
                                <td>:</td>
                                <td><?= @$detail['CellPhone']; ?></td>
                            </tr>
                            <tr>
                                <td>Asuransi / Penjamin</td>
                                <td>:</td>
                                <td>
                                    <?php
                                    $codeComp = $detail['CompanyCode'];
                                    $penjamin = $this->db->query("SELECT * FROM Company WHERE CompanyCode = '$codeComp'")->row_array();
                                    echo @$penjamin['CompanyName'];
                                    ?>
                                    ( <?= @$detail['EmployeeID']; ?> )
                                </td>
                            </tr>
                            <tr>
                                <td>Perusahaan</td>
                                <td>:</td>
                                <td>
                                    <?php

                                    echo @$detail['NAMA PERUSAHAAN'];

                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                    <a href="<?= base_url('pasien/editIdentitas/' . $detail['PatientCode']); ?>" class="btn btn-sm btn-primary bg-blue-gradient">Edit Identitas</a>
                                    <a href="<?= base_url('pasien/editAsuransi/' . $detail['PatientCode']); ?>" class="btn btn-sm btn-success bg-green-gradient">Edit Asuransi</a>
                                    <!-- <a href="" class="btn btn-sm btn-info">Edit Perusahaan</a> -->
                                    <a href="<?= base_url('pasien/hapusPasien/' . $detail['PatientCode']); ?>" onclick="return confirm('Hapus?')" class="btn btn-sm btn-danger bg-red-gradient">Hapus Pasien</a>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>

            </div><!-- /.box-body -->
            <div class="box-footer">
                <?= date('d F Y'); ?>
            </div><!-- /.box-footer-->
        </div><!-- /.box -->

    </section><!-- /.content -->
</div><!-- /.content-wrapper -->
<!-- Modal -->
<div class="modal fade" id="baru" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel"><i class="fa fa-fw fa-pencil"></i> PASIEN BARU</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">

                <form action="<?= base_url('pasien/formNik'); ?>" method="get">
                    <input type="text" placeholder="NIK..." class="form-control" required name="nik">
                    <button style="width: 100%; border-radius: 0px;" type="submit" class="btn btn-sm btn-success">Daftar By NIK Bridging</button>
                </form>

                <div style="margin-top: 5px; text-align:right">
                    <a href="<?= base_url('pasien/form'); ?>">Daftar Biasa</a>
                </div>


            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="caripasien" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel"><i class="fa fa-fw fa-search"></i> CARI PASIEN</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">

                <form action="<?= base_url('pasien/cari'); ?>" method="get">
                    <select name="jenis" style="margin-bottom: 5px;" class="form-control" required>
                        <option value=""></option>
                        <option value="1">No MR</option>
                        <option value="2">Nama Depan</option>
                        <option value="3">Nama Belakang</option>
                        <!-- <option value="4">Tanggal Lahir</option> -->
                    </select>
                    <input type="text" style="margin-bottom: 5px;" placeholder="KETIK JENIS..." class="form-control" required name="pencarian">
                    <button style="width: 100%; border-radius: 0px;" type="submit" class="btn btn-sm btn-success">Cari</button>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="kartu<?= @$detail['PatientCode']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <div class="row">
                    <div class="col-md-6">
                        <h4 style="font-weight: bolder;" class="modal-title" id="exampleModalLabel"><i class="fa fa-fw fa-credit-card"></i> KARTU PASIEN </h4>
                    </div>
                    <div class="col-md-6" align="right">
                        <a href="<?= base_url('CetakFR/cetakKartu/'.@$detail['PatientCode']); ?>" target="_blank" class="btn btn-sm btn-success" style="border-radius: 0px;"><i class="fa fa-fw fa-print"></i> Cetak Kartu</a>
                    </div>
                </div>


            </div>
            <img src="<?= base_url('aset/img/bg.png'); ?>" class="img img-responsive">

            <div class="row" style="margin-top: -280px;">
                <div class="col-md-1"></div>
                <div class="col-md-10">
                    <table class="table table-striped" style="font-weight: bold;">
                        <tr>
                            <td>Medical Record</td>
                            <td>:</td>
                            <td><?= @$detail['PatientCode']; ?></td>
                        </tr>
                        <tr>
                            <td>No.BPJS / Asuransi</td>
                            <td>:</td>
                            <td><?= @$detail['EmployeeID']; ?></td>
                        </tr>
                        <tr>
                            <td>Nama</td>
                            <td>:</td>
                            <td><?= @$detail['FirstName'] . ' ' . @$detail['LastName']; ?></td>
                        </tr>
                        <tr>
                            <td>Jenis Kelamin</td>
                            <td>:</td>
                            <td>
                                <?php
                                if (@$detail['Sex'] == 1) {
                                    echo "Perempuan";
                                } else {
                                    echo "Laki-laki";
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td>TTL</td>
                            <td>:</td>
                            <td><?= @$detail['DOBPlace'] . ', ' . date('d-m-Y', strtotime(@$detail['DOB'])); ?></td>
                        </tr>
                        <tr>
                            <?php
                            $barcode = @$detail['PatientCode'];
                            ?>
                            <td colspan="3"></td>
                        </tr>

                    </table>
                </div>
                <div class="col-md-1"></div>
            </div>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="<?= @$detail['EmployeeID']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form action="<?= base_url('pencarian/multiRujukan'); ?>" method="get">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel" style="font-weight: bold;">Pilih Fasilitas Kesehatan</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body" align="center">
                    <select name="faskes" class="form-control" required>
                        <option value="1">Faskes 1</option>
                        <option value="2">Faskes 2</option>
                    </select>
                    <input type="text" name="nokartu" value="<?= @$detail['EmployeeID']; ?>" hidden>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-sm btn-primary">Submit</button>
                </div>
            </form>
        </div>
    </div>
</div>