<section class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1>
                </h1>
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="<?php echo base_url();?>">Dashboard</a></li>
                    <li class="breadcrumb-item"><?php echo $parent;?></li>
                    <li class="breadcrumb-item active"><?php echo $title;?></li>
                </ol>
            </div>
        </div>
    </div>
</section>
<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="card card-default">
                    <div class="card-header">
                        <h3 class="card-title"><?php 
                        echo $title;
                        $tglawal = $awal;
                        $tglakhir= $akhir;
                        $tglgabung = date("m/d/Y", strtotime($awal))." - ".date("m/d/Y", strtotime($akhir));
                        ?></h3>
                    </div>
                    <form action="<?php echo(base_url()); ?>index.php/lp_simrs_report/disposedokigd" method="post" autocomplete="off">
                        <div class="card-body">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">Tanggal :</label>
                                <div class="col-sm-4">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text">
                                                <i class="far fa-calendar-alt"></i>
                                            </span>
                                        </div>
                                        <input type="text" name="tanggal" class="form-control float-right" id="reservation" value="<?php echo $tglgabung;?>">
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    <button type="submit" class="btn btn-outline-info">Search </button>
                                </div>
                            </div>
                        </div>
                    </form>
                    <div class="card-body">
                        <?php if($this->session->flashdata('message')){?>
                        <div id="alert" class="alert alert-success alert-dismissable">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <i class="icon fa fa-check"></i> Alert!
                            <?php echo $this->session->flashdata('message');?>
                        </div>
                        <?php }?>
                        <script> 
                            setTimeout(function() {
                                $('#alert').hide('fast');
                            }, 3000);
                        </script>
                        <table id="example1" class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Idxdaftar</th>
                                    <th>No MR</th>
                                    <th>Tgl Registrasi</th>
                                    <th>DPJP Awal</th>
                                    <th>UGD Triage</th>
                                    <th>Kajian Awal Medis</th>
                                    <th>Disposisi</th>
                                    <th>Tujuan Disposisi</th>
                                    <th>Penerima Disposisi</th>
                                    <th>Pelimpahan DPJP</th>
                                    <th>Resume Medis</th>
                                    <th>DPJP Terakhir</th>
                                    <th>Status Keluar</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $no=0;
                                    foreach ($datanya as $dat) { 
                                        $pelimpahandpjp = "";
                                        $dpjpterakhir = $dat->dokterawal;

                                        $rea1    = str_replace('{', '', $dat->tglpelimpah);
                                        $reb1    = str_replace('}', '', $rea1);
                                        $ex1     = explode(",",$reb1);

                                        $rea2    = str_replace('{', '', $dat->klinikpelimpah);
                                        $reb2    = str_replace('}', '', $rea2);
                                        $rec2    = str_replace('"', '', $reb2);
                                        $ex2     = explode(",",$rec2);

                                        $rea3    = str_replace('{', '', $dat->dpjppelimpah);
                                        $reb3    = str_replace('}', '', $rea3);
                                        $ex3     = explode('","',$reb3);

                                        $rea4    = str_replace('{', '', $dat->smfpelimpah);
                                        $reb4    = str_replace('}', '', $rea4);
                                        $ex4     = explode(",",$reb4);

                                        $rea5    = str_replace('{', '', $dat->dpjppengganti);
                                        $reb5    = str_replace('}', '', $rea5);
                                        $ex5     = explode('","',$reb5);

                                        $rea6    = str_replace('{', '', $dat->smfpengganti);
                                        $reb6    = str_replace('}', '', $rea6);
                                        $ex6     = explode(",",$reb6);

                                        $count  = count($ex1);
                                        for ($x = 0; $x <= $count; $x++) {
                                            if(isset($ex1[$x])){
                                                if($ex1[$x]!=""){
                                                    $rec4    = str_replace('"', '', $ex4[$x]);
                                                    $rec3    = str_replace('"', '', $ex3[$x]);
                                                    $rec5    = str_replace('"', '', $ex5[$x]);
                                                    $rec6    = str_replace('"', '', $ex6[$x]);
                                                    $pelimpahandpjp = $pelimpahandpjp.$ex1[$x]." - $ex2[$x] - DPJP Pelimpah : $rec3 ($rec4) || DPJP Pengganti : $rec5 ($rec6)</br>";
                                                    $dpjpterakhir = "$rec5 ($rec6)";
                                                }else{
                                                    $pelimpahandpjp = "-";
                                                }
                                            }
                                        }

                                        $diagnosaterapi = "";

                                        $real1    = str_replace('{', '', $dat->diagnosaterapidate);
                                        $rebl1    = str_replace('}', '', $real1);
                                        $recl1    = str_replace('"', '', $rebl1);
                                        $exl1     = explode(",",$recl1);

                                        $real2    = str_replace('{', '', $dat->diagnosaterapidokter);
                                        $rebl2    = str_replace('}', '', $real2);
                                        $exl2     = explode('","',$rebl2);

                                        $real3    = str_replace('{', '', $dat->diagnosaterapismf);
                                        $rebl3    = str_replace('}', '', $real3);
                                        $recl3    = str_replace('"', '', $rebl3);
                                        $exl3     = explode(",",$recl3);

                                        $count2  = count($exl1);
                                        for ($x = 0; $x <= $count2; $x++) {
                                            if(isset($exl1[$x])){
                                                if($exl1[$x]!=""){
                                                    $recl2    = str_replace('"', '', $exl2[$x]);
                                                    $diagnosaterapi = $diagnosaterapi.$exl1[$x]." - $recl2($exl3[$x])</br>";
                                                }else{
                                                    $diagnosaterapi = "-";
                                                }
                                            }
                                        }

                                        $ugdtriage = "";    
                                    
                                        $reat1    = str_replace('{', '', $dat->tgltriage);
                                        $rebt1    = str_replace('}', '', $reat1);
                                        $ext1     = explode(",",$rebt1);

                                        $reat2    = str_replace('{', '', $dat->jamtriage);
                                        $rebt2    = str_replace('}', '', $reat2);
                                        $ext2     = explode(",",$rebt2);

                                        $reat3    = str_replace('{', '', $dat->triagedokter);
                                        $rebt3    = str_replace('}', '', $reat3);
                                        $ext3     = explode('","',$rebt3);

                                        $reat4    = str_replace('{', '', $dat->triagesmf);
                                        $rebt4    = str_replace('}', '', $reat4);
                                        $rect4    = str_replace('"', '', $rebt4);
                                        $ext4     = explode(",",$rect4);

                                        $count3  = count($ext1);
                                        for ($x = 0; $x <= $count3; $x++) {
                                            if(isset($ext1[$x])){
                                                if($ext1[$x]!=""){
                                                    $rect3    = str_replace('"', '', $ext3[$x]);
                                                    $ugdtriage = $ugdtriage.$ext1[$x]." $ext2[$x] - $rect3 ($ext4[$x])</br>";
                                                }else{
                                                    $ugdtriage = "-";
                                                }
                                                
                                            }
                                        }

                                        $resumemedis = "";

                                        $rear1    = str_replace('{', '', $dat->resumedate);
                                        $rebr1    = str_replace('}', '', $rear1);
                                        $exr1     = explode(",",$rebr1);

                                        $rear2    = str_replace('{', '', $dat->resumedokter);
                                        $rebr2    = str_replace('}', '', $rear2);
                                        $exr2     = explode(",",$rebr2);

                                        $rear3    = str_replace('{', '', $dat->resumesmf);
                                        $rebr3    = str_replace('}', '', $rear3);
                                        $exr3     = explode(",",$rebr3);

                                        $count4  = count($exr1);
                                        for ($x = 0; $x <= $count4; $x++) {
                                            if(isset($exr1[$x])){
                                                if($exr1[$x]!=""){
                                                    $recr1    = str_replace('"', '', $exr1[$x]);
                                                    $recr2    = str_replace('"', '', $exr2[$x]);
                                                    $resumemedis = $resumemedis.$recr1." - $recr2 ($exr3[$x])</br>";
                                                }else{
                                                    $resumemedis = "-";
                                                }   
                                            }
                                        }

                                        $no++;
                                        echo("
                                            <tr>
                                                <td>".$no."</td>
                                                <td>".$dat->idxdaftar."</td>
                                                <td>".$dat->nomr."</td>
                                                <td>".$dat->tglreg."</td>
                                                <td>".$dat->dokterawal."</td>
                                                <td>".$ugdtriage."</td>
                                                <td>".$diagnosaterapi."</td>
                                                <td>".$dat->disposisismf." - ".$dat->disposisi."</td>
                                                <td>".$dat->tujuansmf."</td>
                                                <td>".$dat->terimadisposisismf." - ".$dat->terimadisposisi."</td>
                                                <td>".$pelimpahandpjp."</td>
                                                <td>".$resumemedis."</td>
                                                <td>".$dpjpterakhir."</td>
                                                <td>".$dat->statuskeluar."</td>
                                            </tr>
                                        ");
                                    }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>