Update Patient Tabel Migrations Birthdate menjadi DATE dan Patcom menjadi null dan bukan []

This commit is contained in:
mikael-zakaria 2025-10-06 09:47:15 +07:00
parent 082e5d4d1c
commit f24c72cb16
2 changed files with 7 additions and 9 deletions

View File

@ -59,7 +59,7 @@ class CreatePatientRegTables extends Migration {
'NameAlias' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
'Gender' => ['type' => 'INT', 'constraint' => 11, 'null' => true],
'PlaceOfBirth' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
'Birthdate' => ['type' => 'DATETIME', 'null' => true],
'Birthdate' => ['type' => 'DATE', 'null' => true],
'Street_1' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
'Street_2' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
'Street_3' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],

View File

@ -78,16 +78,16 @@ class PatientModel extends Model {
if (empty($rows)) { return null; }
$patient = $rows[0];
if (method_exists($this, 'transformPatientData')) { $patient = $this->transformPatientData($patient); }
unset($patient['Address']);
unset($patient['IdentifierType']);
unset($patient['Identifier']);
unset($patient['Comment']);
if (method_exists($this, 'transformPatientData')) { $patient = $this->transformPatientData($patient); }
// Default nested structures
$patient['PatIdt'] = null;
$patient['PatAtt'] = [];
$patient['PatCom'] = [];
foreach ($rows as $row) {
if ($row['IdentifierType'] && $row['Identifier'] && !$patient['PatIdt']) {
@ -97,10 +97,6 @@ class PatientModel extends Model {
];
}
if ($row['Comment']) {
$patient['PatCom'] = $row['Comment'];
}
if ($row['Address']) {
$patient['PatAtt'][] = ['Address' => $row['Address']];
}
@ -116,7 +112,7 @@ class PatientModel extends Model {
$db = \Config\Database::connect();
$patidt = $input['PatIdt'] ?? [];
$patatt = $input['PatAtt'] ?? [];
$patcom['Comment'] = $input['PatCom'] ?? [];
$patcom['Comment'] = $input['PatCom'] ?? null;
$input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo'];
$input['Birthdate'] = $this->isValidDateTime($input['Birthdate']);
$input['DeathDateTime'] = $this->isValidDateTime($input['DeathDateTime']);
@ -164,7 +160,7 @@ class PatientModel extends Model {
$db = \Config\Database::connect();
$patidt = $input['PatIdt'] ?? [];
$patatt = $input['PatAtt'] ?? [];
$patcom['Comment'] = $input['PatCom'] ?? [];
$patcom['Comment'] = $input['PatCom'] ?? null;
$input['LinkTo'] = empty($input['LinkTo']) ? null : $input['LinkTo'];
$input['Birthdate'] = $this->isValidDateTime($input['Birthdate']);
$input['DeathDateTime'] = $this->isValidDateTime($input['DeathDateTime']);
@ -195,6 +191,7 @@ class PatientModel extends Model {
$exists = $db->table('patcom')->where('InternalPID', $InternalPID)->get()->getRowArray();
if ($exists) {
$db->table('patcom')->where('InternalPID', $InternalPID)->update($patcom);
$this->checkDbError($db, 'Update patcom');
} else {
$patcom['InternalPID'] = $InternalPID;
$db->table('patcom')->insert($patcom);
@ -290,6 +287,7 @@ class PatientModel extends Model {
$patient["BirthdateConversion"] = $this->formatedDateForDisplay($patient["Birthdate"]);
$patient["LinkTo"] = $this->getLinkedPatients($patient['LinkTo']);
$patient["Custodian"] = $this->getCustodian($patient['Custodian']);
$patient['PatCom'] = $patient['Comment'];
return $patient;
}