<?php
date_default_timezone_set("Asia/Jakarta");
?>
<style>
    td {
        font-size: 10pt;
    }

    th {
        font-size: 10pt;
    }

    .blink_me {
        animation: blinker 1s linear infinite;
    }

    @keyframes blinker {
        60% {
            opacity: 0;
        }
    }

    .ulclass {
        background-color: #E5F4FC;
        cursor: pointer;
        z-index: 1;
        position: absolute;
        width: 60%;
        overflow: scroll;
    }

    .liclass {
        font-size: 14px;
        font-weight: bold;
        padding: 12px;
        text-align: left;
        border: thin solid #F0F8FF;
    }

    .liclass:hover {
        background-color: #64CBFF;
    }
</style>
<!-- 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>
                            <li>
                                <a title="TingkatNyeri">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> Tingkat Nyeri :
                                        <?= $pasien['tingkat_nyeri']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="PernahRawat">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> Pernah DiRawat :
                                        <?= $pasien['pernahDirawat']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Psikososial">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> Psikososial :
                                        <?= $pasien['Psikososial']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Spiritual">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> Spiritual :
                                        <?= $pasien['Spiritual']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="RiwayatPenyakit">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> RiwayatPenyakit :
                                        <?= $pasien['Riwayatpenyakit']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="AlergiObat">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i> AlergiObat :
                                        <?= $pasien['alergi_obat']; ?></small>
                                </a>
                            </li>
                        </ul>
                        <label id="lbltglplgsep" class="hidden"></label>
                    </div>
                    <!-- /.box-body -->
                </div>

                <!-- CPPT -->
                <div class="box box-solid box-primary">
                    <div class="box-header with-border">
                        <span><small><i class="fa fa-user"> Histori Cppt</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">
                            <!-- riki -->

                            <li>
                                <a href="#" data-toggle="modal" data-target="#ModalCppt<?= $headerCppt['IdHeader']; ?>">
                                    <small><i class="fa fa-fw fa-search"></i> Lihat Cppt</small>
                                    <!-- <small>~ CPPT <?= date('d M Y', strtotime($headerCppt['DateHeader'])); ?></small> -->
                                </a>
                            </li>


                        </ul>
                        <label id="lbltglplgsep" class="hidden"></label>
                    </div>
                    <!-- /.box-body -->
                </div>

                <!-- CPPT -->
                <div class="box box-solid box-info">
                    <div class="box-header with-border">
                        <span><small><i class="fa fa-user"> I-Care</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">
                            <!-- riki -->

                            <li>
                                <a href="<?= base_url("icare/cekRiwayatPelayanan/" . $pasien['EmployeeID']); ?>" >
                                    <small><i class="fa fa-fw fa-search"></i> Lihat I-Care</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-sticky-note"></i>
                                        <?= $pasien['PatientCode']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Nama">
                                    <small><i class="fa fa-fw fa-slideshare"></i>
                                        <?= $pasien['Description']; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="NIK">
                                    <small><i class="fa fa-fw fa-black-tie"></i>
                                        <?php
                                        $tglL = $pasien['NIK'];
                                        echo $tglL;
                                        ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Tanggal Lahir">
                                    <small><i class="fa fa-fw fa-calendar-check-o"></i>
                                        <?php
                                        $tglL = date('d-m-Y', strtotime($pasien['DOB']));
                                        echo $tglL;
                                        ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Jenis Kelamin">
                                    <small><i class="fa fa-fw fa-odnoklassniki"></i>
                                        <?php
                                        if ($pasien['Sex'] == 1) {
                                            echo "Perempuan";
                                        } else {
                                            echo "Laki-laki";
                                        }; ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Umur">
                                    <small><i class="fa fa-fw fa-hourglass-start"></i>
                                        <?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";
                                        ?></small>
                                </a>
                            </li>


                        </ul>
                        <label id="lbltglplgsep" class="hidden"></label>
                    </div>
                    <!-- /.box-body -->
                </div>

                <div class="box box-solid box-info">
                    <div class="box-header with-border">
                        <span><small><i class="fa fa-user"> Case saat ini</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 Kunjungan">
                                    <small><i class="fa fa-fw  fa-cc"></i>
                                        <?php
                                        $tglL = $pasien['Case ID'];
                                        echo $tglL;
                                        ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Penjamin">
                                    <small><i class="fa fa-fw fa-bank"></i>
                                        <?php
                                        $tglL = $pasien['jaminan'];
                                        echo $tglL;
                                        ?></small>
                                </a>
                            </li>

                            <li>
                                <a title="Tanggal Masuk">
                                    <small><i class="fa fa-fw fa-calendar-check-o"></i>
                                        <?php
                                        $tglL = date('d-m-Y', strtotime($pasien['Intake Date']));
                                        echo $tglL;
                                        ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Presenting Problem">
                                    <small><i class="fa fa-fw fa-medkit"></i>
                                        <?php
                                        $tglL = $pasien['Presenting Problem'];
                                        echo $tglL;
                                        ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Category">
                                    <small><i class="fa fa-fw fa-sticky-note-o"></i>
                                        <?php
                                        $tglL = $pasien['Category'];
                                        echo $tglL;
                                        ?></small>
                                </a>
                            </li>
                            <li>
                                <a title="Status">
                                    <small><i class="fa fa-fw fa-bookmark-o"></i>
                                        <?php
                                        $tglL = $pasien['Case Status'];
                                        echo $tglL;
                                        ?></small>
                                </a>
                            </li>

                        </ul>
                        <label id="lbltglplgsep" class="hidden"></label>
                    </div>
                    <!-- /.box-body -->
                </div>


                <div class="box box-solid box-danger">
                    <div class="box-header with-border">
                        <span><small><i class="fa fa-user"> Case Histori</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">

                            <?php foreach ($histori as $histori) { ?>
                                <li>
                                    <a target="_blank" href="<?= base_url('rekamMedis/histori/' . $histori['PatientCode'] . '/' . $histori['Case ID']); ?>" title="<?php
                                                                                                                                                                    echo $histori['Presenting Problem'];
                                                                                                                                                                    ?>">
                                        <small><i class="fa fa-fw fa-medkit"></i>
                                            <?php
                                            $tglL = date('d-m-Y', strtotime($histori['Intake Date']));
                                            echo $histori['Case ID'] . ' ~ ' . $tglL . ' ~ ' . $histori['Category'];
                                            ?></small>
                                    </a>
                                </li>
                            <?php } ?>

                        </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">
                        <?php
                        // Session 
                        if ($this->session->flashdata('message')) {
                            echo $this->session->flashdata('message');
                        }
                        ?>
                        <h3 class="box-title">Form Pemeriksaan <small><a style="display:none;" href="<?= base_url('rekamMedis/histori/' . $pasien['PatientCode'] . '/' . $pasien['Case ID']); ?>"><i class="fa fa-fw fa-desktop"></i> Histori</a></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">
                        <?php
                        $id = $this->uri->segment(4);
                        $db = $this->db->query("SELECT c.Description,e.diagnosa_primer FROM Cases c join erm_pemeriksaan_fisik e on c.[Case ID] = e.case_id 
                    where c.PatientCode = '$id' ")->row_array();
                        ?>
                        <?php if ($db['diagnosa_primer'] == 'B20') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B20.0') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B20.1') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B20.2') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B20.3') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B20.4') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B20.5') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B20.6') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B20.7') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B20.8') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B20.9') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == '098.7') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HIV AIDS 098.7
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == '098.4') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis HEPATITIS 098.4
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == '098.1') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis Syphilis complicating 098.1
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'B18') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis Chronic viral hepatitis B.18
                            </div>
                        <?php } elseif ($db['diagnosa_primer'] == 'A16') { ?>
                            <div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-ban"></i> Alert !!!</h4>Pasien Ini Diagnosis Respiratory tuberculosis
                            </div>
                        <?php } else { ?>

                        <?php } ?>
                        <small>
                            <!-- Custom Tabs -->
                            <div class="nav-tabs-custom">
                                <?php
                                if ($tab['TaskID'] == '1') {
                                    $aktif1 = "active";
                                } else if ($tab['TaskID'] == '2') {
                                    $aktif2 = "active";
                                } else if ($tab['TaskID'] == '3') {
                                    $aktif3 = "active";
                                } else if ($tab['TaskID'] == '4') {
                                    $aktif4 = "active";
                                } else if ($tab['TaskID'] == '5') {
                                    $aktif5 = "active";
                                } else if ($tab['TaskID'] == '6') {
                                    $aktif6 = "active";
                                }

                                ?>
                                <ul class="nav nav-tabs">
                                    <li class="<?= @$aktif1; ?>"><a href="#tab_1" data-toggle="tab">Pemeriksaan</a></li>
                                    <li style="display:none;" class="<?= @$aktif2; ?>"><a href="#tab_2" data-toggle="tab">Diagnosa</a></li>
                                    <li style="display:none;" class="<?= @$aktif3; ?>"><a href="#tab_3" data-toggle="tab">Rujukan</a></li>
                                    <li style="display:none;" class="<?= @$aktif4; ?>"><a href="#tab_4" data-toggle="tab">Tindakan</a></li>
                                    <li style="display:none;" class="<?= @$aktif5; ?>"><a href="#tab_5" data-toggle="tab">Obat</a></li>
                                    <li class="<?= @$aktif2; ?>"><a href="#tab_2" data-toggle="tab">Obat</a></li>
                                    <li class="<?= @$aktif6; ?>"><a href="#tab_6" id="tabLab" data-toggle="tab">Laboratory</a></li>
                                    <li class=""><a href="#tab_8" data-toggle="tab">SKS</a></li>
                                    <li class=""><a href="#tab_9" data-toggle="tab">CPPT</a></li>
                                    <li class=""><a href="#tab_7" data-toggle="tab">Cetak</a></li>

                                    <li class="pull-right"><a href="#" class="text-muted"><i class="fa fa-gear"></i></a>
                                    </li>
                                </ul>
                                <div class="tab-content">
                                    <div class="tab-pane <?= @$aktif1; ?>" id="tab_1">
                                        <?php
                                        if ($countPemeriksaan > 0) {
                                            $action = base_url('rekamMedis/updatePemeriksaan/' . $pasien['Case ID']);
                                        } else {
                                            $action = base_url('rekamMedis/prosesPemeriksaan');
                                        }
                                        ?>
                                        <form class="myForm" onsubmit="btnSimpan.disabled = true; return true;" method="post" action="<?= $action ?>" enctype="multipart/form-data">
                                            <div id="panelOdontogram" style="display:none;" class="alert alert-success" role="alert">
                                                <h4 class="alert-heading">Odontogram</h4>
                                                <p>Pemeriksaan yang dilakukan untuk POLI GIGI</p>
                                                <hr>
                                                <button type="button" data-toggle="modal" data-target="#modal-info" style="margin-top: 10px;" class="btn btn-sm btn-info"><i class="fa fa-hourglass-3 fa-fw"></i> Pemeriksaan Odontogram</button>
                                                <a href="<?= base_url('PemeriksaanGigi/ViewPemeriksaan/'.$pasien['Case ID'].'/'.$pasien['PatientCode']) ?>" class="btn btn-sm btn-warning" style="margin-top: 10px;"><i class="fa fa-hourglass-3 fa-fw"></i> Pemeriksaan Odontogram</a>
                                            </div>
                                            <br><br>


                                            <input required type="text" name="CaseID" id="CaseID" hidden value="<?= $pasien['Case ID']; ?>">
                                            <input required type="text" name="PatientCode" id="PatientCode" hidden value="<?= $pasien['PatientCode']; ?>">
                                            <label style="font-size:15px;" for="Pemeriksaan">Poli</label><br>
                                            <select id="poli" onchange="checkPoli()" name="poli" class="teanganData" data-live-search="true">
                                                <?php
                                                foreach ($poli as $p) :
                                                ?>
                                                    <option selected value="<?= $p['ActivityClass']; ?>"><?= $p['ActivityClass']; ?></option>

                                                <?php
                                                endforeach;
                                                ?>
                                            </select>
                                            <br>
                                            <br>
                                            <label style="font-size:15px;" for="Pemeriksaan">Keluhan Utama</label>
                                            <textarea required class="form-control" placeholder="keluhan utama" name="keluhanUtama" rows="2" cols="80"><?= strip_tags((!empty($hasilpemeriksaan['keluhan_utama'])) ? $hasilpemeriksaan['keluhan_utama'] : ''); ?> (<?= $pasien['Keluhan']; ?>)</textarea>
                                            <br>
                                            <div style="display:none;">
                                                <label style="font-size:15px;" for="Pemeriksaan" style="margin-top: 10px;">Penyakit Terdahulu</label>
                                                <input type="text" class="form-control" name="penyakitTerdahulu" value="<?= strip_tags((!empty($hasilpemeriksaan['penyakit_terdahulu'])) ? $hasilpemeriksaan['penyakit_terdahulu'] : ''); ?>">
                                                <br>
                                            </div>
                                            <label style="font-size:15px;" for="Pemeriksaan">Pemeriksaan Fisik</label>
                                            <textarea class="form-control" placeholder="catatan fisik" name="pemeriksaanFisik" rows="5" cols="80"><?= strip_tags((!empty($hasilpemeriksaan['pemeriksaan_fisik'])) ? $hasilpemeriksaan['pemeriksaan_fisik'] : ''); ?></textarea>
                                            <br>
                                            <label style="font-size:15px;" for="Pemeriksaan">Diagnosa</label><br>
                                            <?php
                                            $kdicd = $hasilpemeriksaan["diagnosa_primer"];
                                            $qdata = $this->db->query("select * from ICD9 where ICD_CODE = '$kdicd'")->row_array();
                                            ?>
                                            <input type="text" readonly class="form-control" id="txtCariDiagnosa" value="<?= $hasilpemeriksaan['diagnosa_primer'] . ' - ' . $qdata['DESCRPTION']; ?>" placeholder="Pilih Diagnosa 1">
                                            <input type="hidden" name="txtCariIdDiagnosa" id="txtCariIdDiagnosa" value="<?= $hasilpemeriksaan['diagnosa_primer']; ?>">
                                            <br>
                                            <?php
                                            $kdicd1 = $hasilpemeriksaan["diagnosa_sekunder"];
                                            $qdata1 = $this->db->query("select * from ICD9 where ICD_CODE = '$kdicd1'")->row_array();
                                            ?>
                                            <label style="font-size:15px;" for="Pemeriksaan">Diagnosa Sekunder</label><br>
                                            <input type="text" readonly class="form-control" id="txtCariDiagnosa1" placeholder="Pilih Diagnosa 2" value="<?= $hasilpemeriksaan['diagnosa_sekunder'] . ' - ' . $qdata1['DESCRPTION']; ?>">
                                            <input type="hidden" name="txtCariIdDiagnosa1" id="txtCariIdDiagnosa1" value="<?= $hasilpemeriksaan['diagnosa_sekunder']; ?>">
                                            <br>
                                            <div style="display:none;" id="PanelUsiaKehamilan">
                                                <label style="font-size:15px;" for="Pemeriksaan">Usia Kehamilan</label><br>
                                                <select name="usiakehamilan" class="teanganData " data-live-search="true">
                                                    <option value="">-- Pilih Usia Kehamilan --</option>
                                                    <?php
                                                    foreach ($usiakehamilan as $dd) :
                                                        if ($hasilpemeriksaan['kdhamil'] == $dd['KodeUsia']) {
                                                    ?>
                                                            <option selected value="<?= $dd['KodeUsia']; ?>"><?= $dd['Description']; ?></option>
                                                        <?php
                                                        } else {
                                                        ?>
                                                            <option value="<?= $dd['KodeUsia']; ?>"><?= $dd['Description']; ?></option>
                                                    <?php
                                                        }
                                                    endforeach;
                                                    ?>
                                                    ?>
                                                </select>
                                            </div>

                                            <br>
                                            <div style="display:none;" id="PanelJenisImunisasi">
                                                <label style="font-size:15px;" for="Pemeriksaan">Jenis Imunisasi</label><br>
                                                <select name="jenisimunisasi" class="teanganData " data-live-search="true">
                                                    <option value="">-- Pilih Jenis --</option>
                                                    <?php
                                                    foreach ($jenisimunisasi as $dd) :
                                                        if ($hasilpemeriksaan['kdimunisasi'] == $dd['Kodeimun']) {
                                                    ?>
                                                            <option selected value="<?= $dd['Kodeimun']; ?>"><?= $dd['Description']; ?></option>
                                                        <?php
                                                        } else {
                                                        ?>
                                                            <option value="<?= $dd['Kodeimun']; ?>"><?= $dd['Description']; ?></option>
                                                    <?php
                                                        }
                                                    endforeach;
                                                    ?>
                                                </select>
                                            </div>

                                            <br>
                                            <div style="display:none;" id="PanelJenisKB">
                                                <label style="font-size:15px;" for="Pemeriksaan">Jenis KB</label><br>
                                                <select name="jeniskb" class="teanganData " data-live-search="true">
                                                    <option value="">-- Pilih Jenis KB --</option>
                                                    <?php
                                                    foreach ($jeniskb as $dd) :
                                                        if ($hasilpemeriksaan['kdkb'] == $dd['KodeKB']) {
                                                    ?>
                                                            <option selected value="<?= $dd['KodeKB']; ?>"><?= $dd['Description']; ?></option>
                                                        <?php
                                                        } else {
                                                        ?>
                                                            <option value="<?= $dd['KodeKB']; ?>"><?= $dd['Description']; ?></option>
                                                    <?php
                                                        }
                                                    endforeach;
                                                    ?>
                                                </select>
                                            </div>
                                            <br>
                                            <div style="display:none;" id="PanelDiagnosabidan">
                                                <label style="font-size:15px;" for="Pemeriksaan">Panel Diagnosa</label>
                                                <textarea class="form-control" placeholder="Panel diagnosa" name="paneldiagnosa" rows="2" cols="80"><?= strip_tags((!empty($hasilpemeriksaan['paneldiag'])) ? $hasilpemeriksaan['paneldiag'] : ''); ?></textarea>
                                                <br>
                                            </div>

                                            <div style="display:none;">
                                                <label style="font-size:15px;" for="Pemeriksaan">Diagnosa Sekunder</label>
                                                <textarea class="form-control" placeholder="diagnosa sekunder" name="diagnosaSekunder" rows="2" cols="80"><?= strip_tags((!empty($hasilpemeriksaan['diagnosa_sekunder'])) ? $hasilpemeriksaan['diagnosa_sekunder'] : ''); ?></textarea>
                                                <br>
                                            </div>

                                            <label style="font-size:15px;" for="Pemeriksaan">Rencana Tindakan</label>
                                            <textarea class="form-control" placeholder="Rencana Tindakan (Jika Tidak Ada beri 0 atau -)" name="rencanaTindakan" rows="2" cols="80" required><?= strip_tags((!empty($hasilpemeriksaan['rencana_tindakan'])) ? $hasilpemeriksaan['rencana_tindakan'] : ''); ?></textarea> <br>
                                            <label style="font-size:15px;" for="Pemeriksaan" style="margin-top: 10px;">Terapi Obat</label>
                                            <textarea class="form-control" placeholder="obat" name="obat" rows="5" cols="80"><?= strip_tags((!empty($hasilpemeriksaan['obat'])) ? $hasilpemeriksaan['obat'] : ''); ?></textarea>
                                            <br>
                                            <?php
                                            $patientcode = $this->uri->segment(4);
                                            $dbquery = $this->db->query("Select top 1 e.case_id,e.alergi from erm_pemeriksaan_fisik e
                                                Join Cases c on c.[Case ID] = e.case_id
                                                where c.PatientCode = '$patientcode' order by e.case_id Desc")->row_array();

                                            $dbalergi = $this->db->query("Select top 1 cd.[Case ID],cd.alergi_obat from CaseDetail cd
                                                Join Cases c on c.[Case ID] = cd.[Case ID]
                                                where c.PatientCode = '$patientcode' order by cd.[Case ID] Desc")->row_array();
                                            ?>
                                            <label style="font-size:15px;" for="Pemeriksaan" style="margin-top: 10px;">Alergi</label>
                                            <textarea class="form-control" placeholder="alergi" name="alergi" rows="2" cols="80"><?= strip_tags((!empty($hasilpemeriksaan['alergi'])) ? $hasilpemeriksaan['alergi'] : '');
                                                                                                                                    $dbquery['alergi']; ?> (<?= $dbalergi['alergi_obat']; ?>)</textarea>
                                            <br>
                                            <label style="font-size:15px;" for="tindakan">Status Pulang</label><br>
                                            <select onchange="setTindakLanjut();" name="tindakLanjut" id="tindakLanjut" required="" class="form-control">
                                                <option value=""></option>
                                                <option value="Pulang">Pulang</option>
                                                <option value="Kontrol">Kontrol</option>
                                                <option value="Rujuk Eksternal">Rujuk Eksternal</option>
                                                <option value="Meninggal">Meninggal</option>
                                            </select>
                                            <br>
                                            <div class="row" style="display:none;" id="panelTanggalKontrol">
                                                <div class="col-md-3">
                                                    <label style="font-size:15px;" for="Pemeriksaan" style="margin-top: 10px;">Tanggal Kontrol</label>
                                                </div>
                                                <div class="col-md-9">
                                                    <input type="date" onfocus="this.showPicker()" class="form-control" id="tanggalKontrol" name="tanggalKontrol" value="<?= strip_tags((!empty($hasilpemeriksaan['tanggal_kontrol'])) ? $hasilpemeriksaan['tanggal_kontrol'] : ''); ?>">
                                                </div>
                                            </div>

                                            <div class="row" style="display:none;" id="panelTanggalMeninggal">
                                                <div class="col-md-3">
                                                    <label style="font-size:15px;" for="Pemeriksaan" style="margin-top: 10px;">Tanggal Meninggal</label>
                                                </div>
                                                <div class="col-md-9">
                                                    <input type="date" onfocus="this.showPicker()" class="form-control" id="tanggalMeninggal" name="tanggalMeninggal" value="<?= strip_tags((!empty($hasilpemeriksaan['tanggal_meninggal'])) ? $hasilpemeriksaan['tanggal_meninggal'] : ''); ?>">
                                                </div>
                                            </div>

                                            <div style="display:none;" id="panelRujukEksternal">
                                                <div class="row">
                                                    <div class="col-md-2">
                                                        <label style="font-size:15px;" for="Pemeriksaan" style="margin-top: 10px;">Poli Tujuan</label>
                                                    </div>
                                                    <div class="col-md-10">
                                                        <input type="text" class="form-control" id="poliTujuan" name="poliTujuan" value="<?= strip_tags((!empty($hasilpemeriksaan['poli_tujuan'])) ? $hasilpemeriksaan['poli_tujuan'] : ''); ?>">
                                                    </div>
                                                </div>
                                                <br>
                                                <div class="row">
                                                    <div class="col-md-2">
                                                        <label style="font-size:15px;" for="Pemeriksaan" style="margin-top: 10px;">Instansi Tujuan</label>
                                                    </div>
                                                    <div class="col-md-10">
                                                        <input type="text" class="form-control" id="instansiTujuan" name="instansiTujuan" value="<?= strip_tags((!empty($hasilpemeriksaan['instansi_tujuan'])) ? $hasilpemeriksaan['instansi_tujuan'] : ''); ?>">
                                                    </div>
                                                    <br>
                                                </div>
                                            </div>
                                            <br>
                                            <label style="font-size:15px;" for="Pemeriksaan" style="margin-top: 10px;">Edukasi</label>
                                            <textarea class="form-control" placeholder="catatan" name="catatan" rows="2" cols="80"><?= strip_tags((!empty($hasilpemeriksaan['catatan'])) ? $hasilpemeriksaan['catatan'] : ''); ?></textarea>
                                            <br>
                                            <div align="right">
                                                <?php
                                                if ($countPemeriksaan > 0) {
                                                    $button = "Update Pemeriksaan";
                                                } else {
                                                    $button = "Simpan Pemeriksaan";
                                                }
                                                ?>
                                                <button type="submit" id="btnSimpan" style="margin-top: 10px;" class="btn btn-sm btn-success"><?= $button; ?></button>
                                            </div>
                                        </form>
                                    </div><!-- /.tab-pane -->
                                    <div class="tab-pane <?= @$aktif4; ?>" id="tab_4">
                                        <?php
                                        if ($countTindakan > 0) {
                                            $actionTindakan = base_url('rekamMedis/updateTindakan/' . $pasien['Case ID']);
                                        } else {
                                            $actionTindakan = base_url('rekamMedis/prosesTindakan');
                                        }
                                        ?>
                                        <form onsubmit="btnSimpan.disabled = true; return true;" method="post" action="<?= $actionTindakan ?>">
                                            <input type="text" name="CaseID" hidden value="<?= $pasien['Case ID']; ?>">
                                            <textarea id="editor3" rows="2" name="Tindakan" cols="80"> <?= $hasilTindakan['Tindakan']; ?>
                                            </textarea>

                                            <div align="right">
                                                <?php
                                                if ($countTindakan > 0) {
                                                    $buttonTindakan = "Update Tindakan";
                                                } else {
                                                    $buttonTindakan = "Simpan Tindakan";
                                                }
                                                ?>
                                                <button type="submit" style="margin-top: 10px;" class="btn btn-sm btn-success"><?= $buttonTindakan; ?></button>
                                            </div>
                                        </form>
                                    </div><!-- /.tab-pane -->
                                    <div class="tab-pane <?= @$aktif5; ?>" id="tab_5">
                                        <table class="table table-striped table-hover">
                                            <thead>
                                                <tr>
                                                    <th>No.</th>
                                                    <th>Nama Obat</th>
                                                    <th>Jumlah</th>
                                                    <th>Satuan</th>
                                                    <th>Dosis</th>
                                                    <th>Cara Pakai</th>
                                                    <th></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                if ($countObat > 0) {
                                                    $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>
                                                            <td><?= $obat['CaraPakai']; ?></td>
                                                            <td><a onclick="return confirm('Hapus obat ?');" href="<?= base_url('rekamMedis/hapusObat/' . $obat['id'] . '/' . $obat['Case ID']); ?>"><i class="fa fa-trash"></i></a></td>
                                                        </tr>
                                                    <?php
                                                    endforeach;
                                                } else {
                                                    ?>
                                                    <tr>
                                                        <td colspan="6">Belum ada resep obat!</td>
                                                    </tr>
                                                <?php
                                                }
                                                ?>
                                            </tbody>
                                        </table>

                                        <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#exampleModal"><i class="fa fa-fw fa-plus"></i></button>
                                    </div><!-- /.tab-pane -->
                                    <div class="tab-pane <?= @$aktif6; ?>" id="tab_6">
                                        <?php
                                        $id = $this->uri->segment(3);
                                        $datalab = $this->db->query("Select Cases.[Case ID] as caseid,Cases.[PatientCode],CaseDetail.DoctorID from Cases 
                                    join CaseDetail on Cases.[Case ID] = CaseDetail.[Case ID] 
                                    where Cases.[Case ID] = '$id' ")->row_array();
                                        ?>
                                        <form action="<?= base_url('RekamMedis/ProsesLab/' . $datalab['caseid']); ?>" method="post">
                                            <input type="hidden" name="DoctorID" value="<?= $datalab['DoctorID']; ?>">
                                            <input type="hidden" name="caseid" value="<?= $datalab['caseid']; ?>">
                                            <input type="hidden" name="PatientCode" value="<?= $datalab['PatientCode']; ?>">
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <input type="checkbox" name="cekLab" id="cekLab" onclick="showLab('divLab')"> <label for="cekLab" style="font-weight: normal; cursor: pointer;">Cek Laboratorium</label>
                                                </div>
                                                <div id="divLab" style="display:none">
                                                    <table border='0' id="tab_lab" class="table table-striped table-hover">
                                                        <tr>
                                                            <td width='150px'>Laboraorium Item</td>
                                                            <td></td>
                                                            <td></td>
                                                        </tr>
                                                    </table>
                                                    <div class="row" style="margin-top: 15px;">
                                                        <div class="col-md-12">
                                                            <button id="add_lab" class="btn btn-primary btn-sm" type="button">
                                                                <i class="glyphicon glyphicon-plus"></i>
                                                            </button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <div align="right">
                                                <?php if ($HeaderLab['status'] == NULL) { ?>
                                                    <button type="submit" style="margin-top: 10px;" class="btn btn-sm btn-success">Simpan Laboratory</button>
                                                <?php } else { ?>
                                                    <button type="submit" style="margin-top: 10px;" class="btn btn-sm btn-danger" disabled>Simpan Laboratory</button>
                                                <?php } ?>
                                            </div>
                                            <br>
                                        </form>
                                        <select id="tglRequestHeader" onchange="checkTglRequestHeader()" name="tglRequestHeader" class="teanganData" data-live-search="true">
                                                <option selected value="">-Search By Tanggal Request-</option>
                                                <?php
                                                foreach ($listHeader as $l) :
                                                ?>
                                                    <?php if($tglRequest == $l['tglRequest'] ){ ?>
                                                        <option selected value="<?= $l['tglRequest']; ?>"><?= $l['tglRequest']; ?></option>
                                                    <?php }else{ ?>                                                    
                                                        <option value="<?= $l['tglRequest']; ?>"><?= $l['tglRequest']; ?></option>
                                                    <?php } ?>
                                                <?php
                                                endforeach;
                                                ?>
                                        </select>
                                        <table id="example1" class="table table-striped">
                                            <tr>
                                                <td><b>Header ID</b></td>
                                                <td><b>Tgl Request</b></td>
                                                <td><b>CASE ID</b></td>
                                                <td><b>PACKED ID</b></td>
                                                <td><b>DESCRIPTION</b></td>
                                                <td>
                                                    <?php if ($HeaderLab['status'] == 1) { ?>

                                                    <?php } else { ?>
                                                        <b><button type="button" data-toggle="modal" data-target="#modal-sample<?= $datalab['caseid'] ?>" class="btn btn-sm btn-success"><i class="fa fa-solid fa-eye"></i> Lihat Hasil</button></b>
                                                    <?php } ?>
                                                </td>
                                            </tr>
                                            <tbody>
                                                <?php foreach ($list as $d) : ?>
                                                    <tr>
                                                        <td><?= $d['IdRequestHeader']; ?></td>
                                                        <td><?= $d['tglRequest']; ?></td>
                                                        <td><?= $d['CaseID']; ?></td>
                                                        <td><?= $d['PackedID']; ?></td>
                                                        <td><?= $d['Description']; ?></td>
                                                        <td>
                                                            <?php if ($d['status'] == '1') { ?>
                                                                <a href="<?= base_url('RekamMedis/hapusrequeslab/' . $d['PackedID'] . '/' . $d['CaseID']); ?>" onclick="return confirm('Apakah anda yakin data ini akan dihapus ?')" class="btn btn-danger btn-sm"><i class="fa fa-fw fa-trash"></i></a>
                                                            <?php } else { ?>
                                                                <a class="btn btn-default btn-sm" disabled><i class="fa fa-trash"></i></a>
                                                            <?php } ?>
                                                        </td>
                                                    </tr>
                                            </tbody>
                                        <?php
                                                endforeach;
                                        ?>
                                        </table>
                                        <hr>
                                    </div><!-- /.tab-pane -->

                                    <!-- Modal Lihat Resep -->
                                    <div id="modal-sample<?= $datalab['caseid']; ?>" class="modal fade">
                                        <div class="modal-dialog">
                                            <form action="<?php echo site_url('Modal/add'); ?>" method="post">
                                                <div class="modal-content">
                                                    <div class="modal-header bg-primary">
                                                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                        <h4 class="modal-title">View DataLab</h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <div class="form-group">
                                                            <table id="example1" class="table table-striped">
                                                                <tr>
                                                                    <td><b>LAB NO</b></td>
                                                                    <td><b>NAMA PEMERIKSAAN</b></td>
                                                                    <td><b>HASIL NILAI</b></td>
                                                                    <td><b>NILAI NORMAL</b></td>
                                                                </tr>
                                                                <tr>
                                                                    <td colspan="4">
                                                                        <center><?= $HeaderLab['Description']; ?></center>
                                                                    </td>
                                                                </tr>
                                                                <tbody>
                                                                    <?php foreach ($viewlab as $d) : ?>
                                                                        <tr>
                                                                            <td><?= $d['LabNo']; ?></td>
                                                                            <td><?= $d['Bahasa']; ?></td>
                                                                            <td><?= $d['ResultValue']; ?></td>
                                                                            <td><?= $d['Normalvalue']; ?></td>
                                                                        </tr>
                                                                </tbody>
                                                            <?php endforeach; ?>
                                                            </table>
                                                            <small>
                                                                <table width="100%" border="0" style="border-collapse: collapse; ">
                                                                    <tr>
                                                                        <td></td>
                                                                    </tr>
                                                                </table>
                                                            </small>
                                                        </div>
                                                        <br><br><br><br><br><br><br>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                    </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                                <!-- End Modal -->
                                <div class="tab-pane" id="tab_7">
                                    <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>
                                </div><!-- /.tab-pane -->

                                <div class="tab-pane" id="tab_8">
                                    <?php $this->load->view('rekamMedis/page/sks'); ?>
                                </div><!-- /.tab-pane -->

                                <div class="tab-pane" id="tab_9">
                                    <?php $this->load->view('rekamMedis/page/cppt'); ?>
                                </div><!-- /.tab-pane -->

                                <!-- Resep Obat Klinik --->
                                <div class="tab-pane <?= @$aktif6; ?>" id="tab_2">
                                    <!-- FORM -->
                                    <form enctype="multipart/form-data"   action="<?= base_url('Obat/ProsesObat/' . $this->uri->segment(3) . '/' . $this->uri->segment(4)); ?>" id="formSubmitObatNonRacikan" method="post">
                                        <b>OBAT NON-RACIKAN </b>
                                        <hr>
                                        <table border='0' class="table" id="tab_obat">
                                            <tr>
                                                <b>
                                                    <td style="display:none;" width='100px'>IdResep</td>
                                                    <b>
                                                        <td width='300px'>Nama Obat</td>
                                                        <td style='display:none;' width='300px'>Nama Obat</td>
                                                        <td width='200px'>Qty</td>
                                                        <td style='display:none;' width='100px'>Satuan</td>
                                                        <td width='200px'>Frekuensi</td>
                                                        <td width='50px'>AturanPakai</td>
                                                        <td width='200px'>Keterangan</td>
                                                        <td style='display:none;' width='50px'>~</td>
                                                    </b>
                                            </tr>
                                        </table>

                                        <table border='0' class="table">
                                            <tr>
                                                <b>
                                                    <td width='100px'>IdResep</td>
                                                    <b>
                                                        <td width='100px'>Case ID</td>
                                                        <td width='200px'>Nama Pasien</td>
                                                        <td width='100px'>Jenis</td>
                                                        <td width='200px'>Tanggal</td>
                                                        <td width='200px'>Category</td>
                                                        <td width='200px'>Nama Dokter</td>
                                                        <td width='50px'>~</td>
                                                    </b>
                                            </tr>
                                            <?php foreach ($trxheader as $d) : ?>
                                                <tr>
                                                    <td><?= $d['ResepId']; ?></td>
                                                    <td><?= $d['CaseID']; ?></td>
                                                    <td><?= $d['Description']; ?></td>
                                                    <td><?= $d['Jenis']; ?></td>
                                                    <td><?= $d['Intake Date']; ?></td>
                                                    <td><?= $d['Category']; ?></td>
                                                    <td><?= $d['FirstName']; ?></td>
                                                    <td><a href="<?= base_url('Apotik/rDetail/' . $d['CaseID'] . '/' . $d['ResepId']); ?>" class="btn btn-success">Detail</a></td>
                                                </tr>
                                            <?php endforeach; ?>
                                        </table>
                                        <br>
                                        <input type="hidden" name="user" value="<?= $user['nama']; ?>" class="">
                                        <input type="hidden" name="idDokter" value="<?= $user['IdAlias']; ?>" class="">
                                        <div class="row" style="margin-top: 15px;">
                                            <?php
                                            $CaseID =  $this->uri->segment(3);
                                            $mr = $this->uri->segment(4);
                                            $cases =   $this->db->query("Select * From Cases Where [Case ID] = '$CaseID' ")->row_array();
                                            ?>
                                            <div class="col-md-12">
                                                <?php
                                                if ($cases['Case Status'] == 'CLOSED' || $cases['Case Status'] == 'CANCEL') {
                                                ?>
                                                    <button id="add_obat" class="btn btn-primary btn-sm" type="button" Disabled>
                                                        <i class="glyphicon glyphicon-plus"> </i> Tambah
                                                    </button>
                                                    <button type="submit" id="btnSimpan" class="btn btn-sm btn-success" Disabled><i class="fa fa-fw fa-save"></i> Simpan Resep</button>
                                                <?php
                                                } else {
                                                ?>
                                                    <button id="add_obat" class="btn btn-primary btn-sm" type="button">
                                                        <i class="glyphicon glyphicon-plus"> </i> Tambah
                                                    </button>
                                                    <button type="button" onClick="checkObatNonRacikan();" id="btnSimpanNonRacikan" class="btn btn-sm btn-success"><i class="fa fa-fw fa-save"></i> Simpan Resep</button>
                                                <?php } ?>
                                            </div>
                                        </div>
                                    </form>
                                    <br>
                                    <?php $this->load->view('rekamMedis/obatracikan'); ?>
                                    <!-- End Resep -->
                                </div>
                            </div><!-- /.tab-content -->
                    </div><!-- nav-tabs-custom -->
                    </small>
                </div><!-- /.box-body -->
                <div class="box-footer">
                    <small>Daftar Pemeriksaan <?= date('d F Y'); ?> - @Klinik <?= date('Y'); ?></small>
                </div>
            </div><!-- /.box -->
        </div>
</div>
</section><!-- /.content -->
</div><!-- /.content-wrapper -->


<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <form action="<?= base_url('rekamMedis/prosesObat'); ?>" method="post">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Resep Obat</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <label for="">Nama Obat</label><br>
                    <input type="text" name="CaseID" value="<?= $pasien['Case ID']; ?>" hidden>
                    <select required class="teanganData" data-live-search="true" name="Obat" required style="width: 100%;">
                        <option value="">- Pilih -</option>
                        <?php
                        foreach ($pharmacy as $phar) :
                        ?>
                            <option value="<?= $phar['Description']; ?>"><?= $phar['Description']; ?></option>
                        <?php
                        endforeach;
                        ?>
                    </select><br>
                    <label for="">Jumlah</label>
                    <input type="text" class="form-control" required name="Jumlah" placeholder="ketik jumlah obat">
                    <label for="">Satuan</label>
                    <select name="Satuan" required class="form-control">
                        <option value="">- Pilih -</option>
                        <option value="Lembar">Lembar</option>
                        <option value="Botol">Botol</option>
                        <option value="Pcs">Pcs</option>
                        <option value="Tablet">Tablet</option>
                        <option value="Ampul">Ampul</option>
                    </select>
                    <label for="">Dosis</label> <br>
                    <select required class="teanganData" data-live-search="true" name="Dosis" required style="width: 100%;">
                        <option value="">- Pilih -</option>
                        <?php
                        foreach ($dosis as $dos) :
                        ?>
                            <option value="<?= $dos['Dosis']; ?>"><?= $dos['Dosis']; ?></option>
                        <?php
                        endforeach;
                        ?>
                    </select><br>
                    <label for="">Cara Pakai</label><br>
                    <select class="teanganData" data-live-search="true" name="CaraPakai" required style="width: 100%;" required>
                        <option value="">- Pilih -</option>
                        <?php
                        foreach ($caraPakai as $cara) :
                        ?>
                            <option value="<?= $cara['CaraPakai']; ?>"><?= $cara['CaraPakai']; ?></option>
                        <?php
                        endforeach;
                        ?>
                    </select>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">Simpan</button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="modal modal-default fade" id="modal-info" style="display: none;">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span></button>
                <h4 class="modal-title">Odontogram</h4>
            </div>
            <div class="modal-body">
                <img width="100%" src="<?php echo base_url(); ?>/assets/odontogram.jpeg">
                <div class="row">
                    <!-- left column -->
                    <div class="col-md-6">
                        <!-- general form elements -->
                        <div class="box box-primary">
                            <!-- form start -->
                            <form class="form-horizontal">
                                <div class="box-body">

                                    <div class="form-group">
                                        <label style="color:black;" for="inputEmail3" class="col-sm-2 control-label">Elemen Gigi</label>

                                        <div class="col-sm-10">
                                            <select style="color:black;" id="odontogram" name="odontogram" class="teanganData" data-live-search="true">
                                                <option style="color:black;" value="">--pilih--</option>
                                                <?php
                                                foreach ($element as $d) :
                                                ?>
                                                    <option value="<?= $d['ElemenGigi']; ?>"><?= $d['ElemenGigi']; ?></option>
                                                <?php
                                                endforeach;
                                                ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label style="color:black;" for="inputEmail3" class="col-sm-2 control-label">Diagnosa</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="diagnosa" placeholder="diagnosa">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label style="color:black;" for="inputPassword3" class="col-sm-2 control-label">Prosedur</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="prosedur" placeholder="prosedur">
                                        </div>
                                    </div>
                                </div><!-- /.box-body -->
                                <div class="box-footer">
                                    <button type="button" onclick="simpanOdontogram();" class="btn btn-info pull-right">Simpan</button>
                                </div><!-- /.box-footer -->
                            </form>
                        </div><!-- /.box -->
                    </div>

                    <!-- left column -->
                    <div class="col-md-6">
                        <!-- general form elements -->
                        <div class="box box-primary">
                            <!-- form start -->
                            <form class="form-horizontal">
                                <div class="box-body">
                                    <table style="font-size: 10px;" id="example1" class="table table-bordered table-hover table-striped">
                                        <thead>
                                            <tr>
                                                <th>Elemen Gigi</th>
                                                <th>Diagnosa</th>
                                                <th>prosedur</th>
                                                <th>~</th>
                                            </tr>
                                        </thead>
                                        <tbody id="tbodyOdontogram"></tbody>
                                    </table>

                                </div><!-- /.box-body -->

                            </form>
                        </div><!-- /.box -->
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-outline pull-left" data-dismiss="modal">Close</button>
            </div>
        </div>

    </div>

</div>

<!-- Modal Cari Diagnosa -->
<div class="modal fade" id="ModalCariDiagnosa" 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">Daftar Diagnosa Primer</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="col-ms-4">
                    <input type="text" class="form-control" id="textCariDiagnosa" placeholder="Ketik Nama Diagnosa"><br>
                </div>
                <div class="col-ms-2">
                    <button type="button" class="btn btn-primary" id="btnFilter">Filter</button>
                </div>
                <table class="table table-hover mt-3">
                    <thead>
                        <tr>
                            <th scope="col" width="50%">Kode Diagnosa</th>
                            <th scope="col" width="40%">Nama Diagnosa</th>
                            <th scope="col" width="10%">Action</th>
                        </tr>
                    </thead>
                    <tbody id="ListDiagnosa">

                    </tbody>
                </table>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
        </div>
    </div>
</div>
</div>
<!-- End of Modal Cari Diagnosa -->

<!-- Modal Detail Cppt -->
<div class="modal fade" id="ModalCppt<?= $headerCppt['IdHeader']; ?>" 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">CPPT Terbit :
                    <?php
                    if (@$headerCppt['Note'] == 1) {
                        echo date('d F Y', strtotime($headerCppt['DateHeader']));
                    } else {
                        echo "<b><u>CPPT Baru belum terbit!</u></b>";
                    }
                    ?>
                </h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <ul class="timeline">
                    <!-- timeline time label -->
                    <li class="time-label">
                        <span class="bg-red">
                            Histori Cppt -
                            <?php
                            if ($headerCppt['Note'] == 1) {
                                echo "Berjalan";
                            } else {
                                echo "Selesai";
                            }
                            ?>
                        </span>
                        - <a href="<?= base_url('addCpptNonDokter/cetakcpptdokter/' . $this->uri->segment(3) . '/' . $this->uri->segment(4) . '/' . $headerCppt["IdHeader"]); ?>" target="_blank" class="btn btn-sm btn-success"> <i class="fa fa-print"> Cetak </i></a>
                    </li>
                    <!-- /.timeline-label -->
                    <!-- timeline item -->
                    <?php
                    foreach ($listCppt 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 :
                                        <?php
                                        if ($list['UserCategory'] == '1') {
                                            echo "Dokter / Bidan";
                                        } else if ($list['UserCategory'] == '3') {
                                            echo "Perawat";
                                        } else {
                                            echo "Apoteker";
                                        }
                                        ?>

                                    </small></h3>
                                    <div class="timeline-body">
                                    <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>
                                        <?= $list['Description']; ?>
                                    </p>
                                </div>
                                <table class="table table-bordered table-striped dataTable">
                                <tr>
                                    <td>Subject</td>
                                    <td>Object</td>
                                    <td>Assesment</td>
                                    <td>Penilaian</td>
                                </tr>
                                <tr>
                                    <td><?= $list['Subjek']; ?></td>
                                    <td><?= $list['Objek']; ?></td>
                                    <td><?= $list['Asesment']; ?></td>
                                    <td><?= $list['Penilaian']; ?></td>
                                </tr>
                                </table>
                            </div>
                        </li>
                    <?php
                    endforeach;
                    ?>
                </ul>
                <?php
                $id      = $this->uri->segment(3);
                $patient = $this->uri->segment(4);
                ?>
                <form action="<?= base_url('Sks/cppt/' . $id . '/' . $patient); ?>" method="post">
                    <table class="table table-striped">
                        <tr>
                            <td>Resume Medis</td>
                            <td><textarea required class="form-control" name="resume"></textarea></td>
                        </tr>
                        <tr>
                        <tr>
                            <td>Pilih Keterangan</td>
                            <td>
                                <select required name="keterangan" id="" class="form-control">
                                    <option value="">Pilih Keterangan</option>
                                    <option value="1" selected>Belum Selesai</option>
                                    <option value="0">Selesai</option>
                                </select>
                            </td>
                        </tr>
                        <td>
                            <?php
                            if (@$headerCppt['Note'] == 1) {
                            ?>
                                <button type="submit" class="btn btn-success">Save</button>
                            <?php
                            } else {
                            ?>
                                <button type="button" disabled class="btn btn-success">Save</button>
                            <?php
                            }
                            ?>
                        </td>
                        </tr>
                    </table>
                </form>
            </div>

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

<!-- Modal Cari Diagnosa -->
<div class="modal fade" id="ModalCariDiagnosa1" 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">Daftar Diagnosa Sekunder</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="col-ms-4">
                    <input type="text" class="form-control" id="textCariDiagnosa1" placeholder="Ketik Nama Diagnosa"><br>
                </div>
                <div class="col-ms-2">
                    <button type="button" class="btn btn-primary" id="btnFilter1">Filter</button>
                </div>
                <table class="table table-hover mt-3">
                    <thead>
                        <tr>
                            <th scope="col" width="50%">Kode Diagnosa</th>
                            <th scope="col" width="40%">Nama Diagnosa</th>
                            <th scope="col" width="10%">Action</th>
                        </tr>
                    </thead>
                    <tbody id="ListDiagnosa1">

                    </tbody>
                </table>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
        </div>
    </div>
</div>
<!-- End of Modal Cari Diagnosa -->

<!-- Modal Detail Cppt -->
<?php foreach ($cppt as $d) : ?>
    <div class="modal fade" id="ModalCppt<?= $d['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 CPPT - Tgl :<?= date('d-m-Y', strtotime($d['TglResume'])) . '- Waktu' . date('H:i', strtotime($d['WaktuResume'])) ?></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="box box-solid box-danger">
                        <div class="box-header with-border">
                            <span><small>Detail Cppt</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">
                            <?php foreach ($cppt as $d) : ?>
                                <div style="padding: 5px;"><?= $d['ResumMedis']; ?></div>
                            <?php endforeach; ?>
                        </div>
                        <!-- /.box-body -->
                    </div>
                </div>
                <?php
                $id      = $this->uri->segment(3);
                $patient = $this->uri->segment(4);
                ?>
                <form action="<?= base_url('Sks/cppt/' . $id . '/' . $patient); ?>" method="post">
                    <table class="table table-striped">
                        <tr>
                            <td>Resume Medis</td>
                            <td><textarea class="form-control" name="resume"></textarea></td>
                        </tr>
                        <tr>
                        <tr>
                            <td>Pilih Keterangan</td>
                            <td>
                                <select name="keterangan" id="" class="form-control">
                                    <option value="">Pilih Keterangan</option>
                                    <option value="Belum">Belum Selesai</option>
                                    <option value="Selesai">Selesai</option>
                                </select>
                            </td>
                        </tr>
                        <td>
                            <button type="submit" class="btn btn-success">Save</button>
                        </td>
                        </tr>
                    </table>
                </form>
                <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 Cppt  -->



<link rel="stylesheet" href="<?= base_url('assets/snakbar/'); ?>snackbar.min.css">
<script src="<?= base_url('assets/snakbar/'); ?>snackbar.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>



    document.getElementById("tindakLanjut").value = "<?= strip_tags((!empty($hasilpemeriksaan['tindak_lanjut'])) ? $hasilpemeriksaan['tindak_lanjut'] : ''); ?>";

    var poli = "<?= strip_tags((!empty($hasilpemeriksaan['poli'])) ? $hasilpemeriksaan['poli'] : ''); ?>";
    document.getElementById("poli").value = poli;
    if (poli == 'POLI GIGI') {
        document.getElementById("panelOdontogram").style.display = "block";
    }

    var tglKontrol = "<?= strip_tags((!empty($hasilpemeriksaan['tanggal_kontrol'])) ? $hasilpemeriksaan['tanggal_kontrol'] : ''); ?>";
    if (tglKontrol != '' && tglKontrol != '1900-01-01') {
        document.getElementById("panelTanggalKontrol").style.display = "block";
    }

    var tglMeninggal = "<?= strip_tags((!empty($hasilpemeriksaan['tanggal_meninggal'])) ? $hasilpemeriksaan['tanggal_meninggal'] : ''); ?>";
    if (tglMeninggal != '' && tglMeninggal != '1900-01-01') {
        document.getElementById("panelTanggalMeninggal").style.display = "block";
    }

    var poliTujuan = "<?= strip_tags((!empty($hasilpemeriksaan['poli_tujuan'])) ? $hasilpemeriksaan['poli_tujuan'] : ''); ?>";
    var rujukExternal = "<?= strip_tags((!empty($hasilpemeriksaan['instansi_tujuan'])) ? $hasilpemeriksaan['instansi_tujuan'] : ''); ?>";
    if (poliTujuan != '' || rujukExternal != '') {
        document.getElementById("panelRujukEksternal").style.display = "block";
    }

    function setTindakLanjut() {
        var tindakLanjut = document.getElementById("tindakLanjut").value;

        if (tindakLanjut == '' || tindakLanjut == 'Pulang') {
            document.getElementById("panelTanggalKontrol").style.display = "none";
            document.getElementById("tanggalKontrol").required = false;

            document.getElementById("panelRujukEksternal").style.display = "none";
            document.getElementById("poliTujuan").required = false;
            document.getElementById("instansiTujuan").required = false;

            document.getElementById("panelTanggalMeninggal").style.display = "none";
            document.getElementById("tanggalMeninggal").required = false;
        }

        if (tindakLanjut == 'Kontrol') {
            document.getElementById("panelTanggalKontrol").style.display = "block";
            document.getElementById("tanggalKontrol").required = true;

            document.getElementById("panelRujukEksternal").style.display = "none";
            document.getElementById("poliTujuan").required = false;
            document.getElementById("instansiTujuan").required = false;

            document.getElementById("panelTanggalMeninggal").style.display = "none";
            document.getElementById("tanggalMeninggal").required = false;
        }

        if (tindakLanjut == 'Rujuk Eksternal') {
            document.getElementById("panelRujukEksternal").style.display = "block";
            document.getElementById("poliTujuan").required = true;
            document.getElementById("instansiTujuan").required = true;

            document.getElementById("panelTanggalKontrol").style.display = "none";
            document.getElementById("tanggalKontrol").required = false;

            document.getElementById("panelTanggalMeninggal").style.display = "none";
            document.getElementById("tanggalMeninggal").required = false;
        }

        if (tindakLanjut == 'Meninggal') {
            document.getElementById("panelTanggalMeninggal").style.display = "block";
            document.getElementById("tanggalMeninggal").required = true;

            document.getElementById("panelRujukEksternal").style.display = "none";
            document.getElementById("poliTujuan").required = false;
            document.getElementById("instansiTujuan").required = false;

            document.getElementById("panelTanggalKontrol").style.display = "none";
            document.getElementById("tanggalKontrol").required = false;
        }

    }



    $(document).ready(function() {

        var i = 1;

        $("#add_row").click(function() {

            $('#tab_logic').append('<tr style="margin-top:20px;" id="addr' + i + '"></tr>');

            $('#addr' + i).html("<td width='50px; font-size:15px;font-weight:bold;'>" + i + "</td><td><br><textarea class='form-control' placeholder='Title Tindakan Medis' name='titleTindakanMedis[]' id='titleTindakanMedis" + i + "' rows='1' cols='80'></textarea><br><textarea class='form-control' placeholder='Keterangan Tindakan Medis' name='tindakanMedis[]' id='tindakanMedis" + i + "' rows='1' cols='80'></textarea><br><input required type='file' onClick='chooseImage(" + i + ");' onChange='showMyImage(this)' class='form-control' name='image[]' id='image" + i + "' accept='image/*'><br><hr></td>");


            i++;
        });

    });


    function chooseImage(id) {
        localStorage.setItem("chooseImage", id);
    }



    function showMyImage(fileInput) {
        var files = fileInput.files;
        console.log(files);
        var id = localStorage.getItem("chooseImage");
        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            var imageType = /image.*/;
            if (!file.type.match(imageType)) {
                continue;
            }
            var img = document.getElementById("myImg" + id);
            img.file = file;
            var reader = new FileReader();
            reader.onload = (function(aImg) {
                return function(e) {
                    aImg.src = e.target.result;
                };
            })(img);
            reader.readAsDataURL(file);
        }
    }

    function showAlert(msg, success = false) {
        if (success) {
            Snackbar.show({
                text: msg,
                pos: 'top-center',
                actionTextColor: 'green'
            });
        } else {
            Snackbar.show({
                text: msg,
                pos: 'top-center'
            });
        }

    }

    loadOdontogram();

    function simpanOdontogram() {
        var odontogram = document.getElementById("odontogram").value;
        var diagnosa = document.getElementById("diagnosa").value;
        var prosedur = document.getElementById("prosedur").value;
        var caseId = document.getElementById("CaseID").value;
        if (odontogram == "") {
            showAlert('Silahkan Pilih elementGigi');
            return;
        }

        $.ajax({
            url: '<?php echo base_url() ?>rekamMedis/prosesSaveOdontogram',
            method: "POST",
            data: {
                elemenGigi: odontogram,
                diagnosa: diagnosa,
                prosedur: prosedur,
                caseId: caseId
            },
            dataType: 'json',
            success: function(data) {
                var success = data.success;
                if (success == 1) {
                    showAlert('Data berhasil ditambahkan');
                    loadOdontogram();
                } else {
                    showAlert('Data gagal ditambahkan');
                }
            }
        });
    }


    function loadOdontogram() {
        // $('#example1').DataTable().fnDestroy();
        var caseId = document.getElementById("CaseID").value;
        var PatientCode = document.getElementById("PatientCode").value;
        if (caseId == "") {
            showAlert('Invalid Case Id');
            return;
        }
        $.ajax({
            url: '<?php echo base_url() ?>rekamMedis/loadOdontogram',
            method: "POST",
            data: {
                caseId: caseId,
                PatientCode: PatientCode
            },
            dataType: 'json',
            success: function(data) {
                var success = data.success;
                if (success == 1) {
                    var html = '';
                    var i;
                    for (i = 0; i < data.data.length; i++) {

                        html += '<tr>' +
                            '<td class=' + 'text-center' + '>' + data.data[i].elemenGigi + '</td>' +
                            '<td class=' + 'text-center' + '>' + data.data[i].diagnosa + '</td>' +
                            '<td class=' + 'text-center' + '>' + data.data[i].prosedur + '</td>' +
                            '<td class=' + 'text-center' + '>' + '<a onclick=' + 'hapusOdontogram(' + data.data[i].ermPemeriksaanGigiId + ')' + ' href=' + '#' + '>hapus</a>' + '</td>' +
                            '</tr>';
                    }
                    $('#tbodyOdontogram').html(html);

                }
            }
        });
    }


    function hapusOdontogram(id) {
        if (id === "") {
            showAlert('invalid request');
            return;
        }

        $.ajax({
            url: '<?php echo base_url() ?>rekamMedis/hapusOdontogram',
            method: "POST",
            data: {
                id: id
            },
            dataType: 'json',
            success: function(data) {
                var success = data.success;
                if (success == 1) {
                    showAlert('Data berhasil dihapus');
                    loadOdontogram();
                } else {
                    showAlert('Data gagal dihapus');
                }
            }
        });
    }

    checkPoli();
    checkKeterangan();

    function checkPoli() {
        var poli = document.getElementById("poli").value;
        if (poli == 'POLI GIGI') {
            document.getElementById("panelOdontogram").style.display = "block";
        } else {
            document.getElementById("panelOdontogram").style.display = "none";
        }

        if (poli == 'POLI KEBIDANAN') {
            document.getElementById("PanelUsiaKehamilan").style.display = "block";
        } else {
            document.getElementById("PanelUsiaKehamilan").style.display = "none";
        }

        if (poli == 'POLI KEBIDANAN') {
            document.getElementById("PanelJenisImunisasi").style.display = "block";
        } else {
            document.getElementById("PanelJenisImunisasi").style.display = "none";
        }

        if (poli == 'POLI KEBIDANAN') {
            document.getElementById("PanelJenisKB").style.display = "block";
        } else {
            document.getElementById("PanelJenisKB").style.display = "none";
        }

        if (poli == 'POLI KEBIDANAN') {
            document.getElementById("PanelDiagnosabidan").style.display = "block";
        } else {
            document.getElementById("PanelDiagnosabidan").style.display = "none";
        }

    }

    document.getElementById("tglRequestHeader").value = '<?php echo $tglrequest; ?>';
    function checkTglRequestHeader(){
        var tglRequestHeader = document.getElementById("tglRequestHeader").value;

        if(tglRequestHeader != ''){
            var url  = removeParam("tglRequest",window.location.href) + '?tglRequest='+tglRequestHeader;
            window.location.href = url;
        }
    }

    function removeParam(key, sourceURL) {
        var rtn = sourceURL.split("?")[0],
            param,
            params_arr = [],
            queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
        if (queryString !== "") {
            params_arr = queryString.split("&");
            for (var i = params_arr.length - 1; i >= 0; i -= 1) {
                param = params_arr[i].split("=")[0];
                if (param === key) {
                    params_arr.splice(i, 1);
                }
            }
            if (params_arr.length) rtn = rtn + "?" + params_arr.join("&");
        }
        return rtn;
    }

    function checkKeterangan() {
        var keterangan = document.getElementById("keterangan").value;

        if (keterangan == 'Sakit') {
            document.getElementById("formsks").style.display = "block";
            document.getElementById("formsehat").style.display = "none";
        } else if (keterangan == 'Sehat') {
            document.getElementById("formsks").style.display = "none";
            document.getElementById("formsehat").style.display = "block";
        } else {
            document.getElementById("formsks").style.display = "none";
            document.getElementById("formsehat").style.display = "none";
        }

    }
</script>

<script>
    $(document).ready(function() {
        var i = 1;
        $("#add_lab").click(function() {
            $('#tab_lab').append('<tr  id="addl' + i + '"></tr>');
            $('#addl' + i).html(
                "<td width='150px'  align='center'><div> <input required type='text' style='400px;' name='PackedID[]' id=\"lab" + i + "\"  autocomplete='off' class='form-control' onkeydown=\"searchLab(" + i + ")\"  placeholder='Search Lab' /> <div id=\"labList" + i + "\" > </div> </div></td> " +
                "<td width='10px'  align=center'><div style='display:none;' id=\"searchLab" + i + "\" class='spinner-border text-primary spinner-border-sm' role='status'>  <span class='sr-only'></span></div></td>" +
                "<td width='10px' align='center' ><button  type='button' id='btnDelete' style='font-size:12px;'  class='btn btn-danger btnDelete'>x</button></td>");
            i++;
        });
    });

    $(document).ready(function() {
        $("#tab_lab").on('click', '#btnDelete', function() {
            $(this)
                .closest('tr')
                .remove();
            i--;
        });
    });

    function showLab(boxLab) {
        var chboxs = document.getElementsByName("labs");
        var vis = "none";
        for (var i = 0; i < chboxs.length; i++) {
            if (chboxs[i].checked) {
                vis = "block";
                break;
            }
        }
        document.getElementById(boxLab).style.display = vis;
    }

    function showLab(box3) {
        var chboxs = document.getElementsByName("cekLab");
        var vis = "none";
        for (var i = 0; i < chboxs.length; i++) {
            if (chboxs[i].checked) {
                vis = "block";
                break;
            }
        }
        document.getElementById(box3).style.display = vis;
    }

    function searchLab(e) {
        var query = document
            .getElementById('lab' + e)
            .value;
        if (query.length < 2) {
            return true;
        }

        document.getElementById("searchLab" + e).style.display = "block";

        if (query != '') {
            $.ajax({
                url: '<?php echo base_url() ?>RekamMedis/searchLab',
                method: "POST",
                data: {
                    keyword: query,
                    id: e
                },
                dataType: 'json',
                success: function(data) {
                    var success = data.status;

                    if (success == '00') {

                        $('#labList' + e).fadeIn();
                        $('#labList' + e).html(data.data);

                    }
                    document.getElementById("searchLab" + e).style.display = "none";
                }
            });
        }
    }

    function setLabCode(text, id) {
        if (text == 'empty') {
            $('#lab' + id).val('');
            $('#labList' + id).fadeOut();
            return;
        }checkJumlah
        $('#lab' + id).val(text);
        $('#labList' + id).fadeOut();
    }
</script>

<script>
    $(document).ready(function() {
        var i = 1;
        $("#add_obat").click(function() {
            $('#tab_obat').append('<tr  id="addri' + i + '"></tr>');
            $('#addri' + i).html(
                "<td width='80px' style='display:none'  align='center'><div><input type='text' name='IdResep' Value='#ID' required class='form-control' Disabled>" +
                "<td width='700px'  align='center'><div> <label id=\"satuanDisplay" + i + "\" style='font-size:12px;'></label> <label id=\"stokDisplay" + i + "\" style='font-size:12px;'></label>  <input required type='text'  name='obatDisplay[]' id=\"obatDisplay" + i + "\"  autocomplete='off' class='form-control' onkeydown=\"searchObat(" + i + ")\"  placeholder='Search Obat' /> <div id=\"obatList" + i + "\" > </div> </div></td> " +
                "<td width='700px' style='display:none;'  align='center'><div> <label style='font-size:12px;'></label> <label style='font-size:12px;'></label>  <input required type='text' style='400px;' name='obat[]' id=\"obat" + i + "\"  autocomplete='off' class='form-control'   /> </div></td> " +
                "<td width='30px'  align='center'><div><label style='font-size:12px;'></label> <label style='font-size:12px;'></label> <input type='number' name='qty[]' id=\"qty" + i + "\" onKeyUp=\"checkJumlah(this)\"  required class='form-control' placeholder='Qty'>" +
                "<td width='80px' style='display:none;'  align='center'><div><label style='font-size:12px;'></label> <label style='font-size:12px;'></label> <input type='text' name='satuan[]' id=\"satuan" + i + "\" required class='form-control' placeholder='Satuan'>" +
                "<td width='50px'  align='center'><div><label style='font-size:12px;'></label> <label style='font-size:12px;'></label> <input type='text' placeholder='exp: 3 x 1' name='aturan_pakai[]' required class='form-control' placeholder='AturanPakai'>" +
                "<td width='150px'  align='center'><div><label style='font-size:12px;'></label> <label style='font-size:12px;'></label> <select name='cara_pakai[]' required class='form-control'><option></option><option value='Sebelum Makan'>Sebelum Makan</option><option value='Setelah Makan'>Setelah Makan</option><option value='Saat Makan'>Saat Makan</option><option value='Dioles'>Dioles</option><option value='DiMasukan Melalui Anus'>Di Masukan Melalui Anus</option><option value='Jika Perlu'>Jika Perlu</option><option value='Antibiotik Habiskan'>Antibiotik Habiskan</option><option value='Tetes Kanan'>Tetes Kanan</option><option value='Tetes Kiri'>Tetes Kiri</option><option value='Tetes Kanan Tetes Kiri'>Tetes Kanan - Tetes Kiri</option></select>" +
                "<td width='100px'  align='center'><div><label style='font-size:12px;'></label> <label style='font-size:12px;'></label> <input type='text' name='keterangan[]' id=\"keterangan" + i + "\" required class='form-control'  placeholder='Keterangan'>" +
                "<td width='150px' style='display:none;'  align='center'><div><label style='font-size:12px;'></label> <label style='font-size:12px;'></label> <input type='text' name='stok' id=\"stok" + i + "\" required class='form-control in' placeholder='stok'>" +
                "<td width='10px'  align=center'><label style='font-size:12px;'></label> <label style='font-size:12px;'></label> <div style='display:none;' id=\"searchObat" + i + "\" class='spinner-border text-primary spinner-border-sm' role='status'>  <span class='sr-only'></span></div></td>" +
                "<td width='100px' align='center' ><label style='font-size:12px;'><br><button  type='button' id='btnDelete' style='font-size:12px;'  class='btn btn-danger btnDelete'>x</button></td>");
            i++;
        });
    });

    function checkJumlah(selectedObject){
        //alert("tes");
        var jumlahId = selectedObject.id;
        var jumlahValue = selectedObject.value;
        var stockId = jumlahId.replace("qty", "stok") 

        var stockValue = document.getElementById(stockId).value;
        if(stockValue == ''){
            document.getElementById(jumlahId).value = "";
            return;
        }
        if(parseInt(jumlahValue) > parseInt(stockValue)){
            document.getElementById(jumlahId).value = "";
            alert("melebihi Stok Obat");
            return;
        }
    }

    $(document).ready(function() {
        $("#tab_obat").on('click', '#btnDelete', function() {
            $(this)
                .closest('tr')
                .remove();
            i--;
        });
    });


    function checkObatNonRacikan(){
        var qtys = document.getElementsByName("qty[]");
        if(qtys == null || qtys == undefined){
            alert("Silahkan Masukan Obat");
            return false;
        }

        if(qtys.length < 1){
            alert("Silahkan Masukan Obat");
            return false;
        }

        for (var i = 0, len = qtys.length; i < len; i++) {
            if(qtys[i].value == "" || qtys[i].value == "0" || qtys[i].value < 0 ){
                alert("Stok Obat ada yang Habis.. Silahkan check kembali..");
                return false;
            }
        }   
        document.getElementById("btnSimpanNonRacikan").disabled = true;
        document.getElementById("formSubmitObatNonRacikan").submit();
        return true;
    }


    function searchObat(e) {
        document
            .getElementById('satuan' + e)
            .value = '';
        var query = document
            .getElementById('obatDisplay' + e)
            .value;
        if (query.length < 2) {
            return true;
        }

        document.getElementById("searchObat" + e).style.display = "block";

        if (query != '') {
            $.ajax({
                url: '<?php echo base_url() ?>RekamMedis/searchObat',
                method: "POST",
                data: {
                    keyword: query,
                    id: e
                },
                dataType: 'json',
                success: function(data) {
                    var success = data.status;

                    if (success == '00') {

                        $('#obatList' + e).fadeIn();
                        $('#obatList' + e).html(data.data);

                    }
                    document.getElementById("searchObat" + e).style.display = "none";
                }
            });
        }
    }

    function setObatCode(text, id) {
        if (text == 'empty') {
            $('#obatDisplay' + id).val('');
            $('#obat' + id).val('');
            $('#obatList' + id).fadeOut();
            return;
        }
        let obat = text;
        const obatArray = obat.split(" # ");
        let code = obatArray[0];
        let descObat = obatArray[1];
        let satuan = obatArray[2];
        let stok = obatArray[3];
        $('#obat' + id).val(obat);
        $('#obatDisplay' + id).val(descObat);
        $('#satuan' + id).val(satuan);
        $('#code' + id).val(code);
        $('#stok' + id).val(stok);
        $('#obatList' + id).fadeOut();

        document.getElementById('stokDisplay'+id).innerHTML = 'Stok : '+stok;
        document.getElementById('satuanDisplay'+id).innerHTML = 'Satuan : '+satuan;

        Swal.fire(
            'Stok Saat Ini',
            stok,
            'info'
        );
        document.getElementById("qty" + id).disabled = false;
        document.getElementById("satuan" + id).disabled = false;
        document.getElementById("stok" + id).disabled = false;

        if (stok < 1) {
            Swal.fire(
                'MAAF STOK OBAT KOSONG SILAHKAN HUB BAG FARMASI TERKAIT..!',
                stok,
                'error'
            );
            $('#obat' + id).val('');
            $('#obatDisplay' + id).val('');
            $('#satuan' + id).val('');
            $('#stok' + id).val('');
            $('#obatList' + id).fadeOut();
            document.getElementById("qty" + id).disabled = true;
            document.getElementById("stok" + id).disabled = true;
            document.getElementById("satuan" + id).disabled = true;
            return;
        }



    }


</script>