<?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-12">
                <!-- 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 e.diagnosa_primer LIKE '%B20%' and 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 }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_6" data-toggle="tab">Laboratory</a></li>
                                    </li>
                                </ul>
                                <div class="tab-content">
                                    <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 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 <?= @$aktif1; ?>" 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/ProsesLaboratori/'.$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;">
                                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                        <button id="add_lab" class="btn btn-primary btn-sm" type="button">
                                                            <i class="glyphicon glyphicon-plus"></i>
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>
                                            </div>
                                            <br> <br>
                                                    <button type="submit" style="margin-top: 10px;" class="btn btn-sm btn-success">Simpan Laboratory</button> 
                                        </form>
                                                <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 -->
                                     <!-- Resep Obat Klinik --->
                                   
                                </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 -->




<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).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;
        }
        $('#lab' + id).val(text);
        $('#labList' + id).fadeOut();
    }
    
</script>

