<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Sistem Klinik
            <small>Rekam Medis</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Klinik</a></li>
            <li class="active">Dashboard</li>
        </ol>
    </section>

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

        <!-- Default box -->
        <div class="box">
            <div class="box-header with-border">
                <small>Halo <?= $user['nama']; ?> ! Apa kabar mu hari ini...? </small>
                <div class="box-tools pull-right">
                    <button class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse"><i class="fa fa-minus"></i></button>
                    <button class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove"><i class="fa fa-times"></i></button>
                </div>
            </div>
            <div class="box-body">
                <?php
                if ($user['dept'] == 1 || $user['dept'] == 13 ) {
                    $tgls = date('Y-m-d');
                ?>
                    <div class="row">
                        <div class="col-md-2" align="center">
                            <a href="<?= base_url('rekamMedis/pasien'); ?>">
                                <img height="140px" src="<?= base_url('images/sep2.png'); ?>" alt="">
                            </a> <br>
                            <p>Pemeriksaan</p>
                        </div>
                        <div class="col-md-2" align="center">
                            <a href="<?= base_url('rekamMedis/record'); ?>">
                                <img height="140px" src="<?= base_url('images/pengajuan.png'); ?>" alt="">
                            </a> <br>
                            <p>Data Rekam Medis</p>
                        </div>
                        <!-- <div class="col-md-2" align="center">
                            <a href="<?= base_url('kontrol/buatKontrol'); ?>">
                            <img height="140px" src="<?= base_url('images/kontrol.png'); ?>" alt="">
                            </a> <br>
                            <p>Rencana Kontrol</p>
                        </div> -->
                        <div class="col-md-2" align="center">
                            <a href="<?= base_url('rekamMedis/cariBerkas'); ?>">
                                <img height="140px" src="<?= base_url('images/card.png'); ?>" alt="">
                            </a> <br>
                            <p>Cari Berkas</p>
                        </div>
                        <div class="col-md-2" align="center">
                            <a href="#">
                                <img height="140px" src="<?= base_url('images/jadwal.png'); ?>" alt="">
                            </a> <br>
                            <p>Jadwal Praktek</p>
                        </div>
                        <div class="col-md-2" align="center">
                            <a href="#">
                                <img height="140px" src="<?= base_url('images/laporan.png'); ?>" alt="">
                            </a> <br>
                            <p>Laporan</p>
                        </div>
                    </div>
                <?php
                } else if ($user['dept'] == 2) {
                    $tgls = date('Y-m-d');
                ?>
                    <div class="row">

                        <div class="col-md-2" align="center">
                            <a href="<?= base_url('rekamMedis/record'); ?>">
                                <img height="140px" src="<?= base_url('images/pengajuan.png'); ?>" alt="">
                            </a> <br>
                            <p>Data Rekam Medis</p>
                        </div>
                        <!-- <div class="col-md-2" align="center">
                            <a href="<?= base_url('kontrol/buatKontrol'); ?>">
                            <img height="140px" src="<?= base_url('images/kontrol.png'); ?>" alt="">
                            </a> <br>
                            <p>Rencana Kontrol</p>
                        </div> -->

                        <div class="col-md-2" align="center">
                            <a href="#">
                                <img height="140px" src="<?= base_url('images/jadwal.png'); ?>" alt="">
                            </a> <br>
                            <p>Jadwal Praktek</p>
                        </div>
                        <div class="col-md-2" align="center">
                            <a href="#">
                                <img height="140px" src="<?= base_url('images/laporan.png'); ?>" alt="">
                            </a> <br>
                            <p>Laporan</p>
                        </div>
                    </div>
                <?php
                } else if ($user['dept'] == 3 || $user['dept'] == 5) {
                    $tgls = date('Y-m-d');
                ?>
                    <div class="row">

                        <div class="col-md-2" align="center">
                            <a href="<?= base_url('anamnesa/pasien'); ?>">
                                <img height="140px" src="<?= base_url('images/pengajuan.png'); ?>" alt="">
                            </a> <br>
                            <p>Pasien</p>
                        </div>


                        <div class="col-md-2" align="center">
                            <a href="" data-toggle="modal" data-target="#antrian">
                                <img height="140px" src="<?= base_url('images/jadwal.png'); ?>" alt="">
                            </a> <br>
                            <p>Praktek</p>
                        </div>
                        <div class="col-md-2" align="center">
                            <a href="#">
                                <img height="140px" src="<?= base_url('images/laporan.png'); ?>" alt="">
                            </a> <br>
                            <p>Laporan</p>
                        </div>
                          <div class="col-md-2" align="center">
                            <a href="#" data-toggle="modal" data-target="#pcare">
                                <img height="140px" src="<?= base_url('images/1.png'); ?>" alt="">
                            </a> <br>
                            <p>PcareBpjsID</p>
                        </div>
                    </div>
                    <?php
                } else if ($user['dept'] == 34 ) {
                ?>
                 <div class="row">
                    <div class="col-md-6">
                        <!-- AREA CHART -->
                        <div class="box box-secondary" style="display: none;">
                            <div class="box-header with-border">
                                <h3 class="box-title">Area Chart</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-times"></i></button>
                                </div>
                            </div>
                            <div class="box-body chart-responsive">
                                <div class="chart" id="revenue-chart" style="height: 300px;"></div>
                            </div><!-- /.box-body -->
                        </div><!-- /.box -->

                        <!-- DONUT CHART -->
                        <div class="box box-secondary">
                            <div class="box-header with-border">
                            <i class="fa fa-bar-chart-o"></i>
                                Pasien Terdaftar Hari Ini
                                <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-times"></i></button>
                  </div>
                </div>
                <div class="box-body chart-responsive">
                <canvas id="myChart" style="width:100%;hight:300px;max-width:600px"></canvas>
                </div>
                </div><!-- /.box -->

                    </div><!-- /.col (LEFT) -->
                    <div class="col-md-6">
                        <!-- LINE CHART -->
                        <div class="box box-secondary">
                            <div class="box-header with-border">
                                Info Grafik Pasien
                                <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-times"></i></button>
                                </div>
                            </div>
                            <div class="box-body chart-responsive">
                                <?php
                                $idBpjs = $this->db->query("SELECT * FROM Utama")->row_array();
                                $bpjsid = $this->db->query('SELECT * FROM BPJS_ID')->row_array();
                                $sId = $bpjsid['BPJS_ID'];
                                date_default_timezone_set("Asia/Jakarta");
                                $tgls = date('Y-m-d');
                                $total = $this->db->query("SELECT * FROM Cases WHERE [Intake Date] = '$tgls'")->num_rows();

                                $bpjs = $this->db->query("SELECT * FROM Cases WHERE CompanyCode = '$sId' AND [Intake Date] = '$tgls'")->num_rows();
                                @$pBpjs = ($bpjs / $total) * 100;

                                $pribadi = $this->db->query("SELECT * FROM Cases WHERE CompanyCode = '1' AND [Intake Date] = '$tgls'")->num_rows();
                                @$pPribadi = ($pribadi / $total) * 100;

                                $perusahaan = $this->db->query("SELECT * FROM Cases WHERE CompanyCode != '1' AND CompanyCode != '$sId' AND [Intake Date] = '$tgls'")->num_rows();
                                @$pPerusahaan = ($perusahaan / $total) * 100;
                                ?>
                                <center>
                                    <div class="chart" id="line-chart" style="height: 300px;display:none"></div>
                                    <br>
                                    <p><small>Pasien pakai <code>Jaminan</code> <?= date('d F Y'); ?> :</small></p>
                                    <div class="progress vertical">
                                        <div class="progress-bar progress-bar-green" role="progressbar" aria-valuenow="<?= number_format($pBpjs); ?>" aria-valuemin="0" aria-valuemax="100" style="height: <?= number_format($pBpjs); ?>%">
                                            <span class="sr-only"><?= number_format($pBpjs); ?>%</span>
                                            <label for=""><?= number_format($pBpjs); ?>%</label>
                                        </div>
                                    </div>
                                    <div class="progress vertical">
                                        <div class="progress-bar progress-bar-aqua" role="progressbar" aria-valuenow="<?= $pPribadi; ?>" aria-valuemin="0" aria-valuemax="100" style="height: <?= $pPribadi; ?>%">
                                            <span class="sr-only"><?= $pPribadi; ?>%</span>
                                            <label for=""><?= $pPribadi; ?>%</label>
                                        </div>
                                    </div>
                                    <div class="progress vertical">
                                        <div class="progress-bar progress-bar-yellow" role="progressbar" aria-valuenow="<?= $pPerusahaan; ?>" aria-valuemin="0" aria-valuemax="100" style="height: <?= $pPerusahaan; ?>%">
                                            <span class="sr-only"><?= $pPerusahaan; ?>%</span>
                                            <label for=""><?= $pPerusahaan; ?>%</label>
                                        </div>
                                    </div> <br>
                                    <button class="btn btn-sm btn-success" style="border-radius:0px; margin-top:-10px">BPJS (<?= @$bpjs; ?>)</button>
                                    <button class="btn btn-sm btn-info" style="border-radius:0px; margin-top:-10px">PRIBADI (<?= @$pribadi; ?>)</button>
                                    <button class="btn btn-sm btn-warning" style="border-radius:0px; margin-top:-10px">ASURANSI (<?= @$perusahaan; ?>)</button>
                                </center>

                            </div><!-- /.box-body -->

                        </div><!-- /.box -->

                        <!-- BAR CHART -->
                        <div class="box box-success" style="display: none;">
                            <div class="box-header with-border">
                                <h3 class="box-title">Bar Chart</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-times"></i></button>
                                </div>
                            </div>
                            <div class="box-body chart-responsive">
                                <div class="chart" id="bar-chart" style="height: 300px;"></div>
                            </div><!-- /.box-body -->
                        </div><!-- /.box -->

                    </div><!-- /.col (RIGHT) -->
                </div><!-- /.row -->
                <?php
                } else if ($user['dept'] == 4) {
                    redirect('Laboratorium');
                }
                ?>
            </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="antrian" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <form action="<?= base_url('rekamMedis/updateAntrian'); ?>" method="post">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Update Jadwal Dokter Hari Ini</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 class="table table-striped">
                        <tr>
                            <th width="50%">Poli</th>
                            <th width="50%">Dokter</th>
                        </tr>
                        <?php
                        foreach ($antrian as $data) :
                        ?>
                            <tr>
                                <td>
                                    <input type="hidden" name="id[]" value="<?= $data['Id_Poli']; ?>">
                                    <select name="poli[]" class="form-control">
                                        <option value="<?= $data['Jenis']; ?>"><?= $data['Jenis']; ?></option>
                                    </select>
                                </td>
                                <td>

                                    <select name="dokter[]" class="form-control">
                                        <?php
                                        foreach ($dokter as $d) :
                                            if ($data['DoctInCharge'] == $d['DoctorID']) {
                                        ?>
                                                <option selected value="<?= $d['DoctorID']; ?>"><?= $d['FirstName']; ?> <?= $d['LastName']; ?></option>
                                            <?php
                                            } else {
                                            ?>
                                                <option value="<?= $d['DoctorID']; ?>"><?= $d['FirstName']; ?> <?= $d['LastName']; ?></option>
                                        <?php
                                            }

                                        endforeach;
                                        ?>
                                    </select>
                                </td>
                            </tr>
                        <?php
                        endforeach;
                        ?>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-primary">Simpan</button>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- Model -->
