<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Laboratorium <label style="font-weight: normal; font-size:15px" id="timer"></label>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Sis-RS</a></li>
            <li class="active">Laboratorium</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row" style="margin-bottom: 10px;">
            <div class="col-md-8">
                <i class="fa fa-fw fa-calendar"></i> Daftar Pasien <b>LABORATORIUM</b>


            </div>
            <div class="col-md-4" align="right">
                <form action="<?= base_url('Laboratorium/caridatalab'); ?>" method="get">
                    <table>
                        <tr>
                            <td><input type="date" class="form-control" name="tgl" value="<?= date('Y-m-d'); ?>"></td>
                            <td><button style="border-radius: 0px;" type="submit" class="btn btn-sm btn-primary">Cari</button></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="box">
            <div class="box-body">
                <?= $this->session->flashdata('message'); ?>
                <table id="example1" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>No</small></th>
                            <th>Case ID</th>
                            <th>Patient Code</th>
                            <th>Pasien</th>
                            <th>Penjamin</th>
                            <th>Dokter</th>
                            <th>ID Header</th>
                            <th>Tanggal Distribusi</th>
                            <th>Waktu Distribusi</th>
                            <!-- <th>Status</th> -->
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $no = 1;
                        foreach ($pasien as $p) { ?>
                            <tr style="font-size: 9pt;">
                                <td><?= $no ?></td>
                                <td><?= $p['CaseID'] ?></td>
                                <td><?= $p['PatientCode'] ?></td>
                                <td><?= $p['Description'] ?></td>
                                <td><?= $p['CompanyName'] ?></td>
                                <td><?= $p['FirstName'] . '' . $p['LastName']; ?></td>
                                <td><?= $p['IdRequestHeader'] ?></td>
                                <td><?= date('d M Y', strtotime($p['tglRequest'])) ?></td>
                                <td><?= date('H:i:s', strtotime($p['jamRequest'])) ?> WIB</td>
                                <td>
                                    <?php
                                    $caseid = $p['CaseID'];
                                    $qdata = $this->db->query("select lh.IdRequestHeader, ld.PackedID, pd.Description, lh.[status]
                                    from LabRequestHeader lh join LabRequestDetail ld on lh.IdRequestHeader = ld.IdRequestHeader
                                    join tblLabPacked pd on pd.PackedID = ld.PackedID where lh.CaseID = '$caseid' ")->row_array();
                                    ?>
                                    <a href="<?= base_url('laboratorium/proseslaborat/' . $p['CaseID'] . '/' . $p['IdRequestHeader']); ?>" class="btn btn-sm btn-success"><i class="fa fa-fw fa-spinner"></i> PROSES </a>
                                    <a href="" data-toggle="modal" data-target="#Resultlab<?= $p['IdRequestHeader']; ?>" class="btn btn-sm btn-sucess bg-green-gradient" data-backdrop="static" data-keyboard="false"><i class="fa fa-eye"></i> Detail</a>
                                </td>
                            </tr>
                        <?php $no++;
                        } ?>
                    </tbody>
                </table>
            </div>
        </div>

    </section>
</div>

<script type="text/javascript">
    var count = 60;
    var periode = 1;
    var counter = setInterval(timer, 500);

    function timer() {
        count = count - 1;
        if (count <= 0) {
            clearInterval(counter);
            location.reload();
        }

        document.getElementById("timer").innerHTML = 'Akan memuat pada <strong style="color:orange;">' + count + "</strong> detik";
    }
    $(document).ready(function() {
        timer();
    });
</script>

<script>
    function blink_text() {
        $('#status').fadeOut(700);
        $('#status').fadeIn(700);
    }
    setInterval(blink_text, 750);
</script>

<?php
foreach ($pasien as $p) {
    $idheader = $p['IdRequestHeader'];
    $lab = $this->db->query("select lh.IdRequestHeader, ld.PackedID, pd.Description
            from LabRequestHeader lh join LabRequestDetail ld on lh.IdRequestHeader = ld.IdRequestHeader
            join tblLabPacked pd on pd.PackedID = ld.PackedID where lh.IdRequestHeader = '$idheader'
            ")->result_array();
?>
    <div class="modal fade" id="Resultlab<?= $p['IdRequestHeader']; ?>" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-scrollable" role="document">
            <form action="#" method="post">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Result Request Lab</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <table id="example1" class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>No</small></th>
                                    <th>Packed Name</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $no = 1;
                                foreach ($lab as $p) { ?>
                                    <tr>
                                        <td><?= $no ?></td>
                                        <td><?= $p['Description'] ?></td>
                                    </tr>
                                <?php
                                    $no++;
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
<?php } ?>