<?php
date_default_timezone_set("Asia/Jakarta");
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Data Rekam Medis
            <small>Klinik</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Record</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">

        <!-- SELECT2 EXAMPLE -->
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">Rekam Medis</h3>
                <div class="box-tools pull-right">
                        <a href="" data-toggle="modal" data-target="#pencarian" class="btn btn-sm btn-primary bg-blue-gradient" data-backdrop="static" data-keyboard="false"><i class="fa fa-fw fa-search"></i> Cari</a>
                    </div>
            </div><!-- /.box-header -->
            <div class="box-body">
                <small>
                    <table id="example1" class="table table-bordered table-hover table-striped">
                        <thead>
                            <tr>
                                <th>No.</th>
                                <th>Case ID</th>
                                <th>Nama</th>
                                <th>Penjamin</th>
                                <th>Status Pasien</th>
                                <th>Status</th>
                                <th>Poli</th>
                                <th>Dokter</th>
                                <th>Status Cppt</th>
                                <th>Opsi</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $no = 1;
                            foreach ($record as $data) :
                                $Mr = $data['PatientCode'];
                                $statusCppt = $this->db->query("SELECT Note FROM HeaderCppt WHERE Mr = '$Mr' ORDER BY IdHeader DESC")->row_array();
                            ?>
                            <tr>
                                <td><?= $no++; ?></td>
                                <td><?= $data['Case ID']; ?></td>
                                <td><?= $data['Description']; ?></td>
                                <td><?= $data['CompanyName']; ?></td>
                                <td><?= $data['RegStatus']; ?></td>
                                <td><?= $data['Case Status']; ?></td>
                                <td><?= $data['Unit']; ?></td>
                                <td><?= $data['dokter']. ' ' .$data['LastName'] ; ?></td>
                                <td>
                                        <?php
                                        if ($statusCppt['Note'] == '1') {
                                        ?>
                                            <div class="bg-red text-center" style="border-radius: 10px;">Berjalan</div>
                                        <?php
                                        } else if ($statusCppt['Note'] == '0') {
                                        ?>
                                            <div class="bg-blue text-center" style="border-radius: 10px;">Selesai</div>
                                        <?php
                                        }
                                        ?>
                                    </td>
                                <td>
                                    <?php 
                                    if($user['dept'] == 1 || $user['dept'] == 13 || $user['dept'] == 4 ){
                                        ?>
                                        <a href="<?= base_url('rekamMedis/pemeriksaan/'.$data['Case ID']. '/' . $data['PatientCode']); ?>" style="width: 100%" class="btn btn-sm btn-success"><i class="fa fa-fw fa-book"></i> Lihat Detail</a>
                                        <?php 
                                    }else if($user['dept'] == 2){
                                        ?>
                                        <a href="<?= base_url('apotek/pasien/'.$data['Case ID']); ?>" style="width: 100%" class="btn btn-sm btn-success"><i class="fa fa-fw fa-book"></i> Lihat</a>
                                        <?php 
                                    }
                                    ?>
                                </td>
                            </tr>
                            <?php
                            endforeach;
                            ?>
                        </tbody>
                        
                    </table>
                </small>
            </div><!-- /.box-body -->
            <div class="box-footer">
                <small>Daftar Pasien <?= date('d F Y'); ?> - @Klinik <?= date('Y'); ?></small>
            </div>
        </div><!-- /.box -->

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

<!-- Modal -->
<div class="modal fade" id="pencarian" 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">FILTER</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">

                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab"></span> No. Kunjungan</a></li>
                        <li><a href="#tab_2" data-toggle="tab"></span> Status</a></li>
                        <li><a href="#tab_3" data-toggle="tab"></span> Tanggal Masuk</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab_1">
                            <form action="<?= base_url('Cari/kunjungan'); ?>" method="get">
                                <input type="text" class="form-control" required placeholder="no kunjungan" name="src">
                                <button style="margin-top:10px" type="submit" class="btn btn-sm btn-primary"> Cari
                                </button>
                            </form>
                        </div>
                        <div class="tab-pane" id="tab_2">
                            <form action="<?= base_url('Cari/status'); ?>" method="get">
                                <select name="src" class="form-control" required>
                                    <option value=""></option>
                                    <option value="OPEN" selected>OPEN</option>
                                    <option value="CLOSED">CLOSED</option>
                                    <option value="Cancel">CANCEL</option>
                                </select>

                                <input type="date" style="margin-top: 5px" name="tgl" class="form-control" required>
                                <button style="margin-top:10px" type="submit" class="btn btn-sm btn-primary"> Cari
                                </button>
                            </form>
                        </div>
                        <div class="tab-pane" id="tab_3">
                            <?php $tgl = date('d-m-Y'); ?>
                            <form action="<?= base_url('Cari/list'); ?>" method="get">
                                <input value="<?= $tgl; ?>" type="date" class="form-control" required value='<?= date('Y-m-d'); ?>' name="tgl">
                                <button style="margin-top:10px" type="submit" class="btn btn-sm btn-primary"> Cari
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

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