<div class="modal fade" id="pcare" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <form action="<?= base_url('rekamMedis/updatePcare'); ?>" method="post">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Update Password Pcare</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <?php $datapcare = $this->db->query("Select top 1 * From BPJS_ID")->row(); ?>
                    <input type="hidden" name="id" value="<?= $datapcare->ConsID; ?>">
                    <label for="">Username Pcare</label>
                    <input type="text" name="user" class="form-control" value="<?= $datapcare->Username; ?>">
                    <label for="">Password Pcare</label>
                    <input type="text" name="pass" class="form-control" placeholder="Masukkan Password Baru" value="<?= $datapcare->Password; ?>">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-warning">Update</button>
                </div>
            </div>
        </form>
    </div>
</div>
<!-- page script -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
        <?php
        $op = $this->db->query("SELECT * FROM Cases WHERE [Intake Date] = '$tgls' AND Category = 'OP'")->num_rows();
        $ip = $this->db->query("SELECT * FROM Cases WHERE [Intake Date] = '$tgls' AND Category = 'IP'")->num_rows();
        $ob = $this->db->query("SELECT * FROM Cases WHERE [Intake Date] = '$tgls' AND Category = 'OB'")->num_rows();
        ?>

            <script>
            var xValues = ["OP", "OB", "IP"];
            var yValues = [<?= @$op; ?>, <?= @$ob; ?>, <?= @$ip; ?>];
            var barColors = [
            "#b91d47",
            "#00aba9",
            "#2b5797",
            "#e8c3b9",
            "#1e7145"
            ];

            new Chart("myChart", {
            type: "pie",
            data: {
                labels: xValues,
                datasets: [{
                backgroundColor: barColors,
                data: yValues
                }]
            },
            options: {
                title: {
                display: true,
                text: "Patient Kunjungan Hari ini"
                }
            }
            });
    </script>
</script>