custodian to object, deathdatetime -> deathdate

This commit is contained in:
mahdahar 2025-10-21 09:25:48 +07:00
parent 444195cb20
commit 60cfe5616a
2 changed files with 10 additions and 14 deletions

View File

@ -79,7 +79,7 @@ class CreatePatientRegTables extends Migration {
'Ethnic' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'Ethnic' => ['type' => 'INT', 'constraint' => 11, 'null' => true],
'Citizenship' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'Citizenship' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
'DeathIndicator'=> ['type' => 'INT', 'constraint' => 11, '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], 'LinkTo' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'CreateDate' => ['type' => 'DATETIME', 'null' => true],
'DelDate' => ['type' => 'DATETIME', 'null' => true] 'DelDate' => ['type' => 'DATETIME', 'null' => true]

View File

@ -14,7 +14,7 @@ class PatientModel extends BaseModel {
protected $primaryKey = 'InternalPID'; protected $primaryKey = 'InternalPID';
protected $allowedFields = ['PatientID', 'AlternatePID', 'Prefix', 'NameFirst', 'NameMiddle', 'NameMaiden', 'NameLast', 'Suffix', 'NameAlias', 'Gender', 'Birthdate', 'PlaceOfBirth', 'Street_1', 'Street_2', 'Street_3', 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', '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 $useTimestamps = true;
protected $createdField = 'CreateDate'; protected $createdField = 'CreateDate';
@ -122,8 +122,6 @@ class PatientModel extends BaseModel {
$modelPatIdt = new PatIdtModel(); $modelPatIdt = new PatIdtModel();
$input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo']; $input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo'];
$input['Birthdate'] = $this->isValidDateTime($input['Birthdate']);
$input['DeathDateTime'] = $this->isValidDateTime($input['DeathDateTime']);
$db->transBegin(); $db->transBegin();
@ -169,8 +167,6 @@ class PatientModel extends BaseModel {
$modelPatAtt = new PatAttModel(); $modelPatAtt = new PatAttModel();
$input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo']; $input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo'];
$input['Birthdate'] = $this->isValidDateTime($input['Birthdate']);
$input['DeathDateTime'] = $this->isValidDateTime($input['DeathDateTime']);
$db->transBegin(); $db->transBegin();
@ -219,12 +215,12 @@ class PatientModel extends BaseModel {
} }
private function transformPatientData(array $patient): array { private function transformPatientData(array $patient): array {
$patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"], $patient["DeathDateTime"]); $patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"], $patient["DeathDate"]);
$patient["DeathDateTime"] = $this->formattedDate($patient["DeathDateTime"]); $patient["DeathDate"] = $this->formattedDate($patient["DeathDate"]);
$patient["CreateDate"] = $this->formattedDate($patient["CreateDate"]); $patient["CreateDate"] = $this->formattedDate($patient["CreateDate"]);
$patient["BirthdateConversion"] = $this->formatedDateForDisplay($patient["Birthdate"]); $patient["BirthdateConversion"] = $this->formatedDateForDisplay($patient["Birthdate"]);
$patient["LinkTo"] = $this->getLinkedPatients($patient['LinkTo']); $patient["LinkTo"] = $this->getLinkedPatients($patient['LinkTo']);
$patient["Custodian"] = $this->getCustodian($patient['Custodian']); $patient["Custodian"] = $this->getCustodian($patient['Custodian'][0]);
$patient['PatCom'] = $patient['Comment']; $patient['PatCom'] = $patient['Comment'];
return $patient; return $patient;
@ -249,19 +245,19 @@ class PatientModel extends BaseModel {
return $this->select('InternalPID, PatientID') return $this->select('InternalPID, PatientID')
->where('InternalPID', (int) $custodianId) ->where('InternalPID', (int) $custodianId)
->findAll() ?: null; ->first() ?: null;
} }
// Conversion to (Years Months Days) - For Age // Conversion to (Years Months Days) - For Age
private function calculateAgeFromBirthdate($birthdate, $deathdatetime) { private function calculateAgeFromBirthdate($birthdate, $deathdate) {
$dob = new \DateTime($birthdate); $dob = new \DateTime($birthdate);
// Cek DeathTime // Cek DeathTime
if ($deathdatetime == null) { if ($deathdate == null) {
$today = new \DateTime(); $today = new \DateTime();
} else { } else {
$deathdatetime = new \DateTime($deathdatetime); $deathdate = new \DateTime($deathdate);
$today = $deathdatetime; $today = $deathdate;
} }
$diff = $today->diff($dob); $diff = $today->diff($dob);