From 98a69c245f1de6801398fcc89ee935223bc18f6d Mon Sep 17 00:00:00 2001 From: mikael-zakaria Date: Mon, 11 Aug 2025 16:14:26 +0700 Subject: [PATCH] Update Patient create, perbaikan Birthdate dan Age --- app/Controllers/Patient.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index 9099f1d..121110b 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -81,6 +81,9 @@ class Patient extends Controller { } else { + $patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"]); + $patient["Birthdate"] = date("d-m-Y", strtotime($patient["Birthdate"])); + if ($patient['LinkTo'] != null) { $ids = explode(',', $patient['LinkTo']); // dari string jadi array @@ -390,4 +393,13 @@ class Patient extends Controller { } } + private function calculateAgeFromBirthdate($birthdate) { + $dob = new DateTime($birthdate); + $today = new DateTime(); + $diff = $today->diff($dob); + + $formattedAge = "{$diff->y} years {$diff->m} months {$diff->d} days"; + return $formattedAge; + } + } \ No newline at end of file