<?php
session_start();
require_once '../config.php';
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'kader') { exit; }

$id = $_GET['id'];

try {
    // 1. Hapus riwayat pemeriksaan dulu (Foreign Key)
    $stmt1 = $pdo->prepare("DELETE FROM pemeriksaan_bumil WHERE id_bumil = ?");
    $stmt1->execute([$id]);

    // 2. Hapus data ibu hamil
    $stmt2 = $pdo->prepare("DELETE FROM ibu_hamil WHERE id_bumil = ?");
    $stmt2->execute([$id]);

    header("Location: bumil_index.php?status=deleted");
    exit;
} catch (PDOException $e) {
    die("Gagal menghapus data: " . $e->getMessage());
}