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 32d3530..2d71618 100644 --- a/app/Database/Migrations/2025-09-02-070826_Patient_Reg.php +++ b/app/Database/Migrations/2025-09-02-070826_Patient_Reg.php @@ -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], diff --git a/app/Models/PatientModel.php b/app/Models/PatientModel.php index 4a00e5c..44b3517 100644 --- a/app/Models/PatientModel.php +++ b/app/Models/PatientModel.php @@ -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; }