<?php
require_once('../conf/conf.php');
header('Content-Type: application/json');

if(isset($_POST['id'])) {
    $id = validTeks($_POST['id']);
    
    $sql = "SELECT * FROM template_resume_pasien_ranap WHERE id = '$id'";
    $hasil = bukaquery($sql);
    
    if($template = mysqli_fetch_assoc($hasil)) {
        echo json_encode([
            'success' => true,
            'data' => [
                'diagnosa_awal' => $template['diagnosa_awal'],
                'alasan' => $template['alasan'],
                'keluhan_utama' => $template['keluhan_utama'],
                'pemeriksaan_fisik' => $template['pemeriksaan_fisik'],
                'jalannya_penyakit' => $template['jalannya_penyakit'],
                'pemeriksaan_penunjang' => $template['pemeriksaan_penunjang'],
                'hasil_laborat' => $template['hasil_laborat'],
                'tindakan_dan_operasi' => $template['tindakan_dan_operasi'],
                'obat_di_rs' => $template['obat_di_rs'],
                'diagnosa_utama' => $template['diagnosa_utama'],
                'kd_diagnosa_utama' => $template['kd_diagnosa_utama'],
                'diagnosa_sekunder' => $template['diagnosa_sekunder'],
                'kd_diagnosa_sekunder' => $template['kd_diagnosa_sekunder'],
                'prosedur_utama' => $template['prosedur_utama'],
                'kd_prosedur_utama' => $template['kd_prosedur_utama'],
                'cara_keluar' => $template['cara_keluar'],
                'ket_keluar' => $template['ket_keluar'],
                'alergi' => $template['alergi'],
                'diet' => $template['diet'],
                'lab_belum' => $template['lab_belum'],
                'edukasi' => $template['edukasi'],
                'cara_keluar' => $template['cara_keluar'],
                'keadaan' => $template['keadaan'],
                'dilanjutkan' => $template['dilanjutkan']
            ]
        ]);
    } else {
        echo json_encode([
            'success' => false,
            'message' => 'Template tidak ditemukan'
        ]);
    }
} else {
    echo json_encode([
        'success' => false,
        'message' => 'ID template tidak valid'
    ]);
}
?> 