<?php
defined('BASEPATH') OR exit('No direct script access allowed');

function split_obat($value)
{    
  $output = '<table style="width: 100%">';

  $split_0 = explode('#', $value);

  if(!empty($split_0))
  {
    foreach ($split_0 as $key) 
    {
      $split_1 = explode(';', $key);
      $output .= '<tr><td>'.$split_1[1].'</td><td>'.$split_1[0].'</td><td>'.$split_1[2].'</td></tr>';
    } 
  }

  $output .= '</table>';

  return $output;
}

function split_procedure($value)
{    
  $output = '<table style="width: 100%">';

  $split_0 = explode('#', $value);

  if(!empty($split_0))
  {
    foreach ($split_0 as $key) 
    {
      $output .= '<tr><td>'.$key.'</td></tr>';
    } 
  }

  $output .= '</table>';

  return $output;
}

?>

<div class="modal-content">
  <div class="modal-header">
    <h4 class="modal-title" id="modal-title"></h4>
    <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="card card-primary card-outline card-outline-tabs" id="riwayat_kunjungan">
      <div class="card-header p-0 border-bottom-0">
        <ul class="nav nav-tabs" id="custom-tabs-four-tab" role="tablist">
          <li class="nav-item">
            <a class="nav-link active" id="riwayat_rme-tab" data-toggle="pill" href="#riwayat_rme" role="tab" aria-controls="riwayat_rme" aria-selected="true">RME</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" id="riwayat_bpjs-tab" data-toggle="pill" href="#riwayat_bpjs" role="tab" aria-controls="riwayat_bpjs" aria-selected="true" onclick="riwayat_kunjungan_bpjs($('input[name=bpjs_noKartu]').val())">BPJS</a>
          </li>
        </ul>
      </div>
      <div class="card-body">      
        <input type="hidden" name="service_aktif">
        <div class="tab-content" id="custom-tabs-tabContent">
          <div class="tab-pane fade show active" id="riwayat_rme" role="tabpanel" aria-labelledby="riwayat_rme-tab">
            <div class="table-responsive">
              <?php if(!empty($data)){ ?>
                <table id="example1" class="table table-sm table-bordered">
                  <thead>
                    <tr>
                      <th style="width: 50px; text-align: center;">No</th>
                      <th style="text-align: center;">Detail Kunjungan</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php 
                    $urut = 0; foreach ($data as $key){ $urut++; ?>
                      <tr>
                        <td><?php echo $urut ?></td>
                        <td>
                          <div class="row">
                            <div class="col-12 col-sm-12 col-md-12 col-lg-3"> 
                              <table style="width: 100%" class="table table-striped">
                                <tr>
                                  <td>Tanggal Pemeriksaan</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->tgl_pemeriksaan ?></td>
                                </tr>
                                <tr>
                                  <td>Nomor Rawat</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->no_rawat ?></td>
                                </tr>
                                <tr><th colspan="4">PEMERIKSAAN FISIK</th></tr>
                                <tr>
                                  <td>Tensi</td>
                                  <td align="center"> : </td>
                                  <td><?php echo $key->bpjs_sistole.'/'.$key->bpjs_diastole ?></td>                    
                                  <td>mmHg</td>
                                </tr>
                                <tr>
                                  <td>Tinggi Badan</td>
                                  <td align="center"> : </td>
                                  <td><?php echo $key->bpjs_tinggiBadan ?></td>                      
                                  <td>cm</td>
                                </tr>
                                <tr>
                                  <td>Berat Badan</td>
                                  <td align="center"> : </td>
                                  <td><?php echo $key->bpjs_beratBadan ?></td>                      
                                  <td>kg</td>
                                </tr>
                                <tr>
                                  <td>Respirasi rate</td>
                                  <td align="center"> : </td>
                                  <td><?php echo $key->bpjs_respRate ?> </td>                      
                                  <td>/ minute</td>
                                </tr>
                                <tr>
                                  <td>Lingkar Perut</td>
                                  <td align="center"> : </td>
                                  <td><?php echo $key->bpjs_lingkarPerut ?></td>                      
                                  <td>cm</td>
                                </tr>
                                <tr>
                                  <td>Heart Rate</td>
                                  <td align="center"> : </td>
                                  <td><?php echo $key->bpjs_heartRate ?></td>                      
                                  <td>bpm</td>
                                </tr>
                                <tr>
                                  <td>Suhu</td>
                                  <td align="center"> : </td>
                                  <td><?php echo $key->bpjs_suhu ?></td>                      
                                  <td><sup>o</sup>C</td>
                                </tr>
                              </table>
                            </div>

                            <div class="col-12 col-sm-12 col-md-12 col-lg-6"> 
                              <table style="width: 100%" class="table table-striped">
                                <tr><th colspan="4">PEMERIKSAAN DOKTER</th></tr>
                                <tr>
                                  <td>Diagnosa 1</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_nmDiag1 ?></td>
                                </tr>
                                <tr>
                                  <td>Diagnosa 2</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_nmDiag2 ?></td>
                                </tr>
                                <tr>
                                  <td>Diagnosa 3</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_nmDiag3 ?></td>
                                </tr>
                                <tr>
                                  <td>Subject (Keluhan)</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_keluhan ?></td>
                                </tr>
                                <tr>
                                  <td>Object</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->object ?></td>
                                </tr>
                                <tr>
                                  <td>Asesmen</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_anamnesa ?></td>
                                </tr>
                                <tr>
                                  <td>Plan</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->plan ?></td>
                                </tr>
                                <tr>
                                  <td>Intruksi (Terapi Obat)</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_terapiObat ?></td>
                                </tr>
                                <tr>
                                  <td>Terapi Non Obat</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_terapiNonObat ?></td>
                                </tr>
                                <tr>
                                  <td>BMHP</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_bmhp ?></td>
                                </tr>
                                <tr>
                                  <td>Alergi Makanan</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_nm_alergiMakan ?></td>
                                </tr>
                                <tr>
                                  <td>Alergi Udara</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_nm_alergiUdara ?></td>
                                </tr>
                                <tr>
                                  <td>Alergi Obat</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_nm_alergiObat ?></td>
                                </tr>
                                <tr>
                                  <td>Kesadaran</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_nmSadar ?></td>
                                </tr>
                                <tr>
                                  <td>Prognosa</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_nmPrognosa ?></td>
                                </tr>
                                <tr>
                                  <td>Status Pulang</td>
                                  <td align="center"> : </td>
                                  <td colspan="2"><?php echo $key->bpjs_nmStatusPulang ?></td>
                                </tr>
                              </table>
                            </div>
                            <div class="col-12 col-sm-12 col-md-12 col-lg-3"> 
                              <table style="width: 100%" class="table table-striped">
                                <tr><th colspan="4">Diet</th></tr>
                                <tr><td colspan="4"><?php echo $key->diet ?></td></tr>
                                <tr><th colspan="4">Procedure</th></tr>
                                <tr><td colspan="4"><?php echo split_procedure($key->procedure_pemeriksaan) ?></td></tr>
                                <tr><th colspan="4">Pemberian Obat <a class="btn btn-xs btn-warning float-right" onclick="ambil_pemberian_obat('<?php echo $key->id ?>')">Copy resep</a></th></tr>
                                <tr><td colspan="4"><?php if($key->pemberian_obat != ''){ echo split_obat($key->pemberian_obat); } else echo 'Tidak diberikan obat' ?></td></tr>
                              </table>
                            </div>
                          </div>
                        </td>
                      </tr>
                    <?php } ?>
                  </tbody>
                </table>
              <?php } else echo '<center>BELUM ADA PEMERIKSAAN</center>'; ?>
            </div>  
          </div>
          <div class="tab-pane fade show active" id="riwayat_bpjs" role="tabpanel" aria-labelledby="riwayat_bpjs-tab">
            <div id="table_riwayat_kunjungan_bpjs"></div> 
          </div>
        </div>
      </div>
    </div>

  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal" class="close"><i class="fas fa-times"></i> Batal</button>
  </div>
</div>