<?php
date_default_timezone_set("Asia/Jakarta");
$caseID = $this->uri->segment(3);
$cekid = $this->db->query("select* from erm_formresum where case_id = '$caseID'")->row_array();
$d = $this->db->query("Select * from Patient p join Cases c on p.PatientCode = c.PatientCode where c.[Case ID] = '$caseID' ")->row_array();
$tgll = date('Y-m-d', strtotime(@$d['DOB']));
$tanggal_lahir = new DateTime($tgll);
$sekarang = new DateTime("today");
if ($tanggal_lahir > $sekarang) {
    $thn = "0";
    $bln = "0";
    $tgl = "0";
}
$thn = $sekarang->diff($tanggal_lahir)->y;
$bln = $sekarang->diff($tanggal_lahir)->m;
$tgl = $sekarang->diff($tanggal_lahir)->d;
?>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Resum Medis
            <?php
            if ($cekid > 0) {
            ?>
                - <a href="<?= base_url('Form/cetakresume/' . $this->uri->segment(3)) ?>" target="_blank" class="btn btn-primary"><i class="fa fa-print"></i> Cetak </a><br>
            <?php } else { ?>

            <?php } ?>
        </h1>
        <ol class="breadcrumb">
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="card" style="padding: 15px; background-color: white;border-radius: 5px;">
            <div class="card-body">
            <?php
                            // Session 
                            if ($this->session->flashdata('message')) {
                                echo $this->session->flashdata('message');
                            }
            ?>
                <div class="row text-center">
                    <div class="col-md-2"></div>
                    <div class="col-md-2">
                        <img src="<?= base_url('images/logo.png'); ?>" height="80px">
                    </div>
                    <div class="col-md-6">
                        <h4 style="font-weight: bold;">
                            <?= $unit['NamaPerusahaan']; ?><br>
                            Resum Medis
                        </h4>
                    </div>
                    <div class="col-md-2"></div>
                </div>
                <div class="row text-center">
                    <div class="col-md-2"></div>
                    <div class="col-md-8">
                        <hr>
                    </div>
                    <div class="col-md-2"></div>
                </div>
                <table class="table table-striped table-hover" id="example1" style="border-collapse: collapse;text-align:left width:100%;">
                        <tr>
                            <td>No.MR</td>
                            <td>:</td>
                            <td><?= $d['PatientCode']; ?></td>
                        </tr>
                        <tr>
                            <td>No.Reg</td>
                            <td>:</td>
                            <td><?= $d['Case ID']; ?></td>
                        </tr>
                        <tr>
                            <td>Nama</td>
                            <td>:</td>
                            <td><?= $d['Description']; ?></td>
                        </tr>
                        <tr>
                            <td>Kunjungan</td>
                            <td>:</td>
                            <td><?= date('d-m-Y', strtotime($d['Intake Date'])); ?></td>
                        </tr>
                        <tr>
                            <td>Jenis Kelamin</td>
                            <td>:</td>
                            <?php
                            if ($d['Sex'] == 1) {
                                $Jenis = "Perempuan";
                            } else {
                                $Jenis = "Laki - Laki";
                            }
                            ?>
                            <td><?= $Jenis; ?></td>
                        </tr>
                        <tr>
                            <td>Tanggal Lahir</td>
                            <td>:</td>
                            <td>
                                <?php
                                if ($d['DOB'] == '') {
                                } else {
                                    echo date('d-m-Y', strtotime($d['DOB']));
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Umur</td>
                            <td>:</td>
                            <td><?= $thn . ' th ' . $bln . ' bulan ' . $tgl . ' hari'; ?></td>
                        </tr>
                        <tr>
                            <td>Alamat</td>
                            <td>:</td>
                            <td><?= $d['HomeAddress1']; ?></td>
                        </tr>
                    </table>
                    <hr><br>
                <form action="<?= base_url('Form/prosesResume/' . $this->uri->segment(3)); ?>" method="post">
                    <p style="text-align: center;"><b>RESUM MEDIS</b></p>
                    <table class="table table-striped" id="example1" style="border-collapse: collapse;text-align:left width:100%;">
                    <tr>
                        <td>Alasan Berobat</td>
                        <td>:</td>
                        <td><input type="text" name="keluhan" class="form-control" value="<?=  $hasil['keluhan_utama'];  ?>"></td>
                    </tr>
                    <tr>
                        <td>Diagnosa</td>
                        <td>:</td>
                        <td><input type="text" name="diagnosa" class="form-control" value="<?=  $hasil['diagnosa_primer'].'-'.$hasil['DESCRPTION']; ?>" ></td>
                    </tr>
                    <tr>
                        <td>Pemeriksaan Fisik *)</td>
                        <td>:</td>
                        <td><textarea name="pemeriksaanfisik" id="" class="form-control" cols="30" rows="10" ><?=  $hasil['pemeriksaan_fisik'];  ?></textarea></td>
                    </tr>
                    <tr>
                        <td>Terapi Yang Diberikan / Obat</td>
                        <td>:</td>
                        <td><textarea name="terapi" id="" class="form-control">
                        <?=  $hasil['obat'];  ?>
                        <?php foreach ($nonracik as $nr) : ?>
                            <?= $nr['Description'].' - Dosis:' . $nr['frekuensi']  . ','; ?><br>
                        <?php endforeach; ?>
                        </textarea></td>
                    </tr>
                    <tr>
                        <td>Pemeriksaan Penunjang *)</td>
                        <td>:</td>
                        <td><textarea name="penunjang" id=""  class="form-control"></textarea></td>
                    </tr>
                    <tr>
                        <td>Edukasi</td>
                        <td>:</td>
                        <td><input type="text" name="edukasi" class="form-control" value=""></td>
                    </tr>
                    <tr>
                        <td>Kontrol Kembali Tanggal</td>
                        <td>:</td>
                        <td><input name="kontrol" type="date" class="form-control" value=""></td>
                    </tr>
                    </table>
                    <br>
                    <div class="row">
                        <div class="col-md-12">
                            <?php
                            if ($cekid > 0) {
                            ?>
                                <button type="submit" class="btn btn-sm btn-danger" style="width: 100%;" disabled>Data Sudah Di Input</button>
                            <?php } else { ?>
                                <button onclick="return confirm('Apakah pengisian sudah benar?')" type="submit" class="btn btn-sm btn-primary" style="width: 100%;">Simpan</button>
                            <?php } ?>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>              