<!-- 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">
                <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><br>
                <div class="box-body">
                    <div class="nav-tabs-custom">
                        <ul class="nav nav-tabs">
                            <li class="active"><a href="#tab_1" data-toggle="tab">Patient</a></li>
                            <li><a href="#tab_2" data-toggle="tab">Patient No Mr</a></li>
                        </ul>
                        <div class="tab-content">
                            <div class="tab-pane active" id="tab_1">
                                <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>Tanggal</th>
                                                <th>RencanaDr</th>
                                                <th>Transaksi</th>
                                                <th>SKS</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><?= $data['LastOP']; ?></td>
                                                    <td><?= $data['namaDokter'] . ' ' . $data['lasNameDokter']; ?></td>
                                                    <td><?= $data['CompanyName']; ?></td>
                                                    <td><?= date("d/m/Y", strtotime($data['Intake Date'])); ?></td>
                                                    <?php
                                                    $IdCase = $data['Case ID'];
                                                    $qdataquery = $this->db->query("SELECT  rencana_tindakan AS total FROM erm_pemeriksaan_fisik where case_id = '$IdCase'")->row_array();
                                                    $querydata = $this->db->query("SELECT COUNT(t.TransactionID) as ttl from Activity a join TransactionHeader t on t.TransactionID = a.TransactionID
                                                    where a.[Case ID] = '$IdCase' ")->row_array();
                                                    if ($qdataquery['total'] == '0' || $qdataquery['total'] == '-') {
                                                    ?>
                                                        <td></td>
                                                    <?php
                                                    } else {
                                                    ?>
                                                        <td>
                                                            <a href="" data-toggle="modal" data-target="#Modaltindakandr<?= $data['Case ID']; ?>" class="btn btn-sm btn-primary bg-yellow-gradient" data-backdrop="static" data-keyboard="false"><i class="fa fa-fw fa-eye"></i> lihat</a>
                                                        </td>
                                                    <?php }  ?>
                                                    <td>

                                                        <?php if ($querydata['ttl'] == 0) {  ?>
                                                        <?php } else { ?>
                                                            <!-- <a href="" data-toggle="modal" data-target="#ModalDetail<?= $data['Case ID']; ?>" class="btn btn-sm btn-primary bg-blue-gradient" data-backdrop="static" data-keyboard="false"><i class="fa fa-fw fa-eye"></i> Lihat</a> -->
                                                            <a href="<?= base_url('Transaction/detailheader/' . $data['Case ID']); ?>" class="btn btn-sm btn-primary bg-blue-gradient"><i class="fa fa-fw fa-eye"></i> Lihat</a></a>
                                                        <?php } ?>

                                                        <?php if ($data['Case Status'] == 'OPEN') { ?>
                                                            <a href="<?= base_url('Transaction/AddTransaction/' . $data['Case ID']); ?>" data-toggle="modal" class="btn btn-sm btn-success"><i class="fa fa-plus fa-fw"></i> Add Transaction</a>
                                                        <?php } else { ?>
                                                            <a href="#" data-toggle="modal" class="btn btn-sm btn-danger" disabled><?= $data['Case Status']; ?></a>
                                                        <?php } ?>
                                                    </td>
                                                    <td>
                                                        <div class="btn-group">
                                                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                                                <span class="caret"></span>
                                                            </button>
                                                            <ul class="dropdown-menu">
                                                                <li><a href="<?= base_url('Sks/PrintSurat/' . $data['Case ID'] . '/' . $data['PatientCode']); ?>" target="new_tab">Surat Sakit</a></li>
                                                                <li><a href="<?= base_url('Sks/PrintSuratSehat/' . $data['Case ID']); ?>">Surat Keterangan Dokter</a></li>
                                                                <li><a href="<?= base_url('Sks/PrintRujukan/' . $data['Case ID']); ?>">Surat Rujukan</a></li>
                                                                <li><a href="<?= base_url('Sks/Printformpendaftaran'); ?>">Form Pendaftaran</a></li>
                                                            </ul>
                                                        </div>
                                                    </td>
                                                </tr>
                                            <?php
                                            endforeach;
                                            ?>
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <th>No.</th>
                                                <th>Case ID</th>
                                                <th>Nama</th>
                                                <th>Poli</th>
                                                <th>Dokter</th>
                                                <th>Penjamin</th>
                                                <th>Tanggal</th>
                                                <th>RencanaDr</th>
                                                <th>Transaksi</th>
                                                <th>SKS</th>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </small>
                            </div>
                            <div class="tab-pane" id="tab_2">
                            <div class="box-body">
                                <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>Tanggal</th>
                                            <th>Transaksi</th>
                                            <th>SKS</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $no =1; 
                                        foreach($nomr as $p) : 
                                        ?>
                                        <tr>
                                            <td><?= $no++; ?></td>
                                            <td><?= $p['Case ID']; ?></td>
                                            <td><?= $p['Description']; ?></td>
                                            <td><?= $p['Unit']; ?></td>
                                            <td><?= $p['FirstName']; ?></td>
                                            <td><?= $p['CompanyName']; ?></td>
                                            <td><?= $p['Intake Date']; ?></td>
                                            <td>
                                            <?php if ($p['Case Status'] == 'OPEN') { ?>
                                                <a href="<?= base_url('Transaction/detailheader/' . $p['Case ID']); ?>" class="btn btn-sm btn-primary bg-blue-gradient"><i class="fa fa-fw fa-eye"></i> Lihat</a></a>
                                                            <a href="<?= base_url('Transaction/AddTransaction/' . $p['Case ID']); ?>" data-toggle="modal" class="btn btn-sm btn-success"><i class="fa fa-plus fa-fw"></i> Add Transaction</a>
                                                        <?php } else { ?>
                                                            <a href="#" data-toggle="modal" class="btn btn-sm btn-danger" disabled><?= $p['Case Status']; ?></a>
                                            <?php } ?>
                                            </td>
                                            <td>
                                                        <div class="btn-group">
                                                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                                                <span class="caret"></span>
                                                            </button>
                                                            <ul class="dropdown-menu">
                                                                <li><a href="<?= base_url('Sks/PrintSurat/' . $p['Case ID']); ?>" target="new_tab">Surat Sakit</a></li>
                                                                <li><a href="<?= base_url('Sks/PrintSuratSehat/' . $p['Case ID']); ?>">Surat Keterangan Dokter</a></li>
                                                                <li><a href="<?= base_url('Sks/PrintRujukan/' . $p['Case ID']); ?>">Surat Rujukan</a></li>
                                                                <li><a href="<?= base_url('Sks/Printformpendaftaran'); ?>">Form Pendaftaran</a></li>
                                                            </ul>
                                                        </div>
                                            </td>
                                        </tr>
                                        <?php endforeach; ?>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <th>No.</th>
                                            <th>Case ID</th>
                                            <th>Nama</th>
                                            <th>Poli</th>
                                            <th>Dokter</th>
                                            <th>Penjamin</th>
                                            <th>Tanggal</th>
                                            <th>Transaksi</th>
                                            <th>SKS</th>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
            </section>

<!-- Modal Detail -->
<?php
foreach ($pasien as $data) :
    $caseid = $data['Case ID'];
    $dt =   $this->db->query("select c.[Case ID],c.PatientCode,c.Description,c.[Case Status],
    c.[Intake Date],c.[Closed Date],c.Category,
    c.[Presenting Problem],d.FirstName,cp.CompanyName from Cases c 
    join erm_pemeriksaan_fisik erm on c.[Case ID] = erm.case_id 
    join CaseDetail cd on cd.[Case ID] = c.[Case ID]
    join Doctor d on d.DoctorID = cd.DoctorID
    join Company cp on cp.CompanyCode = c.CompanyCode
    where c.[Case ID] = '$caseid'
    ")->row_array();
?>
    <div class="modal fade" id="ModalDetail<?= $data['Case ID'] ?>" 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">Detail Treatment <?= $data['Case ID'] ?></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <fieldset>
                        <legend>Transaction</legend>
                        <table id="tblid" class="table table-bordered table-hover table-striped">
                            <tr>
                                <td>Case ID</td>
                                <td>:</td>
                                <td><input type="text" name="" class="form-control" value="<?= $dt['Case ID']; ?>" readonly></td>

                                <td>Mr</td>
                                <td>:</td>
                                <td><input type="text" name="" class="form-control" value="<?= $dt['PatientCode']; ?>" readonly></td>
                            </tr>
                            <tr>
                                <td>Nama</td>
                                <td>:</td>
                                <td><input type="text" name="" class="form-control" value="<?= $dt['Description']; ?>" readonly></td>

                                <td>Penjamin</td>
                                <td>:</td>
                                <td><input type="text" name="" class="form-control" value="<?= $dt['CompanyName']; ?>" readonly></td>
                            </tr>
                            <tr>
                                <td>Category</td>
                                <td>:</td>
                                <td><input type="text" name="" class="form-control" value="<?= $dt['Category']; ?>" readonly></td>

                                <td>Doctor</td>
                                <td>:</td>
                                <td><input type="text" name="" class="form-control" value="<?= $dt['FirstName']; ?>" readonly></td>
                            </tr>
                            <tr>
                                <td>Diagnosa</td>
                                <td>:</td>
                                <td><input type="text" name="" class="form-control" value="<?= $dt['Presenting Problem']; ?>" readonly></td>

                                <td>Status</td>
                                <td>:</td>
                                <td><input type="text" name="" class="form-control" value="<?= $dt['Case Status']; ?>" readonly></td>
                            </tr>
                            <tr>
                                <td>Intake Date</td>
                                <td>:</td>
                                <td><input type="text" name="" class="form-control" value="<?= date('d-m-Y', strtotime($dt['Intake Date'])); ?>" readonly></td>

                                <td>Close Date</td>
                                <td>:</td>
                                <td><input type="text" name="" class="form-control" value="<?= date('d-m-Y', strtotime($dt['Closed Date'])); ?>" readonly></td>
                            </tr>
                        </table>
                    </fieldset>

                    <table id="example1" class="table table-bordered table-hover table-striped">
                        <th>Transaksi ID</th>
                        <th>Category</th>
                        <th>Harga</th>
                        <th>Doctor</th>
                        <?php
                        $IdCase = $data['Case ID'];
                        $d = $this->db->query("Select a.ID,th.TransactionID,a.Activity,m.Description,m.Category,a.Charge,a.DoctorID,d.FirstName,a.COA, th.Transaction_Date
            From MedicalProcedure m join Activity a on a.Activity = m.ProcedureCode
            join Doctor d on d.DoctorID = a.DoctorID
            join TransactionHeader th on th.TransactionID = a.TransactionID where a.[Case ID] = '$IdCase' ")->result_array();
                        ?>
                        <?php foreach ($d as $dquery) : ?>
                            <tr>
                                <td><a href="<?= base_url('Transaction/detailTransaction/' . $IdCase . '/' . $dquery['TransactionID']) ?>" id="btnCari"><?= $dquery['TransactionID']; ?></a></td>
                                <td><?= $dquery['Category']; ?></td>
                                <td><?= $dquery['Charge']; ?></td>
                                <td><?= $dquery['FirstName']; ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </table>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
                </div>
            </div>
        </div>
    </div>
<?php endforeach; ?>
<!-- End of Modal Detail -->

<!-- Modal Detail -->
<?php
foreach ($pasien as $data) :
?>
    <div class="modal fade" id="Modaltindakandr<?= $data['Case ID'] ?>" 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">Detail Treatment <?= $data['Case ID'] ?></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 id="example1" class="table table-bordered table-hover table-striped">
                        <th>Description</th>
                        <?php
                        $IdCase = $data['Case ID'];
                        $dquery = $this->db->query("Select * from erm_pemeriksaan_fisik where case_id = '$IdCase' ")->row_array();
                        ?>
                        <tr>
                            <td><?= $dquery['rencana_tindakan']; ?></td>
                        </tr>

                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
                </div>
            </div>
        </div>
    </div>
<?php endforeach; ?>
<!-- End of Modal Detail -->

<!-- Modal Pencarian-->
<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> Mr/PatientCode</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/CaseIDtrx'); ?>" method="get">
                                <input type="text" class="form-control" required placeholder="no kunjungan" 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_2">
                            <form action="<?= base_url('Cari/CariMrTrx'); ?>" method="get">
                                <input type="text" style="margin-top: 5px" name="mr" class="form-control" required>
                                <button style="margin-top:10px" type="submit" class="btn btn-sm btn-primary"> Cari
                                </button>
                            </form>
                        </div>
                        <div class="tab-pane" id="tab_3">
                            <?php $tgl = date('d-m-Y'); ?>
                            <form action="<?= base_url('Cari/CaritglTrx'); ?>" method="get">
                                <input value="<?= $tgl; ?>" 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>
</div>