PDO::ERRMODE_EXCEPTION] ); // Check if content exists $stmt = $pdo->prepare('SELECT id, ipd_id FROM ipd_discharge WHERE ipd_id = ?'); $stmt->execute([$ipdId]); $existing = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($existing)) { echo "āœ“ No discharge content found for IPD ID $ipdId\n"; echo " The content will be auto-generated on next view.\n"; exit(0); } echo "Found " . count($existing) . " discharge record(s) for IPD ID $ipdId\n"; // Delete the content $stmt = $pdo->prepare('DELETE FROM ipd_discharge WHERE ipd_id = ?'); $deleted = $stmt->execute([$ipdId]); if ($deleted) { echo "\nāœ“ Successfully cleared discharge content for IPD ID $ipdId\n"; echo " Next time you view the discharge summary, it will regenerate with the new logic.\n"; echo " If your template has demographic tokens ({{PATIENT_NAME}}, {{UHID}}, etc.),\n"; echo " the auto-generated content will NOT include the patient information table.\n"; } else { echo "\nāœ— Failed to clear discharge content\n"; exit(1); } } catch (\Throwable $e) { echo "\nāœ— Error: " . $e->getMessage() . "\n"; exit(1); }