diff --git a/app/Database/Migrations/2025-09-02-070826_Patient_Reg.php b/app/Database/Migrations/2025-09-02-070826_Patient_Reg.php index 7f9c53b..1d50415 100644 --- a/app/Database/Migrations/2025-09-02-070826_Patient_Reg.php +++ b/app/Database/Migrations/2025-09-02-070826_Patient_Reg.php @@ -79,7 +79,7 @@ class CreatePatientRegTables extends Migration { 'Ethnic' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'Citizenship' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'DeathIndicator'=> ['type' => 'INT', 'constraint' => 11, 'null' => true], - 'DeathDateTime' => ['type' => 'DATETIME', 'null' => true], + 'DeathDate' => ['type' => 'DATETIME', 'null' => true], 'LinkTo' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true] diff --git a/app/Models/Patient/PatientModel.php b/app/Models/Patient/PatientModel.php index 44a2ebc..491877b 100644 --- a/app/Models/Patient/PatientModel.php +++ b/app/Models/Patient/PatientModel.php @@ -14,7 +14,7 @@ class PatientModel extends BaseModel { protected $primaryKey = 'InternalPID'; protected $allowedFields = ['PatientID', 'AlternatePID', 'Prefix', 'NameFirst', 'NameMiddle', 'NameMaiden', 'NameLast', 'Suffix', 'NameAlias', 'Gender', 'Birthdate', 'PlaceOfBirth', 'Street_1', 'Street_2', 'Street_3', 'City', 'Province', 'ZIP', 'EmailAddress1', 'EmailAddress2', 'Phone', 'MobilePhone', 'Custodian', 'AccountNumber', 'Country', 'Race', 'MaritalStatus', 'Religion', 'Ethnic', 'Citizenship', - 'DeathIndicator', 'DeathDateTime', 'LinkTo', 'CreateDate', 'DelDate' ]; + 'DeathIndicator', 'DeathDate', 'LinkTo', 'CreateDate', 'DelDate' ]; protected $useTimestamps = true; protected $createdField = 'CreateDate'; @@ -122,8 +122,6 @@ class PatientModel extends BaseModel { $modelPatIdt = new PatIdtModel(); $input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo']; - $input['Birthdate'] = $this->isValidDateTime($input['Birthdate']); - $input['DeathDateTime'] = $this->isValidDateTime($input['DeathDateTime']); $db->transBegin(); @@ -169,8 +167,6 @@ class PatientModel extends BaseModel { $modelPatAtt = new PatAttModel(); $input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo']; - $input['Birthdate'] = $this->isValidDateTime($input['Birthdate']); - $input['DeathDateTime'] = $this->isValidDateTime($input['DeathDateTime']); $db->transBegin(); @@ -219,12 +215,12 @@ class PatientModel extends BaseModel { } private function transformPatientData(array $patient): array { - $patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"], $patient["DeathDateTime"]); - $patient["DeathDateTime"] = $this->formattedDate($patient["DeathDateTime"]); + $patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"], $patient["DeathDate"]); + $patient["DeathDate"] = $this->formattedDate($patient["DeathDate"]); $patient["CreateDate"] = $this->formattedDate($patient["CreateDate"]); $patient["BirthdateConversion"] = $this->formatedDateForDisplay($patient["Birthdate"]); $patient["LinkTo"] = $this->getLinkedPatients($patient['LinkTo']); - $patient["Custodian"] = $this->getCustodian($patient['Custodian']); + $patient["Custodian"] = $this->getCustodian($patient['Custodian'][0]); $patient['PatCom'] = $patient['Comment']; return $patient; @@ -249,19 +245,19 @@ class PatientModel extends BaseModel { return $this->select('InternalPID, PatientID') ->where('InternalPID', (int) $custodianId) - ->findAll() ?: null; + ->first() ?: null; } // Conversion to (Years Months Days) - For Age - private function calculateAgeFromBirthdate($birthdate, $deathdatetime) { + private function calculateAgeFromBirthdate($birthdate, $deathdate) { $dob = new \DateTime($birthdate); // Cek DeathTime - if ($deathdatetime == null) { + if ($deathdate == null) { $today = new \DateTime(); } else { - $deathdatetime = new \DateTime($deathdatetime); - $today = $deathdatetime; + $deathdate = new \DateTime($deathdate); + $today = $deathdate; } $diff = $today->diff($dob);