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