<?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">
                <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><!-- /.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>Antrian</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $no = 1;
                            foreach ($pasien as $data) :
                            ?>
                            <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><?= $data['NoAntrian']; ?></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-pencil fa-fw"></i> Edit</a>
                                        <br>
                                            <a href="<?= base_url('anamnesa/detail/' . $data['Case ID']); ?>" style="width: 100%;" class="btn btn-sm btn-primary"><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></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>
                 <td>
                    NoBpjs 
                    <input type="text" name="NoBpjs" class="form-control" value="<?= $m['PlanNo']; ?>" 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;
?>
<!-- Modal -->
<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_1" data-toggle="tab"></span> No. Kunjungan</a></li>
                        <li><a href="#tab_2" data-toggle="tab"></span> No.MR</a></li>
                        <li><a href="#tab_3" data-toggle="tab"></span> Tanggal Masuk</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab_1">
                            <form action="<?= base_url('Cari/listcari'); ?>" method="get">
                                <input type="text" class="form-control" required placeholder="no kunjungan" name="cari">
                                <button style="margin-top:10px" type="submit" class="btn btn-sm btn-primary"> Cari
                                </button>
                            </form>
                        </div>
                        <div class="tab-pane" id="tab_2">
                            <form action="<?= base_url('Cari/listcarimr'); ?>" method="get">
                                <input type="text" class="form-control" required placeholder="no mr" name="cari">
                                <button style="margin-top:10px" type="submit" class="btn btn-sm btn-primary"> Cari
                                </button>
                            </form>
                        </div>
                        <div class="tab-pane" id="tab_3">
                            <form action="<?= base_url('Cari/listcaritgl'); ?>" method="get">
                                <input value="" type="date" class="form-control" required value='<?= date('Y-m-d'); ?>' name="cari">
                                <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>