<style type="text/css">
.buttons-html5, .buttons-print{background: orange; color:#fff; border:0px; float: left; margin-right: 5px; margin-top: 7px}
.DTFC_LeftBodyWrapper{margin-top: -7px;}
table.dataTable{margin-top: 0px !important}
</style>

<div class="row" id="portlet-content">
    <div class="col-md-12">
        <div class="portlet light" style="position:relative">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-list"></i> Detail Pasien <?=$judul?>
                </div> 

                
                <div class="actions">
                    <form action="<?=site_url()?>/front_office/ugd_dir/ugd/fillter" method="get">
                        <input type="hidden" name="dari" value="<?=$dari?>">
                        <input type="hidden" name="id_sub_spesialis" value="<?=@$id_sub_spesialis?$id_sub_spesialis:'null'?>">
                        <?php if($tgl_awal != null)$tgl_awal = date('m/d/yy',strtotime($tgl_awal));?>
                        <?php if($tgl_akhir != null) $tgl_akhir = date('m/d/yy',strtotime($tgl_akhir));?>
                        <input style="border-radius:3px" required class="datess" type="text" name="tgl_awal" value="<?=$tgl_awal?>" placeholder="tgl awal" autocomplete="off">
                        <input style="border-radius:3px" required class="datess" type="text" name="tgl_akhir" value="<?=$tgl_akhir?>" placeholder="tgl akhir" autocomplete="off">
                        <input type="submit" value="submit" name="submit">
                    </form>
                </div> 
               

               
                
            </div>           
            <?php 
            $a=$query->num_rows();
            if($a != 0){ ?>
            <div id="dataTables_processing">
                Loading Data..
            </div>
            <?php }?>
            <div class="portlet-body" id="page-content" style="<?=$a!=0?'display: none':''?>">
                <div class="table-responsive" style="border:0px;">
                    <?php 
                    if($a == 0){ ?>
                    <div class="" class="form-group" style="margin-bottom:40px; margin-top: 0px; margin-left:0px; padding-bottom: 30px; border-radius:4px; background: linear-gradient(to left, #d14415,#d16b49, #fad2d2 ,transparent,transparent,transparent,transparent)">
                      <div class="col-sm-12 col-md-12" style="text-align: right; color: #fff"><h2><strong>Tidak ada data</strong></h2></div><br><br>
                    </div>
                    <?php }else{ ?>
                    <table id="example" class="table table-bordered table-striped table-hover datatable" >
                      <thead>

                        <tr style="background: #5578eb; color:#fff;">
                          <th style="min-width: 50px"><i class="fa fa-th-large"></i></th>
                          <th class="text-center" style="min-width:30px; width: 30px !important" style="margin-left: 200px;"><div style="width:30px !important">NO.</div></th>
                          <th class="text-left" style="min-width: 140px">TGL KUNJUNGAN.</th>
                          <th class="text-left" style="min-width: 80px">NO RM.</th>
                          <th class="text-left" style="min-width: 200px">NAMA PASIEN</th>
                          <th class="text-left" style="min-width: 110px">TIPE PASIEN</th>
                          <th class="text-left" style="min-width: 400px">ALAMAT</th>
                          <?php if($active == 'pemeriksaan_lab'){ ?>
                          <th class="text-left" style="min-width: 100px">PETUGAS</th>
                          <th class="text-left" style="min-width: 100px">KETERANGAN</th>
                          <th class="text-left" style="min-width: 200px">PRINT</th>
                          <?php }?>
                        </tr>
                      </thead>

                      <tbody>
                       
                        <?php $i=1; 
                       
                        foreach($query->result() as $key) { 

                        $green = false;
                        if($active == 'pemeriksaan_lab'){
                        
                        }else{
                            if($key->id_dokter_jaga!='0'){$green=true;}else{$green=false;}
                        }
                        ?>

                          <tr style="font-size:12px; <?=$green?'background: #d1ebd4;':''?> <?=($key->active=='0')?'text-decoration: line-through; opacity:0.4;':''?>">
                            <td class="" style="background: #fcf4dc;" align="left">
                                <div style="width: 80px">
                                <?php if( $this->session->userdata('id_jabatan') != '7' ){ ?>
                                    <?php if($active == 'pemeriksaan_lab' || $active == 'radiologi'){ ?>
                                    <a class="tooltips btn-xs btn-info" data-toggle="m-tooltip" data-container="body" title="Periksa" href="<?= site_url('front_office/ugd_dir/ugd/tmbh_pemeriksaan/'.$key->id_re_pasien.'/'.$key->id_re_kunjungan.'/'.$active)?>" ><i class='fa fa-stethoscope'></i></a>  
                                    <?php }else{ ?>
                                    <a class="tooltips btn-xs btn-info" data-toggle="m-tooltip" data-container="body" title="Periksa" href="<?= site_url('front_office/ugd_dir/ugd/perawat_dokter_pemeriksa/'.$key->id_re_pasien.'/'.$key->id_re_kunjungan.'/'.$active)?>" ><i class='fa fa-stethoscope'></i></a>  
                                    <?php }?>
                                <?php }?>
                                
                                <?php if($active == 'pemeriksaan_lab'){ ?>
                                <a class="tooltips btn-xs btn-info" target="_Blank" data-toggle="m-tooltip" data-container="body" title="BHP" href="<?= site_url('front_office/ugd_dir/ugd/laboratorium_penggunaan_tambah/'.$key->id_re_kunjungan)?>">add bhp</a>
                                <?php }else{ ?>
                                <a class="tooltips btn-xs btn-danger" data-toggle="m-tooltip" data-container="body" title="Batal Periksa" onclick="return confirm('Batalkan Pemeriksaan?')"  href="<?= site_url('front_office/ugd_dir/ugd/batal_pemeriksaan/'.$key->id_re_kunjungan)?>"><i class='fa fa-times'></i></a>
                                <?php }?>
                                </div>
                            </td>
                            <td align="center"> <?=$i;?> </td>
                            <td align="left"><?=$key->tgl_kunjungan?></td>
                            <td align="left">BBMC-<?=$key->nrm?></td>
                            <td align="left"><?=strtoupper($key->nama_pasien)?></td>
                            
                            <td align="left">
                                <?=strtoupper($this->Content_m->get_value('bbmc_re_tipe_pasien','id_tipe_pasien',$key->id_type_pasien,'tipe_pasien'))?>    
                            </td>
                            <td align="left"><?=strtoupper($key->alamat)?></td>
                            <?php if($active == 'pemeriksaan_lab'){ ?>
                            <td>
                               <?=strtoupper($this->Content_m->get_value('bbmc_re_staff','id_re_staff',$key->admin_lab,'nama_staff'))?>
                            </td>
                            <td>
                                <?php if($key->done_bhp_lab == '1'){ ?>
                                <a class="tooltips btn-xs btn-success" data-toggle="m-tooltip" onclick="return confirm('Batal?')" data-container="body" title="done" href="<?= site_url('front_office/ugd_dir/ugd/undone/'.$key->id_re_kunjungan)?>">done</a>
                                <?php }else{ ?>
                                <a class="tooltips btn-xs btn-warning" data-toggle="m-tooltip" onclick="return confirm('BHP sudah terinput?')" data-container="body" title="done" href="<?= site_url('front_office/ugd_dir/ugd/done/'.$key->id_re_kunjungan)?>"><i class="fa fa-check"></i></a>
                                <?php }?>
                            </td>
                            <td>
                                <?php 
                                $this->db->where('id_re_kunjungan',$key->id_re_kunjungan);
                                $qa = $this->Content_m->select_db('bbmc_tr_laboratorium');
                                foreach ($qa->result() as $keyb ) { ?>

                                    <?php 
                                    $cek = $this->Content_m->get_value('bbmc_re_laboratorium_kecuali','tindakan_lab',$keyb->tindakan_lab,'tindakan_lab');
                                    if($cek == ''){ ?>

                                    <?php 
                                    $this->db->where('id_re_laboratorium',$keyb->id_re_laboratorium);
                                    $cek = $this->Content_m->get_values('bbmc_tr_laboratorium_hasil','tindakan_lab',$keyb->tindakan_lab,'tindakan_lab');
                                    if($cek != ''){ ?>

                                    <?php if($active == 'pemeriksaan_lab'){ 
                                    $this->db->where('deleted','0');
                                    $template = $this->Content_m->get_value('bbmc_re_laboratorium_template','tindakan_lab',$keyb->tindakan_lab,'template_set');
                                    //echo $this->db->last_query();
                                    }?>

                                    <a target="_Blank" href="<?=site_url()?>/front_office/ugd_dir/ugd/hasil_pemeriksaan_lab/<?=$key->id_re_pasien?>/<?=$keyb->id_re_laboratorium?>/<?=$key->id_re_kunjungan?>/<?=$keyb->tindakan_lab?>/<?=@$template?>"><i class="fa fa-print"></i> <?=$this->Content_m->get_value('siak_re_account_chart','id',$keyb->tindakan_lab,'name')?></a><br>
                                    <?php }else{ 
                                        echo "Belum menginput hasil<br>";
                                    } ?>

                                    <?php }?>

                                <?php }?>



                            </td>
                            <?php }?>

                          </tr>
                        <?php $i++; } ?>
                      </tbody>     
                    </table>
                    <?php }?>



                </div>
            </div>
         
           
        </div>
    </div>
</div>


<script>
$(document).ready(function() {
    var buttonCommon = {
        exportOptions: {
            format: {
                body: function ( data, row, column, node ) {
                    return (column === 5) ? data.replace( /\n/g, '"&CHAR(10)&CHAR(13)&"' ) : data.replace(/(&nbsp;|<([^>]+)>)/ig, "\n");;
                }
            }
        },
        customize: function( xlsx ) {
          var sheet = xlsx.xl.worksheets['sheet1.xml'];
          $('row c', sheet).attr( 's', '55' );
       }
    };
 
    $('#example').DataTable( {
        scrollY:        "300px",
        scrollX:        true,
        scrollCollapse: true,
        dom: 'lBfrtip',
        buttons: [
            $.extend( true, {}, buttonCommon, {
                extend: 'excelHtml5',
                text: 'Print Table Data',
                title:''
            } )
        ],
        lengthMenu: [ [10, 50, 200, -1], [10, 50, 200, 'All Data'] ],
        fixedColumns: {
            leftColumns: 1
        },
        fnInitComplete: function(oSettings, json) {
          $('#dataTables_processing').css('display','none');
          $('#page-content').css('display','block');
          $('#fillter-content').css('display','block');
        }

    } );
} );

$('.tooltips').tooltip({ container: 'body' }) 
$(".datess" ).datepicker({
    autoclose: true,
    dateFormat: 'yyyy-mm-dd'
});
</script>

