<?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>
            Monitoring <label style="font-weight: normal; font-size:15px" id="timer"></label>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Monitoring</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">Daftar Pasien</h3>
                <div class="box-tools pull-right">
                    <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    <button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
                </div>
            </div><!-- /.box-header -->
            <div class="box-body">
                <?php
                // Session 
                if ($this->session->flashdata('message')) {
                    echo $this->session->flashdata('message');
                }
                ?>
                <form action="<?= base_url('rekamMedis/monitoring?type=' . $type); ?>" method="post">
                    <label for="">Tanggal</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class="fa fa-calendar"></i>
                        </div>
                        <input type="date" onfocus="this.showPicker()" required name="tanggal" value="<?php echo $tanggal; ?>" class="form-control pull-right" width="20%">
                    </div><!-- /.input group -->
                    <button class="btn btn-xs btn-primary" style="margin-top:8px;"><i class="fa fa-search"></i> Cari</button>
                </form>
                <br>
                    <form id="myForm" method="post" action="<?= base_url('rekamMedis/prosesBulkMonitoring') ?>" enctype="multipart/form-data">
                        <button type="button" onclick="checkIsChecked();" id="btnBulkProses" class="btn btn-xs btn-danger"><i class="fa fa-hourglass-3 fa-fw"></i> Bulk Proses</button>
                        <br><br>
                        <table id="example1" class="table table-bordered table-hover table-striped">
                            <thead>
                                <tr>
                                    <th><input type="checkbox" id="checkAll" value="1"></th>
                                    <th>No.</th>
                                    <th>Case ID</th>
                                    <th>Nama</th>
                                    <th>Penjamin</th>
                                    <th>Dokter</th>
                                    <th>Poli</th>
                                    <th>Header</th>
                                    <th>Tanggal Dibuat</th>
                                    <th>NoAntrian</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $no = 1;
                                foreach ($pasien as $data) :
                                ?>
                                    <tr>
                                        <td><input type="checkbox" name="proses[]" value="<?= $data['erm_pemeriksaan_fisik_id'] . '#' . $data['case_id'] . '#' . $data['header']; ?>" class="checkBoxMonitoring"></td>
                                        <td><?= $no++; ?></td>
                                        <td>
                                            <?php
                                            if ($user['dept'] == 1 || $user['dept'] == 13) {
                                            ?>
                                                <a href="<?= base_url('rekamMedis/pemeriksaan/' . $data['case_id']); ?>" style="width: 100%"><i class="fa fa-fw fa-book"></i> <?= $data['case_id']; ?></a>
                                            <?php
                                            } else if ($user['dept'] == 2 || $user['dept'] == 1) {
                                            ?>
                                              
                                            <?php
                                            }
                                            ?>
                                              <a href="<?= base_url('apotek/pasien/' . $data['case_id']); ?>" style="width: 100%"><i class="fa fa-fw fa-book"></i> <?= $data['case_id']; ?></a>
                                        </td>
                                        <td><?= $data['FirstName']; ?></td>
                                        <td><?= $data['CompanyName']; ?></td>
                                        <td><?= $data['dokter'].' '.$data['LastName']; ?></td>
                                        <td><?= $data['Unit']; ?></td>
                                        <td><?= $data['header']; ?></td>
                                        <td><?= $data['createDate']; ?></td>
                                        <td><?= $data['NoAntrian']; ?></td>
                                        <td>
                                            <button type="button" onclick="prosesMonitoring('<?= $data['case_id']; ?>', '<?= $data['header']; ?>', '<?= $data['erm_pemeriksaan_fisik_id']; ?>' )" class="btn btn-sm btn-warning"><i class="fa fa-hourglass-3 fa-fw"></i> Proses</button>
                                            <button type="button" data-toggle="modal" data-target="#modal-info<?= $data['case_id'] ?>"  class="btn btn-sm btn-success"><i class="fa fa-solid fa-eye"></i> Lihat Resep</button>
                                        </td>
                                    </tr>
                                <?php
                                endforeach;
                                ?>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <th>No.</th>
                                    <th>Case ID</th>
                                    <th>Nama</th>
                                    <th>Penjamin</th>
                                    <th>Header</th>
                                    <th></th>
                                </tr>
                            </tfoot>
                        </table>
                    </form>
            </div><!-- /.box-body -->
            <div class="box-footer">
                <small>Monitoring Pasien <?= date('d F Y'); ?> - @Klinik <?= date('Y'); ?></small>
            </div>
        </div><!-- /.box -->

        <?php 
        foreach ($pasien as $data) :
        ?>
        <!-- Modal Lihat Resep -->
        <div id="modal-info<?=$data['case_id'];?>" class="modal fade">
        <div class="modal-dialog">
        <form action="<?php echo site_url('Modal/add'); ?>" method="post">
        <div class="modal-content">
            <div class="modal-header bg-primary">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Vie Data Resep</h4>
            </div>
            <div class="modal-body">
            <table>
                <tr>
                    <td><label>Obat Pasien</label></td>    
                    <td><textarea class="form-control" " rows="6" cols="80"><?= strip_tags((!empty($data['obat'])) ? $data['obat'] : '' ); ?></textarea></td>
                </tr>
                <tr>
                    <td><label>Tindakan</label></td>   
                    <td><textarea class="form-control" " rows="6" cols="80"><?= strip_tags((!empty($data['rencana_tindakan'])) ? $data['rencana_tindakan'] : '' ); ?></textarea></td>
                </tr>
                <!-- <tr>
                    <td><label>Tindakan Lab</label></td>   
                    <?php 
                    foreach ($lab as $d) :
                    ?>
                    <td><?= $d['Description'];?></textarea></td>
                    <?php endforeach; ?>
                </tr> -->
        </table>
            <br><br><br><br><br><br><br>
            </div>
            <div class="modal-footer">
            <a target="_blank" href="<?= base_url('RekamMedis/cetakresep/' . $data['case_id'] ); ?>" class="btn btn-sm btn-warning"><i class="fa fa-fw fa-print"></i> PRINT RESEP</a>
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
         </form>
        </div>
        </div>    
        </div>
        <?php endforeach; ?>
        <!-- End Modal -->
    </section><!-- /.content -->
</div><!-- /.content-wrapper -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
    $('#checkAll').on('click', function() {
        $(this).closest('table').find('tbody :checkbox')
            .prop('checked', this.checked)
            .closest('tr').toggleClass('selected', this.checked);
    });


    function checkIsChecked() {
        var isChecked = false;
        $('#example1').find('input[type="checkbox"]:checked').each(function() {
            isChecked = true;
        });

        if (isChecked) {
            if (confirm("Apakah yakin akan diproses data yang dipilih?") == true) {
                document.getElementById("btnBulkProses").disabled = true;
                document.getElementById("myForm").submit();
            }
        } else {
            alert('silahkan pilih data');
        }
    }

    function prosesMonitoring($caseId, header, ermId) {

        if (confirm("Apakah yakin akan diproses?") == true) {
            var url = "<?= base_url() ?>" + "rekamMedis/prosesMonitoring?c=" + $caseId + "&header=" + header + "&ermId=" + ermId;
            window.location = url;
        }
    }
</script>
<script type="text/javascript">
    var count = 120;
    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>