<div class="row" id="info-content" style="display:block">
    <div class="col-md-12">
        <div class="portlet box green-haze" style="position:relative">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-user"></i> Informasi Pasien
                </div>
            </div>
            <div class="portlet-body form">
                <form class="form-horizontal form-bordered form-row-stripped" role="form">
                    <div class="form-body">
                        <div class="form-group">
                            <div class="col-md-6">
                                <div class="row">
                                    <label class="form-control-static col-md-4">Nomor Rekam Medis </label>
                                    <p class="form-control-static col-md-8">
                                        : &nbsp; BBMC-<?=$this->Content_m->get_value('bbmc_tr_pasien','id_re_pasien',$id_re_pasien,'nrm')?> 
                                    </p>
                                </div>
                                <div class="row">
                                    <label class="form-control-static col-md-4">Nama Pasien </label>
                                    <p class="form-control-static col-md-8">
                                        : &nbsp; <?=strtoupper($this->Content_m->get_value('bbmc_tr_pasien','id_re_pasien',$id_re_pasien,'nama_pasien'))?>  / <?=$this->Content_m->get_tipe_pasien($id_re_pasien)?>
                                    </p>
                                </div>
                                <div class="row">
                                    <label class="form-control-static col-md-4">Umur  </label>
                                    <p class="form-control-static col-md-8">
                                        : &nbsp; <?=strtoupper($this->Content_m->get_value('bbmc_tr_pasien','id_re_pasien',$id_re_pasien,'umur_tahun'))?> TAHUN <?=strtoupper($this->Content_m->get_value('bbmc_tr_pasien','id_re_pasien',$id_re_pasien,'umur_bulan'))?> BULAN
                                    </p>
                                </div>
                                <div class="row">
                                     <div style="padding:0px; <?=$get_kunjungan->id_dokter_jaga!='-1'?'display: block':'display: none'?>">
                                          <label class="form-control-static col-md-4">Dokter </label>
                                          <p class="form-control-static col-md-8">
                                              : &nbsp; 
                                              <?php 
                                              $id_dokter_jaga = $this->Content_m->get_value('bbmc_tr_kunjungan','id_re_kunjungan',$id_re_kunjungan,'id_dokter_jaga');
                                              echo "<b>".$this->Content_m->get_value('bbmc_re_staff_medis','id_staff_medis',$id_dokter_jaga,'staff_medis')."</b>";
                                              ?>  
                                          </p>
                                      </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="row">
                                    <label class="form-control-static col-md-4">Pendidikan  </label>
                                    <p class="form-control-static col-md-8">
                                        <?php $id_pendidikan = $this->Content_m->get_value('bbmc_tr_pasien','id_re_pasien',$id_re_pasien,'id_pendidikan');
                                        $pendidikan = $this->Content_m->get_value('bbmc_re_jenjang_pendidikan','id_jenj_didik',$id_pendidikan,'nm_jenj_didik');
                                        ?>
                                        : &nbsp; <?=strtoupper($pendidikan)?> 
                                    </p>
                                </div>
                                <div class="row">
                                    <label class="form-control-static col-md-4">Pekerjaan  </label>
                                    <p class="form-control-static col-md-8">
                                        <?php $id_pekerjaan = $this->Content_m->get_value('bbmc_tr_pasien','id_re_pasien',$id_re_pasien,'id_pekerjaan');
                                        $pendidikan = $this->Content_m->get_value('bbmc_re_pekerjaan','id_pekerjaan',$id_pekerjaan,'nm_pekerjaan');
                                        ?>
                                        : &nbsp; <?=strtoupper($pendidikan)?> 
                                    </p>
                                </div>
                                <div class="row">
                                    <label class="form-control-static col-md-4">Alamat  </label>
                                    <p class="form-control-static col-md-8">
                                        : &nbsp; <?=strtoupper($this->Content_m->get_value('bbmc_tr_pasien','id_re_pasien',$id_re_pasien,'alamat'))?> 
                                    </p>
                                </div>
                            </div>
                        </div>                                    
                    </div>
                </form>

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

