diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index 3b38804..a81a08c 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -182,6 +182,12 @@ class Patient extends Controller { $this->db->table('patient')->insert($dataPatient); $newInternalPatientId = $this->db->insertID(); + $dbError = $this->db->error(); + if (!empty($dbError['message'])) { + $this->db->transRollback(); + return $this->failServerError('Insert patient failed: ' . $dbError['message']); + } + $dataPatidt['InternalPID'] = $newInternalPatientId; $this->db->table('patidt')->insert($dataPatidt); @@ -190,8 +196,7 @@ class Patient extends Controller { if ($this->db->transStatus() === false) { $dbError = $this->db->error(); // ambil error terakhir return $this->failServerError( - 'Failed to create patient data (transaction rolled back): ' . - ($dbError['message'] ?? 'Unknown database error') + 'Failed to create patient data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error') ); }