Update Patient
This commit is contained in:
parent
97350a1f18
commit
6111c63cf4
@ -82,30 +82,11 @@ class Patient extends Controller {
|
||||
} else {
|
||||
|
||||
$patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"]);
|
||||
|
||||
$Birthdate = \DateTime::createFromFormat('Y-m-d H:i', $patient["Birthdate"]);
|
||||
if ($Birthdate) {
|
||||
$patient["Birthdate"] = $Birthdate->format('Y-m-d H:i'); // Format database
|
||||
$patient["BirthdateConversion"] = $Birthdate->format('j M Y'); // Format tampilan
|
||||
} else {
|
||||
$patient["Birthdate"] = null;
|
||||
$patient["BirthdateConversion"] = null;
|
||||
}
|
||||
|
||||
$CreateDate = \DateTime::createFromFormat('Y-m-d H:i', $patient["CreateDate"]);
|
||||
if ($CreateDate) {
|
||||
$patient["CreateDate"] = $CreateDate->format('Y-m-d H:i');
|
||||
} else {
|
||||
$patient["CreateDate"] = null;
|
||||
}
|
||||
|
||||
// $DisableDate = \DateTime::createFromFormat('Y-m-d H:i', $patient["CreateDate"]);
|
||||
// if ($CreateDate) {
|
||||
// $patient["CreateDate"] = $CreateDate->format('Y-m-d H:i');
|
||||
// } else {
|
||||
// $patient["CreateDate"] = null;
|
||||
// }
|
||||
|
||||
$patient["Birthdate"] = $this->formatDateForDB($patient["Birthdate"]);
|
||||
$patient["DeathDateTime"] = $this->formatDateForDB($patient["DeathDateTime"]);
|
||||
$patient["BirthdateConversion"] = $this->formatDateForDisplay($patient["Birthdate"]);
|
||||
|
||||
if ($patient['LinkTo'] != null) {
|
||||
|
||||
$ids = explode(',', $patient['LinkTo']); // dari string jadi array
|
||||
@ -558,16 +539,49 @@ class Patient extends Controller {
|
||||
|
||||
$formattedAge = "";
|
||||
if ($diff->y > 0){
|
||||
$formattedAge .= "{$diff->y} Tahun ";
|
||||
$formattedAge .= "{$diff->y} Years ";
|
||||
}
|
||||
if ($diff->m > 0){
|
||||
$formattedAge .= "{$diff->m} Bulan ";
|
||||
$formattedAge .= "{$diff->m} Months ";
|
||||
}
|
||||
if ($diff->d > 0){
|
||||
$formattedAge .= "{$diff->d} Hari";
|
||||
$formattedAge .= "{$diff->d} Days";
|
||||
}
|
||||
|
||||
return $formattedAge;
|
||||
}
|
||||
|
||||
private function formatDateForDB($dateString) {
|
||||
// Ubah ke format Y-m-d H:i
|
||||
$date = \DateTime::createFromFormat('Y-m-d H:i', $dateString);
|
||||
|
||||
// Kalau gagal, coba parse bebas
|
||||
if (!$date) {
|
||||
$timestamp = strtotime($dateString);
|
||||
if ($timestamp) {
|
||||
return date('Y-m-d H:i', $timestamp);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return $date->format('Y-m-d H:i');
|
||||
}
|
||||
|
||||
private function formatDateForDisplay($dateString) {
|
||||
// Ubah ke format j M Y
|
||||
$date = \DateTime::createFromFormat('Y-m-d H:i', $dateString);
|
||||
|
||||
// Kalau gagal, coba parse bebas
|
||||
if (!$date) {
|
||||
$timestamp = strtotime($dateString);
|
||||
if ($timestamp) {
|
||||
return date('j M Y', $timestamp);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return $date->format('j M Y');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user