<?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>
            PASIEN KLINIK <label style="font-weight: normal; font-size:15px" id="timer"></label>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Anamnesa</a></li>
            <li class="active">Pasien</li>
        </ol>
    </section>

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

        <!-- SELECT2 EXAMPLE -->
        <div class="box box-primary">
        <?php if(count($jkn) > 0 || count($nomr) > 0) { ?>
            <div class="alert alert-warning" role="alert">
            <h4 class="alert-heading">Notifikasi JKN Baru!</h4>
            <b>JKN Tanpa MR : <?php echo count($nomr); ?> </b>
            <hr>
            <b>JKN : <?php echo count($jkn); ?> </b>
            </div>
        <?php } ?>
            <div class="box-header with-border">
            <ul class="nav nav-tabs">
                 <li class="active"><a href="#tab_1" data-toggle="tab">Anamnesa</a></li>
                 <li style="display:none;" class="<?= @$aktif2; ?>"><a href="#tab_2" data-toggle="tab">Anamnesa JKN</a></li>
             </ul>
            <div class="tab-content">
            <div class="tab-pane active" id="tab_1">
                <br>
                <button style="display:none;" class="btn btn-primary">POLI UMUM</button>
                <button style="display:none;"  class="btn btn-default">POLI KEBIDANAN</button>
                <button style="display:none;" class="btn btn-success">POLI GIGI</button>
                <h3 class="box-title"></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 class="box-body">
                <small>
                    <table id="example2" class="table ">
                        <thead>
                            <tr>
                                <th>No.</th>
                                <th>Case ID</th>
                                <th>No Kartu</th>
                                <th>Antrian</th>
                                <th>Nama</th>
                                <th>Penjamin</th>
                                <th>Status Pasien</th>
                                <th>Poli</th>
                                <th>Status Cppt</th>
                                <th>Sumber</th>
                                <th>Catatan</th>
                                <th>Alert</th>
                                <th>Opsi</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $no = 1;
                            foreach ($pasien as $d) :
                            $case = $d['Case ID']; 
                            $idpasien = $d['PatientCode'];
                            $data = $this->db->query("SELECT c.Description,e.diagnosa_primer FROM Cases c join erm_pemeriksaan_fisik e on c.[Case ID] = e.case_id 
                            where c.PatientCode = '$idpasien' ")->row_array();
                            $statusCppt = $this->db->query("SELECT Note FROM HeaderCppt WHERE Mr = '$idpasien' ORDER BY IdHeader DESC")->row_array();
                            ?>
                            <tr class="<?php
                                            if ($d['LastOP'] == 'POLI BIDAN') echo "table";
                                            elseif ($d['LastOP'] == 'POLI UMUM') echo "bg-primary";
                                            elseif ($d['LastOP'] == 'POLI GIGI') echo "bg-green";
                                            ?>">
                                    <td><?= $no++; ?>.</td>
                                    <td><?= $d['Case ID']; ?></td>
                                    <td><?= $d['PlanNo']; ?></td>
                                    <td><?= $d['QueueNo']; ?></td>
                                    <td><?= $d['Description']; ?></td>
                                    <td><?= $d['CompanyName']; ?></td>
                                    <td><?= $d['Case Status']; ?></td>
                                    <td><?= $d['LastOP']; ?></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><?= $d['RefferedBy']; ?></td>
                                    <td><?= $d['noteCases']; ?></td>
                                    <td>
                                    <?php
                                        if($data['diagnosa_primer'] == 'A16' || $data['diagnosa_primer'] == 'B18' || $data['diagnosa_primer'] == 'O98.7' || $data['diagnosa_primer'] == 'O98.4' || $data['diagnosa_primer'] == 'O98.1' || $data['diagnosa_primer'] == 'B20.1' || $data['diagnosa_primer'] == 'B20.0' || $data['diagnosa_primer'] == 'B20.2' || $data['diagnosa_primer'] == 'B20.3' || $data['diagnosa_primer'] == 'B20.4' || $data['diagnosa_primer'] == 'B20.5' || $data['diagnosa_primer'] == 'B20.6'|| $data['diagnosa_primer'] == 'B20.7' || $data['diagnosa_primer'] == 'B20.8' || $data['diagnosa_primer'] == 'B20.9' || $data['diagnosa_primer'] == 'B20'){
                                        ?>
                                        <span class="badge bg-red">Pasien infectious !!!</span>
                                        <?php }else{ ?>

                                        <?php } ?>
                                    </td>
                                    <td>
                                        <?php
                                        if ($user['dept'] == 1) {
                                        ?>

                                        <?php
                                        } else if ($user['dept'] == 2) {
                                        ?>

                                        <?php
                                        } else if ($user['dept'] == 3) {
                                        ?>
                                            <a href="<?= base_url('anamnesa/form/' . $case .'/' .$d['PatientCode']); ?>" style="width: 100%" class="btn btn-sm btn-success"><i class="fa fa-fw fa-edit"></i> Anamnesa</a>
                                        <?php
                                        }
                                        ?>
                                    </td>
                                </tr>
                            <?php

                            endforeach;
                            ?>
                        </tbody>
        
                    </table>
                </small>
            </div><!-- /.box-body -->
            </div><!-- /.box-header -->
            <div class="tab-pane <?= @$aktif2; ?>" id="tab_2">
            <br>
            <p align="center"><b>Daftar Pasien Bridging JKN TIDAK ADA MR</b></p>
            <div class="box-body">
              <small>
              <table id="example2" class="table table-striped">
                        <thead>
                            <tr>
                                <th>No.</th>
                                <th>NomorKartu</th>
                                <th>Keluhan</th>
                                <th>TujuanPoli</th>
                                <th>NomorAntrian</th>
                                <th>Tanggal</th>
                                <th>Opsi</th>
                            </tr>
                        </thead>
                        <tbody>
                          <?php $no=1; foreach($nomr as $d): ?>
                            <tr>
                                <td><?= $no++; ?>.</td>
                                <td><?= $d['NomorKartu']; ?></td>
                                <td><?= $d['Keluhan']; ?></td>
                                <td><?= $d['NamaPoli']; ?></td>
                                <td><?= $d['NomorAntrean']; ?></td>
                                <td><?= date('d-m-Y', strtotime($d['TanggalPeriksa'])); ?></td>
                                <td>  <a href="<?= base_url('pendaftaran/NoBpjs?nokartu='.$d['NomorKartu']); ?>" style="width: 100%" class="btn btn-sm btn-success"><i class="fa fa-fw fa-edit"></i> Daftarkan</a></td>
                            </tr>
                        </tbody>
                        <?php endforeach; ?>
                    </table>
            </small>
            </div>

            <div class="box-body">
            <p align="center"><b>Daftar Pasien Bridging JKN</b></p>
              <small>
              <table id="example3" class="table table-striped">
                        <thead>
                            <tr>
                                <th>No.</th>
                                <th>PatientCode(Mr)</th>
                                <th>Nama Pasien</th>
                                <th>Penjamin</th>
                                <th>Keluhan</th>
                                <th>Poli</th>
                                <th>NomorAntrean</th>
                                <th>Tanggal</th>
                                <th>Opsi</th>
                            </tr>
                        </thead>
                        <?php $no = 1; foreach($jkn as $d) : ?>
                        <tbody>
                            <tr style="background-color: orange;">
                            <td><?= $no++; ?>.</td>
                            <td><?= $d['PatientCode']; ?></td>
                            <td><?= $d['FirstName']; ?></td>
                            <td><?= $d['CompanyName']; ?></td>
                            <td><?= $d['Keluhan']; ?></td>
                            <td><?= $d['description']; ?></td>
                            <td><?= $d['NomorAntrean']; ?></td>
                            <td><?= date('d-m-Y', strtotime($d['TanggalPeriksa'])); ?></td>
                            <td>  <a href="<?= base_url('anamnesa/formjkn/' .$d['PatientCode']); ?>" style="width: 100%" class="btn btn-sm btn-success"><i class="fa fa-fw fa-edit"></i> Anamnesa</a></td>
                            </tr>
                        </tbody>
                        <?php endforeach; ?>
s                    </table>
              </small> 
            </div>
            </div>            
            </div>
            <div class="box-footer">
                <small>Daftar Pasien <?= date('d F Y'); ?> - @Klinik <?= date('Y'); ?></small>
            </div>
        </div><!-- /.box -->

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

<div class="modal fade" id="ModalListPatient" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-scrollable" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Daftar Treatment</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>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
            </div>
        </div>
    </div>
</div>

<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_10" data-toggle="tab"></span> No.MR</a></li>
                        <li><a href="#tab_11" data-toggle="tab"></span> Tanggal Masuk</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab_10">
                            <form action="<?= base_url('cases/nomranamesa'); ?>" method="get">
                                <input type="text" class="form-control" required placeholder="no mr" 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_11">
                            <form action="<?= base_url('cases/tglanamesa'); ?>" method="get">
                                <input value="" 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>

<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>