<?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>
            Pemeriksaan
            <small>Klinik</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Pemeriksaan</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">

        <div class="row">
            <div class="col-md-3">


                <!-- ------------------------- -->
                <div class="box box-solid box-success">
                    <div class="box-header with-border">
                        <span><small><i class="fa fa-edit"> Anamnesa</i></small> </span>
                        <div class="box-tools">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse">
                                <i class="fa fa-minus"></i>
                            </button>
                        </div>
                    </div>
                    <div class="box-body no-padding">
                        <ul class="nav nav-pills nav-stacked">

                            <li>
                                <a title="Berat Badan">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> Berat Badan :
                                        <?= $pasien['BeratBadan']; ?> kg.</small>
                                </a>
                            </li>
                            <li>
                                <a title="Tinggi Badan">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> Tinggi Badan :
                                        <?= $pasien['TinggiBadan']; ?> cm.</small>
                                </a>
                            </li>
                            <li>
                                <a title="RespRate">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> RespRate :
                                        <?= $pasien['respRate']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Suhu">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> Suhu : <?= $pasien['Suhu']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Tensi">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> Tensi :
                                        <?= $pasien['Tensi']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Diastole">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> Diastole :
                                        <?= $pasien['Diastole']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="HeartRate">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> HeartRate :
                                        <?= $pasien['heartRate']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Keluhan">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> Keluhan :
                                        <?= $pasien['Keluhan']; ?></small>
                                </a>
                            </li>

                        </ul>
                        <label id="lbltglplgsep" class="hidden"></label>
                    </div>
                    <!-- /.box-body -->
                </div>
                <div class="box box-solid box-warning">
                    <div class="box-header with-border">
                        <span><small><i class="fa fa-user"> Pasien</i></small> </span>
                        <div class="box-tools">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse">
                                <i class="fa fa-minus"></i>
                            </button>
                        </div>
                    </div>
                    <div class="box-body no-padding">
                        <ul class="nav nav-pills nav-stacked">
                            <li>
                                <a title="No.MR">
                                    <small><i class="fa fa-fw fa-sort-numeric-asc"></i>
                                        <?= $pasien['PatientCode']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Nama">
                                    <small><i class="fa fa-fw fa-medkit"></i>
                                        <?= $pasien['Description']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Tgl.Kunjungan">
                                    <small><i class="fa fa-fw fa-calendar"></i> <?= $pasien['Intake Date']; ?></small>
                                </a>
                            </li>

                            <li>
                                <a title="Poli">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> <?= $pasien['Unit']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Diagnosa">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> <?= $pasien['NoAntrian']; ?></small>
                                </a>
                            </li>

                        </ul>
                        <label id="lbltglplgsep" class="hidden"></label>
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>
            <div class="col-md-9">
                <!-- SELECT2 EXAMPLE -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><i class="fa fa-battery-half"></i> Histori</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>
                        <?php 
                        if($Chistori > 0){
                            ?>
        <table class="table table-striped">
<tr>
    <td valign="top" width="20%">Case ID/MR</td>
    <td valign="top" width="5%">:</td>
    <td valign="top"><?= $pasien['Case ID'].'/'.$pasien['PatientCode'];?></td>
</tr>
<tr>
    <td valign="top">Nama</td>
    <td valign="top">:</td>
    <td valign="top"><?= $pasien['Description'];?></td>
</tr>
<tr>
    <td valign="top">Jenis Kelamin</td>
    <td valign="top">:</td>
    <td valign="top"><?php 
        if($pasien['Sex'] == 1)
        {
            echo "P";
        }else{
            echo "L";
        }
    ;?></td>
</tr>
<tr>
    <td valign="top">Tanggal Lahir</td>
    <td valign="top">:</td>
    <td valign="top"><?php 
    $tglL = date('Y-m-d',strtotime($pasien['DOB']));
    echo $tglL;
    ?>
    </td>
</tr>
<tr>
    <td valign="top">Umur</td>
    <td valign="top">:</td>
    <td valign="top">
    <?php
    // tanggal lahir
    
    $tanggal = new DateTime($tglL);

    // tanggal hari ini
    $today = new DateTime('today');

    // tahun
    $y = $today->diff($tanggal)->y;

    // bulan
    $m = $today->diff($tanggal)->m;

    // hari
    $d = $today->diff($tanggal)->d;
    echo "" . $y . " tahun " . $m . " bulan " . $d . " hari";
    ?>
    </td>
</tr>
</table>
<hr>

<table width="100%" border="0" style="border-collapse: collapse; ">
<?php 
if($countPemeriksaan > 0){
    ?>
    <tr>
        <td width="20%" valign="top">Poli</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['poli']; ?>
        </td>
    </tr>
    <tr>
        <td width="20%" valign="top">Keluhan Utama</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['keluhan_utama']; ?>
        </td>
    </tr>
    <tr>
        <td width="20%" valign="top">Pemeriksaan Fisik</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['pemeriksaan_fisik']; ?>
        </td>
    </tr>
    <?php 
    if($hasilpemeriksaan['poli']== 'POLI GIGI'){
    ?>
    <tr>
        <td colspan="3"><b>Pemeriksaan Gigi :</b> </td>
    </tr>
    <tr>
        <td valign="top"  style="margin-top: -6px;">Element Gigi</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
            <?= $pemeriksaangigi['elemenGigi']; ?>
        </td>
    </tr>
    <tr>
        <td valign="top">Diagnosa</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
            <?= $pemeriksaangigi['diagnosa']; ?>
        </td>
    </tr>
    <tr>
        <td valign="top">Prosedur</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
            <?= $pemeriksaangigi['prosedur']; ?>
        </td>
    </tr>
    <?php }else{ ?>

    <?php } ?>
    <?php 
    if($hasilpemeriksaan['poli']== 'POLI KEBIDANAN'){
    ?>
  <tr>
        <td width="20%" valign="top">Usia Kehamilan</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $usiahamil['Description']; ?>
        </td>
    </tr>
    <tr>
        <td width="20%" valign="top">Jenis Imunisasi</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
        <?= $imunisasi['Description']; ?>
        </td>
    </tr>
    <tr>
        <td width="20%" valign="top">Jenis KB</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
        <?= $kb['Description']; ?>
        </td>
    </tr>
    <?php }else{ ?>

   <?php } ?>
    <tr>
        <td width="20%" valign="top">Diagnosa Primer</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['diagnosa_primer'].' ('.$hasilpemeriksaan['DESCRPTION'].')'; ?>
        </td>
    </tr>
    <tr>
        <td width="20%" valign="top">Diagnos Sekunder</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['diagnosa_sekunder'].' ('.$hasilpemeriksaan['DESCRPTION'].')'; ?>
        </td>
    </tr>
    <?php if($hasilpemeriksaan['poli'] == 'POLI KEBIDANAN') { ?>
    <tr>
        <td width="20%" valign="top">Panel Diagnosa</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['paneldiag']; ?>
        </td>
    </tr>
    <?php }else{ ?>

    <?php } ?>
    <tr>
        <td width="20%" valign="top">Rencana Tindakan</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['rencana_tindakan']; ?>
        </td>
    </tr>
    <tr>
        <td width="20%" valign="top">Tindak Lanjut</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['tindak_lanjut']; ?>
        </td>
    </tr>
    <?php if($hasilpemeriksaan['tanggal_meninggal'] != '' && $hasilpemeriksaan['tanggal_meninggal'] != '1900-01-01'){ ?>
    <tr>
        <td width="20%" valign="top">Tanggal Meninggal</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['tanggal_meninggal']; ?>
        </td>
    </tr>
    <?php }?>
    
    <?php if($hasilpemeriksaan['tanggal_kontrol'] != '' && $hasilpemeriksaan['tanggal_kontrol'] != '1900-01-01'){ ?>
    <tr>
        <td width="20%" valign="top">Tanggal Kontrol</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['tanggal_kontrol']; ?>
        </td>
    </tr>
    <?php }?>
    <?php if($hasilpemeriksaan['poli_tujuan'] != ''){ ?>
    <tr>
        <td width="20%" valign="top">Poli Tujuan</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['poli_tujuan']; ?>
        </td>
    </tr>
    <?php }?>
    <?php if($hasilpemeriksaan['instansi_tujuan'] != ''){ ?>
    <tr>
        <td width="20%" valign="top">Instansi Tujuan</td>
        <td align="center" valign="top" width="5%">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['instansi_tujuan']; ?>
        </td>
    </tr>
    <?php }?>
    <tr>
        <td valign="top">Obat</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['obat']; ?>
        </td>
    </tr>
    <tr>
     <?php
        $caseid = $this->uri->segment(4);
        $queryobat = $this->db->query("select rh.ResepId,rh.CaseID,rh.Category,rh.PatientCode,rh.InTakeDate,rd.PharmacyCode,ph.Description,RH.Jenis from Resep_Header RH
        JOIN Resep_Detail rd on rh.ResepId = rd.ResepId
        join Pharmacy ph on ph.PharmacyCode = rd.PharmacyCode
        where RH.CaseID = '$caseid'
        order by rd.ResepId DESC")->result_array();

        $racikan = $this->db->query("Select d.PharmacyCode,h.ResepId,h.[Case ID],h.QtyRacikan,h.Frekuensi,p.Description,p.PharmacyUnit as Satuan,D.iQty as Jumlah  FROM Resep_Racikan_H H 
        join Resep_Racikan_D d on d.ResepID = H.ResepId
        join Pharmacy p on p.PharmacyCode = d.PharmacyCode
        where h.[Case ID] = '$caseid'")->result_array();

      ?>
        <td valign="top">Non-Racikan</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
        <?php foreach($queryobat as $qd) : ?>
        <?= $qd['Description'].',';?>
        <?php endforeach; ?>
        </td>
    </tr>
    <tr>
    <td valign="top">Racikan</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
        <?php foreach($racikan as $qr) : ?>
        <?= $qr['Description'].',';?>
        <?php endforeach; ?>
    </td>
    </tr>
    <tr>
        <td valign="top">Catatan</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['catatan']; ?>
        </td>
    </tr>
    <tr>
        <td valign="top">Alergi</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
            <?= $hasilpemeriksaan['alergi']; ?>
        </td>
    </tr>
    <?php 
}
?>

<?php 
if($countDiagnosa > 0){
    ?>
    <tr>
        <td valign="top">Diagnosa</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
            <?= $hasilDiagnosa['ICD_Code'].'-'.$hasilDiagnosa['DESCRPTION']; ?>
        </td>
    </tr>
    <?php 
}
?>

<?php 
if($countRujukan > 0){
    ?>
    <tr>
        <td valign="top">Rujukan</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
            <?= $hasilRujukan['Rujukan']; ?>
        </td>
    </tr>
    <tr>
        <td valign="top">Poli</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
            <?= $hasilRujukan['Poli']; ?>
        </td>
    </tr>
    <?php 
}
?>

<?php 
if($countTindakan > 0){
    ?>
    <tr>
        <td valign="top">Tindakan</td>
        <td align="center" valign="top">:</td>
        <td valign="top">
            <?= $hasilTindakan['Tindakan']; ?>
        </td>
    </tr>
    <?php 
}
?>

<?php 
if($countObat > 0){
    ?>
    <tr>
        <td colspan="3"><br></td>
    </tr>
    <tr>
        <td valign="top" colspan="3">Resep Obat</td>
    </tr>
    <tr>
        <td colspan="3">
        <table border='1' width="90%" style="border-collapse: collapse; ">
            <tr>
                <td>No.</td>
                <td>Obat</td>
                <td>Jumlah</td>
                <td>Satuan</td>
                <td>Dosis</td>
            </tr>
        <?php 
        $no=1;
        foreach($hasilObat as $obat):
        ?>
            <tr>
                <td><?= $no++; ?>.</td>
                <td><?= $obat['Obat']; ?></td>
                <td><?= $obat['Jumlah']; ?></td>
                <td><?= $obat['Satuan']; ?></td>
                <td><?= $obat['Dosis']; ?></td>
            </tr>
        <?php 
        endforeach;
        ?>
        </table>
        </td>
    </tr>
    <?php 
}
?>
</table>
                            <?php 
                        }else{
                            echo "Tidak ada histori";
                        }
                        $uri = $this->uri->segment('4');
                        ?>
                        </small>
                        <br>         
                        <a href="<?= base_url('rekamMedis/cetakRekamMedis/' . $pasien['Case ID']); ?>" target="_blank" class="btn btn-success btn-sm"><i class="fa fa-fw fa-print"></i> Cetak Rekam Medis</a>
                        <a href="<?= base_url('rekamMedis/pemeriksaan/'.$uri); ?>" class="btn btn-sm btn-danger pull-right"><i class="fa fa-undo"></i> Batal</a>
                    </div>
                </div><!-- /.box -->
            </div>
        </div>



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