-- Hasta belgeleri/onam arşivi tablosu
CREATE TABLE IF NOT EXISTS patient_documents (
  id INT AUTO_INCREMENT PRIMARY KEY,
  patient_id INT NOT NULL,
  file_name VARCHAR(255) NOT NULL COMMENT 'Sistemde saklanan dosya adı',
  original_name VARCHAR(255) NOT NULL COMMENT 'Orijinal dosya adı',
  file_type VARCHAR(50) COMMENT 'MIME type (application/pdf, image/jpeg, etc.)',
  file_size INT COMMENT 'Dosya boyutu (bytes)',
  document_type VARCHAR(100) COMMENT 'Belge türü (Onam Formu, Tetkik Sonucu, Rapor, vb.)',
  notes TEXT COMMENT 'Belge hakkında notlar',
  uploaded_by INT COMMENT 'Yükleyen kullanıcı ID',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (patient_id) REFERENCES patients(id) ON DELETE CASCADE,
  FOREIGN KEY (uploaded_by) REFERENCES users(id) ON DELETE SET NULL,
  INDEX idx_patient_id (patient_id),
  INDEX idx_document_type (document_type),
  INDEX idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
