<?php
    // Ambil parameter no_rawat yang dienkripsi
    $norawat = isset($_GET['iyem']) ? encrypt_decrypt(urldecode($_GET['iyem']),"d") : "";
    if($norawat!=""){
        $norawat = json_decode($norawat, true);
        $norawat = $norawat['norawat'];
    }

    // Query untuk mengambil data pasien
    $query_pasien = bukaquery("SELECT reg_periksa.no_rkm_medis, pasien.nm_pasien 
                              FROM reg_periksa 
                              INNER JOIN pasien ON reg_periksa.no_rkm_medis=pasien.no_rkm_medis 
                              WHERE reg_periksa.no_rawat='$norawat'");
    
    if($result_pasien = mysqli_fetch_array($query_pasien)) {
        $no_rkm_medis = $result_pasien['no_rkm_medis'];
        $nama_pasien = $result_pasien['nm_pasien'];
    }
?>
<div class="block-header">
    <h2><center>RESUME MEDIS PASIEN</center></h2>
</div>
<div class="row clearfix">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <table width="100%">
                    <tr>
                        <td width="20%"><b>No. Rekam Medis</b></td>
                        <td width="1%">:</td>
                        <td width="79%"><b><?php echo $no_rkm_medis; ?></b></td>
                    </tr>
                    <tr>
                        <td><b>Nama Pasien</b></td>
                        <td>:</td>
                        <td><b><?php echo $nama_pasien; ?></b></td>
                    </tr>
                </table>
            </div>
            <div class="body">
                <div class="table-responsive">
                    <?php
                    // Debug untuk melihat nilai no_rawat
                    echo "<div class='alert alert-info'>No Rawat: ".$norawat."</div>";
                    
                    $query = bukaquery("select resume_pasien.kd_dokter,dokter.nm_dokter,resume_pasien.kondisi_pulang,
                            resume_pasien.keluhan_utama,resume_pasien.jalannya_penyakit,resume_pasien.pemeriksaan_penunjang,
                            resume_pasien.hasil_laborat,resume_pasien.diagnosa_utama,resume_pasien.kd_diagnosa_utama,
                            resume_pasien.diagnosa_sekunder,resume_pasien.kd_diagnosa_sekunder,resume_pasien.diagnosa_sekunder2,
                            resume_pasien.kd_diagnosa_sekunder2,resume_pasien.diagnosa_sekunder3,resume_pasien.kd_diagnosa_sekunder3,
                            resume_pasien.diagnosa_sekunder4,resume_pasien.kd_diagnosa_sekunder4,resume_pasien.prosedur_utama,
                            resume_pasien.kd_prosedur_utama,resume_pasien.prosedur_sekunder,resume_pasien.kd_prosedur_sekunder,
                            resume_pasien.prosedur_sekunder2,resume_pasien.kd_prosedur_sekunder2,resume_pasien.prosedur_sekunder3,
                            resume_pasien.kd_prosedur_sekunder3,resume_pasien.obat_pulang 
                            from resume_pasien inner join dokter on resume_pasien.kd_dokter=dokter.kd_dokter 
                            where resume_pasien.no_rawat='$norawat'");
                    
                    // Debug untuk melihat hasil query
                    // if(mysqli_num_rows($query) == 0) {
                    //     echo "<div class='alert alert-warning'>Data resume tidak ditemukan untuk No Rawat: ".$norawat."</div>";
                    // }
                    
                    if($result = mysqli_fetch_array($query)) {
                        ?>
                        <div style="margin-top: 20px;">
                            <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleRawatJalan()">
                                <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
                                    RESUME RAWAT JALAN 
                                    <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconRawatJalan">keyboard_arrow_down</i>
                                </h4>
                            </div>
                            <div id="contentRawatJalan">
                                <table class="table table-bordered">
                                    <tr>
                                        <td width="20%" bgcolor="#f8f9fa">Dokter Penanggung Jawab</td>
                                        <td width="30%"><?php echo $result['nm_dokter']; ?></td>
                                        <td width="20%" bgcolor="#f8f9fa">Kondisi Pulang</td>
                                        <td width="30%"><?php echo $result['kondisi_pulang']; ?></td>
                                    </tr>
                                </table>
                                
                                <table class="table table-bordered">
                                    <tr><td colspan="2" bgcolor="#f8f9fa"><b>RIWAYAT PERAWATAN</b></td></tr>
                                    <tr>
                                        <td width="30%" bgcolor="#f8f9fa">Keluhan Utama</td>
                                        <td width="70%"><?php echo nl2br($result['keluhan_utama']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Jalannya Penyakit</td>
                                        <td><?php echo nl2br($result['jalannya_penyakit']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Pemeriksaan Penunjang</td>
                                        <td><?php echo nl2br($result['pemeriksaan_penunjang']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Hasil Laboratorium</td>
                                        <td><?php echo nl2br($result['hasil_laborat']); ?></td>
                                    </tr>
                                </table>

                                <table class="table table-bordered">
                                    <tr><td colspan="3" bgcolor="#f8f9fa"><b>DIAGNOSA & PROSEDUR AKHIR</b></td></tr>
                                    <tr bgcolor="#f8f9fa">
                                        <td width="30%">Diagnosa/Prosedur</td>
                                        <td width="50%">Keterangan</td>
                                        <td width="20%">Kode ICD</td>
                                    </tr>
                                    <tr>
                                        <td>Diagnosa Utama</td>
                                        <td><?php echo $result['diagnosa_utama']; ?></td>
                                        <td><?php echo $result['kd_diagnosa_utama']; ?></td>
                                    </tr>
                                    <tr>
                                        <td>Diagnosa Sekunder 1</td>
                                        <td><?php echo $result['diagnosa_sekunder']; ?></td>
                                        <td><?php echo $result['kd_diagnosa_sekunder']; ?></td>
                                    </tr>
                                    <tr>
                                        <td>Diagnosa Sekunder 2</td>
                                        <td><?php echo $result['diagnosa_sekunder2']; ?></td>
                                        <td><?php echo $result['kd_diagnosa_sekunder2']; ?></td>
                                    </tr>
                                    <tr>
                                        <td>Diagnosa Sekunder 3</td>
                                        <td><?php echo $result['diagnosa_sekunder3']; ?></td>
                                        <td><?php echo $result['kd_diagnosa_sekunder3']; ?></td>
                                    </tr>
                                    <tr>
                                        <td>Diagnosa Sekunder 4</td>
                                        <td><?php echo $result['diagnosa_sekunder4']; ?></td>
                                        <td><?php echo $result['kd_diagnosa_sekunder4']; ?></td>
                                    </tr>
                                    <tr>
                                        <td>Prosedur Utama</td>
                                        <td><?php echo $result['prosedur_utama']; ?></td>
                                        <td><?php echo $result['kd_prosedur_utama']; ?></td>
                                    </tr>
                                    <tr>
                                        <td>Prosedur Sekunder 1</td>
                                        <td><?php echo $result['prosedur_sekunder']; ?></td>
                                        <td><?php echo $result['kd_prosedur_sekunder']; ?></td>
                                    </tr>
                                    <tr>
                                        <td>Prosedur Sekunder 2</td>
                                        <td><?php echo $result['prosedur_sekunder2']; ?></td>
                                        <td><?php echo $result['kd_prosedur_sekunder2']; ?></td>
                                    </tr>
                                    <tr>
                                        <td>Prosedur Sekunder 3</td>
                                        <td><?php echo $result['prosedur_sekunder3']; ?></td>
                                        <td><?php echo $result['kd_prosedur_sekunder3']; ?></td>
                                    </tr>
                                </table>

                                <table class="table table-bordered">
                                    <tr><td bgcolor="#f8f9fa"><b>OBAT-OBATAN WAKTU PULANG</b></td></tr>
                                    <tr><td><?php echo nl2br($result['obat_pulang']); ?></td></tr>
                                </table>
                            </div>
                        </div>
                        <?php
                    }

                    // Query untuk resume rawat inap
                    $query_ranap = bukaquery("select resume_pasien_ranap.kd_dokter,dokter.nm_dokter,
                            resume_pasien_ranap.diagnosa_awal,resume_pasien_ranap.alasan,
                            resume_pasien_ranap.keluhan_utama,resume_pasien_ranap.pemeriksaan_fisik,
                            resume_pasien_ranap.jalannya_penyakit,resume_pasien_ranap.pemeriksaan_penunjang,
                            resume_pasien_ranap.hasil_laborat,resume_pasien_ranap.tindakan_dan_operasi,
                            resume_pasien_ranap.obat_di_rs,resume_pasien_ranap.diagnosa_utama,
                            resume_pasien_ranap.kd_diagnosa_utama,resume_pasien_ranap.diagnosa_sekunder,
                            resume_pasien_ranap.kd_diagnosa_sekunder,resume_pasien_ranap.diagnosa_sekunder2,
                            resume_pasien_ranap.kd_diagnosa_sekunder2,resume_pasien_ranap.diagnosa_sekunder3,
                            resume_pasien_ranap.kd_diagnosa_sekunder3,resume_pasien_ranap.diagnosa_sekunder4,
                            resume_pasien_ranap.kd_diagnosa_sekunder4,resume_pasien_ranap.prosedur_utama,
                            resume_pasien_ranap.kd_prosedur_utama,resume_pasien_ranap.prosedur_sekunder,
                            resume_pasien_ranap.kd_prosedur_sekunder,resume_pasien_ranap.prosedur_sekunder2,
                            resume_pasien_ranap.kd_prosedur_sekunder2,resume_pasien_ranap.prosedur_sekunder3,
                            resume_pasien_ranap.kd_prosedur_sekunder3,resume_pasien_ranap.alergi,
                            resume_pasien_ranap.diet,resume_pasien_ranap.lab_belum,resume_pasien_ranap.edukasi,
                            resume_pasien_ranap.cara_keluar,resume_pasien_ranap.ket_keluar,resume_pasien_ranap.keadaan,
                            resume_pasien_ranap.ket_keadaan,resume_pasien_ranap.dilanjutkan,
                            resume_pasien_ranap.ket_dilanjutkan,resume_pasien_ranap.kontrol,resume_pasien_ranap.obat_pulang 
                            from resume_pasien_ranap inner join dokter on resume_pasien_ranap.kd_dokter=dokter.kd_dokter 
                            where resume_pasien_ranap.no_rawat='$norawat'");

                    if($result_ranap = mysqli_fetch_array($query_ranap)) {
                        ?>
                        <div style="margin-top: 20px;">
                            <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleRawatInap()">
                                <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
                                    RESUME RAWAT INAP
                                    <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconRawatInap">keyboard_arrow_down</i>
                                </h4>
                            </div>
                            <div id="contentRawatInap">
                                <table class="table table-bordered">
                                    <tr>
                                        <td width="20%" bgcolor="#f8f9fa">Dokter DPJP</td>
                                        <td width="30%"><?php echo $result_ranap['nm_dokter']; ?></td>
                                        <td width="20%" bgcolor="#f8f9fa">Cara Keluar</td>
                                        <td width="30%"><?php echo $result_ranap['cara_keluar'].(empty($result_ranap['ket_keluar'])?"":", ".$result_ranap['ket_keluar']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Keadaan Pulang</td>
                                        <td><?php echo $result_ranap['keadaan'].(empty($result_ranap['ket_keadaan'])?"":", ".$result_ranap['ket_keadaan']); ?></td>
                                        <td bgcolor="#f8f9fa">Dilanjutkan</td>
                                        <td><?php echo $result_ranap['dilanjutkan'].(empty($result_ranap['ket_dilanjutkan'])?"":", ".$result_ranap['ket_dilanjutkan']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Tanggal Kontrol</td>
                                        <td colspan="3"><?php echo $result_ranap['kontrol']; ?></td>
                                    </tr>
                                </table>

                                <table class="table table-bordered">
                                    <tr><td colspan="2" bgcolor="#f8f9fa"><b>RIWAYAT PERAWATAN</b></td></tr>
                                    <tr>
                                        <td width="30%" bgcolor="#f8f9fa">Diagnosa Awal</td>
                                        <td width="70%"><?php echo nl2br($result_ranap['diagnosa_awal']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Alasan Masuk Dirawat</td>
                                        <td><?php echo nl2br($result_ranap['alasan']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Keluhan Utama</td>
                                        <td><?php echo nl2br($result_ranap['keluhan_utama']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Pemeriksaan Fisik</td>
                                        <td><?php echo nl2br($result_ranap['pemeriksaan_fisik']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Jalannya Penyakit</td>
                                        <td><?php echo nl2br($result_ranap['jalannya_penyakit']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Pemeriksaan Penunjang</td>
                                        <td><?php echo nl2br($result_ranap['pemeriksaan_penunjang']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Hasil Laborat</td>
                                        <td><?php echo nl2br($result_ranap['hasil_laborat']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Tindakan/Operasi</td>
                                        <td><?php echo nl2br($result_ranap['tindakan_dan_operasi']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Obat di RS</td>
                                        <td><?php echo nl2br($result_ranap['obat_di_rs']); ?></td>
                                    </tr>
                                </table>

                                <table class="table table-bordered">
                                    <tr><td colspan="2" bgcolor="#f8f9fa"><b>KONDISI AKHIR & ANJURAN</b></td></tr>
                                    <tr>
                                        <td width="30%" bgcolor="#f8f9fa">Alergi</td>
                                        <td width="70%"><?php echo nl2br($result_ranap['alergi']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Diet</td>
                                        <td><?php echo nl2br($result_ranap['diet']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Lab Belum Selesai</td>
                                        <td><?php echo nl2br($result_ranap['lab_belum']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Edukasi</td>
                                        <td><?php echo nl2br($result_ranap['edukasi']); ?></td>
                                    </tr>
                                    <tr>
                                        <td bgcolor="#f8f9fa">Obat Pulang</td>
                                        <td><?php echo nl2br($result_ranap['obat_pulang']); ?></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <?php
                    }

                    // Tambahan untuk Asuhan Medis IGD
                    $query_igd = bukaquery("select penilaian_medis_igd.tanggal,penilaian_medis_igd.kd_dokter,penilaian_medis_igd.anamnesis,
                            penilaian_medis_igd.hubungan,penilaian_medis_igd.keluhan_utama,penilaian_medis_igd.rps,
                            penilaian_medis_igd.rpk,penilaian_medis_igd.rpd,penilaian_medis_igd.rpo,penilaian_medis_igd.alergi,
                            penilaian_medis_igd.keadaan,penilaian_medis_igd.gcs,penilaian_medis_igd.kesadaran,
                            penilaian_medis_igd.td,penilaian_medis_igd.nadi,penilaian_medis_igd.rr,penilaian_medis_igd.suhu,
                            penilaian_medis_igd.spo,penilaian_medis_igd.bb,penilaian_medis_igd.tb,penilaian_medis_igd.kepala,
                            penilaian_medis_igd.mata,penilaian_medis_igd.gigi,penilaian_medis_igd.leher,penilaian_medis_igd.thoraks,
                            penilaian_medis_igd.abdomen,penilaian_medis_igd.ekstremitas,penilaian_medis_igd.genital,
                            penilaian_medis_igd.ket_fisik,penilaian_medis_igd.ket_lokalis,penilaian_medis_igd.ekg,
                            penilaian_medis_igd.rad,penilaian_medis_igd.lab,penilaian_medis_igd.diagnosis,
                            penilaian_medis_igd.tata,dokter.nm_dokter 
                            from penilaian_medis_igd inner join dokter on penilaian_medis_igd.kd_dokter=dokter.kd_dokter 
                            where penilaian_medis_igd.no_rawat='$norawat'");

                    if($result_igd = mysqli_fetch_array($query_igd)) {
                        ?>
                        <div style="margin-top: 20px;">
                            <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleIGD()">
                                <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
                                    PENILAIAN AWAL MEDIS IGD
                                    <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconIGD">keyboard_arrow_down</i>
                                </h4>
                            </div>
                            <div id="contentIGD">
                                <table class="table table-bordered">
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr>
                                                    <td width="33%" border="0">Tanggal : <?php echo $result_igd['tanggal']; ?></td>
                                                    <td width="33%" border="0">Dokter : <?php echo $result_igd['kd_dokter']." ".$result_igd['nm_dokter']; ?></td>
                                                    <td width="33%" border="0">Anamnesis : <?php echo $result_igd['anamnesis'].($result_igd['hubungan']==""?"":", ".$result_igd['hubungan']); ?></td>
                                    </tr>
                                </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                    <tr><td colspan="2" bgcolor="#f8f9fa"><b>I. RIWAYAT KESEHATAN</b></td></tr>
                                    <tr>
                                        <td colspan="2">Keluhan Utama : <?php echo nl2br($result_igd['keluhan_utama']); ?></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">Riwayat Penyakit Sekarang : <?php echo nl2br($result_igd['rps']); ?></td>
                                    </tr>
                                    <tr>
                                        <td width="50%">Riwayat Penyakit Dahulu : <?php echo nl2br($result_igd['rpd']); ?></td>
                                        <td width="50%">Riwayat Alergi : <?php echo $result_igd['alergi']; ?></td>
                                    </tr>
                                    <tr>
                                        <td width="50%">Riwayat Penyakit Keluarga : <?php echo nl2br($result_igd['rpk']); ?></td>
                                        <td width="50%">Riwayat Penggunaan Obat : <?php echo nl2br($result_igd['rpo']); ?></td>
                                    </tr>
                                </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                    <tr><td colspan="4" bgcolor="#f8f9fa"><b>II. PEMERIKSAAN FISIK</b></td></tr>
                                    <tr>
                                        <td width="25%">Keadaan Umum : <?php echo $result_igd['keadaan']; ?></td>
                                        <td width="25%">Kesadaran : <?php echo $result_igd['kesadaran']; ?></td>
                                        <td width="25%">GCS(E,V,M) : <?php echo $result_igd['gcs']; ?></td>
                                        <td width="25%">TB : <?php echo $result_igd['tb']; ?> Cm</td>
                                    </tr>
                                    <tr>
                                        <td width="25%">BB : <?php echo $result_igd['bb']; ?> Kg</td>
                                        <td width="25%">TD : <?php echo $result_igd['td']; ?> mmHg</td>
                                        <td width="25%">Nadi : <?php echo $result_igd['nadi']; ?> x/menit</td>
                                        <td width="25%">RR : <?php echo $result_igd['rr']; ?> x/menit</td>
                                    </tr>
                                    <tr>
                                        <td width="25%">Suhu : <?php echo $result_igd['suhu']; ?> °C</td>
                                        <td width="25%">SpO2 : <?php echo $result_igd['spo']; ?> %</td>
                                        <td width="25%">Kepala : <?php echo $result_igd['kepala']; ?></td>
                                        <td width="25%">Mata : <?php echo $result_igd['mata']; ?></td>
                                    </tr>
                                    <tr>
                                        <td width="25%">Gigi & Mulut : <?php echo $result_igd['gigi']; ?></td>
                                        <td width="25%">Leher : <?php echo $result_igd['leher']; ?></td>
                                        <td width="25%">Thoraks : <?php echo $result_igd['thoraks']; ?></td>
                                        <td width="25%">Abdomen : <?php echo $result_igd['abdomen']; ?></td>
                                    </tr>
                                    <tr>
                                        <td width="25%">Genital & Anus : <?php echo $result_igd['genital']; ?></td>
                                        <td width="25%">Ekstremitas : <?php echo $result_igd['ekstremitas']; ?></td>
                                        <td colspan="2">Keterangan Fisik : <?php echo $result_igd['ket_fisik']; ?></td>
                                    </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>III. STATUS LOKALIS</b></td></tr>
                                                <tr>
                                                    <td width="100%" align="center">
                                                        <?php
                                                        // Cek dan tampilkan gambar
                                                        $lokasi_gambar = "webapps/gambar/";
                                                        $nama_gambar = "semua.png";
                                                        $path_gambar = $lokasi_gambar . $nama_gambar;
                                                        
                                                        if (file_exists($path_gambar)) {
                                                            echo '<img src="' . str_replace('pages/', '', $path_gambar) . '" alt="Gambar Lokalis" style="max-width:100%; height:auto;">';
                                                        } else {
                                                            echo '<img src="../webapps/gambar/semua.png" alt="Gambar Lokalis" style="max-width:100%; height:auto;">';
                                                        }
                                                        ?>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Keterangan : <?php echo nl2br($result_igd['ket_lokalis']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td colspan="3" bgcolor="#f8f9fa"><b>IV. PEMERIKSAAN PENUNJANG</b></td></tr>
                                                <tr>
                                                    <td width="33%">EKG : <?php echo nl2br($result_igd['ekg']); ?></td>
                                                    <td width="33%">Radiologi : <?php echo nl2br($result_igd['rad']); ?></td>
                                                    <td width="33%">Laborat : <?php echo nl2br($result_igd['lab']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>V. DIAGNOSIS/ASESMEN</b></td></tr>
                                                <tr>
                                                    <td><?php echo nl2br($result_igd['diagnosis']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>VI. TATALAKSANA</b></td></tr>
                                                <tr>
                                                    <td><?php echo nl2br($result_igd['tata']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <?php
                    }

                    // Tambahan untuk Asuhan Medis Umum
                    $query_umum = bukaquery("select penilaian_medis_ralan.tanggal,penilaian_medis_ralan.kd_dokter,penilaian_medis_ralan.anamnesis,
                            penilaian_medis_ralan.hubungan,penilaian_medis_ralan.keluhan_utama,penilaian_medis_ralan.rps,
                            penilaian_medis_ralan.rpd,penilaian_medis_ralan.rpk,penilaian_medis_ralan.rpo,penilaian_medis_ralan.alergi,
                            penilaian_medis_ralan.keadaan,penilaian_medis_ralan.gcs,penilaian_medis_ralan.kesadaran,penilaian_medis_ralan.td,
                            penilaian_medis_ralan.nadi,penilaian_medis_ralan.rr,penilaian_medis_ralan.suhu,penilaian_medis_ralan.spo,
                            penilaian_medis_ralan.bb,penilaian_medis_ralan.tb,penilaian_medis_ralan.kepala,penilaian_medis_ralan.gigi,
                            penilaian_medis_ralan.tht,penilaian_medis_ralan.thoraks,penilaian_medis_ralan.abdomen,penilaian_medis_ralan.genital,
                            penilaian_medis_ralan.ekstremitas,penilaian_medis_ralan.kulit,penilaian_medis_ralan.ket_fisik,
                            penilaian_medis_ralan.ket_lokalis,penilaian_medis_ralan.penunjang,penilaian_medis_ralan.diagnosis,
                            penilaian_medis_ralan.tata,penilaian_medis_ralan.konsulrujuk,dokter.nm_dokter 
                            from penilaian_medis_ralan inner join dokter on penilaian_medis_ralan.kd_dokter=dokter.kd_dokter 
                            where penilaian_medis_ralan.no_rawat='$norawat'");

                    if($result_umum = mysqli_fetch_array($query_umum)) {
                        ?>
                        <div style="margin-top: 20px;">
                            <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleUmum()">
                                <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
                                    PENILAIAN AWAL MEDIS RAWAT JALAN UMUM
                                    <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconUmum">keyboard_arrow_down</i>
                                </h4>
                </div>
                            <div id="contentUmum">
                                <table class="table table-bordered">
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr>
                                                    <td width="33%" border="0">Tanggal : <?php echo $result_umum['tanggal']; ?></td>
                                                    <td width="33%" border="0">Dokter : <?php echo $result_umum['kd_dokter']." ".$result_umum['nm_dokter']; ?></td>
                                                    <td width="33%" border="0">Anamnesis : <?php echo $result_umum['anamnesis'].($result_umum['hubungan']==""?"":", ".$result_umum['hubungan']); ?></td>
                                            </tr>
                                        </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td colspan="2" bgcolor="#f8f9fa"><b>I. RIWAYAT KESEHATAN</b></td></tr>
                                                <tr>
                                                    <td colspan="2">Keluhan Utama : <?php echo nl2br($result_umum['keluhan_utama']); ?></td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">Riwayat Penyakit Sekarang : <?php echo nl2br($result_umum['rps']); ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="50%">Riwayat Penyakit Dahulu : <?php echo nl2br($result_umum['rpd']); ?></td>
                                                    <td width="50%">Riwayat Alergi : <?php echo $result_umum['alergi']; ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="50%">Riwayat Penyakit Keluarga : <?php echo nl2br($result_umum['rpk']); ?></td>
                                                    <td width="50%">Riwayat Penggunaan Obat : <?php echo nl2br($result_umum['rpo']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td colspan="4" bgcolor="#f8f9fa"><b>II. PEMERIKSAAN FISIK</b></td></tr>
                                                <tr>
                                                    <td width="25%">Keadaan Umum : <?php echo $result_umum['keadaan']; ?></td>
                                                    <td width="25%">Kesadaran : <?php echo $result_umum['kesadaran']; ?></td>
                                                    <td width="25%">GCS(E,V,M) : <?php echo $result_umum['gcs']; ?></td>
                                                    <td width="25%">TB : <?php echo $result_umum['tb']; ?> Cm</td>
                                                </tr>
                                                <tr>
                                                    <td width="25%">BB : <?php echo $result_umum['bb']; ?> Kg</td>
                                                    <td width="25%">TD : <?php echo $result_umum['td']; ?> mmHg</td>
                                                    <td width="25%">Nadi : <?php echo $result_umum['nadi']; ?> x/menit</td>
                                                    <td width="25%">RR : <?php echo $result_umum['rr']; ?> x/menit</td>
                                                </tr>
                                                <tr>
                                                    <td width="25%">Suhu : <?php echo $result_umum['suhu']; ?> °C</td>
                                                    <td width="25%">SpO2 : <?php echo $result_umum['spo']; ?> %</td>
                                                    <td width="25%">Kepala : <?php echo $result_umum['kepala']; ?></td>
                                                    <td width="25%">THT : <?php echo $result_umum['tht']; ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="25%">Gigi & Mulut : <?php echo $result_umum['gigi']; ?></td>
                                                    <td width="25%">Thoraks : <?php echo $result_umum['thoraks']; ?></td>
                                                    <td width="25%">Abdomen : <?php echo $result_umum['abdomen']; ?></td>
                                                    <td width="25%">Genital : <?php echo $result_umum['genital']; ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="25%">Ekstremitas : <?php echo $result_umum['ekstremitas']; ?></td>
                                                    <td width="25%">Kulit : <?php echo $result_umum['kulit']; ?></td>
                                                    <td colspan="2">Keterangan Fisik : <?php echo $result_umum['ket_fisik']; ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>III. STATUS LOKALIS</b></td></tr>
                                                <tr>
                                                    <td width="100%" align="center">
                                                        <?php
                                                        // Cek dan tampilkan gambar
                                                        $lokasi_gambar = "webapps/gambar/";
                                                        $nama_gambar = "semua.png";
                                                        $path_gambar = $lokasi_gambar . $nama_gambar;
                                                        
                                                        if (file_exists($path_gambar)) {
                                                            echo '<img src="' . str_replace('pages/', '', $path_gambar) . '" alt="Gambar Lokalis" style="max-width:100%; height:auto;">';
                                                        } else {
                                                            echo '<img src="../webapps/gambar/semua.png" alt="Gambar Lokalis" style="max-width:100%; height:auto;">';
                                                        }
                                                        ?>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Keterangan : <?php echo nl2br($result_umum['ket_lokalis']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>IV. PEMERIKSAAN PENUNJANG</b></td></tr>
                                                <tr>
                                                    <td><?php echo nl2br($result_umum['penunjang']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>V. DIAGNOSIS</b></td></tr>
                                                <tr>
                                                    <td><?php echo nl2br($result_umum['diagnosis']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>VI. TATALAKSANA</b></td></tr>
                                                <tr>
                                                    <td><?php echo nl2br($result_umum['tata']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>VII. KONSUL/RUJUK</b></td></tr>
                                                <tr>
                                                    <td><?php echo nl2br($result_umum['konsulrujuk']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <?php
                    }
                    
                    // Tambahan untuk Asuhan Medis Rawat Inap
                    $query_inap = bukaquery("select penilaian_medis_ranap.tanggal,penilaian_medis_ranap.kd_dokter,penilaian_medis_ranap.anamnesis,
                            penilaian_medis_ranap.hubungan,penilaian_medis_ranap.keluhan_utama,penilaian_medis_ranap.rps,penilaian_medis_ranap.rpk,
                            penilaian_medis_ranap.rpd,penilaian_medis_ranap.rpo,penilaian_medis_ranap.alergi,penilaian_medis_ranap.keadaan,
                            penilaian_medis_ranap.gcs,penilaian_medis_ranap.kesadaran,penilaian_medis_ranap.td,penilaian_medis_ranap.nadi,
                            penilaian_medis_ranap.rr,penilaian_medis_ranap.suhu,penilaian_medis_ranap.spo,penilaian_medis_ranap.bb,
                            penilaian_medis_ranap.tb,penilaian_medis_ranap.kepala,penilaian_medis_ranap.mata,penilaian_medis_ranap.gigi,
                            penilaian_medis_ranap.tht,penilaian_medis_ranap.thoraks,penilaian_medis_ranap.jantung,penilaian_medis_ranap.paru,
                            penilaian_medis_ranap.abdomen,penilaian_medis_ranap.ekstremitas,penilaian_medis_ranap.genital,
                            penilaian_medis_ranap.kulit,penilaian_medis_ranap.ket_fisik,penilaian_medis_ranap.ket_lokalis,
                            penilaian_medis_ranap.lab,penilaian_medis_ranap.rad,penilaian_medis_ranap.penunjang,
                            penilaian_medis_ranap.diagnosis,penilaian_medis_ranap.tata,penilaian_medis_ranap.edukasi,
                            dokter.nm_dokter from penilaian_medis_ranap 
                            inner join dokter on penilaian_medis_ranap.kd_dokter=dokter.kd_dokter 
                            where penilaian_medis_ranap.no_rawat='$norawat'");

                    if($result_inap = mysqli_fetch_array($query_inap)) {
                        ?>
                        <div style="margin-top: 20px;">
                            <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleInap()">
                                    <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
                                        PENILAIAN AWAL MEDIS RAWAT INAP
                                    <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconInap">keyboard_arrow_down</i>
                                </h4>
                </div>
                            <div id="contentInap">
                                <table class="table table-bordered">
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr>
                                                    <td width="33%" border="0">Tanggal : <?php echo $result_inap['tanggal']; ?></td>
                                                    <td width="33%" border="0">Dokter : <?php echo $result_inap['kd_dokter']." ".$result_inap['nm_dokter']; ?></td>
                                                    <td width="33%" border="0">Anamnesis : <?php echo $result_inap['anamnesis'].($result_inap['hubungan']==""?"":", ".$result_inap['hubungan']); ?></td>
                                            </tr>
                                        </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td colspan="2" bgcolor="#f8f9fa"><b>I. RIWAYAT KESEHATAN</b></td></tr>
                                                <tr>
                                                    <td colspan="2">Keluhan Utama : <?php echo nl2br($result_inap['keluhan_utama']); ?></td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">Riwayat Penyakit Sekarang : <?php echo nl2br($result_inap['rps']); ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="50%">Riwayat Penyakit Dahulu : <?php echo nl2br($result_inap['rpd']); ?></td>
                                                    <td width="50%">Riwayat Alergi : <?php echo $result_inap['alergi']; ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="50%">Riwayat Penyakit Keluarga : <?php echo nl2br($result_inap['rpk']); ?></td>
                                                    <td width="50%">Riwayat Penggunaan Obat : <?php echo nl2br($result_inap['rpo']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td colspan="4" bgcolor="#f8f9fa"><b>II. PEMERIKSAAN FISIK</b></td></tr>
                                                <tr>
                                                    <td width="25%">Keadaan Umum : <?php echo $result_inap['keadaan']; ?></td>
                                                    <td width="25%">Kesadaran : <?php echo $result_inap['kesadaran']; ?></td>
                                                    <td width="25%">GCS(E,V,M) : <?php echo $result_inap['gcs']; ?></td>
                                                    <td width="25%">TB : <?php echo $result_inap['tb']; ?> Cm</td>
                                                </tr>
                                                <tr>
                                                    <td width="25%">BB : <?php echo $result_inap['bb']; ?> Kg</td>
                                                    <td width="25%">TD : <?php echo $result_inap['td']; ?> mmHg</td>
                                                    <td width="25%">Nadi : <?php echo $result_inap['nadi']; ?> x/menit</td>
                                                    <td width="25%">RR : <?php echo $result_inap['rr']; ?> x/menit</td>
                                                </tr>
                                                <tr>
                                                    <td width="25%">Suhu : <?php echo $result_inap['suhu']; ?> °C</td>
                                                    <td width="25%">SpO2 : <?php echo $result_inap['spo']; ?> %</td>
                                                    <td width="25%">Kepala : <?php echo $result_inap['kepala']; ?></td>
                                                    <td width="25%">Mata : <?php echo $result_inap['mata']; ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="25%">Gigi & Mulut : <?php echo $result_inap['gigi']; ?></td>
                                                    <td width="25%">THT : <?php echo $result_inap['tht']; ?></td>
                                                    <td width="25%">Thoraks : <?php echo $result_inap['thoraks']; ?></td>
                                                    <td width="25%">Jantung : <?php echo $result_inap['jantung']; ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="25%">Paru : <?php echo $result_inap['paru']; ?></td>
                                                    <td width="25%">Abdomen : <?php echo $result_inap['abdomen']; ?></td>
                                                    <td width="25%">Genital : <?php echo $result_inap['genital']; ?></td>
                                                    <td width="25%">Ekstremitas : <?php echo $result_inap['ekstremitas']; ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="25%">Kulit : <?php echo $result_inap['kulit']; ?></td>
                                                    <td colspan="3">Keterangan Fisik : <?php echo $result_inap['ket_fisik']; ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>IV. PEMERIKSAAN PENUNJANG</b></td></tr>
                                                <tr>
                                                    <td><?php echo nl2br($result_inap['penunjang']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>V. DIAGNOSIS</b></td></tr>
                                                <tr>
                                                    <td><?php echo nl2br($result_inap['diagnosis']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>VI. TATALAKSANA</b></td></tr>
                                                <tr>
                                                    <td><?php echo nl2br($result_inap['tata']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <table width="100%" border="0" align="center" cellpadding="3px" cellspacing="0" class="tbl_form">
                                                <tr><td bgcolor="#f8f9fa"><b>VII. EDUKASI</b></td></tr>
                                                <tr>
                                                    <td><?php echo nl2br($result_inap['edukasi']); ?></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <?php
                    }

                    // Tambahkan SOAPIE di sini
        $query_soapie = bukaquery("select pemeriksaan_ralan.tgl_perawatan,pemeriksaan_ralan.jam_rawat,
                pemeriksaan_ralan.suhu_tubuh,pemeriksaan_ralan.tensi,pemeriksaan_ralan.nadi,
                pemeriksaan_ralan.respirasi,pemeriksaan_ralan.tinggi,pemeriksaan_ralan.berat,
                pemeriksaan_ralan.spo2,pemeriksaan_ralan.gcs,pemeriksaan_ralan.kesadaran,
                pemeriksaan_ralan.keluhan,pemeriksaan_ralan.pemeriksaan,pemeriksaan_ralan.alergi,
                pemeriksaan_ralan.lingkar_perut,pemeriksaan_ralan.rtl,pemeriksaan_ralan.penilaian,
                pemeriksaan_ralan.instruksi,pemeriksaan_ralan.evaluasi,pemeriksaan_ralan.nip,
                pegawai.nama,pegawai.jbtn 
                from pemeriksaan_ralan inner join pegawai on pemeriksaan_ralan.nip=pegawai.nik 
                where pemeriksaan_ralan.no_rawat='$norawat' 
                order by pemeriksaan_ralan.tgl_perawatan,pemeriksaan_ralan.jam_rawat");
        
        if(mysqli_num_rows($query_soapie) > 0) {
            ?>
                        <div style="margin-top: 20px;">
                            <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleSOAPIE()">
                                <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
                                    SOAPIE
                                    <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconSOAPIE">keyboard_arrow_down</i>
                                </h4>
                            </div>
                            <div id="contentSOAPIE">
            <table class="table table-bordered">
                <tr bgcolor="#f8f9fa">
                    <th width="4%">No</th>
                    <th width="15%">Tanggal</th>
                    <th width="30%">Dokter/Paramedis</th>
                    <th width="20%">Profesi/Jabatan</th>
                </tr>
                <?php
                $no = 1;
                while($row = mysqli_fetch_array($query_soapie)) {
                    ?>
                    <tr>
                        <td align="center"><?php echo $no; ?></td>
                        <td><?php echo $row['tgl_perawatan'].' '.$row['jam_rawat']; ?></td>
                        <td><?php echo $row['nip'].' '.$row['nama']; ?></td>
                        <td><?php echo $row['jbtn']; ?></td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <table class="table table-bordered" style="margin-bottom: 0;">
                                <?php if(!empty($row['keluhan'])) { ?>
                                    <tr>
                                        <td width="15%" bgcolor="#f8f9fa"><b>Subjek</b></td>
                                        <td width="85%"><?php echo nl2br($row['keluhan']); ?></td>
                                    </tr>
                                <?php } ?>
                                <?php if(!empty($row['pemeriksaan'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Objek</b></td>
                                        <td><?php echo nl2br($row['pemeriksaan']); ?></td>
                                    </tr>
                                <?php } ?>
                                <tr>
                                    <td bgcolor="#f8f9fa"><b>Vital Sign</b></td>
                                    <td>
                                        Suhu: <?php echo $row['suhu_tubuh']; ?>°C, 
                                                            TD: <?php echo $row['tensi']; ?> mmHg, 
                                                            Nadi: <?php echo $row['nadi']; ?> x/m, 
                                                            RR: <?php echo $row['respirasi']; ?> x/m, 
                                                            SpO2: <?php echo $row['spo2']; ?>%, 
                                                            GCS: <?php echo $row['gcs']; ?>
                                    </td>
                                </tr>
                                <?php if(!empty($row['penilaian'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Asesmen</b></td>
                                        <td><?php echo nl2br($row['penilaian']); ?></td>
                                    </tr>
                                <?php } ?>
                                <?php if(!empty($row['rtl'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Plan</b></td>
                                        <td><?php echo nl2br($row['rtl']); ?></td>
                                    </tr>
                                <?php } ?>
                                <?php if(!empty($row['instruksi'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Instruksi</b></td>
                                        <td><?php echo nl2br($row['instruksi']); ?></td>
                                    </tr>
                                <?php } ?>
                                <?php if(!empty($row['evaluasi'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Evaluasi</b></td>
                                        <td><?php echo nl2br($row['evaluasi']); ?></td>
                                    </tr>
                                <?php } ?>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4" style="padding: 0;"><hr style="margin: 0;"></td>
                    </tr>
                    <?php
                    $no++;
                }
                ?>
            </table>
        </div>
    </div>
    <?php
} else {
    // echo "<div class='alert alert-info'>Belum ada data SOAPIE</div>";
}
?>
<!--                         
<div style="margin-top: 20px;">
    <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleCPPT()">
        <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
            CPPT
            <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconCPPT">keyboard_arrow_down</i>
        </h4>
    </div>
    <div id="contentCPPT">
        <?php
        $query_cppt = bukaquery("SELECT pemeriksaan_ranap.tgl_perawatan,pemeriksaan_ranap.jam_rawat,
                pemeriksaan_ranap.suhu_tubuh,pemeriksaan_ranap.tensi,pemeriksaan_ranap.nadi,
                pemeriksaan_ranap.respirasi,pemeriksaan_ranap.tinggi,pemeriksaan_ranap.berat,
                pemeriksaan_ranap.spo2,pemeriksaan_ranap.gcs,pemeriksaan_ranap.kesadaran,
                pemeriksaan_ranap.keluhan,pemeriksaan_ranap.penilaian,pemeriksaan_ranap.rtl,
                pemeriksaan_ranap.pemeriksaan,pemeriksaan_ranap.alergi,pemeriksaan_ranap.nip,
                pegawai.nama,pegawai.jbtn,pemeriksaan_ranap.instruksi,pemeriksaan_ranap.evaluasi 
                FROM pemeriksaan_ranap 
                INNER JOIN pegawai ON pemeriksaan_ranap.nip=pegawai.nik 
                WHERE pemeriksaan_ranap.no_rawat='$norawat' 
                ORDER BY pemeriksaan_ranap.tgl_perawatan,pemeriksaan_ranap.jam_rawat");
        
        if(mysqli_num_rows($query_cppt) > 0) {
            ?>
            <table class="table table-bordered">
                <tr bgcolor="#f8f9fa">
                    <th width="4%">No</th>
                    <th width="15%">Tanggal</th>
                    <th width="30%">Dokter/Paramedis</th>
                    <th width="20%">Profesi/Jabatan</th>
                </tr>
                <?php
                $no = 1;
                while($row = mysqli_fetch_array($query_cppt)) {
                    ?>
                    <tr>
                        <td align="center"><?php echo $no; ?></td>
                        <td><?php echo $row['tgl_perawatan'].' '.$row['jam_rawat']; ?></td>
                        <td><?php echo $row['nip'].' '.$row['nama']; ?></td>
                        <td><?php echo $row['jbtn']; ?></td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <table class="table table-bordered" style="margin-bottom: 0;">
                                <?php if(!empty($row['keluhan'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Subjek</b></td>
                                        <td><?php echo nl2br($row['keluhan']); ?></td>
                                    </tr>
                                <?php } ?>
                                <?php if(!empty($row['pemeriksaan'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Objek</b></td>
                                        <td><?php echo nl2br($row['pemeriksaan']); ?></td>
                                    </tr>
                                <?php } ?>
                                <tr>
                                    <td bgcolor="#f8f9fa"><b>Vital Sign</b></td>
                                    <td>
                                        Suhu: <?php echo $row['suhu_tubuh']; ?>°C, 
                                        TD: <?php echo $row['tensi']; ?> mmHg, 
                                        Nadi: <?php echo $row['nadi']; ?> x/m, 
                                        RR: <?php echo $row['respirasi']; ?> x/m, 
                                        SpO2: <?php echo $row['spo2']; ?>%, 
                                        GCS: <?php echo $row['gcs']; ?>
                                    </td>
                                </tr>
                                <?php if(!empty($row['penilaian'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Asesmen</b></td>
                                        <td><?php echo nl2br($row['penilaian']); ?></td>
                                    </tr>
                                <?php } ?>
                                <?php if(!empty($row['rtl'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Plan</b></td>
                                        <td><?php echo nl2br($row['rtl']); ?></td>
                                    </tr>
                                <?php } ?>
                                <?php if(!empty($row['instruksi'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Instruksi</b></td>
                                        <td><?php echo nl2br($row['instruksi']); ?></td>
                                    </tr>
                                <?php } ?>
                                <?php if(!empty($row['evaluasi'])) { ?>
                                    <tr>
                                        <td bgcolor="#f8f9fa"><b>Evaluasi</b></td>
                                        <td><?php echo nl2br($row['evaluasi']); ?></td>
                                    </tr>
                                <?php } ?>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4" style="padding: 0;"><hr style="margin: 0;"></td>
                    </tr>
                    <?php
                    $no++;
                }
                ?>
            </table>
            <?php
        } else {
            // echo "<div class='alert alert-info'>Belum ada data CPPT</div>";
        }
        ?>
    </div>
</div> -->

<div style="margin-top: 20px;">
    <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleObat()">
        <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
            PEMBERIAN OBAT
            <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconObat">keyboard_arrow_down</i>
        </h4>
    </div>
    <div id="contentObat">
        <?php
        // Query untuk pemberian obat
        $query_obat = bukaquery("SELECT detail_pemberian_obat.tgl_perawatan,detail_pemberian_obat.jam,
                databarang.kode_sat,detail_pemberian_obat.kode_brng,detail_pemberian_obat.jml,
                detail_pemberian_obat.total,databarang.nama_brng 
                FROM detail_pemberian_obat 
                INNER JOIN databarang ON detail_pemberian_obat.kode_brng=databarang.kode_brng  
                WHERE detail_pemberian_obat.no_rawat='$norawat' 
                ORDER BY detail_pemberian_obat.tgl_perawatan,detail_pemberian_obat.jam");

        if(mysqli_num_rows($query_obat) > 0) {
            ?>
            <table class="table table-bordered">
                <!-- <tr>
                    <td colspan="7" bgcolor="#f8f9fa"><b>Pemberian Obat/BHP/Alkes</b></td>
                </tr> -->
                <tr bgcolor="#f8f9fa" align="center">
                    <th width="4%">No.</th>
                    <th width="15%">Tanggal</th>
                    <th width="10%">Kode</th>
                    <th width="35%">Nama Obat/BHP/Alkes</th>
                    <th width="10%">Jumlah</th>
                    <th width="16%">Aturan Pakai</th>
                    <th width="10%">Biaya</th>
                </tr>
                <?php
                $no = 1;
                while($row = mysqli_fetch_array($query_obat)) {
                    // Query untuk aturan pakai
                    $aturan = bukaquery("SELECT aturan FROM aturan_pakai 
                            WHERE tgl_perawatan='".$row['tgl_perawatan']."' 
                            AND jam='".$row['jam']."' 
                            AND no_rawat='$norawat' 
                            AND kode_brng='".$row['kode_brng']."'");
                    $aturan_pakai = mysqli_fetch_array($aturan);
                    ?>
                    <tr>
                        <td align="center"><?php echo $no; ?></td>
                        <td><?php echo $row['tgl_perawatan'].' '.$row['jam']; ?></td>
                        <td><?php echo $row['kode_brng']; ?></td>
                        <td><?php echo $row['nama_brng']; ?></td>
                        <td><?php echo $row['jml'].' '.$row['kode_sat']; ?></td>
                        <td><?php echo isset($aturan_pakai['aturan']) ? $aturan_pakai['aturan'] : ''; ?></td>
                        <td align="right"><?php echo number_format($row['total'], 0, ',', '.'); ?></td>
                    </tr>
                    <?php
                    $no++;
                }
                ?>
            </table>

            <?php
            // Query untuk retur obat
            $query_retur = bukaquery("SELECT databarang.kode_brng,databarang.nama_brng,
                    detreturjual.kode_sat,detreturjual.h_retur,
                    (detreturjual.jml_retur * -1) as jumlah,
                    (detreturjual.subtotal * -1) as total 
                    FROM detreturjual 
                    INNER JOIN databarang ON detreturjual.kode_brng=databarang.kode_brng  
                    INNER JOIN returjual ON returjual.no_retur_jual=detreturjual.no_retur_jual 
                    WHERE returjual.no_retur_jual LIKE '%$norawat%' 
                    ORDER BY databarang.nama_brng");

            if(mysqli_num_rows($query_retur) > 0) {
                ?>
                <table class="table table-bordered" style="margin-top: 20px;">
                    <tr>
                        <td colspan="5" bgcolor="#f8f9fa"><b>Retur Obat</b></td>
                    </tr>
                    <tr bgcolor="#f8f9fa" align="center">
                        <th width="4%">No.</th>
                        <th width="10%">Kode</th>
                        <th width="66%">Nama Obat/BHP/Alkes</th>
                        <th width="10%">Jumlah</th>
                        <th width="10%">Biaya</th>
                    </tr>
                    <?php
                    $no = 1;
                    while($row = mysqli_fetch_array($query_retur)) {
                        ?>
                        <tr>
                            <td align="center"><?php echo $no; ?></td>
                            <td><?php echo $row['kode_brng']; ?></td>
                            <td><?php echo $row['nama_brng']; ?></td>
                            <td><?php echo $row['jumlah'].' '.$row['kode_sat']; ?></td>
                            <td align="right"><?php echo number_format($row['total'], 0, ',', '.'); ?></td>
                        </tr>
                        <?php
                        $no++;
                    }
                    ?>
                </table>
                <?php
            }
        } else {
            // echo "<div class='alert alert-info'>Belum ada data pemberian obat</div>";
        }
        ?>
    </div>
</div>

<div style="margin-top: 20px;">
    <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleLab()">
        <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
            PEMERIKSAAN LABORATORIUM
            <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconLab">keyboard_arrow_down</i>
        </h4>
</div> 
    <div id="contentLab">
        <?php
        // Query untuk Laboratorium PK & MB
        $query_lab = bukaquery("SELECT periksa_lab.tgl_periksa,periksa_lab.jam 
                FROM periksa_lab 
                WHERE periksa_lab.kategori<>'PA' AND periksa_lab.no_rawat='$norawat' 
                GROUP BY CONCAT(periksa_lab.no_rawat,periksa_lab.tgl_periksa,periksa_lab.jam) 
                ORDER BY periksa_lab.tgl_periksa,periksa_lab.jam");

        if(mysqli_num_rows($query_lab) > 0) {
            ?>
            <table class="table table-bordered">
                <tr>
                    <td colspan="7" bgcolor="#f8f9fa"><b>Pemeriksaan Laboratorium PK & MB</b></td>
                </tr>
                <tr bgcolor="#f8f9fa" align="center">
                    <th width="4%">No.</th>
                    <th width="15%">Tanggal</th>
                    <th width="10%">Kode</th>
                    <th width="26%">Nama Pemeriksaan</th>
                    <th width="18%">Dokter PJ</th>
                    <th width="17%">Petugas</th>
                    <th width="10%">Biaya</th>
                </tr>
                <?php
                $no = 1;
                while($row_lab = mysqli_fetch_array($query_lab)) {
                    $query_detail = bukaquery("SELECT periksa_lab.kd_jenis_prw, 
                            jns_perawatan_lab.nm_perawatan,petugas.nama,periksa_lab.biaya,
                            periksa_lab.dokter_perujuk,dokter.nm_dokter 
                            FROM periksa_lab 
                            INNER JOIN jns_perawatan_lab ON periksa_lab.kd_jenis_prw=jns_perawatan_lab.kd_jenis_prw 
                            INNER JOIN petugas ON periksa_lab.nip=petugas.nip 
                            INNER JOIN dokter ON periksa_lab.kd_dokter=dokter.kd_dokter 
                            WHERE periksa_lab.kategori<>'PA' AND periksa_lab.no_rawat='$norawat' 
                            AND periksa_lab.tgl_periksa='".$row_lab['tgl_periksa']."' 
                            AND periksa_lab.jam='".$row_lab['jam']."'");

                    $first_row = true;
                    while($row_detail = mysqli_fetch_array($query_detail)) {
                        ?>
                        <tr>
                            <td align="center"><?php echo $first_row ? $no : ''; ?></td>
                            <td><?php echo $first_row ? $row_lab['tgl_periksa'].' '.$row_lab['jam'] : ''; ?></td>
                            <td><?php echo $row_detail['kd_jenis_prw']; ?></td>
                            <td><?php echo $row_detail['nm_perawatan']; ?></td>
                            <td><?php echo $row_detail['nm_dokter']; ?></td>
                            <td><?php echo $row_detail['nama']; ?></td>
                            <td align="right"><?php echo number_format($row_detail['biaya'], 0, ',', '.'); ?></td>
                        </tr>
                        <?php
                        // Query untuk detail pemeriksaan
                        $query_hasil = bukaquery("SELECT template_laboratorium.Pemeriksaan, 
                                detail_periksa_lab.nilai,template_laboratorium.satuan,
                                detail_periksa_lab.nilai_rujukan,detail_periksa_lab.biaya_item,
                                detail_periksa_lab.keterangan 
                                FROM detail_periksa_lab 
                                INNER JOIN template_laboratorium ON detail_periksa_lab.id_template=template_laboratorium.id_template 
                                WHERE detail_periksa_lab.no_rawat='$norawat' 
                                AND detail_periksa_lab.kd_jenis_prw='".$row_detail['kd_jenis_prw']."' 
                                AND detail_periksa_lab.tgl_periksa='".$row_lab['tgl_periksa']."' 
                                AND detail_periksa_lab.jam='".$row_lab['jam']."' 
                                ORDER BY detail_periksa_lab.kd_jenis_prw,template_laboratorium.urut");

                        if(mysqli_num_rows($query_hasil) > 0) {
                            ?>
                            <tr bgcolor="#f8f9fa">
                                <td></td>
                                <td></td>
                                <td></td>
                                <td align="center">Detail Pemeriksaan</td>
                                <td align="center">Hasil</td>
                                <td align="center">Nilai Rujukan</td>
                                <td></td>
                            </tr>
                            <?php
                            while($row_hasil = mysqli_fetch_array($query_hasil)) {
                                $style = '';
                                switch(strtolower($row_hasil['keterangan'])) {
                                    case 'l': $style = 'color:#0000FF'; break;
                                    case 'h': $style = 'color:#FF0000'; break;
                                    case 't': $style = 'font-weight:bold'; break;
                                }
                                ?>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td><?php echo $row_hasil['Pemeriksaan']; ?></td>
                                    <td style="<?php echo $style; ?>"><?php echo $row_hasil['nilai'].' '.$row_hasil['satuan']; ?></td>
                                    <td><?php echo $row_hasil['nilai_rujukan']; ?></td>
                                    <td align="right"><?php echo number_format($row_hasil['biaya_item'], 0, ',', '.'); ?></td>
                                </tr>
                                <?php
                            }
                        }

                        // Query untuk saran dan kesan
                        $query_saran = bukaquery("SELECT saran,kesan 
                                FROM saran_kesan_lab 
                                WHERE no_rawat='$norawat' 
                                AND tgl_periksa='".$row_lab['tgl_periksa']."' 
                                AND jam='".$row_lab['jam']."'");
                        if($row_saran = mysqli_fetch_array($query_saran)) {
                            ?>
                            <tr>
                                <td></td>
                                <td>Kesan</td>
                                <td colspan="5">: <?php echo $row_saran['kesan']; ?></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td>Saran</td>
                                <td colspan="5">: <?php echo $row_saran['saran']; ?></td>
                            </tr>
                            <?php
                        }
                        $first_row = false;
                    }
                    $no++;
                }
                ?>
            </table>
            <?php
        }

        // Query untuk Laboratorium PA
        $query_pa = bukaquery("SELECT periksa_lab.tgl_periksa,periksa_lab.jam,periksa_lab.kd_jenis_prw, 
                jns_perawatan_lab.nm_perawatan,petugas.nama,periksa_lab.biaya,
                periksa_lab.dokter_perujuk,dokter.nm_dokter 
                FROM periksa_lab 
                INNER JOIN jns_perawatan_lab ON periksa_lab.kd_jenis_prw=jns_perawatan_lab.kd_jenis_prw 
                INNER JOIN petugas ON periksa_lab.nip=petugas.nip 
                INNER JOIN dokter ON periksa_lab.kd_dokter=dokter.kd_dokter 
                WHERE periksa_lab.kategori='PA' AND periksa_lab.no_rawat='$norawat' 
                ORDER BY periksa_lab.tgl_periksa,periksa_lab.jam");

        if(mysqli_num_rows($query_pa) > 0) {
            ?>
            <table class="table table-bordered" style="margin-top: 20px;">
                <tr>
                    <td colspan="7" bgcolor="#f8f9fa"><b>Pemeriksaan Laboratorium PA</b></td>
                </tr>
                <tr bgcolor="#f8f9fa" align="center">
                    <th width="4%">No.</th>
                    <th width="15%">Tanggal</th>
                    <th width="10%">Kode</th>
                    <th width="26%">Nama Pemeriksaan</th>
                    <th width="18%">Dokter PJ</th>
                    <th width="17%">Petugas</th>
                    <th width="10%">Biaya</th>
                </tr>
                <?php
                $no = 1;
                while($row_pa = mysqli_fetch_array($query_pa)) {
                    ?>
                    <tr>
                        <td align="center"><?php echo $no; ?></td>
                        <td><?php echo $row_pa['tgl_periksa'].' '.$row_pa['jam']; ?></td>
                        <td><?php echo $row_pa['kd_jenis_prw']; ?></td>
                        <td><?php echo $row_pa['nm_perawatan']; ?></td>
                        <td><?php echo $row_pa['nm_dokter']; ?></td>
                        <td><?php echo $row_pa['nama']; ?></td>
                        <td align="right"><?php echo number_format($row_pa['biaya'], 0, ',', '.'); ?></td>
                    </tr>
                    <?php
                    // Query untuk detail PA
                    $query_detail_pa = bukaquery("SELECT diagnosa_klinik,makroskopik,mikroskopik,
                            kesimpulan,kesan 
                            FROM detail_periksa_labpa 
                            WHERE no_rawat='$norawat' 
                            AND kd_jenis_prw='".$row_pa['kd_jenis_prw']."' 
                            AND tgl_periksa='".$row_pa['tgl_periksa']."' 
                            AND jam='".$row_pa['jam']."'");
                    
                    if($row_detail_pa = mysqli_fetch_array($query_detail_pa)) {
                        ?>
                        <tr>
                            <td></td>
                            <td></td>
                            <td>Diagnosa Klinis</td>
                            <td colspan="4">: <?php echo $row_detail_pa['diagnosa_klinik']; ?></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td></td>
                            <td>Makroskopik</td>
                            <td colspan="4">: <?php echo $row_detail_pa['makroskopik']; ?></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td></td>
                            <td>Mikroskopik</td>
                            <td colspan="4">: <?php echo $row_detail_pa['mikroskopik']; ?></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td></td>
                            <td>Kesimpulan</td>
                            <td colspan="4">: <?php echo $row_detail_pa['kesimpulan']; ?></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td></td>
                            <td>Kesan</td>
                            <td colspan="4">: <?php echo $row_detail_pa['kesan']; ?></td>
                        </tr>
                        <?php
                        // Cek gambar PA
                        $file = bukaquery("SELECT photo FROM detail_periksa_labpa_gambar 
                                WHERE no_rawat='$norawat' 
                                AND kd_jenis_prw='".$row_pa['kd_jenis_prw']."' 
                                AND tgl_periksa='".$row_pa['tgl_periksa']."' 
                                AND jam='".$row_pa['jam']."'");
                        if($row_file = mysqli_fetch_array($file)) {
                            if(!empty($row_file['photo'])) {
                                ?>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td colspan="5" align="center">
                                        <img src="../webapps/labpa/<?php echo $row_file['photo']; ?>" alt="Gambar PA" style="max-width:450px; height:auto;"/>
                                    </td>
                                </tr>
                                <?php
                            }
                        }
                    }
                    $no++;
                }
                ?>
            </table>
            <?php
        }

        if(mysqli_num_rows($query_lab) == 0 && mysqli_num_rows($query_pa) == 0) {
            // echo "<div class='alert alert-info'>Belum ada data pemeriksaan laboratorium</div>";
        }
        ?>
    </div>
</div>

<!-- Tambahkan di bagian style -->
<style type="text/css">
    #contentLab {
        display: none;
    }
</style>

<!-- Tambahkan di bagian JavaScript -->
<script type="text/javascript">
    function toggleLab() {
        toggleContent('contentLab', 'iconLab');
    }
    
    // Tambahkan di window.onload
    window.onload = function() {
        // ... existing code ...
        document.getElementById('contentLab').style.display = "none";
    };
</script>

<div style="margin-top: 20px;">
    <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleRadiologi()">
        <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
            PEMERIKSAAN RADIOLOGI
            <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconRadiologi">keyboard_arrow_down</i>
        </h4>
    </div>
    <div id="contentRadiologi">
        <?php
        // Query untuk pemeriksaan radiologi
        $query_rad = bukaquery("SELECT periksa_radiologi.tgl_periksa,periksa_radiologi.jam,
                periksa_radiologi.kd_jenis_prw,jns_perawatan_radiologi.nm_perawatan,
                petugas.nama,periksa_radiologi.biaya,periksa_radiologi.dokter_perujuk,
                dokter.nm_dokter,
                CONCAT(
                    IF(periksa_radiologi.proyeksi<>'',CONCAT('Proyeksi : ',periksa_radiologi.proyeksi,', '),''),
                    IF(periksa_radiologi.kV<>'',CONCAT('kV : ',periksa_radiologi.kV,', '),''),
                    IF(periksa_radiologi.mAS<>'',CONCAT('mAS : ',periksa_radiologi.mAS,', '),''),
                    IF(periksa_radiologi.FFD<>'',CONCAT('FFD : ',periksa_radiologi.FFD,', '),''),
                    IF(periksa_radiologi.BSF<>'',CONCAT('BSF : ',periksa_radiologi.BSF,', '),''),
                    IF(periksa_radiologi.inak<>'',CONCAT('Inak : ',periksa_radiologi.inak,', '),''),
                    IF(periksa_radiologi.jml_penyinaran<>'',CONCAT('Jml Penyinaran : ',periksa_radiologi.jml_penyinaran,', '),''),
                    IF(periksa_radiologi.dosis<>'',CONCAT('Dosis Radiasi : ',periksa_radiologi.dosis),'')
                ) as proyeksi 
                FROM periksa_radiologi 
                INNER JOIN jns_perawatan_radiologi ON periksa_radiologi.kd_jenis_prw=jns_perawatan_radiologi.kd_jenis_prw 
                INNER JOIN petugas ON periksa_radiologi.nip=petugas.nip 
                INNER JOIN dokter ON periksa_radiologi.kd_dokter=dokter.kd_dokter 
                WHERE periksa_radiologi.no_rawat='$norawat' 
                ORDER BY periksa_radiologi.tgl_periksa,periksa_radiologi.jam");

        if(mysqli_num_rows($query_rad) > 0) {
            ?>
            <table class="table table-bordered">
                <tr>
                    <td colspan="7" bgcolor="#f8f9fa"><b>Pemeriksaan Radiologi</b></td>
                </tr>
                <tr bgcolor="#f8f9fa" align="center">
                    <th width="4%">No.</th>
                    <th width="15%">Tanggal</th>
                    <th width="10%">Kode</th>
                    <th width="26%">Nama Pemeriksaan</th>
                    <th width="18%">Dokter PJ</th>
                    <th width="17%">Petugas</th>
                    <th width="10%">Biaya</th>
                </tr>
                <?php
                $no = 1;
                while($row = mysqli_fetch_array($query_rad)) {
                    ?>
                    <tr>
                        <td align="center"><?php echo $no; ?></td>
                        <td><?php echo $row['tgl_periksa'].' '.$row['jam']; ?></td>
                        <td><?php echo $row['kd_jenis_prw']; ?></td>
                        <td><?php echo $row['nm_perawatan'].'<br>'.$row['proyeksi']; ?></td>
                        <td><?php echo $row['nm_dokter']; ?></td>
                        <td><?php echo $row['nama']; ?></td>
                        <td align="right"><?php echo number_format($row['biaya'], 0, ',', '.'); ?></td>
                    </tr>
                    <?php
                    $no++;
                }
                ?>
            </table>

            <?php
            // Query untuk hasil radiologi
            $query_hasil = bukaquery("SELECT tgl_periksa,jam,hasil 
                    FROM hasil_radiologi 
                    WHERE no_rawat='$norawat' 
                    ORDER BY tgl_periksa,jam");

            if(mysqli_num_rows($query_hasil) > 0) {
                ?>
                <table class="table table-bordered" style="margin-top: 20px;">
                    <tr>
                        <td colspan="3" bgcolor="#f8f9fa"><b>Bacaan/Hasil Radiologi</b></td>
                    </tr>
                    <tr bgcolor="#f8f9fa" align="center">
                        <th width="4%">No.</th>
                        <th width="15%">Tanggal</th>
                        <th width="81%">Hasil Pemeriksaan</th>
                    </tr>
                    <?php
                    $no = 1;
                    while($row = mysqli_fetch_array($query_hasil)) {
                        ?>
                        <tr>
                            <td align="center"><?php echo $no; ?></td>
                            <td><?php echo $row['tgl_periksa'].' '.$row['jam']; ?></td>
                            <td><?php echo nl2br($row['hasil']); ?></td>
                        </tr>
                        <?php
                        $no++;
                    }
                    ?>
                </table>
                <?php
            }

            // Query untuk gambar radiologi
            $query_gambar = bukaquery("SELECT tgl_periksa,jam,lokasi_gambar 
                    FROM gambar_radiologi 
                    WHERE no_rawat='$norawat' 
                    ORDER BY tgl_periksa,jam");

            if(mysqli_num_rows($query_gambar) > 0) {
                ?>
                <table class="table table-bordered" style="margin-top: 20px;">
                    <tr>
                        <td colspan="3" bgcolor="#f8f9fa"><b>Gambar Radiologi</b></td>
                    </tr>
                    <tr bgcolor="#f8f9fa" align="center">
                        <th width="4%">No.</th>
                        <th width="15%">Tanggal</th>
                        <th width="81%">Gambar Radiologi</th>
                    </tr>
                    <?php
                    $no = 1;
                    while($row = mysqli_fetch_array($query_gambar)) {
                        ?>
                        <tr>
                            <td align="center"><?php echo $no; ?></td>
                            <td><?php echo $row['tgl_periksa'].' '.$row['jam']; ?></td>
                            <td>
                                <div class="row">
                                    <div class="col-md-8 text-center">
                                        <img src="../webapps/radiologi/<?php echo $row['lokasi_gambar']; ?>" 
                                             alt="Gambar Radiologi" 
                                             style="max-width:450px; height:auto; margin-bottom:10px;"/>
                                    </div>
                                    <div class="col-md-4">
                                        <button type="button" 
                                                class="btn btn-primary btn-block mb-2"
                                                onclick="window.open('../webapps/radiologi/<?php echo $row['lokasi_gambar']; ?>', '_blank')">
                                            <i class="material-icons" style="font-size: 16px; vertical-align: middle;">open_in_new</i>
                                            Buka di Tab Baru
                                        </button>
                                        <button type="button" 
                                                class="btn btn-info btn-block"
                                                onclick="showLargeImage('../webapps/radiologi/<?php echo $row['lokasi_gambar']; ?>')">
                                            <i class="material-icons" style="font-size: 16px; vertical-align: middle;">zoom_in</i>
                                            Lihat Lebih Besar
                                        </button>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <?php
                        $no++;
                    }
                    ?>
                </table>
                <?php
            }
        } else {
            // echo "<div class='alert alert-info'>Belum ada data pemeriksaan radiologi</div>";
        }
        ?>
    </div>
</div>

<!-- Modal untuk gambar besar -->
<div class="modal fade" id="imageModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Gambar Radiologi</h5>
                <button type="button" class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-body text-center">
                <div class="img-container" style="overflow: auto; max-height: 80vh;">
                    <img id="largeImage" src="" alt="Gambar Radiologi" style="max-width: 100%; cursor: move;">
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Tambahkan di bagian style -->
<style>
    .modal-lg {
        max-width: 90%;
    }
    .img-container {
        position: relative;
    }
    .btn .material-icons {
        margin-right: 5px;
    }
    .btn-block {
        text-align: left;
    }
</style>

<!-- Tambahkan di bagian JavaScript -->
<script>
    function showLargeImage(imageSrc) {
        $('#largeImage').attr('src', imageSrc);
        $('#imageModal').modal('show');
    }

    $(document).ready(function() {
        let isDragging = false;
        let startX, startY, initialX, initialY;
        const image = document.getElementById('largeImage');
        
        image.addEventListener('mousedown', function(e) {
            isDragging = true;
            startX = e.clientX - initialX;
            startY = e.clientY - initialY;
        });

        image.addEventListener('mousemove', function(e) {
            if (isDragging) {
                e.preventDefault();
                const x = e.clientX - startX;
                const y = e.clientY - startY;
                initialX = x;
                initialY = y;
                image.style.transform = `translate(${x}px, ${y}px)`;
            }
        });

        image.addEventListener('mouseup', function() {
            isDragging = false;
        });

        image.addEventListener('mouseleave', function() {
            isDragging = false;
        });

        // Reset posisi gambar saat modal ditutup
        $('#imageModal').on('hidden.bs.modal', function() {
            image.style.transform = 'translate(0, 0)';
            initialX = 0;
            initialY = 0;
        });

        // Zoom dengan scroll
        $('.img-container').on('wheel', function(e) {
            e.preventDefault();
            const image = $('#largeImage');
            let scale = 1;
            
            if (e.originalEvent.deltaY < 0) {
                scale = 1.1; // zoom in
            } else {
                scale = 0.9; // zoom out
            }

            const currentWidth = image.width();
            const currentHeight = image.height();
            
            image.css({
                'width': currentWidth * scale,
                'height': currentHeight * scale
            });
        });
    });
</script>
</div> 
<style type="text/css">
    #contentRawatJalan, #contentRawatInap, #contentIGD, #contentUmum, #contentInap, #contentSOAPIE, #contentCPPT, #contentObat, #contentLab, #contentRadiologi, #contentOperasi {
        display: none;
    }
 
</style>
<script type="text/javascript">
    // Fungsi untuk toggle content dengan animasi
    function toggleContent(contentId, iconId) {
        var content = document.getElementById(contentId);
        var icon = document.getElementById(iconId);
        
        if (content.style.display === "none" || content.style.display === "") {
            content.style.display = "block";
            icon.innerHTML = "keyboard_arrow_up";
        } else {
            content.style.display = "none";
            icon.innerHTML = "keyboard_arrow_down";
        }
    }

    function toggleRawatJalan() {
        toggleContent('contentRawatJalan', 'iconRawatJalan');
    }

    function toggleRawatInap() {
        toggleContent('contentRawatInap', 'iconRawatInap');
    }

    function toggleIGD() {
        toggleContent('contentIGD', 'iconIGD');
    }

    function toggleUmum() {
        toggleContent('contentUmum', 'iconUmum');
    }

    function toggleInap() {
        toggleContent('contentInap', 'iconInap');
    }

    function toggleSOAPIE() {
        toggleContent('contentSOAPIE', 'iconSOAPIE');
    }

    function toggleCPPT() {
        toggleContent('contentCPPT', 'iconCPPT');
    }

    function toggleObat() {
        toggleContent('contentObat', 'iconObat');
    }

    // Inisialisasi saat halaman dimuat
    window.onload = function() {
        // Pastikan semua konten tersembunyi saat awal
        document.getElementById('contentRawatJalan').style.display = "none";
        document.getElementById('contentRawatInap').style.display = "none";
        document.getElementById('contentIGD').style.display = "none";
        document.getElementById('contentUmum').style.display = "none";
        document.getElementById('contentInap').style.display = "none";
        document.getElementById('contentSOAPIE').style.display = "none";
        document.getElementById('contentCPPT').style.display = "none";
        document.getElementById('contentObat').style.display = "none";
        document.getElementById('contentLab').style.display = "none";
        document.getElementById('contentRadiologi').style.display = "none";
    };

    // Tambahkan fungsi toggleRadiologi di bagian JavaScript sebelum window.onload
    function toggleRadiologi() {
        toggleContent('contentRadiologi', 'iconRadiologi');
    }
    

    
    // Inisialisasi saat halaman dimuat
    // window.onload = function() {
    //     // Pastikan semua konten tersembunyi saat awal
    //     document.getElementById('contentRawatJalan').style.display = "none";
    //     document.getElementById('contentRawatInap').style.display = "none";
    //     document.getElementById('contentIGD').style.display = "none";
    //     document.getElementById('contentUmum').style.display = "none";
    //     document.getElementById('contentInap').style.display = "none";
    //     document.getElementById('contentSOAPIE').style.display = "none";
    //     document.getElementById('contentCPPT').style.display = "none";
    //     document.getElementById('contentObat').style.display = "none";
    //     document.getElementById('contentLab').style.display = "none";
    //     document.getElementById('contentRadiologi').style.display = "none";
    // };
</script> 
<!-- Tambahkan di bagian style -->
<style type="text/css">
    #contentRadiologi {
        display: none;
    }
</style>

<div style="margin-top: 20px;">
    
        <?php
        $query_operasi = bukaquery("SELECT tanggal, diagnosa_preop, diagnosa_postop, jaringan_dieksekusi, 
                selesaioperasi, permintaan_pa, laporan_operasi 
                FROM laporan_operasi 
                WHERE no_rawat='$norawat' 
                GROUP BY no_rawat,tanggal 
                ORDER BY tanggal");

        if(mysqli_num_rows($query_operasi) > 0) {
            ?>
                <div style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 15px; cursor: pointer;" onclick="toggleOperasi()">
                    <h4 style="color: #2196F3; margin: 0; text-align: left; font-weight: bold;">
                        LAPORAN OPERASI
                        <i class="material-icons" style="font-size: 20px; vertical-align: middle;" id="iconOperasi">keyboard_arrow_down</i>
                    </h4>
                </div>
                <div id="contentOperasi">

            <table class="table table-bordered">
                <tr>
                    <td colspan="3" bgcolor="#f8f9fa"><b>Laporan Operasi</b></td>
                </tr>
                <?php
                $no = 1;
                while($row = mysqli_fetch_array($query_operasi)) {
                    ?>
                    <tr>
                        <td width="4%" align="center" valign="top"><?php echo $no; ?></td>
                        <td width="21%" valign="top">Mulai Operasi</td>
                        <td width="75%" valign="top"><?php echo $row['tanggal']; ?></td>
                    </tr>
                    <tr>
                        <td align="center" valign="top"></td>
                        <td valign="top">Diagnosa Pre-operatif</td>
                        <td valign="top"><?php echo $row['diagnosa_preop']; ?></td>
                    </tr>
                    <tr>
                        <td align="center" valign="top"></td>
                        <td valign="top">Jaringan Yang di-Eksisi/-Insisi</td>
                        <td valign="top"><?php echo $row['jaringan_dieksekusi']; ?></td>
                    </tr>
                    <tr>
                        <td align="center" valign="top"></td>
                        <td valign="top">Diagnosa Post-operatif</td>
                        <td valign="top"><?php echo $row['diagnosa_postop']; ?></td>
                    </tr>
                    <tr>
                        <td align="center" valign="top"></td>
                        <td valign="top">Selesai Operasi</td>
                        <td valign="top"><?php echo $row['selesaioperasi']; ?></td>
                    </tr>
                    <tr>
                        <td align="center" valign="top"></td>
                        <td valign="top">Dikirim Untuk Pemeriksaan PA</td>
                        <td valign="top"><?php echo $row['permintaan_pa']; ?></td>
                    </tr>
                    <tr>
                        <td align="center" valign="top"></td>
                        <td valign="top">Laporan</td>
                        <td valign="top"><?php echo nl2br($row['laporan_operasi']); ?></td>
                    </tr>
                    <?php if($no < mysqli_num_rows($query_operasi)) { ?>
                        <tr>
                            <td colspan="3"><hr style="margin: 10px 0;"></td>
                        </tr>
                    <?php }
                    $no++;
                }
                ?>
            </table>
            <?php
        } else {
            // echo "<div class='alert alert-info'>Belum ada data laporan operasi</div>";
        }
        ?>
    </div>
</div>

<!-- Tambahkan di bagian style -->
<style type="text/css">
    #contentOperasi {
        display: none;
    }
</style>

<!-- Tambahkan fungsi JavaScript -->
<script type="text/javascript">
    function toggleOperasi() {
        toggleContent('contentOperasi', 'iconOperasi');
    }
    
    // Tambahkan di window.onload
    window.onload = function() {
        // ... existing code ...
        document.getElementById('contentOperasi').style.display = "none";
    };
</script>

