add patient comment to show/update/create, adding unique key internalPID to patcom

This commit is contained in:
mahdahar 2025-09-04 11:05:13 +07:00
parent 56d5d98288
commit 91e8d1556c
2 changed files with 21 additions and 5 deletions

View File

@ -10,6 +10,7 @@ class Patient extends Controller {
public function __construct() {
$this->db = \Config\Database::connect();
$this->now = date('Y-m-d H:i:s');
}
// OK - Done
@ -62,12 +63,13 @@ class Patient extends Controller {
try {
$patient = $this->db->table('patient')
->select('patient.*, country.Country as CountryName, race.Race as RaceName, religion.Religion as ReligionName, ethnic.Ethnic as EthnicName')
->select('patient.*, country.Country as CountryName, race.Race as RaceName, religion.Religion as ReligionName, ethnic.Ethnic as EthnicName, patcom.Comment as Comment')
->join('country', 'country.IntCountryID = patient.IntCountryID', 'left')
->join('race', 'race.RaceID = patient.RaceID', 'left')
->join('religion', 'religion.ReligionID = patient.ReligionID', 'left')
->join('ethnic', 'ethnic.EthnicID = patient.EthnicID', 'left')
->where('InternalPID', (int) $InternalPID)
->join('patcom', 'patcom.InternalPID = patient.InternalPID', 'left')
->where('patient.InternalPID', (int) $InternalPID)
->get()
->getRowArray();
@ -141,7 +143,6 @@ class Patient extends Controller {
}
// OK - Done
public function create() {
try {
$input = $this->request->getJSON(true);
@ -260,6 +261,8 @@ class Patient extends Controller {
'Address' => 'required|is_unique[patatt.Address]',
];
$dataPatcom = [ "Comment" => $input['Comment'] === '' ? null : ($input['Comment'] ?? null) ];
// =========================
// Validasi semua sebelum insert
// =========================
@ -297,6 +300,12 @@ class Patient extends Controller {
$this->db->table('patatt')->insertBatch($dataPatatt);
}
if($dataPatcom['Comment'] != '') {
$dataPatcom['InternalPID'] = $newInternalPatientId;
$dataPatcom['CreateDate'] = $now;
$this->db->table('patcom')->insert($dataPatcom);
}
$dbError = $this->db->error();
if (!empty($dbError['message'])) {
$this->db->transRollback();
@ -444,6 +453,13 @@ class Patient extends Controller {
'Identifier' => "required|is_unique[patidt.Identifier,InternalPID,{$InternalPID}]"
];
$dataPatcom = [ "Comment" => $input['Comment'] === '' ? null : ($input['Comment'] ?? null) ];
if($dataPatcom['Comment'] != '') {
$dataPatcom['InternalPID'] = $InternalPID;
$dataPatcom['CreateDate'] = $this->now;
$this->db->table('patcom')->upsert($dataPatcom);
}
// Validasi
if (!$this->validateData($dataPatient, $rulesDataPatient)) {
return $this->respond([

View File

@ -54,6 +54,7 @@ class CreateInitialTables extends Migration {
'EndDate' => ['type' => 'DATETIME', 'null' => true],
]);
$this->forge->addKey('PatComID', true);
$this->forge->addUniqueKey('InternalPID', true);
$this->forge->createTable('patcom');
// patdiag
@ -249,8 +250,7 @@ class CreateInitialTables extends Migration {
$this->forge->createTable('religion');
}
public function down()
{
public function down() {
$this->forge->dropTable('country', true);
$this->forge->dropTable('ethnic', true);
$this->forge->dropTable('patatt', true);