<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_ppi/pasien_ppi" 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="tanggalmonitoring" 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>Data Pasien</th>
                                    <th>Ruang Ranap</th>
                                    <th>MRS</th>
                                    <th>KRS</th>
                                    <th>PLELP</th>
                                    <th>PLEKJ</th>
                                    <th>VAPLP</th>
                                    <th>VAPKJ</th>
                                    <th>HAPLP</th>
                                    <th>HAPKJ</th>
                                    <th>IADALP</th>
                                    <th>IADAKJ</th>
                                    <th>IADDLP</th>
                                    <th>IADDKJ</th>
                                    <th>ISKALP</th>
                                    <th>ISKAKJ</th>
                                    <th>ISKDLP</th>
                                    <th>ISKDKJ</th>
                                    <th>IDOBLP</th>
                                    <th>IDOBKJ</th>
                                    <th>IDOTLP</th>
                                    <th>IDOTKJ</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $no=0; $datpasien = array();
                                    foreach($plb as $dat){
                                        $plenama        = $dat->No_rekam_medis." - ".$dat->Nama_pasien." / ".$dat->Umur." Th / ".$dat->Jenis_kelamin;
                                        $ruangpasang    = $dat->Kode." - ".$dat->Nama." - Kelas ".$dat->Kelas;
                                        $datpasien[] = array("nama" => $plenama,"ruang" => $ruangpasang,"mrs" => $dat->Tanggal_mrs,"krs" => $dat->Tanggal_krs,"idmrs" => $dat->FK_datamrs_datamedisplebitis_ID);
                                    }

                                    foreach($vap as $dat){
                                        $plenama        = $dat->No_rekam_medis." - ".$dat->Nama_pasien." / ".$dat->Umur." Th / ".$dat->Jenis_kelamin;
                                        $ruangpasang    = $dat->Kode." - ".$dat->Nama." - Kelas ".$dat->Kelas;
                                        $datpasien[] = array("nama" => $plenama,"ruang" => $ruangpasang,"mrs" => $dat->Tanggal_mrs,"krs" => $dat->Tanggal_krs,"idmrs" => $dat->FK_datamrs_datamedissvap_ID);
                                    }

                                    foreach($hap as $dat){
                                        $plenama        = $dat->No_rekam_medis." - ".$dat->Nama_pasien." / ".$dat->Umur." Th / ".$dat->Jenis_kelamin;
                                        $ruangpasang    = $dat->Kode." - ".$dat->Nama." - Kelas ".$dat->Kelas;
                                        $datpasien[] = array("nama" => $plenama,"ruang" => $ruangpasang,"mrs" => $dat->Tanggal_mrs,"krs" => $dat->Tanggal_krs,"idmrs" => $dat->FK_datamrs_datamedishap_ID);
                                    }

                                    foreach($iadanak as $dat){
                                        $plenama        = $dat->No_rekam_medis." - ".$dat->Nama_pasien." / ".$dat->Umur." Th / ".$dat->Jenis_kelamin;
                                        $ruangpasang    = $dat->Kode." - ".$dat->Nama." - Kelas ".$dat->Kelas;
                                        $datpasien[] = array("nama" => $plenama,"ruang" => $ruangpasang,"mrs" => $dat->Tanggal_mrs,"krs" => $dat->Tanggal_krs,"idmrs" => $dat->FK_datamrs_datamedissiadanak_ID);
                                    }

                                    foreach($iaddewasa as $dat){
                                        $plenama        = $dat->No_rekam_medis." - ".$dat->Nama_pasien." / ".$dat->Umur." Th / ".$dat->Jenis_kelamin;
                                        $ruangpasang    = $dat->Kode." - ".$dat->Nama." - Kelas ".$dat->Kelas;
                                        $datpasien[] = array("nama" => $plenama,"ruang" => $ruangpasang,"mrs" => $dat->Tanggal_mrs,"krs" => $dat->Tanggal_krs,"idmrs" => $dat->FK_datamrs_datamedissiaddewasa_ID);
                                    }

                                    foreach($iskanak as $dat){
                                        $plenama        = $dat->No_rekam_medis." - ".$dat->Nama_pasien." / ".$dat->Umur." Th / ".$dat->Jenis_kelamin;
                                        $ruangpasang    = $dat->Kode." - ".$dat->Nama." - Kelas ".$dat->Kelas;
                                        $datpasien[] = array("nama" => $plenama,"ruang" => $ruangpasang,"mrs" => $dat->Tanggal_mrs,"krs" => $dat->Tanggal_krs,"idmrs" => $dat->FK_datamrs_datamedissiskanak_ID);
                                    }

                                    foreach($iskdewasa as $dat){
                                        $plenama        = $dat->No_rekam_medis." - ".$dat->Nama_pasien." / ".$dat->Umur." Th / ".$dat->Jenis_kelamin;
                                        $ruangpasang    = $dat->Kode." - ".$dat->Nama." - Kelas ".$dat->Kelas;
                                        $datpasien[] = array("nama" => $plenama,"ruang" => $ruangpasang,"mrs" => $dat->Tanggal_mrs,"krs" => $dat->Tanggal_krs,"idmrs" => $dat->FK_datamrs_datamedissiskdewasa_ID);
                                    }

                                    foreach($idobersih as $dat){
                                        $plenama        = $dat->No_rekam_medis." - ".$dat->Nama_pasien." / ".$dat->Umur." Th / ".$dat->Jenis_kelamin;
                                        $ruangpasang    = $dat->Kode." - ".$dat->Nama." - Kelas ".$dat->Kelas;
                                        $datpasien[] = array("nama" => $plenama,"ruang" => $ruangpasang,"mrs" => $dat->Tanggal_mrs,"krs" => $dat->Tanggal_krs,"idmrs" => $dat->FK_datamrs_datamedissiob_ID);
                                    }

                                    foreach($idoterkontaminasi as $dat){
                                        $plenama        = $dat->No_rekam_medis." - ".$dat->Nama_pasien." / ".$dat->Umur." Th / ".$dat->Jenis_kelamin;
                                        $ruangpasang    = $dat->Kode." - ".$dat->Nama." - Kelas ".$dat->Kelas;
                                        $datpasien[] = array("nama" => $plenama,"ruang" => $ruangpasang,"mrs" => $dat->Tanggal_mrs,"krs" => $dat->Tanggal_krs,"idmrs" => $dat->FK_datamrs_datamedissiobt_ID);
                                    }


                                    $unique_pasien = array_unique($datpasien, SORT_REGULAR);
                                    foreach($unique_pasien as $item){ $no++;
                                    //================================================================Search Data Plebitis hitung monitoring Ke & Kejadian
                                    $tgl = 1; $plelp = 0; $plekj=0;
                                    foreach($mplb as $dat){
                                        if($dat->FK_datamrs_datamedisplebitis_ID==$item['idmrs']){
                                            $plekj = $plekj + $dat->Diagnosa_nilai_plebitis_ppi;
                                            if($tgl == 1){
                                                $tgl = $dat->Tanggal_pemasangan_infus;
                                                $plelp = $plelp + $dat->Lama_pemakaian_infus;
                                            }else if($tgl !=$dat->Tanggal_pemasangan_infus){
                                                $tgl = $dat->Tanggal_pemasangan_infus;
                                                $plelp = $plelp + $dat->Lama_pemakaian_infus;
                                            }
                                        }
                                        
                                    }
                                    if($plelp==0){$plelp="-";}if($plekj==0){$plekj="-";}
                                    //================================================================Search Data Vap hitung monitoring Ke & Kejadian
                                    $tgl = 1; $vaplp = 0; $vapkj=0;
                                    foreach($mvap as $dat){
                                        if($dat->FK_datamrs_datamedissvap_ID==$item['idmrs']){
                                            if($dat->Diagnosa_ppi_dpjp!="TIDAK"){$vapkj = $vapkj + 1;}
                                            if($tgl == 1){
                                                $tgl = $dat->Tanggal_pemasangan_ventilator;
                                                $vaplp = $vaplp + $dat->Lama_pemakaian_ventilator;
                                            }else if($tgl !=$dat->Tanggal_pemasangan_ventilator){
                                                $tgl = $dat->Tanggal_pemasangan_ventilator;
                                                $vaplp = $vaplp + $dat->Lama_pemakaian_ventilator;
                                            }
                                        }
                                    }
                                    if($vaplp==0){$vaplp="-";}if($vapkj==0){$vapkj="-";}
                                    //================================================================Search Data Hap hitung monitoring Ke & Kejadian
                                    $tgl = 1; $haplp = 0; $hapkj=0;
                                    foreach($mhap as $dat){
                                        if($dat->FK_datamrs_datamedishap_ID==$item['idmrs']){
                                            if($dat->Diagnosa_ppi_dpjp!="TIDAK"){$hapkj = $hapkj + 1;}
                                            if($tgl == 1){
                                                $tgl = $dat->Tanggal_mulai_tirah_baring;
                                                $haplp = $haplp + $dat->Lama_tirah_baring;
                                            }else if($tgl !=$dat->Tanggal_mulai_tirah_baring){
                                                $tgl = $dat->Tanggal_mulai_tirah_baring;
                                                $haplp = $haplp + $dat->Lama_tirah_baring;
                                            }
                                        }
                                    }
                                    if($haplp==0){$haplp="-";}if($hapkj==0){$hapkj="-";}
                                    //================================================================Search Data IAD Anak hitung monitoring Ke & Kejadian
                                    $tgl = 1; $iadanaklp = 0; $iadanakkj=0;
                                    foreach($iadanak as $dat){
                                        if($dat->FK_datamrs_datamedissiadanak_ID==$item['idmrs']){
                                            if($dat->Diagnosa_ppi_dpjp!="TIDAK"){$iadanakkj = $iadanakkj + 1;}
                                            if($tgl == 1){
                                                $tgl = $dat->Tanggal_pemasangan_cvc;
                                                $iadanaklp = $iadanaklp + $dat->Lama_pemakaian_cvc;
                                            }else if($tgl !=$dat->Tanggal_pemasangan_cvc){
                                                $tgl = $dat->Tanggal_pemasangan_cvc;
                                                $iadanaklp = $iadanaklp + $dat->Lama_pemakaian_cvc;
                                            }
                                        }
                                    }
                                    if($iadanaklp==0){$iadanaklp="-";}if($iadanakkj==0){$iadanakkj="-";}
                                    //================================================================Search Data IAD Dewasa hitung monitoring Ke & Kejadian
                                    $tgl = 1; $iaddewasalp = 0; $iaddewasakj=0;
                                    foreach($iaddewasa as $dat){
                                        if($dat->FK_datamrs_datamedissiaddewasa_ID==$item['idmrs']){
                                            if($dat->Diagnosa_ppi_dpjp!="TIDAK"){$iaddewasakj = $iaddewasakj + 1;}
                                            if($tgl == 1){
                                                $tgl = $dat->Tanggal_pemasangan_cvc;
                                                $iaddewasalp = $iaddewasalp + $dat->Lama_pemakaian_cvc;
                                            }else if($tgl !=$dat->Tanggal_pemasangan_cvc){
                                                $tgl = $dat->Tanggal_pemasangan_cvc;
                                                $iaddewasalp = $iaddewasalp + $dat->Lama_pemakaian_cvc;
                                            }
                                        }
                                    }
                                    if($iaddewasalp==0){$iaddewasalp="-";}if($iaddewasakj==0){$iaddewasakj="-";}
                                    //================================================================Search Data ISK Anak hitung monitoring Ke & Kejadian
                                    $tgl = 1; $iskanaklp = 0; $iskanakkj=0;
                                    foreach($iskanak as $dat){
                                        if($dat->FK_datamrs_datamedissiskanak_ID==$item['idmrs']){
                                            if($dat->Diagnosa_ppi_dpjp!="TIDAK"){$iskanakkj = $iskanakkj + 1;}
                                            if($tgl == 1){
                                                $tgl = $dat->Tanggal_pemasangan_catheter_urine;
                                                $iskanaklp = $iskanaklp + $dat->Lama_pemakaian_catheter_urine;
                                            }else if($tgl !=$dat->Tanggal_pemasangan_catheter_urine){
                                                $tgl = $dat->Tanggal_pemasangan_catheter_urine;
                                                $iskanaklp = $iskanaklp + $dat->Lama_pemakaian_catheter_urine;
                                            }
                                        }
                                    }
                                    if($iskanaklp==0){$iskanaklp="-";}if($iskanakkj==0){$iskanakkj="-";}
                                    //================================================================Search Data ISK Dewasa hitung monitoring Ke & Kejadian
                                    $tgl = 1; $iskdewasalp = 0; $iskdewasakj=0;
                                    foreach($iskdewasa as $dat){
                                        if($dat->FK_datamrs_datamedissiskdewasa_ID==$item['idmrs']){
                                            if($dat->Diagnosa_ppi_dpjp!="TIDAK"){$iskdewasakj = $iskdewasakj + 1;}
                                            if($tgl == 1){
                                                $tgl = $dat->Tanggal_pemasangan_catheter_urine;
                                                $iskdewasalp = $iskdewasalp + $dat->Lama_pemakaian_catheter_urine;
                                            }else if($tgl !=$dat->Tanggal_pemasangan_catheter_urine){
                                                $tgl = $dat->Tanggal_pemasangan_catheter_urine;
                                                $iskdewasalp = $iskdewasalp + $dat->Lama_pemakaian_catheter_urine;
                                            }
                                        }
                                    }
                                    if($iskdewasalp==0){$iskdewasalp="-";}if($iskdewasakj==0){$iskdewasakj="-";}
                                    //================================================================Search Data IDO Bersih hitung monitoring Ke & Kejadian
                                    $tgl = 1; $idolp = 0; $idokj=0;
                                    foreach($mido as $dat){
                                        if($dat->FK_datamrs_datamedissiob_ID==$item['idmrs']){
                                            if($dat->Diagnosa_ppi_dpjp!="TIDAK"){$idokj = $idokj + 1;}
                                            if($tgl == 1){
                                                $tgl = $dat->Tanggal_operasi;
                                                $idolp = $idolp + $dat->Lama_hari_perawatan;
                                            }else if($tgl !=$dat->Tanggal_operasi){
                                                $tgl = $dat->Tanggal_operasi;
                                                $idolp = $idolp + $dat->Lama_hari_perawatan;
                                            }
                                        }
                                    }
                                    if($idolp==0){$idolp="-";}if($idokj==0){$idokj="-";}
                                    //================================================================Search Data IDO Terkontaminasi hitung monitoring Ke & Kejadian
                                    $tgl = 1; $idotlp = 0; $idotkj=0;
                                    foreach($midot as $dat){
                                        if($dat->FK_datamrs_datamedissiobt_ID==$item['idmrs']){
                                            if($dat->Diagnosa_ppi_dpjp!="TIDAK"){$idotkj = $idotkj + 1;}
                                            if($tgl == 1){
                                                $tgl = $dat->Tanggal_operasi;
                                                $idotlp = $idotlp + $dat->Lama_hari_perawatan;
                                            }else if($tgl !=$dat->Tanggal_operasi){
                                                $tgl = $dat->Tanggal_operasi;
                                                $idotlp = $idotlp + $dat->Lama_hari_perawatan;
                                            }
                                        }
                                    }
                                    if($idotlp==0){$idotlp="-";}if($idotkj==0){$idotkj="-";}
                                            echo("
                                            <tr>
                                                <td>".$no."</td>
                                                <td>".$item['nama']."</td>
                                                <td>".$item['ruang']."</td>
                                                <td>".$item['mrs']."</td>
                                                <td>".$item['krs']."</td>
                                                <td>".$plelp."</td>
                                                <td>".$plekj."</td>
                                                <td>".$vaplp."</td>
                                                <td>".$vapkj."</td>
                                                <td>".$haplp."</td>
                                                <td>".$hapkj."</td>
                                                <td>".$iadanaklp."</td>
                                                <td>".$iadanakkj."</td>
                                                <td>".$iaddewasalp."</td>
                                                <td>".$iaddewasakj."</td>
                                                <td>".$iskanaklp."</td>
                                                <td>".$iskanakkj."</td>
                                                <td>".$iskdewasalp."</td>
                                                <td>".$iskdewasakj."</td>
                                                <td>".$idolp."</td>
                                                <td>".$idokj."</td>
                                                <td>".$idotlp."</td>
                                                <td>".$idotkj."</td>
                                            </tr>
                                        ");

                                     }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
