<?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>
            Data Rekam Medis
            <small>Klinik</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Berkas</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">CPPT <small>status count : <?= $countHeader; ?></small></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">
                <div class="row">
                    <div class="col-md-3">
                        <table class="table table-striped">
                            <tr>
                                <th>Histori CPPT</th>
                            </tr>
                            <?php
                            foreach ($cpptHeader as $list) :
                            ?>
                                <tr>
                                    <td>
                                        <a href="<?= base_url('addCpptNonDokter/listAndForm/' . $this->uri->segment(3) . '/' . $this->uri->segment(4) . '?form=' . $list['IdHeader']); ?>" style="width: 100%;" class="btn btn-sm btn-success">
                                            <i class="fa fa-fw fa-calendar"></i> Terbit :
                                            <?= date('d M Y', strtotime($list['DateHeader'])); ?>
                                            <?php
                                            if ($list['Note'] == '1') {
                                                echo "( Berjalan )";
                                            } else if ($list['Note'] == '0') {
                                                echo "( Selesai )";
                                            }
                                            ?>
                                        </a>
                                    </td>
                                </tr>
                            <?php
                            endforeach;
                            ?>
                        </table>
                    </div>
                    <div class="col-md-9">

                        <div style="padding: 10px; background-color: gray; border-radius: 10px;color:white; margin-bottom: 30px;">
                            <table width="100%">
                                <tr>
                                    <td colspan="3">
                                        <h3 style="margin-top: -1px; font-weight: bolder;">IDENTITAS</h3>
                                    </td>
                                </tr>
                                <tr>
                                    <td width="10%">No.MR</td>
                                    <td width="5%">:</td>
                                    <td><?= $datapasien['PatientCode']; ?></td>
                                </tr>
                                <tr>
                                    <td>Nama</td>
                                    <td>:</td>
                                    <td><?= $datapasien['Description']; ?></td>
                                </tr>
                                <tr>
                                    <td>Tujuan</td>
                                    <td>:</td>
                                    <td><?= $datapasien['Unit']; ?></td>
                                </tr>
                                <tr>
                                    <td>Dokter</td>
                                    <td>:</td>
                                    <td><?= $datapasien['namaDokter']; ?></td>
                                </tr>
                            </table>
                        </div>

                        <?php
                        extract($_GET);
                        if (isset($form)) {
                            $status = $this->db->query("SELECT IdHeader,Note FROM HeaderCppt WHERE IdHeader = '$form'")->row_array();
                            $listDetail = $this->db->query("SELECT * FROM DetailCppt WHERE IdHeader = '$form'")->result_array();
                        ?>
                            <ul class="timeline">
                                <!-- timeline time label -->
                                <li class="time-label">
                                    <span class="bg-red btn btn-sm btn-primary">
                                        Histori Cppt
                                        <?php
                                        if ($status['Note'] == '1') {
                                            echo "Berjalan";
                                        } else if ($status['Note'] == '0') {
                                            echo "Selesai";
                                        }
                                        ?>
                                    </span>
                                    <a href="<?= base_url('addCpptNonDokter/listAndForm/' . $this->uri->segment(3) . '/' . $this->uri->segment(4)); ?>" class="btn btn-sm btn-warning"><b>x</b></a>
                                    <a href="<?= base_url('addCpptNonDokter/cetakcppt/' . $this->uri->segment(3) . '/' . $this->uri->segment(4) . '/' . $status["IdHeader"]); ?>" target="_blank" class="btn btn-sm btn-success"> <i class="fa fa-print"> Cetak </i></a>
                                </li>
                                <!-- /.timeline-label -->
                                <!-- timeline item -->
                                <?php
                                foreach ($listDetail as $list) :
                                ?>
                                    <li>
                                        <i class="fa fa-envelope bg-blue"></i>
                                        <div class="timeline-item">
                                            <span class="time"><i class="fa fa-calendar-o"></i> <?= date('d F Y', strtotime($list['DateDetail'])); ?> <?= date('H:i', strtotime($list['TimeDetail'])); ?></span>
                                            <h3 class="timeline-header"><a href="#"><?= $list['UserCreated']; ?></a> <small style="color: gray;">Pembuat</small></h3>
                                            <div class="timeline-body">
                                                <p style="font-weight: normal;">
                                                <p style="font-weight: normal;">
                                                    <b>SUBJEK</b> : <?= $list['Subjek']; ?><br>
                                                    <b>OBJEK</b> : <?= $list['Objek']; ?><br>
                                                    <b>ASSESMENT</b> : <?= $list['Asesment']; ?><br>
                                                    <b>PENILAIAN</b> : <?= $list['Penilaian']; ?><br>
                                                    <b>ASUHAN KEPERAWATAN</b> : <?= $list['Asuhankeperawatan']; ?><br>
                                                </p>
                                                </p>
                                            </div>
                                        </div>
                                    </li>
                                <?php
                                endforeach;
                                ?>
                            </ul>

                            <div style="padding: 15px; background-color: gray; color: white;border-radius: 10px;">
                                <form action="<?= base_url('addCpptNonDokter/simpanCpptLama/' . $this->uri->segment(4)); ?>" method="post">
                                    <!-- <label for="">Resume</label> -->
                                    <input type="text" name="idHeader" hidden value="<?= $form; ?>">
                                    <label for="">Subjek</label>
                                    <input type="text" name="Subjek" class="form-control" value="" placeholder="Subjek">
                                    <label for="">Objek</label>
                                    <input type="text" name="Objek" class="form-control" value="" placeholder="Objek">
                                    <label for="">Assesment</label>
                                    <input type="text" name="Asesment" class="form-control" value="" placeholder="Assesment">
                                    <label for="">Penilaian</label>
                                    <input type="text" name="Penilaian" class="form-control" value="" placeholder="Penilaian">
                                    <label for="">Asuhan Keperawatan</label>
                                    <input type="text" name="Asuhan" class="form-control" value="" placeholder="Asuhan Keperawatan">
                                    <label for="">Keterangan</label>
                                    <select name="note" class="form-control" required>
                                        <option value=""></option>
                                        <option value="1">Belum Selesai</option>
                                        <option value="0">Selesai</option>
                                    </select>
                                    <br>
                                    <div id="sig3"></div>
                                    <textarea id="signature64_3" required name="ttd" style="display: none"></textarea>
                                    <button style="width: 80%" class="btn btn-danger btn-block" id="clear_3">Reset</button><br><br>
                                    <?php
                                    if ($status['Note'] == '1') {
                                    ?>
                                        <button type="submit" class="btn btn-sm btn-primary" style="margin-top: 7px;">Simpan</button>
                                    <?php
                                    } else {
                                    ?>
                                        <button type="button" disabled class="btn btn-sm btn-primary" style="margin-top: 7px;">Simpan</button>
                                    <?php
                                    }
                                    ?>
                                </form>
                            </div>
                            <?php
                        } else {
                            // jika baru buat form baru
                            if ($countHeader > 0) {
                            } else {
                            ?>
                                <b>** CPPT Baru</b>
                                <form action="<?= base_url('addCpptNonDokter/simpanCpptBaru/' . $this->uri->segment(4) . '/' . $this->uri->segment(3)); ?>" method="post">
                                    <label for="">Subjek</label>
                                    <input type="text" name="Subjek" class="form-control" value="" placeholder="Subjek">
                                    <label for="">Objek</label>
                                    <input type="text" name="Objek" class="form-control" value="" placeholder="Objek">
                                    <label for="">Assesment</label>
                                    <input type="text" name="Asesment" class="form-control" value="" placeholder="Assesment">
                                    <label for="">Penilaian</label>
                                    <input type="text" name="Penilaian" class="form-control" value="" placeholder="Penilaian">
                                    <label for="">Asuhan Keperawatan</label>
                                    <input type="text" name="Asuhan" class="form-control" value="" placeholder="Asuhan Keperawatan">
                                    <!-- <label for="">Resume</label>
                                    <textarea name="description" class="form-control" required></textarea> -->
                                    <label for="">Keterangan</label>
                                    <select name="note" class="form-control" required>
                                        <option value=""></option>
                                        <option value="1">Belum Selesai</option>
                                        <option value="0">Selesai</option>
                                    </select>
                                    <br>
                                    <div id="sig3"></div>
                                    <textarea id="signature64_3" required name="ttd" style="display: none"></textarea>
                                    <button style="width: 80%" class="btn btn-danger btn-block" id="clear_3">Reset</button><br><br>
                                    <button type="submit" class="btn btn-sm btn-primary" style="margin-top: 7px;">Simpan</button>
                                </form>
                        <?php
                                // akhir form baru
                            }
                        }
                        ?>
                    </div>
                </div>
            </div><!-- /.box-body -->
        </div><!-- /.box -->

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