<?php if($get_kunjungan->id_dokter_jaga == '0'){ ?>
<div class="alert alert-danger">
Silahkan isi pemeriksaan utama terlebih dahulu.
</div>
<?php }else{ ?>
<div class="row" id="portlet-content">
    <div class="col-md-12">
        <div class="portlet light" style="position:relative">           
            <div class="portlet-body form" id="page-content" style="display:none">
              <form action="<?= site_url('front_office/'.$controller_dir.$controller.'/update_data_pengobatan') ?>" method="post" id="<?=$controller?>" enctype="multipart/form-data" class="horizontal-form">
                <input type="hidden" name="id_re_kunjungan" value="<?=$id_re_kunjungan?>">
                <input type="hidden" name="status_resep" value="<?=$get_kunjungan->status_resep?>">

                <div class="form-body">
                  <div class="alert alert-danger display-hide" style="display:none;" id="error">
                    <button class="close" data-close="alert"></button>
                    <span id="error-text"></span>
                  </div>

                 

                  <div class="row">
                    <div class="col-md-12">
                      <div class="form-group" id="icd">
                        <h4 class="form-section" style="margin:0px 0px 5px 0px !important; padding-bottom:10px !important; font-size:13px !important"><i class="fa fa-file-text-o"></i><strong> Data Detail Obat </strong><hr style="margin:10px 0px 0px 0px !important">

                         </h4>
                        
                       
                        <div class="table-responsive">
                          <?php 
                          $this->db->where('active','1');
                          $daftar_obat = $this->Content_m->select_db('bbmc_re_apotik_obat');
                          
                          $this->db->where('id_re_kunjungan',$id_re_kunjungan);
                          $q = $this->Content_m->select_db('bbmc_tr_pengobatan'); 
                          //echo $this->db->last_query();
                          ?>
                          <table id="<?= $controller ?>_table" class="table table-bordered table-striped table-hover" style="margin-bottom:0px; width:100%; font-size:11px !important">
                              <thead>
                                <tr>
                                  <th class="text-center col-md-1" style="font-size:10px !important">Kategori</th>
                                  <?php if($q->num_rows() == 0){ ?>
                                  <th colspan="5" class="text-left col-md-4" style="font-size:10px !important">Obat
                                  </th>
                                  <?php }else{ ?>
                                  <th class="text-center col-md-1" style="font-size:10px !important">No</th>
                                  <th class="text-left col-md-2" style="font-size:10px !important">Nama Obat</th>
                                  <th class="text-left col-md-1" style="font-size:10px !important">Sediaan</th>
                                  <th class="text-left col-md-1" style="font-size:10px !important">Jenis Obat</th>
                                  <?php if($get_kunjungan->status_resep != '3'){ ?>
                                  <th class="text-left col-md-1" style="font-size:10px !important">Tersedia</th>
                                  <?php }?>
                                  <?php }?>
                                  <th class="text-left col-md-1" style="font-size:10px !important">Jumlah</th>
                                  <th class="text-left col-md-3" style="font-size:10px !important">Dosis dan cara pemakaian</th>
                                  <th class="text-left col-md-3" style="font-size:10px !important">Keterangan</th>
                                  <?php if($get_kunjungan->status_resep != '3'){ ?>
                                  <th class="text-center col-md-1" style="font-size:10px !important">Aksi</th>
                                  <?php }?>
                                </tr>
                              </thead>
                              <tbody>
                                <?php 
                                $i=1;
                                foreach ($q->result() as $key ) { ?>
                                <tr style="" class="pengobatan<?=$i?>">   
                                  <input type="hidden" name="id_re_pengobatan[]" value="<?=$key->id_re_pengobatan?>">
                                  <input type="hidden" name="kategori_obat_asuransi[]" value="">
                                  
                                  <td align="center"></td>
                                  <td align="center"><?=$i?></td>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                        <input type="hidden" class="form-control " name="id_obat[<?=$i?>][]" value="<?=$keyb->id_obat?>" placeholder="">
                                        <?=$this->Content_m->get_value('bbmc_re_apotik_obat','id_re_apotik_obat',$keyb->id_obat,'nama_obat')."<br>"?>
                                      <?php }?>
                                      
                                  </td>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                        <?=$this->Content_m->get_value('bbmc_re_apotik_obat','id_re_apotik_obat',$keyb->id_obat,'sediaan')."<br>"?>
                                      <?php }?>
                                  </td>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                        <?=$this->Content_m->get_value('bbmc_re_apotik_obat','id_re_apotik_obat',$keyb->id_obat,'jenis_obat')."<br>"?>
                                      <?php }?>
                                  </td>
                                  <?php if($get_kunjungan->status_resep != '3'){ ?>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                       
                                        <span class="stok stok<?=$keyb->id_obat?> minstoka<?=$keyb->id_obat?>" data-id="<?=$keyb->id_obat?>"><?=$this->Content_m->get_value('bbmc_re_apotik_obat','id_re_apotik_obat',$keyb->id_obat,'stok_display');?></span>
                                        <br>
                                      <?php }?>
                                  </td>
                                  <?php }?>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                        <input type="hidden" class="form-control " name="qty[<?=$i?>][]" value="<?=$keyb->qty?>" placeholder="">
                                        <?=$keyb->qty."<br>"?>
                                      <?php }?>
                                  </td>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                        <input type="hidden" class="form-control " name="cara_pemakaian[<?=$i?>][]" value="<?=$keyb->cara_pemakaian?>" placeholder="">
                                        <?=$keyb->cara_pemakaian."<br>"?>
                                      <?php }?>
                                  </td>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                        <input type="hidden" class="form-control " name="keterangan_obat[<?=$i?>][]" value="<?=$keyb->keterangan_obat?>" placeholder="">
                                        <?=$keyb->keterangan_obat."<br>"?>
                                      <?php }?>
                                  </td>
                                  <?php if($get_kunjungan->status_resep != '3'){ ?>
                                  <td align="center"><a data-toggle="tooltip" data-placement="top" title="Hapus Obat" href="<?=site_url()?>/front_office/ugd_dir/ugd/del_pengobatan/<?=$key->id_re_pengobatan?>/<?=$id_re_kunjungan?>" onclick="return confirm('Apakah anda yakin menghapus entry ini?')" data-id="<?=$i?>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></td>
                                  <?php }?>
                                </tr>
                                <?php $i++; $id_pengobatan = $key->id_re_pengobatan; }?>
                                
                                <?php for ($ii=$i; $ii < 15; $ii++) { ?>
                                <tr style="border-top:0px; <?=$ii=='1'?'display: table-row':'display: none'?>" class="pengobatan<?=$ii?>">   
                                  <input type="hidden" name="id_re_pengobatan[]" value="tidakada">
                                  <td align="left">
                                    <select name="kategori_obat_asuransi[<?=$ii?>][]" class="sel2" style="padding: 0px; width: 100%;">
                                          <option value="1" selected>Umum</option>
                                          <option value="2">BPJS</option>
                                    </select>
                                    <a class="btn btn-xs add_puyer" data-id="<?=$ii?>" href="javascript:;" style="margin-top:10px !important; padding:0px">
                                      <i class="fa fa-plus"></i>
                                    </a>  
                                  </td>
                                  <td colspan="5" align="left">
                                    <?php for ($z1=0; $z1 < 15; $z1++) { ?>
                                    <div style="<?=$z1==0?'display: block;':'display: none;'?>" class="sel2<?=$ii?>_<?=$z1?>">
                                      <select name="id_obat[<?=$ii?>][]" class="sel2" style="padding: 0px; width: 100%;">
                                          <option value=""></option>
                                          <?php foreach ($daftar_obat->result() as $key ) { ?>
                                          <option <?=($key->stok_display <= 0)?'disabled':''?> value="<?=$key->id_re_apotik_obat?>"><?=$key->nama_obat?> <?=$key->sediaan?> <?=$key->jenis_obat?> <b>STOK:<?=$key->stok_display?></b></option>
                                          <?php }?>
                                      </select>
                                    </div>
                                    <?php }?>
                                  </td>
                                  <td colspan="1" align="left">
                                    <?php for ($z2=0; $z2 < 15; $z2++) { ?>
                                    <div style="<?=$z2==0?'display: block;':'display: none;'?>" class="qty<?=$ii?>_<?=$z2?>">
                                    <input type="number" class="form-control " name="qty[<?=$ii?>][]" value="" placeholder="Jml..">
                                    </div>
                                    <?php }?>
                                  </td>
                                  <td colspan="1" align="left">
                                    <?php for ($z3=0; $z3 < 15; $z3++) { ?>
                                    <div style="<?=$z3==0?'display: block;':'display: none;'?>" class="ket<?=$ii?>_<?=$z3?>">
                                    <input type="text" class="form-control" name="cara_pemakaian[<?=$ii?>][]" value="" placeholder="Ketik cara pemakaian ..">
                                    </div>
                                    <?php }?>

                                  </td>
                                  <td colspan="1" align="left">
                                    <?php for ($z3=0; $z3 < 15; $z3++) { ?>
                                    <div style="<?=$z3==0?'display: block;':'display: none;'?>" class="ket_obat<?=$ii?>_<?=$z3?>">
                                    <input type="text" class="form-control" name="keterangan_obat[<?=$ii?>][]" value="" placeholder="Ketik keterangan ..">
                                    </div>
                                    <?php }?>

                                  </td>
                                  <td  align="center" style="text-align: center; vertical-align: top; padding-top: 15px"><a data-toggle="tooltip" data-placement="top" title="Hapus Pengobatan" href="javascript:;" class="del_pengobatan" data-id="<?=$ii?>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></td>
                                </tr>
                                <?php }?>
                              </tbody>
                            </table>

                            <?php if($get_kunjungan->status_resep != '3'){ ?>
                            <a class="btn btn-xs blue add_pengobatan" href="javascript:;" style="margin-top:10px !important">
                              <i class="fa fa-plus"></i>
                            </a>  
                            <?php }?>                         
                        </div>
                      </div> 
                    </div>
                  </div>
                  <script type="text/javascript">

                    var a2="<?=$i=='1'?'2':$i?>";
                    $(".add_pengobatan").click(function(){
                        $(".pengobatan"+a2).css('display','table-row');
                        a2++;
                    });

                    $(".del_pengobatan").click(function(){
                        var b2= $(this).attr('data-id');
                        $(".pengobatan"+b2).css('display','none');
                        if(confirm("Hapus entry ini?")){
                          return true;
                        }
                    });

                    var zz='1';
                    $(".add_puyer").click(function(){

                      var dataid = $(this).attr('data-id');
                      $(".sel2"+dataid+"_"+zz).css('display','block');
                      $(".qty"+dataid+"_"+zz).css('display','block');
                      $(".ket"+dataid+"_"+zz).css('display','block');
                     //alert(dataid);
                      zz++;
                    });

                  </script>


                </div>
                <div class="form-actions right">
                  <a type="button" class="btn default" href="<?= site_url('front_office/'.$controller_dir.$controller) ?>">Kembali</a>
                  <?php if($get_kunjungan->status_resep != '3'){ ?>
                  <button type="submit" class="btn blue"><i class="fa fa-check"></i> Simpan</button>
                  <?php }?>
                </div>
              </form>
            </div>
            <?php $this->load->view('front_office/include/loading');?>
        </div>
    </div>
</div>
<?php }?>



<script type="text/javascript">
	$(document).ready(function() {
    //alert(1);
     /*-------------Datepicker-------------*/
    $(".sel2").select2({
      placeholder: "Pilih .. ",
      language: "id"
    });
    $("#loading-content,#loading").fadeOut("fast", function() {
      $("#page-content").fadeIn("fast");
    });
  });
</script>


<?php $this->load->view('front_office/script/form_data'); ?>






