<?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
            <small>Klinik</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Pasien</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 <?= $this->session->userdata('doctorId');?></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">
                <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>Poli</th>
                                <th>Dokter</th>
                                <th>Penjamin</th>
                                <th>Status Pasien</th>
                                <th>Status Cppt</th>
                                <th>Antrian</th>
                                <th>Alert</th>
                                <th>Option</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $no = 1;
                            foreach ($pasien 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><button class="btn btn-sm btn-success" style="background-color:"><i class="fa fa-stethoscope fa-fw"></i> <?= $data['LastOP']; ?></button> </td>
                                <td><?= $data['namaDokter']. ' ' .$data['lasNameDokter']; ?></td>
                                <td><?= $data['CompanyName']; ?></td>
                                <td><?= $data['RegStatus']; ?></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><?= $data['QueueNo']; ?></td>
                                <td>
                                <?php
                                        if($data['KdDiag1'] == 'A16' || $data['KdDiag1'] == 'B18' || $data['KdDiag1'] == 'O98.7' || $data['KdDiag1'] == 'O98.4' || $data['KdDiag1'] == 'O98.1' || $data['KdDiag1'] == 'B20.1' || $data['KdDiag1'] == 'B20.0' || $data['KdDiag1'] == 'B20.2' || $data['KdDiag1'] == 'B20.3' || $data['KdDiag1'] == 'B20.4' || $data['KdDiag1'] == 'B20.5' || $data['KdDiag1'] == 'B20.6'|| $data['KdDiag1'] == 'B20.7' || $data['KdDiag1'] == 'B20.8' || $data['KdDiag1'] == 'B20.9' || $data['KdDiag1'] == 'B20'){
                                        ?>
                                        <span class="badge bg-red">Pasien infectious !!!</span>
                                        <?php }else{ ?>

                                        <?php } ?>
                                </td>
                                <td>
                                    <?php 
                                    if($user['dept'] == 1){
                                        ?>
                                        <form  action="<?= base_url('rekamMedis/add'); ?>" method="post">
                                        <input hidden type="text" name="caseID" value="<?= $data['Case ID']; ?>">
                                        <input hidden type="text" name="PatientCode" value="<?= $data['PatientCode']; ?>">
                                        <button type="submit" class="btn btn-sm btn-success"><i class="fa fa-stethoscope fa-fw"></i> Pemeriksaan</button>
                                        </form>
                                        <?php 
                                    }else if($user['dept'] == 2){
                                        
                                    }else{
                                        ?>
                                        <a href="" data-toggle="modal" data-target="#detail<?=$data['Case ID'];?>" class="btn btn-sm btn-success"><i class="fa fa-search fa-fw"></i> Detail</a>
                                        <?php 
                                    }
                                    ?>
                                    
                                </td>
                            </tr>
                            <?php
                            endforeach;
                            ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th>No.</th>
                                <th>Case ID</th>
                                <th>Nama</th>
                                <th>Penjamin</th>
                                <th>Status Pasien</th>
                                <th>Antrian</th>
                                <th>Alert</th>
                                <th>Option</th>
                            </tr>
                        </tfoot>
                    </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 -->
<?php 
foreach($pasien as $m):
?>
<div class="modal fade" id="detail<?= $m['Case ID']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <form action="<?= base_url('anamnesa/updateAnamnesa/'.$m['Case ID']); ?>" method="post">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Anamnesa</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <small>
        <b>Nama :</b> <?= $m['Description'];?> <br>
        <table class="table table-striped" style="margin-top: 10px;">
            <tr>
                <td colspan="4">
                Case ID 
                <input type="text" name="CaseID" class="form-control" value="<?= $m['Case ID']; ?>" readonly>
                </td>
            </tr>
            <tr>
                <td>Poli Tujuan</td>
                <td>
                    <select name="Unit" class="form-control" required>
                        <option value="">- Pilih -</option>
                        <?php
                        foreach($poli as $klinik):
                            if($m['Unit'] == $klinik['Jenis']){
                                ?>
                                <option selected value="<?= $klinik['Jenis']; ?>"><?= $klinik['Jenis']; ?></option>
                                <?php 
                            }else{
                                ?>
                                <option value="<?= $klinik['Jenis']; ?>"><?= $klinik['Jenis']; ?></option>
                                <?php
                            }
                        endforeach;
                        ?>
                    </select>
                </td>
                <td>Dokter Tujuan</td>
                <td>
                    <select name="DoctorID" class="teanganData" data-live-search="true" required>
                        <option value="">- Pilih -</option>
                        <?php
                        foreach($dokter as $dok):
                            if($m['DoctorID'] == $dok['DoctorID']){
                                ?>
                                <option selected value="<?= $dok['DoctorID']; ?>"><?= $dok['FirstName']; ?>, <?= $dok['LastName']; ?></option>
                                <?php 
                            }else{
                                ?>
                                <option value="<?= $dok['DoctorID']; ?>"><?= $dok['FirstName']; ?>, <?= $dok['LastName']; ?></option>
                                <?php 
                            }
                        endforeach;
                        ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td>Berat Badan *cm</td>
                <td><input type="text" name="BeratBadan" value="<?= $m['BeratBadan']; ?>" class="form-control"></td>
                <td>Tinggi Badan *kg</td>
                <td><input type="text" name="TinggiBadan" value="<?= $m['TinggiBadan']; ?>" class="form-control"></td>
            </tr>
            <tr>
                <td>RespRate</td>
                <td><input type="text" name="respRate" value="<?= $m['respRate']; ?>" class="form-control"></td>
                <td>HeartRate</td>
                <td><input type="text" name="heartRate" value="<?= $m['heartRate']; ?>" class="form-control"></td>
            </tr>
            <tr>
                <td>Tensi</td>
                <td><input type="text" name="Tensi" value="<?= $m['Tensi']; ?>" class="form-control"></td>
                <td>Suhu</td>
                <td><input type="text" name="Suhu" value="<?= $m['Suhu']; ?>" class="form-control"></td>
            </tr>
            <tr>
                <td>Diastole</td>
                <td><input type="text" name="Diastole" value="<?= $m['Diastole']; ?>" class="form-control"></td>
                <td>Keluhan</td>
                <td>
                    <textarea name="Keluhan" class="form-control"><?= $m['Keluhan']; ?></textarea>
                </td>
                </td>
            </tr>
        </table>
        </small>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-success" >Update</button>
        <a target="_blank" href="<?= base_url('anamnesa/cetakantrian/'.$m['Case ID']); ?>" class="btn btn-primary">Print Antrian</a>
      </div>
    </div>
    </form>
  </div>
</div>
<?php 
endforeach;
?>
